Del*_*son 5 scripting powershell
上周我开发了一个脚本来检查是否在指定的机器上启用了 psremoting。本周我开始编写一个可以在指定机器上启用 psremoting 的脚本,但我无法让 psexec 在 powershell 中运行(另外,是的,我知道可以通过组策略启用 psremoting)。这是我的脚本:
$input = Read-Host @"
Select Option
(1)Manually enter computer(s)
(2)Retrieve computer(s) from file
Option
"@
If ($input -eq 1){
$count = Read-Host "How many computers"
$Computers = 1..$count
$b=0;$c=1; ForEach ($Computer in $Computers) {$Computers[$b] = Read-Host "Computer" $c; $b++; $c++}
} ElseIF ($input-eq 2) {
$Computers = Read-Host "File"
$Computers = Get-Content $Computers
} Else {
write-host "Invalid Option"
Exit
}
cls
$User = Read-Host "Enter username"
$Pass = Read-Host "Enter password"
cls
$PSExec = "C:\Windows\System32\PSExec\PSExec.exe"
ForEach ($Computer in $Computers){
# & $PSExec \\$Computer -u $User -p $Pass -h -c "C:\Temp\mybat.bat"
& $PSExec \\$Computer -u $User -p $Pass "ipconfig"
}
Run Code Online (Sandbox Code Playgroud)
执行脚本时出现以下错误:
PSExec.exe : At C:\MyStuff\EnablePSRemoting.ps1:34 char:1 + & $PSExec $Computer -u $User -p $Pass "ipconfig" + ~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:String) [], RemoteException +fullyQualifiedErrorId :本地命令错误
PsExec v2.11 - 远程执行进程 版权所有 (C) 2001-2014 Mark Russinovich Sysinternals - www.sysinternals.com 系统找不到指定的文件。
然后我尝试直接从 powershell 简单地运行 PSExec,但仍然没有运气。
Start-Process -Filepath "$PSExec" -ArgumentList "\\$computer -u $user -p $pass $command"
正是我需要它做的事情。
归档时间: |
|
查看次数: |
19976 次 |
最近记录: |