如何使用 Powershell 列出服务器中使用服务帐户运行的所有服务

发布于 2024-12-03 13:23:01 字数 154 浏览 0 评论 0原文

我想使用 powershell 更新多台服务器上一个帐户下运行的所有服务的密码。我尝试了 Get-process、Get-WMIObject cmdlet,但这两个命令没有 serviceaccount 使用。有没有办法通过将服务帐户、密码作为参数传递给脚本来更新使用帐户运行的所有服务的密码。

I want to update the password of all the services running under one account on multiple servers using powershell. i tried Get-process, Get-WMIObject cmdlets, but these two commands don't have serviceaccount usage. is there a way to update password of all the services running with an account by passing service account,password as parameters to the script.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寻找一个思念的角度 2024-12-10 13:23:01

要使用特定帐户获取服务列表,您可以执行以下操作:

Get-WmiObject "win32_service" -Filter "StartName='domain\\user'"

要更改这些服务的密码,您可以执行以下操作:

Get-WmiObject "win32_service" -Filter "StartName='domain\\user'" | 
%{$_.StopService();$_.Change($null,$null,$null,$null,$null,$null,$null,"blah");}

从此处: http://www.send4help.net/change-remote-windows-service-credentials-password-powershel-495

To get list of services using a particular account you can do:

Get-WmiObject "win32_service" -Filter "StartName='domain\\user'"

To change the password for these, you can do:

Get-WmiObject "win32_service" -Filter "StartName='domain\\user'" | 
%{$_.StopService();$_.Change($null,$null,$null,$null,$null,$null,$null,"blah");}

From here: http://www.send4help.net/change-remote-windows-service-credentials-password-powershel-495

你不是我要的菜∠ 2024-12-10 13:23:01

试试这个:

Function GLOBAL:GET-PROCESSUSER ( $ProcessID ) {

    (GET-WMIOBJECT win32_process  –filter “Handle=$ProcessID”).GetOwner().User

}

$svcs = Get-Process | Select-Object name, starttime, ID

$a = @()


foreach ($svc in $svcs)
{ 
           if ( $svc.name -ne "Idle" -and $svc.name -ne "System")
           {           


           $al = New-Object System.Object
           $al | Add-Member -type NoteProperty -name Name -Value $svc.name
           $al | Add-Member -type NoteProperty -name Owner -Value ( get-processuser $svc.id)

           $a += $al
           } 
}

$a

评论后编辑:

$a = (GET-WMIOBJECT win32_service) | ? { $_.startname -eq "domain\\username"} | %{$_.StopService();$_.Change($null,$null,$null,$null,$null,$null,$null,"newpassword");}

try this:

Function GLOBAL:GET-PROCESSUSER ( $ProcessID ) {

    (GET-WMIOBJECT win32_process  –filter “Handle=$ProcessID”).GetOwner().User

}

$svcs = Get-Process | Select-Object name, starttime, ID

$a = @()


foreach ($svc in $svcs)
{ 
           if ( $svc.name -ne "Idle" -and $svc.name -ne "System")
           {           


           $al = New-Object System.Object
           $al | Add-Member -type NoteProperty -name Name -Value $svc.name
           $al | Add-Member -type NoteProperty -name Owner -Value ( get-processuser $svc.id)

           $a += $al
           } 
}

$a

Edit after comment:

$a = (GET-WMIOBJECT win32_service) | ? { $_.startname -eq "domain\\username"} | %{$_.StopService();$_.Change($null,$null,$null,$null,$null,$null,$null,"newpassword");}
谎言 2024-12-10 13:23:01

这就是你们所需要的

Get-WMIObject Win32_Service | Where-Object {$_.startname -ne "localSystem" }| Where-Object {$_.startname -ne "NT AUTHORITY\LocalService" } |Where-Object {$_.startname -ne "NT AUTHORITY\NetworkService" } |select startname, name 

This is what you guys need

Get-WMIObject Win32_Service | Where-Object {$_.startname -ne "localSystem" }| Where-Object {$_.startname -ne "NT AUTHORITY\LocalService" } |Where-Object {$_.startname -ne "NT AUTHORITY\NetworkService" } |select startname, name 
为你鎻心 2024-12-10 13:23:01

是的 - 这似乎是最好的方法

Get-WMIObject Win32_Service | Where-Object {($_.startname -ne "NT AUTHORITY\LocalService") -and ($_.startname -ne "NT AUTHORITY\NetworkService") -and ($_.startname -ne "localSystem") } `
|select @{ Name = "Service Account " ; Expression = { ( $_.startname ) } }, `
@{ Name = "Service Dispaly Name " ; Expression = { ( $_.name ) } }, StartMode,State, Status | FT -AutoSize

Yeah - this seems to be the best approach

Get-WMIObject Win32_Service | Where-Object {($_.startname -ne "NT AUTHORITY\LocalService") -and ($_.startname -ne "NT AUTHORITY\NetworkService") -and ($_.startname -ne "localSystem") } `
|select @{ Name = "Service Account " ; Expression = { ( $_.startname ) } }, `
@{ Name = "Service Dispaly Name " ; Expression = { ( $_.name ) } }, StartMode,State, Status | FT -AutoSize
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文