First off i'm a a newb at Powershell and scripting for that matter, so I know what my goal is just can't figure out what I'm doing wrong.
My goal is have a script that first asks for a server name and then checks the version of the OS it is running. Based on the OS version it decides which version of IIS6 or 7 it should restart services on.
The script below doesn't do anything after creating the $OS variable?! Any suggestions?
Write-Output "What server do you want to restart IIS on?"
# Creates Server Variable
$ServerName = Read-Host
# Creates Operating System variable based on $servername variable
$OS = (Get-WmiObject -class Win32_OperatingSystem -computername $ServerName).Caption
if($OS -contains "2003")
{
write-output "Restarting IISADMIN service on $ServerName OS Version $OS"
Stop-Service -force -InputObject $(Get-Service -Computer $ServerName -Name IISADMIN )
Start-Service -InputObject $(Get-Service -Computer $ServerName -Name IISADMIN )
}
else
{
write-output "Restarting W3SVR service on $ServerName OS Version $OS"
Stop-Service -force -InputObject $(Get-Service -Computer $ServerName -Name W3SVC )
Start-Service -InputObject $(Get-Service -Computer $ServerName -Name W3SVC )
}