此腳本完美工作,直到我把$Server
作爲計算機名稱,而不是實際的計算機名稱。請指教。我得到的錯誤是ERROR: Exception calling "DownloadFile" with "2" argument(s): "URI formats are not supported."
腳本工作正常,直到我使用變量爲服務器名稱
$Servers = Get-Content -Path C:\temp\servers.txt
foreach ($Server in $Servers)
{
$web = New-Object System.Net.WebClient
$web.DownloadFile("http://$server:1055/sinfo?gr=1","c:\temp\Test.xml")
[xml] $xdoc = Get-Content c:\Temp\test.xml
$properties = @{
Serialnumber = $xdoc.sinfo.systeminfo.bios.SerialNumber;
Model = $xdoc.sinfo.systeminfo.sys.Model;
Manufacturer = $xdoc.sinfo.systeminfo.sys.Manufacturer;
ComputerName = $xdoc.sinfo.systeminfo.sys.Name;
Domain = $xdoc.sinfo.systeminfo.sys.Domain;
}
}
$obj = new-object psobject -property $properties
$obj | Select-Object model, manufacturer, ComputerName, domain, SerialNumber | export-csv c:\temp\results.csv -NoTypeInformation -Append
有沒有在這些線路的任何空白?也許使用'$($ server.Trim())'代替'$ server'。你是否單獨查看了「http:// $ server:1055/sinfo?gr = 1」的輸出,而不是「DownloadFile」的一部分? – Matt 2014-10-28 17:37:42
如果你這樣做,那麼每次循環運行時,properties變量都會被覆蓋,因此$ obj將只包含最後一個服務器的結果 – Paul 2014-10-28 17:40:28
@Matt我已經看過這個文件,它是xml格式。我試過修剪,並且一放入$服務器變量,仍然得到「URI格式不受支持」 – NobleMan 2014-10-28 18:02:04