小编Tom*_* M.的帖子

如何通过PowerShell获取Windows Service的登录身份帐户

Powershell的新手,我猜这是存在的,但我找不到。我正在寻找一个powershell命令,该命令将向我显示用于运行Windows服务的帐户?我首先要检查它是否正在运行,然后确保使用正确的AD帐户来运行它。到目前为止,我有以下内容...

$serviceName = '<my service name>'

If (Get-Service $serviceName -ErrorAction SilentlyContinue) {

    If ((Get-Service $serviceName).Status -eq 'Running') {
        $status = "$serviceName found and is running."

    } Else {
        $status = "$serviceName found, but it is not running."
    }

    #Here is where I should check Log On As name

} Else {

    $status = "$serviceName not found."
}

write-host "Status: $status`n"

pause
Run Code Online (Sandbox Code Playgroud)

我的大部分搜索都将我带到Get-WmiObject,但没有找到我想要的东西。在此先感谢您的帮助。

powershell

3
推荐指数
2
解决办法
7399
查看次数

标签 统计

powershell ×1