0
votes

I am trying to automate the retrieval of OS architecture and when I do I get an Invalid Namespace error.

    foreach($i in $hosts){

         $ip = $i.name
         Get-WmiObject -ComputerName $ip Win32_OperatingSystem

    }

If I take Get-WmiObject -ComputerName $ip Win32_OperatingSystem and replace $ip with a legit IP it works perfectly. I even added Write-Host to the front of Get-WMIObject so it would display the entire command that would run. I ran the output from Write-Host and the command completes successfully.

Error: Get-WmiObject : Invalid namespace At line:4 char:18 + Get-WmiObject <<<< -ComputerName $ip Win32_OperatingSystem + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

The $hosts variable is a PSCustomObject with two noteProperty fields. The first is name and the second is user. The name field holds an IP address of the system.

1
What's the content of $hosts, and where is it coming from?Adi Inbar
The $hosts file is a PSCustomObject with two noteProperty fields. The first is name and the second is user. The name field holds an IP address of the system.jgrant

1 Answers

1
votes

It turns out there were trailing whitespaces after the IPs. I used .trim() and now everything works just fine.