I am writing a simple powershell script, which basically accepts the names of a number of PCs and save it into an array, then do two things (in this case lets take PsInfo and PsGetsid) on each of the PC. What I need is to take PC1, do PsInfo, followed by PsGetsid, then take PC2, do PsInfo, followed by PsGetsid etc. With my code, what I am getting is, it take PC1, do PsInfo, then take PC2, do PsInfo etc. Then it will do the second command on each PC.
However, if I change the array to a static array (no user input), it works perfectly. Here is my code :
$list = read-host "Enter the pc names seperated by comma :"
foreach ($element in $list){
Write-Host "PsInfo"
psinfo \\$element
Write-Host "PsGetSid"
psgetsid \\$element
}
And here is my sample output
PS C:\Users\ebinissac\Desktop> ./test1.ps1
Enter the pc names seperated by comma :: ebinissac,ebinissac1,sithu
PsInfo
PsInfo v1.77 - Local and remote system information viewer
Copyright (C) 2001-2009 Mark Russinovich
Sysinternals - www.sysinternals.com
System information for \\ebinissac:
Uptime: 0 days 3 hours 22 minutes 1 second
Kernel version: Windows 7 Enterprise, Multiprocessor Free
Product type: Professional
Product version: 6.1
Service pack: 0
Kernel build number: 7601
Registered organization: xxxxx
Registered owner: xxxx
IE version: 9.0000
System root: C:\WINDOWS
Processors: 8
Processor speed: 3.5 GHz
Processor type: Intel(R) Core(TM) i7-4790 CPU @
Physical memory: 3170 MB
Video driver: Intel(R) HD Graphics 4600
System information for \\ebinissac1:
Uptime: 0 days 8 hours 3 minutes 37 seconds
Kernel version: Windows 10 Enterprise, Multiprocessor Free
Product type: Professional
Product version: 6.3
Service pack: 0
Kernel build number: 10586
Registered organization: xxx
Registered owner: xxx
IE version: 9.0000
System root: C:\WINDOWS
Processors: 8
Processor speed: 3.5 GHz
Processor type: Intel(R) Core(TM) i7-4790 CPU @
Physical memory: 304 MB
Video driver: Intel(R) HD Graphics 4600
System information for \\sithu:
Uptime: 14 days 1 hour 13 minutes 36 seconds
Kernel version: Windows 7 Enterprise, Multiprocessor Free
Product type: Professional
Product version: 6.1
Service pack: 0
Kernel build number: 7601
Registered organization: xxx
Registered owner: xxxx
IE version: 9.0000
System root: C:\WINDOWS
Processors: 8
Processor speed: 3.3 GHz
Processor type: Intel(R) Core(TM) i7-3770 CPU @
Physical memory: 3988 MB
Video driver: Intel(R) HD Graphics 4000
PsGetSid
PsGetSid v1.44 - Translates SIDs to names and vice versa
Copyright (C) 1999-2008 Mark Russinovich
Sysinternals - www.sysinternals.com
\\ebinissac:
SID for \\ebinissac:
S-1-5-21-xxxxxxxxxxxxxxxxx
\\ebinissac1:
SID for \\ebinissac1:
S-1-5-21-xxxxxxxxxxxxxxxxx
\\sithu:
SID for \\sithu:
S-1-5-21-xxxxxxxxxxxxxxxxxx
I am not sure if it has something to do with how the data is read in. Any help will be appreciated. TIY