Last active
November 2, 2023 12:43
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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