SCOM query from command line.


hi all,

i’m looking solution following problem.

i want able execute powershell oneliner cmd.exe, appears working great simple things, not “more complex queries”

 for example:

c:\users\smetj>powershell –command “”ipconfig””

windows ip configuration 

ethernet adapter local area connection 2: 

   connection-specific dns suffix  . :

   ipv4 address. . . . . . . . . . . : 10.1.254.44
   subnet mask . . . . . . . . . . . : 255.255.255.0
   default gateway . . . . . . . . . : 10.1.254.1

c:\users\sys_smetj> 

great! works.  now want same thing powershell command:

get-monitoringclass|where{$_.name -eq "microsoft.exchange.2010.service"}|get-monitoringobject|select healthstate,displayname

when start “operations manager shell” can execute query, want able execute cmd.exe

i understand need load scom powershell extension (-psconsolefile microsoft.enterprisemanagement.operationsmanager.clientshell.console.psc) before can execute this.

2 questions:

  • how can pass query -command switch? keeps failing on spaces, quotes, pipes, ...
  • how can make sure powershell.exe invoked right powsershell extension , make query work? 

(i’m not interested in putting query in file , execute file.)

 

cheers,

 

smetj

invoking long powershell commands cmd indeed headache, due weird character escaping need do.  why -encodedcommand parameter included.

here gussing want full command (imports scom snapin well, takes more lines should):

add-pssnapin *operationsmanager*

cd “$env:programfiles\system center operations manager 2007”

& (resolve-path ‘*noninteractivestartup.ps1’)

get-monitoringclass –name "microsoft.exchange.2010.service" | get-monitoringobject | select healthstate,displayname

here's how use -encodedcommand:

$command = @”

add-pssnapin *operationsmanager*

cd “$env:programfiles\system center operations manager 2007”

& (resolve-path ‘*noninteractivestartup.ps1’)

get-monitoringclass –name "microsoft.exchange.2010.service" | get-monitoringobject | select healthstate,displayname

“@

 

[convert]::tobase64string([text.encoding]::unicode.getbytes($command)) | clip

 

now paste big encoded string cmd script , run:

 

cmd> start powershell.exe -noexit -encodedcommand qqbkagqalqbqahmauwbuageacabpag4aiaaqae8acablahiayqb0agkabwbuahmatqbhag4ayqbnaguacgaqaaoaywbkacaahcbdadoaxabqahiabwbnahiayqbtacaargbpagwazqbzafwauwb5ahmadablag0aiabdaguabgb0aguacgagae8acablahiayqb0agkabwbuahmaiabnageabgbhagcazqbyacaamgawadaanwadiaoajgagacgaugblahmabwbsahyazqatafaayqb0aggaiaayicoatgbvag4asqbuahqazqbyageaywb0agkadgblafmadabhahiadab1ahaalgbwahmamqazickacgbhaguadaatae0abwbuagkadabvahiaaqbuagcaqwbsageacwbzacaaeyboageabqblacaaigbnagkaywbyag8acwbvagyadaauaeuaeabjaggayqbuagcazqauadiamaaxadaalgbtaguacgb2agkaywblaciaiab8acaarwblahqalqbnag8abgbpahqabwbyagkabgbnae8aygbqaguaywb0acaafaagahmazqbsaguaywb0acaasablageabab0aggacwb0ageadablacwarabpahmacabsageaeqbuageabqblaa==

see if works you.

 

thanks,

-lincoln



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS