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:<\/p>\n
gwmi win32_userprofile \n| select @{LABEL=”last used”;EXPRESSION{$_.ConvertToDateTime($_.lastusetime)}}, LocalPath, SID \n| ft -a | Out-File \"C:\\UserProfiles.txt\" -Append\n\n<\/code><\/pre>\n
Advertisement
I’ve added<\/p>\n
$MachineList = Get-Content -Path c:\\listofmachines.txt; \nforeach ($Machine in $MachineList){\n<\/code><\/pre>\n
Advertisement
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.<\/p>\n
I’ve also tried adding<\/p>\n
psexec.exe \\\\$machine\n<\/code><\/pre>\nbefore 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.”<\/p>\n
Thanks for the help fellas.<\/p>","upvoteCount":6,"answerCount":9,"datePublished":"2016-11-17T16:32:14.000Z","author":{"@type":"Person","name":"zfaircloth","url":"https://community.spiceworks.com/u/zfaircloth"},"acceptedAnswer":{"@type":"Answer","text":"
Add this to your Get-WmiObject:<\/p>\n
-ComputerName $Machine\n<\/code><\/pre>\nNo need to mess around with psexec.<\/p>","upvoteCount":4,"datePublished":"2016-11-17T16:33:44.000Z","url":"https://community.spiceworks.com/t/having-an-issue-running-gwmi-command-on-remote-machines/541114/2","author":{"@type":"Person","name":"martin9700","url":"https://community.spiceworks.com/u/martin9700"}},"suggestedAnswer":[{"@type":"Answer","text":"
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:<\/p>\n
gwmi win32_userprofile \n| select @{LABEL=”last used”;EXPRESSION{$_.ConvertToDateTime($_.lastusetime)}}, LocalPath, SID \n| ft -a | Out-File \"C:\\UserProfiles.txt\" -Append\n\n<\/code><\/pre>\nI’ve added<\/p>\n
$MachineList = Get-Content -Path c:\\listofmachines.txt; \nforeach ($Machine in $MachineList){\n<\/code><\/pre>\nSo 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.<\/p>\n
I’ve also tried adding<\/p>\n
psexec.exe \\\\$machine\n<\/code><\/pre>\nbefore 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.”<\/p>\n
Thanks for the help fellas.<\/p>","upvoteCount":6,"datePublished":"2016-11-17T16:32:14.000Z","url":"https://community.spiceworks.com/t/having-an-issue-running-gwmi-command-on-remote-machines/541114/1","author":{"@type":"Person","name":"zfaircloth","url":"https://community.spiceworks.com/u/zfaircloth"}},{"@type":"Answer","text":"