I'm just starting off with Powershell and want to run some basic scripts.
I'm starting off by writing a script to see if MSSQLSERVER is running or stopped and out a message accordingly.
This is what I have so far...
Write-Host "Checking if SQL Server is running.."
function FuncCheckService{
param($MSSQLSERVER)
$arrService = Get-Service -Name $MSSQLSERVER
if ($arrService.Status -eq "Running"){
Write-Host "Service is running"
}
if ($arrService.Status -eq "Stopped"){
Write-Host "service is stopped"
}
}
However when I execute this (within Powershell ISE) all I get is the first line "Checking if SQL Server is running..."
What am I doing wrong with this?
Your function is fine but you never call it. at the end of the scripts, just past the last curly braces put your function name.