Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - PS WMI problem remotely

Reply
 
Old 03-14-2008   #1 (permalink)
Thomas Makro


 
 

PS WMI problem remotely

Hi everybody.

The PS script located at
<http://thepowershellguy.com/blogs/po.../01/29/nested-
relative-wmi-queries-in-powershell.aspx>
....works fine locally. However, when I replace the dot with the name
of a remote computer, I get this error:

An error occurred while enumerating through a collection: Not
supported .
At C:\Usenet.ps1:23 char:2
+ $ <<<< s.get()|% {

How can I solve this?


Regards, Thomas

My System SpecsSystem Spec
Old 03-14-2008   #2 (permalink)
Marco Shaw [MVP]


 
 

Re: PS WMI problem remotely

Thomas Makro wrote:
Quote:

> Hi everybody.
>
> The PS script located at
> <http://thepowershellguy.com/blogs/po.../01/29/nested-
> relative-wmi-queries-in-powershell.aspx>
> ...works fine locally. However, when I replace the dot with the name
> of a remote computer, I get this error:
>
> An error occurred while enumerating through a collection: Not
> supported .
> At C:\Usenet.ps1:23 char:2
> + $ <<<< s.get()|% {
>
> How can I solve this?
I've confirmed this using the v2 CTP and quering a remote Vista SP1 box.
I've just emailed /\/\o\/\/ about this issue...

Marco
My System SpecsSystem Spec
Old 03-15-2008   #3 (permalink)
RichS


 
 

Re: PS WMI problem remotely

My first questions would be:

1) does the $drives variable get populated against the remote machine

2) How does $s and $s2 know they are working againsta a remote machine. Is
it implicit in the objects or do they have to be told?

--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Marco Shaw [MVP]" wrote:
Quote:

> Thomas Makro wrote:
Quote:

> > Hi everybody.
> >
> > The PS script located at
> > <http://thepowershellguy.com/blogs/po.../01/29/nested-
> > relative-wmi-queries-in-powershell.aspx>
> > ...works fine locally. However, when I replace the dot with the name
> > of a remote computer, I get this error:
> >
> > An error occurred while enumerating through a collection: Not
> > supported .
> > At C:\Usenet.ps1:23 char:2
> > + $ <<<< s.get()|% {
> >
> > How can I solve this?
>
> I've confirmed this using the v2 CTP and quering a remote Vista SP1 box.
> I've just emailed /\/\o\/\/ about this issue...
>
> Marco
>
My System SpecsSystem Spec
Old 03-18-2008   #4 (permalink)
thomasmakro


 
 

Re: PS WMI problem remotely

On 15 Mar, 12:26, RichS <Ri...@xxxxxx> wrote:
Quote:

> My first questions would be:
>
> 1) does the $drives variable get populated against the remote machine
Interesting point. Using the Variable Inspector in PowerShellPlus's
Code Editor, I see that $drives refer to the remote computer. This is
as expected.
And so does $qPartition's property "SourceObject".
However, both the $s and $s2, refer to the localhost (\\.\root\cimv2).
I'm not sure how the System.Management.ManagementObjectSearcher works,
but this looks suspicious.
Quote:

> 2) How does $s and $s2 know they are working againsta a remote machine. Is
> it implicit in the objects or do they have to be told?
Seems they have to be told, but how?


Best regards, Thomas
My System SpecsSystem Spec
Old 03-18-2008   #5 (permalink)
Marco Shaw [MVP]


 
 

Re: PS WMI problem remotely

Marco Shaw [MVP] wrote:
Quote:

> Thomas Makro wrote:
Quote:

>> Hi everybody.
>>
>> The PS script located at
>> <http://thepowershellguy.com/blogs/po.../01/29/nested-
>> relative-wmi-queries-in-powershell.aspx>
>> ...works fine locally. However, when I replace the dot with the name
>> of a remote computer, I get this error:
>>
>> An error occurred while enumerating through a collection: Not
>> supported .
>> At C:\Usenet.ps1:23 char:2
>> + $ <<<< s.get()|% {
>>
>> How can I solve this?
>
> I've confirmed this using the v2 CTP and quering a remote Vista SP1 box.
> I've just emailed /\/\o\/\/ about this issue...
>
> Marco
I've not heard back and haven't had the time to see if there was
anything I could do to understand the issue/problem.

Marco
My System SpecsSystem Spec
Old 03-18-2008   #6 (permalink)
Shay Levi


 
 

Re: PS WMI problem remotely


Set the Scope member for each ManagementObjectSearcher object:

$s = New-Object System.Management.ManagementObjectSearcher
$s.Scope = "\\$computer\root\cimv2"
$s2 = New-Object System.Management.ManagementObjectSearcher
$s2.Scope = "\\$computer\root\cimv2"

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> On 15 Mar, 12:26, RichS <Ri...@xxxxxx> wrote:
>
Quote:

>> My first questions would be:
>>
>> 1) does the $drives variable get populated against the remote machine
>>
> Interesting point. Using the Variable Inspector in PowerShellPlus's
> Code Editor, I see that $drives refer to the remote computer. This is
> as expected.
> And so does $qPartition's property "SourceObject".
> However, both the $s and $s2, refer to the localhost (\\.\root\cimv2).
> I'm not sure how the System.Management.ManagementObjectSearcher works,
> but this looks suspicious.
Quote:

>> 2) How does $s and $s2 know they are working againsta a remote
>> machine. Is it implicit in the objects or do they have to be told?
>>
> Seems they have to be told, but how?
>
> Best regards, Thomas
>

My System SpecsSystem Spec
Old 03-19-2008   #7 (permalink)
Thomas Makro


 
 

Re: PS WMI problem remotely

On Mar 18, 9:47 pm, Shay Levi <n...@xxxxxx> wrote:
Quote:

> $s = New-Object System.Management.ManagementObjectSearcher
> $s.Scope = "\\$computer\root\cimv2"
> $s2 = New-Object System.Management.ManagementObjectSearcher
> $s2.Scope = "\\$computer\root\cimv2"
This was the missing part. Works perfectly now. Thanks Shay.

Now, when everything works, in case somebody should be interested,
here's the new version of the script:

$computer = '.'
$drives = Get-WmiObject Win32_DiskDrive -ComputerName $computer

$s = New-Object System.Management.ManagementObjectSearcher
$s.Scope = "\\$computer\root\cimv2"
$s2 = New-Object System.Management.ManagementObjectSearcher
$s2.Scope = "\\$computer\root\cimv2"

$qPartition = new-object System.Management.RelatedObjectQuery
$qPartition.RelationshipClass = 'Win32_DiskDriveToDiskPartition'

$qLogicalDisk = new-object System.Management.RelatedObjectQuery
$qLogicalDisk.RelationshipClass = 'Win32_LogicalDiskToPartition'

$drives |% {
"Physical Disk:" + $_.Caption
$qPartition.SourceObject = $_
$s.Query= $qPartition
$s.get()|% {
" Disk Partition:" + $_.DeviceID
$qLogicalDisk.SourceObject = $_
$s2.query= $qLogicalDisk
$s2.get()|% {
" Logical Disk:" + $_.deviceid
}
}
}


And a few comments:
All disks are enumerated using the above WMI statements, including USB
removable drives. This can be changed by modifying one of the WMI
statements. For the Win32_DiskDrive class, there are a couple of
solutions:
-filter "MediaType='Fixed hard disk media'"
-filter "InterfaceType='IDE'" #and/or SCSI


Best regards, Thomas
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Problem using EnableStatic to remotely set IP address PowerShell
execution policy problem executing remotely with hpc job scheduler PowerShell
problem with running script remotely - ODBC connection - ORACLE DB VB Script
Problem reading registry remotely PowerShell
Can't connect remotely Vista networking & sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46