Command Shell Examples
Useful SQL Queries
March, 2009 - Jonathan Almquist on Operations Manager - Site Home - TechNet Blogs

March, 2009

  • Delete a Management Pack

    Be careful while deleting Management Packs.  I suggest to first query the Management Pack and verify you’re returning the one you want to delete. Return all Management Packs by Display Name get-managementpack | select displayName | sort displayName...
  • Export a Management Pack

    Use this cmdlet to export a Management Pack to a specified path. Unlike the Operations Console, where you can only export unsealed Management Packs, using this cmdlet will export both sealed and unsealed Management Packs in XML format. First query...
  • Import a Management Pack

    Basic cmdlet, but wanted to add to the reference table.  The goal is to someday have the entire reference table complete with examples. install-managementpack " path " main menu
  • Set Management Group Global Settings

    Use this commandlet to set Management Group global settings.  You can use its companion, get-DefaultSetting , to return the current Management Group global settings. Set Auto-Approve New Manually Installed Agents setting Set-DefaultSetting ManagementServer...
  • Return Management Group global settings

    This is a basic commandlet that returns Management Group global settings.  You can use it’s companion, set-DefaultSetting , to configure Management Group global settings. Return all Management Group global settings get-DefaultSetting Return Auto...
  • Get BaseManagedEntityId for Agent

    Get BaseManagedEntityId for Agent get-agent | where {$_.ComputerName -eq " netbios_name "} | select {$_.HostedHealthService.id},name main menu
  • Enable Agent Proxying, by Health Service Id

    Enable Agent Proxying, by Health Service Id $a=get-agent | where {$_.hostedHealthService.id -eq " guid "};$a.set_proxyingEnabled($true);$a.applyChanges() main menu
  • Resolve agent from Health Service Id

    Find Agent, by Health Service Id get-agent | where {$_.hostedHealthService.id -eq " guid "} | select-object name main menu
  • List connected users

    List connected users to SDK (console and command shell users) Get-ManagementGroupConnection | foreach-object {$_.ManagementGroup.getConnectedUserNames()} Count connected users Get-ManagementGroupConnection | foreach-object {$_.ManagementGroup.getConnectedUserNames...
  • All overrides, with settings

    All overrides, with settings Get-ManagementPack | where {$_.sealed -eq $false} | get-override | select-object name,parameter,module,rule,value main menu
  • Overrides modified in date range

    Overrides modified in date range Get-ManagementPack | where {$_.sealed -eq $false} | get-override | where {$_.LastModified.ToLocalTime().date -gt $_.TimeAdded.ToLocalTime().date -and $_.LastModified.ToLocalTime().date -ge " mm/dd/yyyy " -and...
  • Overrides that have been modified

    Overrides that have been modified Get-ManagementPack | where {$_.sealed -eq $false} | get-override | where {$_.LastModified -gt $_.TimeAdded} | fl name,LastModified main menu
  • Overrides created in date range

    Overrides created in date range Get-ManagementPack | where {$_.sealed -eq $false} | get-override | where {$_.TimeAdded.ToLocalTime().date -ge " mm/dd/yyyy " -and $_.TimeAdded.ToLocalTime().date -le " mm/dd/yyyy "} | fl name,TimeAdded...
  • All rules overridden from specific MP

    All rules overriden from specific MP foreach ($rule in Get-ManagementPack | where {$_.DisplayName -match " mp_display_name "} | get-override | where {$_.rule}) {get-rule | where {$_.Id -eq $rule.rule.id} | select-object DisplayName} main menu
  • All monitors overridden from specific MP

    All monitors overriden from specific MP foreach ($monitor in Get-ManagementPack | where {$_.DisplayName -match " mp_display_name "} | get-override | where {$_.monitor}) {get-monitor | where {$_.Id -eq $monitor.monitor.id} | select-object DisplayName...
  • Get BASE class properties (if any)

    Get BASE class properties (if any) foreach ($base in Get-MonitoringClass | where {$_.name -eq " class_name "}) {get-monitoringclass | where {$_.id -eq $base.base.id} | foreach-object {$_.getMonitoringProperties()} | ft -auto parentElement,name...
  • Get BASE class

    Get BASE class foreach ($base in Get-MonitoringClass | where {$_.name -eq " class_name "}) {get-monitoringclass | where {$_.id -eq $base.base.id} | select-object name} main menu
  • Get HOST class properties (if any)

    Get HOST class properties (if any) get-monitoringclass | where {$_.name -eq " class_name "} | foreach-object {$_.findHostClass().PropertyCollection} | ft name main menu
  • Get HOST class

    Get HOST class get-monitoringclass | where {$_.name -eq " class_name "} | foreach-object {$_.findHostClass()} | select-object DisplayName main menu
  • Get class properties

    Get class properties get-monitoringclass | where {$_.name -eq " class_name "} | foreach-object {$_.getMonitoringProperties()} | select-object name main menu
  • Resolve all alerts in specific Resolution State

    Resolve all alerts in specific Resolution State get-alert | where {$_.resolutionState -eq resolution_state_number } | Resolve-Alert main menu
  • Resolve all open alerts generated by specific Agent

    Resolve all open alerts generated by specific Agent get-alert | where {$_.netbiosComputerName -eq " netbios_name " -AND $_.resolutionState -ne 255} | Resolve-Alert To use Criteria Expression for better performance get-alert -criteria 'NetbiosComputerName...
  • Resolve all open alerts, by Alert Name

    Resolve all open alerts, by Alert Name get-alert | where {$_.Name -eq " alert_name " -AND $_.resolutionState -ne 255} | resolve-alert main menu
  • Resolve all open alerts in date range

    Resolve all open alerts in date range get-alert | where {$_.TimeRaised.ToLocalTime().date -ge " mm/dd/yyyy " -and $_.TimeRaised.ToLocalTime().date -le " mm/dd/yyyy " -and $_.resolutionState -ne 255} | resolve-alert main menu
  • Top 10 REPEATING alerts (not closed)

    Top 10 REPEATING alerts (not closed) get-alert | where {$_.RepeatCount -gt 0 -AND $_.resolutionState -ne 255} | sort-object RepeatCount -desc | select-object -first 10 repeatcount,name | ft –auto main menu