Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

PS WMI problem remotely

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-14-2008   #1 (permalink)
Thomas Makro
Guest


 

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]
Guest


 

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
Guest


 

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
Guest


 

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]
Guest


 

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
Guest


 

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
Guest


 

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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't connect remotely Don_M Vista networking & sharing 1 07-06-2008 01:12 PM
Accessing Mail remotely Mike H Vista mail 1 03-01-2008 09:21 AM
Run Dcpromo remotely Santhosh PowerShell 8 01-26-2008 06:01 AM
Printing Remotely Dan Vista print fax & scan 0 11-23-2007 11:41 AM
connecting to a pc remotely... maya Vista General 3 08-01-2007 06:04 PM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com 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 2005-2008