2012-04-28 99 views
0

嗨,我是新來的電源外殼,我不能似乎得到這個腳本來運行它是使用命令提示符在這裏工作組中的計算機上遠程執行命令的錯誤我得到的腳本如下我是Win 7的機器上運行的腳本,我想遠程執行對機器的Windows XP SP3防火牆被關閉和COM設置爲默認的身份驗證設置設置並確定冒充和幫助將是巨大的PowerShell的錯誤WMI

這裏是錯誤 Invoke-WmiMethod:訪問被拒絕。 (從HRESULT異常:0X80070005(E_ACCESSDENIED)) 在C:\用戶\凱文\文件\ WindowsPowerShell \ Microsoft.PowerShell_profile.ps1:57字符:40 + $的NewProc =調用-WmiMethod < < < < -class Win32_Process的-name創建` + CategoryInfo:NotSpecified:(:) [調用-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)"} 

回答

1

我想這是因爲GET-憑據贏得」將密碼傳遞給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