0

I am trying to evaluate a value from a powershell command for a SQL Agent setting on a clustered server using powershell. I am very new to Powershell but we want to set up a monitor to make sure that all of our Windows Server 2008 r2 clusters have this setting correct.

I did find the setting in question by using the following at a PS prompt...

cluster resource 'SQL Server Agent' /prop : RestartAction

The issue is I would like it to return just the number (either 1 or 1(0x1) would be fine) under the Value column in the following output.

Listing properties for 'SQL Server Agent':

T  Resource             Name                           Value
-- -------------------- ------------------------------ -----------------------
D  SQL Server Agent     RestartAction                  1 (0x1)

Because this will be a monitor I need to be able to evaluate if the Value is = 1 or not and then report when it isn't. If I could get the powershell to just return the simple value I can do the rest of setting up the monitor in T-SQL.

I have been scouring the internet trying to find an answer but everything has to do with cmdlets and functions and all I want is the windows server value to be returned. Maybe it is not really that simple but I wanted to check before going down a long scripting venture.

I appreciate any help, thanks!!

2 Answers2

0

Can you use the FailoverClusters module?

(Get-ClusterResource -Cluster Cluster1 -Name 'SQL Server Agent').RestartAction

If not, string parse it:

PS> $clus = cluster /cluster:cluster1 resource 'SQL Server Agent' /prop:RestartAction
PS> $clus[10]
D  SQL Server Agent     RestartAction                  1 (0x1)    

PS> $clus[10] -replace '^.+\((.+)\)$','$1'
0x1
Shay Levy
  • 121,444
  • 32
  • 184
  • 206
0

You can use WMI if you can't load the failoverclusters module and there's no need to parse:

gwmi -ComputerName cluster1 -Authentication PacketPrivacy -Namespace "root\mscluster" -Class MSCluster_Resource -Filter "name LIKE 'SQL Server Agent%'" |
select -ExpandProperty RestartAction
Chad Miller
  • 40,127
  • 3
  • 30
  • 34