Skip to content

Instantly share code, notes, and snippets.

@Graham-Beer
Last active November 5, 2016 17:48
Show Gist options
  • Save Graham-Beer/bf9a4096e4e02fc3cbbdf30368ca6f06 to your computer and use it in GitHub Desktop.
Save Graham-Beer/bf9a4096e4e02fc3cbbdf30368ca6f06 to your computer and use it in GitHub Desktop.
function Get-CMSiteOverview {
param([Switch]$Format)
<#
.DESCRIPTION
Display all site details.
Use format switch to display data as table or leave off for 'raw' data to use a 'manual' Select statement
.EXAMPLES
Get-CMSiteOverview
Get-CMSiteOverview -format
Get-CMSiteOverview | select NetworkOSPath, RoleName
.CREATOR
Graham Beer
#>
#Set CIM search criteria
$SearchCritera = @{
Namespace = "{1}{0}" -f (Get-CimInstance -Namespace Root\SMS -ClassName SMS_ProviderLocation).SiteCode,"root\SMS\Site_"
ClassName = 'SMS_SCI_SysResUse'
}
#Collate site data
$Site = Get-CimInstance @SearchCritera
#Format switch for presentation
if($format) {
#set column for 'Format-Table' cmdlet
$column1 = @{expression={ "$($_.name -replace '\\',' ')`n`n" }; width=30; label="Server"; alignment="center"} #Server Names
$column2 = @{expression={ $_.Group -join ', ' }; width=150; label="Role Types"; alignment="left"} #Server Role Names
$column3 = @{expression="count"; width=25; label="Number of roles"; alignment="center"} #Count of Roles per site
#Display results
return $site | select -Property NetworkOSPath -ExpandProperty rolename |
group networkospath |
Format-Table -wrap $column1, $column2, $column3
}
#Display raw data
$site
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment