15

SCCM & PowerShell

  • Upload
    others

  • View
    56

  • Download
    0

Embed Size (px)

Citation preview

SCCM & PowerShell Objectives

• Brief background on SCCM & PowerShell

• How to write a basic SCCM PowerShell script

• Overview of SCCM WMI Classes • Simplify and automate SCCM administration

using community-provided PSM’s and cmdlet’s

• Q&A

HASMUG - SCCM and PowerShell 2

SCCM & PowerShell Background

• Microsoft doesn’t provide any official PowerShell modules for SCCM 2007

• This has driven the community to develop their own PSM’s and cmdlet’s to help automate and simplify administration

• Microsoft may be releasing a PowerShell console and module with limited base cmdlet’s for SCCM 2012

HASMUG - SCCM & PowerShell 3

SCCM & PowerShell Basic SCCM PowerShell Script

$credental = Get-Credential #or use elevated PS console

#CM Server

$SCCMServer = "CMServer01"

#Site Code

$siteCode = "DMO"

#WMI Name Space

$WMINameSpace = "root/sms/site_$($siteCode)"

#Client

$client = "L-MACHINE01"

#WMI Query

Get-WMIObject -query "Select * from SMS_R_System Where

Name = '$client'" -Namespace $WMInameSpace -

computername $SCCMServer -credential $credential

HASMUG - SCCM and PowerShell 4

SCCM & PowerShell Basic SCCM PowerShell Script (cont.)

__GENUS : 2 __CLASS : SMS_R_System __SUPERCLASS : SMS_Resource __DYNASTY : SMS_BaseClass __RELPATH : SMS_R_System.ResourceId=59469 __PROPERTY_COUNT : 49 __DERIVATION : {SMS_Resource, SMS_BaseClass} __SERVER : CMServer01 __NAMESPACE : root\sms\site_DMO __PATH : \\CMServer01\root\sms\site_DMO:SMS_R_System.ResourceId=59469 Active : 1 ADDomainName : ADSiteName : Redmond AgentName : {SMS_AD_SYSTEM_DISCOVERY_AGENT, MP_ClientRegistration, Heartbeat Discove ry, SMS_AD_SYSTEM_GROUP_DISCOVERY_AGENT} AgentSite : {DMO} HardwareID : 2:F3C4FC29ECD7357B411438D327C94192093F5D23 InternetEnabled : 0 IPAddresses : {192.168.0.20} IPSubnets : {192.168.0.0}

IPv6Addresses : {}

IPv6Prefixes : {}

IPXAddresses : {}

IsClientAMT30Compatible :

LastLogonUserDomain :

LastLogonUserName :

MACAddresses : {00:1E:0B:C3:D2:DA}

Name : L-MACHINE01

NetbiosName : L-MACHINE01

Obsolete : 0

OperatingSystemNameandVersion : Microsoft Windows NT Server 6.1

PreviousSMSUUID : Unknown

PrimaryGroupID : 515

ResourceDomainORWorkgroup : DEMO

ResourceId : 59469

ResourceNames : {L-MACHINE01.Demo.pvt}

ResourceType : 5

SMBIOSGUID : 37373434-3730-5355-4538-313139455846

SMSAssignedSites : {DMO}

SMSInstalledSites : {DMO}

SMSUniqueIdentifier : GUID:2F5516B5-C0BE-4A9E-A107-B26124C55D18

SystemGroupName : {DEMO\DLG.SCCM Client Access, DEMO\Domain Computers}

SystemOUName : {DEMO.PVT/SERVERS, DEMO.PVT/SERVERS/APPLICATION SERVERS} UserAccountControl : 4096

SCCM & PowerShell WMI Classes

• There are MANY SCCM WMI Classes that can contain properties and/or methods.

• Properties – Values available under WMI classes. Ex. System Name,

Domain, booleans, etc.

• Methods – Functions under WMI classes. Ex. Refreshing a

collection or Deleting a package from a distribution point.

HASMUG - SCCM and PowerShell 6

SCCM & PowerShell WMI Classes (cont.)

• SMS_Collection WMI Class (http://msdn.microsoft.com/en-us/library/cc145320.aspx)

– Example method RequestRefresh

– Example property CollectionID

HASMUG - SCCM and PowerShell 7

SCCM & PowerShell PSM’s Available

• SCCM Community Extensions PSM @ http://configmgrcx.codeplex.com/ – Contributors: Michael Niehaus, Donnie Taylor and

some online alias’

• Snowland PSM @ http://www.snowland.se/sccm-posh/ – Contributors: Michael Niehaus, Rikard Ronnkvist,

Stefan Ringler, and Stephen Leuthold (not yet published)

HASMUG - SCCM and PowerShell 8

SCCM & PowerShell SCCM Community Extensions PSM

• Server • Connect-CMProvider

Get-CMAdvertisement Get-CMBootImagePackage Get-CMCollection Get-CMDriverPackage Get-CMImagePackage Get-CMOSInstallPackage Get-CMPackage Get-CMProgram Get-CMSoftwareUpdatesPackage Get-CMTSPackage Show-CMPackage

• Client • Get-CMCliAdvertisement

HASMUG - SCCM and PowerShell 9

SCCM & PowerShell Snowland PSM

• Connect-SCCMServer • Add-SCCMCollectionRule • Add-SCCMDirUserCollectionRule • Add-SCCMDistributionPoint • Get-SCCMAdvertisement • Get-SCCMBootImagePackage • Get-SCCMClientComputerAssociation • Get-SCCMClientHasLocalDP • Get-SCCMCollection • Get-SCCMCollectionMembers • Get-SCCMCollectionRules • Get-SCCMCommands • Get-SCCMComputer • Get-SCCMDriver • Get-SCCMDriverPackage • Get-SCCMImagePackage • Get-SCCMInboxes • Get-SCCMIsR2 • Get-SCCMObject • Get-SCCMOperatingSystemInstallPackage • Get-SCCMPackage

• Get-SCCMParentCollection • Get-SCCMSite • Get-SCCMSiteDefinition • Get-SCCMSiteDefinitionProps • Get-SCCMSubCollectionDetails • Get-SCCMSubCollections • Get-SCCMTaskSequence • Get-SCCMUser • New-SCCMAdvertisement • New-SCCMCollection • New-SCCMPackage • New-SCCMProgram • Set-SCCMClientAction • Update-SCCMDriverPkgSourcePath • Update-SCCMDriverSourcePathnotepad • Update-SCCMPackageSourcePath • Get-SCCMSubCollectionDetails • Get-SCCMClientHasLocalDP • Get-SCCMClientComputerAssociation • Set-SCCMClientAction

SCCM & PowerShell New Snowland PSM cmdlet’s

• New cmdlet’s – Get-SCCMSubCollectionDetails

• Enumerate sub collections underneath a parent

– Get-SCCMClientHasLocalDP • Check to see if client has a local DP (returns TRUE or FALSE

– Get-SCCMClientComputerAssociation • Determine user to client associated via top console user or

last logon.

– Set-SCCMClientAction • Perform actions against SCCM clients. Ex. Machine Policy

Retrieval & Evaluation Cycle

HASMUG - SCCM and PowerShell 11

SCCM & PowerShell New Snowland PSM cmdlet’s (cont.)

• Demo!

HASMUG - SCCM and PowerShell 12

SCCM & PowerShell SCCM App Deploy Tool

HASMUG - SCCM and PowerShell 13

SCCM & PowerShell Conclusion

• PowerShell makes administration easier for SCCM

• Very powerful cmdlet’s available from the community

• Feel free to write your own cmdlet’s and contribute!

HASMUG - SCCM and PowerShell 14