Check the value of $entry while in your loop (for diagnostic purposes). I'm 
betting it is an object and you're looking for the Name property to pass to 
Get-Process.

Foreach ($entry in $list) {

Get-Process -computername $entry.name
}

That worked for me - well, once it hit a machine I had access to and was on.

Good luck,
Joe

From: James Rankin [mailto:kz2...@googlemail.com]
Sent: Tuesday, July 12, 2011 11:33 AM
To: NT System Admin Issues
Subject: Re: Final PS noob question for the week, I promise

I was trying to export the contents of an OU and manipulate that list, the 
command I piped it to was just a simple one I could think of for testing.

Unfortunately that seems to be throwing me errors too

On the first I get

Get-Process : Couldn't connect to remote machine.
At line:1 char:40
+ foreach ($entry in $list) { get-process <<<<  -ComputerName $entry }
    + CategoryInfo          : NotSpecified: (:) [Get-Process], InvalidOperatio
   nException
    + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.Power
   Shell.Commands.GetProcessCommand

And on the second example supplied

Get-Process : Cannot validate argument on parameter 'ComputerName'. The argumen
t is null or empty. Supply an argument that is not null or empty and then try t
he command again.
At line:1 char:61
+ foreach ($entry in $list.Values) { get-process -ComputerName <<<<  $entry }
    + CategoryInfo          : InvalidData: (:) [Get-Process], ParameterBinding
   ValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
   Shell.Commands.GetProcessCommand

I must be missing something simple here :-(
On 12 July 2011 16:23, Michael B. Smith 
<mich...@smithcons.com<mailto:mich...@smithcons.com>> wrote:
Not 100% sure what you are attempting to do, but it seems like that this is 
wrong:

                Format-Wide -column 1 name

You probably want this:

$list = Get-ADComputer -SearchBase "OU=whatever,DC=domain,DC=com" -Filter * 
-SearchScope onelevel | Select name

Although that may return you a hashtable instead of a simple list. In that 
case, instead of:

foreach ($entry in $list) { get-process -ComputerName $entry }

you would need to:

foreach ($entry in $list.Values) { get-process -ComputerName $entry }

Regards,

Michael B. Smith
Consultant and Exchange MVP
http://TheEssentialExchange.com

From: James Rankin [mailto:kz2...@googlemail.com<mailto:kz2...@googlemail.com>]
Sent: Tuesday, July 12, 2011 11:17 AM
To: NT System Admin Issues
Subject: Final PS noob question for the week, I promise

Some of the links provided in earlier threads have been invaluable in teaching 
me things....however just one simple query if I may be so bold, as this is 
annoying me....

If I do

$list = \\path_to_textfile.txt<file:///\\path_to_textfile.txt>

and then run

foreach ($entry in $list) { get-process -ComputerName $entry }

that works fine, but if I do

$list = Get-ADComputer -SearchBase "OU=whatever,DC=domain,DC=com" -Filter * 
-SearchScope onelevel | Format-Wide -column 1 name

and then

foreach ($entry in $list) { get-process -ComputerName $entry }

it throws me errors that look like $entry is not being passed to the command 
correctly. What am I doing wrong here? (I have the ActiveDirectory module 
loaded, so it isn't that). Is it something to do with what format the 
Get-Process command accepts the input in for the -ComputerName parameter? Or am 
I doing something incredibly stupid?


TIA,



JRR
--
"On two occasions...I have been asked, 'Pray, Mr Babbage, if you put into the 
machine wrong figures, will the right answers come out?' I am not able rightly 
to apprehend the kind of confusion of ideas that could provoke such a question."

***** IMPORTANT INFORMATION/DISCLAIMER *****

This document should be read only by those persons to whom it is addressed. If 
you have received this message it was obviously addressed to you and therefore 
you can read it, even it we didn't mean to send it to you. However, if the 
contents of this email make no sense whatsoever then you probably were not the 
intended recipient, or, alternatively, you are a mindless cretin; either way, 
you should immediately kill yourself and destroy your computer (not necessarily 
in that order). Once you have taken this action, please contact us.. no, sorry, 
you can't use your computer, because you just destroyed it, and possibly also 
committed suicide afterwards, but I am starting to digress......

The originator of this email is not liable for the transmission of the 
information contained in this communication. Or are they? Either way it's a 
pretty dull legal query and frankly one I'm not going to dwell on. But should 
you have nothing better to do, please feel free to ruminate on it, and please 
pass on any concrete conclusions should you find them. However, if you pass 
them on via email, be sure to include a disclaimer regarding liability for 
transmission.

In the event that the originator did not send this email to you, then please 
return it to us and attach a scanned-in picture of your mother's brother's wife 
wearing nothing but a kangaroo suit, and we will immediately refund you exactly 
half of what you paid for the can of Whiskas you bought when you went to Pets 
At Home yesterday.

We take no responsibility for non-receipt of this email because we are running 
Exchange 5.5 and everyone knows how glitchy that can be. In the event that you 
do get this message then please note that we take no responsibility for that 
either. Nor will we accept any liability, tacit or implied, for any damage you 
may or may not incur as a result of receiving, or not, as the case may be, from 
time to time, notwithstanding all liabilities implied or otherwise, ummm, hell, 
where was I...umm, no matter what happens, it is NOT, and NEVER WILL BE, OUR 
FAULT!

The comments and opinions expressed herein are my own and NOT those of my 
employer, who, if he knew I was sending emails and surfing the seamier side of 
the Internet, would cut off my manhood and feed it to me for afternoon tea.


~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe ntsysadmin



--
"On two occasions...I have been asked, 'Pray, Mr Babbage, if you put into the 
machine wrong figures, will the right answers come out?' I am not able rightly 
to apprehend the kind of confusion of ideas that could provoke such a question."

***** IMPORTANT INFORMATION/DISCLAIMER *****

This document should be read only by those persons to whom it is addressed. If 
you have received this message it was obviously addressed to you and therefore 
you can read it, even it we didn't mean to send it to you. However, if the 
contents of this email make no sense whatsoever then you probably were not the 
intended recipient, or, alternatively, you are a mindless cretin; either way, 
you should immediately kill yourself and destroy your computer (not necessarily 
in that order). Once you have taken this action, please contact us.. no, sorry, 
you can't use your computer, because you just destroyed it, and possibly also 
committed suicide afterwards, but I am starting to digress......

The originator of this email is not liable for the transmission of the 
information contained in this communication. Or are they? Either way it's a 
pretty dull legal query and frankly one I'm not going to dwell on. But should 
you have nothing better to do, please feel free to ruminate on it, and please 
pass on any concrete conclusions should you find them. However, if you pass 
them on via email, be sure to include a disclaimer regarding liability for 
transmission.

In the event that the originator did not send this email to you, then please 
return it to us and attach a scanned-in picture of your mother's brother's wife 
wearing nothing but a kangaroo suit, and we will immediately refund you exactly 
half of what you paid for the can of Whiskas you bought when you went to Pets 
At Home yesterday.

We take no responsibility for non-receipt of this email because we are running 
Exchange 5.5 and everyone knows how glitchy that can be. In the event that you 
do get this message then please note that we take no responsibility for that 
either. Nor will we accept any liability, tacit or implied, for any damage you 
may or may not incur as a result of receiving, or not, as the case may be, from 
time to time, notwithstanding all liabilities implied or otherwise, ummm, hell, 
where was I...umm, no matter what happens, it is NOT, and NEVER WILL BE, OUR 
FAULT!

The comments and opinions expressed herein are my own and NOT those of my 
employer, who, if he knew I was sending emails and surfing the seamier side of 
the Internet, would cut off my manhood and feed it to me for afternoon tea.


~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
listmana...@lyris.sunbeltsoftware.com<mailto:listmana...@lyris.sunbeltsoftware.com>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to listmana...@lyris.sunbeltsoftware.com
with the body: unsubscribe ntsysadmin

Reply via email to