I’m trying to output the user profile lists in the registry from several different remote machines but have an issue. I can get the list just fine on the local machine or if i’m in a pssession but can’t seem to script it for remote computers. Here’s what I have:

gwmi win32_userprofile 
| select @{LABEL=”last used”;EXPRESSION{$_.ConvertToDateTime($_.lastusetime)}}, LocalPath, SID 
| ft -a | Out-File "C:\UserProfiles.txt" -Append

I’ve added

$MachineList = Get-Content -Path c:\listofmachines.txt; 
foreach ($Machine in $MachineList){

So it will run through my list of machines. Of course I will need to do it remotely, so i’ve tried using both enter-pssession and exit-pssession before and after each loop but just kept getting “Connecting to remote server ******* failed with the following error message: The client cannot connect to the destination specified in the request” yet whenever I just enter-pssession manually I can connect just fine to each machine.

I’ve also tried adding

psexec.exe \\$machine

before each loop. It goes through the computer list but on every one of them it says “PsExec could not start on *****: The system cannot find the file specified.”

Thanks for the help fellas.

6 Spice ups

Add this to your Get-WmiObject:

-ComputerName $Machine

No need to mess around with psexec.

4 Spice ups

You’re the man @martin9700 .

While we are at it, any good tips on how to add the machine name to the output. It’s returning exactly what I want but there’s just no indication of which machine the results are from (unless of course, you just follow along the list, but some of the machines may not be running when it’s ran).

Thanks!

1 Spice up

haha nevermind. Answered my own question and just added $machine to my output. Did i mention i didn’t get much sleep?

2 Spice ups

Just like to mention that I’m pretty sure this Best Answer pushed me over into Pure Capsaicin! Thank you, Mr. ZFaircloth!

3 Spice ups

Ah, that’s why you were so quick today. Trying to cross the finish line haha!

It’s been killing me all week! Guess I’ll have to move on to another community now!! haha

2 Spice ups

This place will become a barren wasteland. You won’t do that!

If you are looking for ransom, I can tell you I don’t have money.
But what I do have are a very particular set of skills, skills I have acquired over a very long career.
Skills that make me a nightmare for people like you.
If you remain in the spiceworks community, that’ll be the end of it.
I will not look for you, I will not pursue you.
But if you don’t, I will look for you, I will find you, and I will return you to the spiceworks community.

@martin9700

2 Spice ups