Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Harry_maxi
Starting Member
10 Posts |
Posted - 2013-09-13 : 08:54:20
|
Hi, i am looking to find powershell expert, so that can help on my query.below script does return sql installed services on server but it will not return anything if service is not installed. my requirement to return wheather service is running then 'running' else 'not installed or not running'.i need full status of any server. can anyone please help me.# Configuration data.# Add your machine names to check for to the list:[Array] $servers = "server name";# Defining output format for each column.$fmtName =@{label="Service Name" ;alignment="left" ;width=30 ;Expression={$_.Name};};$fmtMode =@{label="Start Mode" ;alignment="left" ;width=10 ;Expression={$_.StartMode};};$fmtState =@{label="State" ;alignment="left" ;width=10 ;Expression={$_.State};};$fmtStatus =@{label="Status" ;alignment="left" ;width=10 ;Expression={$_.Status};};$fmtMsg =@{label="Message" ;alignment="left" ;width=50 ; `Expression={ if (($_.StartMode -eq "Auto") -and ($_.State -ne "Running") ) {"Alarm: Stopped"} };};foreach($server in $servers){$srvc = Get-WmiObject `-query "SELECT * FROM win32_service WHERE name LIKE '%SQL%' OR name LIKE '%MSOLAP%'OR name LIKE '%ReportServer%'OR name LIKE '%MSDtsServer%'" `-computername $server `| Sort-Object -property name;Write-Output ("Server: {0}" -f $server);Write-Output $srvc | Format-Table $fmtName, $fmtMode, $fmtState, $fmtStatus, $fmtMsg; } Mnay ThanksAtTitUdE BuIlDs ThE TrUst........! |
|
|
|
|