Skip to content

Instantly share code, notes, and snippets.

@MyITGuy
Last active November 2, 2023 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MyITGuy/4e0bd5b719a64181b46cbde9be0b1e42 to your computer and use it in GitHub Desktop.
Save MyITGuy/4e0bd5b719a64181b46cbde9be0b1e42 to your computer and use it in GitHub Desktop.
Gets resources that have a system role, gets all system role names, sorts them and outputs the resource name, IP address and system role.
Import-Module ($Env:SMS_ADMIN_UI_PATH.Substring(0, $Env:SMS_ADMIN_UI_PATH.Length - 5) + '\ConfigurationManager.psd1')
$SiteCode = (Get-CimInstance -ClassName __NAMESPACE -Namespace "root\sms" | Select-Object -ExpandProperty Name).Substring(5,3)
if ((Get-PSDrive -Name $SiteCode) -isnot [Microsoft.ConfigurationManagement.PowerShell.Provider.CMDriveInfo]) {
New-PSDrive -Name $SiteCode -PSProvider "AdminUI.PS.Provider\CMSite" -Root ([System.Net.Dns]::GetHostByName(($env:computerName))).Hostname -Description "$($SiteCode) Primary Site"
}
Set-Location -Path "$($SiteCode):"
$Resources = Get-CMResource -Fast -ResourceType System | Where-Object { $_.SystemRoles }
$SystemRoles = $Resources | Select-Object -ExpandProperty SystemRoles | Sort-Object -Unique
foreach ($SystemRole In $SystemRoles) {
$SystemRoleResources = $Resources | Where-Object { $_.SystemRoles -eq $SystemRole }
$SystemRoleResources | Select-Object -Property Name,@{Name='IPAddress';Expression={$_.IPAddresses[0]}},@{Name='SystemRole';Expression={$SystemRole}} | Sort-Object -Property Name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment