小编boo*_*nds的帖子

"get-wmiobject win32_process -computername"获取错误"访问被拒绝,代码0x80070005"

我正在尝试在3个终端服务器上找到其$ _.命令行属性中包含某些单词的进程.在我的域管理员帐户下,它工作正常.但是我希望这个脚本可以用于域用户,并且doamin用户在运行此脚本时会出错.

我应该怎么做,以便域用户可以像域管理员一样运行此脚本?提前致谢!

错误:

Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESS DENIED))
At N:\FindWhoIsUsing\FindWhoIsUsing.ps1:7 char:18
get-wmiobject <<<<  win32_process -computername $server -EnableAllPrivileges|
CategoryInfo          : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
Run Code Online (Sandbox Code Playgroud)

Powershell代码:

Write-host "Who is using this profile?"
$profile = Read-host "specify profile name" 
$servers = @("server-01","server-02","server-03")
Foreach($server in $servers)
{
    Write-host $server
    get-wmiobject win32_process -computername $server -EnableAllPrivileges|
    where{$_.name -like "*Processname*" -and
    $_.CommandLine -like "*$profile*"}|
    select @{n="Server";e={$server}},@{n="User";e={$_.getowner().user}},@{n="ProcessID";e= {$_.ProcessID}},{$_.CommandLine}|fl
}
Write-host "DONE Searching!"
Run Code Online (Sandbox Code Playgroud)

powershell powershell-remoting

7
推荐指数
1
解决办法
3万
查看次数

标签 统计

powershell ×1

powershell-remoting ×1