嗨,我是刚接触电源shell,我似乎不能让这个脚本运行它是在工作组中的计算机上使用命令提示符远程执行命令这里是错误我得到的脚本是在我正在运行在win 7机器上的脚本,我要远程执行的机器是windows xp sp3防火墙关闭,com设置默认设置为身份验证设置并识别模拟和帮助会很棒
这是错误 Invoke-WmiMethod:访问被拒绝。 (HRESULT异常:0x80070005(E_ACCESSDENIED)) 在C:\ Users \ Kevin \ Documents \ WindowsPowerShell \ Microsoft.PowerShell_profile.ps1:57 char:40 + $ newproc = Invoke-WmiMethod<<<< -class Win32_process -name创建` + CategoryInfo:NotSpecified:(:) [Invoke-WmiMethod],UnauthorizedAccessException + FullyQualifiedErrorId:System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.InvokeWmiMethod
$command = Read-Host " Enter command to run"
$user = "\Administrator"
$Domainname = $HostName +$user
$login = Get-Credential $domainname
[string]$cmd = "CMD.EXE /C " +$command
}
process {
$newproc = Invoke-WmiMethod -class Win32_process -name Create `
-ArgumentList ($cmd) -EnableAllPrivileges -ComputerName $HostName -authentication Packetprivacy -Impersonation 3 -Credential $login
if ($newproc.ReturnValue -eq 0 )
{ Write-host -foregroundcolor Green "Command $($command) Ran Sucessfully on $($HostName)"}
答案 0 :(得分:1)
我认为这是因为Get-Credential不会将密码传递给Invoke-WmiMethod的-credential。我通过使用“convertto-securestring”
创建凭证密码来做到这一点我知道它不像你必须以纯文本形式输入密码一样安全,但是如果你是唯一一个使用脚本进行维护的人,那就没什么大不了的。
试试这个:
$command = Read-Host " Enter command to run"
$pass = ConvertTo-SecureString "yourpassword" -Force -AsPlainText
$Domainname = 'Domain'
$user = '\administrator'
$login = $Domainname + $user
$cred = (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $login, $pass)
[string]$cmd = "CMD.EXE /C " +$command
}
process {
$newproc = Invoke-WmiMethod -class Win32_process -name Create `
-ArgumentList ($cmd) -EnableAllPrivileges -ComputerName $HostName -authentication Packetprivacy -Impersonation 3 -Credential $cred
if ($newproc.ReturnValue -eq 0 )
{ Write-host -foregroundcolor Green "Command $($command) Ran Sucessfully