我在實驗室環境中運行,需要自動化大約50臺機器。我試圖從服務器恢復一個.xml無線網絡配置文件,然後安裝它。該命令從1個服務器發送到50個客戶端。升級到PS3,System.Net.WebClient不能在某些機器上工作
我最近將我的一些客戶重新映像並從PS2升級到PS3,現在我的下載腳本不再工作了。
它在我的PS2工作站上正常工作。我認爲這可能是一個許可的事情,但我不確定。 ThrustedHosts設置爲*並且腳本執行策略設置爲Unrestricted。
這裏有一個片段,並錯誤:
function InstallProfile(){
clear
$fonction =
@'
param($profileName)
$File = "c:\profiles\profile.xml"
$webclient = New-Object System.Net.WebClient
$webclient.Proxy = $NULL
$ftp = "ftp://anonymous:[email protected]/profiles/$profileName"
$uri = New-Object System.Uri($ftp)
Write-Host (hostname)
$webclient.DownloadFile($uri, $File)
write-host (hostname) (netsh wlan add profile filename="c:\profiles\profile.xml")
'@
$profileName = Read-Host "Enter the profile name(XML file must be present in c:\share\profiles\)"
ExecCmd -fonction $fonction -argument $profileName
func_done
}
#
function ExecCmd
{
param(
$fonction,
$argument
)
$PingTest = RetrieveStatus
$results = @{}
$results = $PingTest.up
$results | sort -uniq | out-Null
$fonctionSB = ConvertTo-ScriptBlock($fonction)
foreach($result in $results)
{
$os = "Windows"
try{
$session = New-PSSession -ComputerName $result.address -Credential $credentials -EA stop
}
catch{
$os = "Not Windows"
}
if($os -eq "Windows"){
Invoke-Command $result.address -ScriptBlock $fonctionSB -Arg $argument -Credential $credentials
Get-PSSession | Remove-PSSession
}
else{
Write-Host $result.address "does not support Powershell commands"
}
}
}
和錯誤:
Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request." + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException + PSComputerName : 192.168.2.110