I've begun delving into the ConfigMgr SDK to start writing some scripts for it. My primary interest is in working on a set of Resource Kit tools for Desired Configuration Manager. I've found that everything I've looked so far has been in WMI. Which is both a blessing and a curse. It certainly makes it easier to access from Powershell's native Get-WMIObject Cmdlet.
Obviously the first thing I needed to be able to do was figure out the right namespace. Easy! root/sms looks good. Wait there's almost no information here... Time poke around some more. Hey look an object named SMS_ProviderLocation What could that be? Turns out it lists the sites that it knows about and most importantly it has a flag on which one is the local site and where the namespace for that site is.
The method to my madness scripting wise is to break down every task in to the smallest reasonable chunks and create scripts or functions out of them. This is what I have done for getting the sitecode.
get-sitecode.ps1
Param (
[switch] $Verbose = $True,
[string] $ComputerName = '.'
)
Begin {
if ($Verbose) {
# Set verbosity
$VerbosePreference = 2
}
$ErrorActionPreference = "Stop"
# Constructed Variables
$script:Namespace = $("root\sms")
Write-Verbose $("Namespace: " + $Script:Namespace)
}
Process {
#get baselines
$q = 'select * from SMS_ProviderLocation where ProviderForLocalSite = true'
$wmi = Get-WmiObject -ComputerName $ComputerName -Namespace $Script:Namespace -Query $q -ErrorAction Stop
Write-Output $wmi.SiteCode
}
No comments:
Post a Comment