by john808 at 2013-01-09 06:30:34
Hi,by john808 at 2013-01-09 06:45:12
I’ve been given a task to write a PS script that will remotely connect to a number of servers and check their OS architecture. Depending on the OS architecture it should then be directed to run another script found on another server.
Breaking this task down I would firstly like to connect to the servers and check the OS architecture. Here’s what I have done…
# Set variable and direct to list of servers
$computer = get-content C:\Servers.txt
# Run script to find OS details
Get-WmiObject -class Win32_OperatingSystem -computername $computer -Credential N00b
This works but doesn’t give me the architecture? I’ve had a search and there does seem to be scripts out there but I’m having trouble understanding them, which in turn makes it’s difficult to customise.
I believe this is very easy but being a noob and not having practised since last year and I’m not only rusty but lacking knowledge. Any help or suggestions would be appreciated.
My simple way of thinking is I need to gather the details and then add an if statement.
Thanks for any help.
I got it to work but does this seem ok…by ArtB0514 at 2013-01-09 07:06:34
# Set variable and direct to list of servers
$computer = get-content C:\Servers.txt
# Run script to find OS details
Get-WmiObject Win32_OperatingSystem -computername $computer -Credential N00b| Select-Object OSArchitecture
I think I now need to include an if/else statement?
$Systems = Get-WmiObject Win32_OperatingSystem -computername $computer -Credential N00b
$Systems | Foreach {
$Sys = $.CSName
Switch ($.OSArchitecture) {
"32-Bit" {Execute-32bitScript -ComputerName $Sys}
"64-Bit" {Execute-64bitScript -ComputerName $Sys}
}
}
by john808 at 2013-01-09 07:13:57Thanks for the reply, I’ll try and understand what’s happening and no doubt come back with questions.