我正在尝试编写应该更改远程服务器的注册表设置(WSUS服务器名称)的脚本。一旦成功脚本应该执行exe和存储在服务器上安装补丁的远程服务器上的VBScript文件。以下是我的进展。
脚本:
#defined variables to use in script as below.##
$Computers = Get-Content "C:\serverlist.txt"
$Path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
$property = "WUServer"
$value = "http://serverFQDN"
$results = foreach ($computer in $Computers) {
if (Test-Connection -ComputerName $computer -Count 1 -Quiet) {
try {
Set-ItemProperty -Path $path -Name $Property -Value $Value -ErrorAction 'Stop'
$status = "WSUS server has been set to http://serverFQDN"
foreach ($computer in $Computers) {
# below step is not getting executed on remote servers. I do not
# get any error but above script do not execute any command on
# remote servers.
foreach ($computer in $computers) {
Invoke-Command -ScriptBlock {
C:\test\Patcher > cscript.exe -nologo test_v1.03.vbs /anlyze:false /reboot:false | Out-Null
}
}
}
} catch {
$status = "Failed"
}
} else {
$status = "Server is not reachable, please check connection and try again"
}
New-Object -TypeName PSObject -Property @{
'Computer' = $computer
'Status' = $status
}
}
$results | Export-Csv -NoTypeInformation -Path "./out.csv"
答案 0 :(得分:0)
这不是有效的语法:
C:\test\Patcher > cscript.exe -nologo test_v1.03.vbs ...
该语句将(尝试)运行位于目录Patcher
中的命令C:\test
,并将其输出重定向到当前工作目录中的文件cscript.exe
。
您可能希望将工作目录更改为C:\test\Patcher
并从该目录运行test_v1.03.vbs
。为此,请将上述行更改为:
Set-Location 'C:\test\Patcher'
& cscript.exe //NoLogo test_v1.03.vbs /anlyze:false /reboot:false | Out-Null