Advertisement
easternnl

Query SCCM with PowerShell

May 27th, 2015
819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Run query's against you're SCCM server
  2. #
  3. $SiteServer = "swd"
  4. $SiteCode = 'SWD'
  5.  
  6. if ($cred -eq $null)
  7. {
  8.     # ask once for credentials
  9.     $cred = Get-credential
  10. }
  11.  
  12. # Test query:
  13. $query = "select SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.Client = 1"
  14. $query = 'select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_OPERATING_SYSTEM on SMS_G_System_OPERATING_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_OPERATING_SYSTEM.Version Like "%6.1%"'
  15. #$query = 'select SMS_G_System_OPERATING_SYSTEM.Version,SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_OPERATING_SYSTEM on SMS_G_System_OPERATING_SYSTEM.ResourceId = SMS_R_System.ResourceId'
  16. #$query = 'select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System '
  17. $result = Get-WmiObject -ComputerName $SiteServer  -Namespace  "ROOT\SMS\site_$SiteCode" -Query $query
  18. $result | select name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement