Reputation: 515
This script works perfectly until I put in $Server
as the computer name instead of the actual computer name. Please advise. The error I get is 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
Upvotes: 0
Views: 536
Reputation: 32170
The colon is the scope operator in PowerShell. Your script is looking for a variable $server:1055
, meaning it's looking for $1055
in the scope or namespace of server
.
Try:
"http://$server`:1055/sinfo?gr=1"
Or:
"http://$($server):1055/sinfo?gr=1"
Or:
"http://${server}:1055/sinfo?gr=1"
Upvotes: 1