Get-NameSpacePerms.ps1
19 Sep 2025Description
Purpose
No synopsis provided.
Detailed Description
No detailed description provided.
Usage
No usage examples provided.
Notes
No additional notes.
Script
function Get-NameSpacePerms {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$Namespace,
[Parameter(Mandatory = $false)]
[string]$ComputerName = $env:COMPUTERNAME
)
# Convert partial namespace to full namespace
$namespaceParts = $Namespace -split "\\"
$rootNamespace = $namespaceParts[0]
$FullNamespace = "root\$rootNamespace"
try {
$cimSession = New-CimSession -ComputerName $ComputerName
$security = Get-CimInstance -Namespace $FullNamespace -ClassName __SystemSecurity -CimSession $cimSession
$securityDescriptor = $security | Invoke-CimMethod -MethodName GetSecurityDescriptor
$dacl = $securityDescriptor.Descriptor.DACL
function Interpret-AccessMask {
param ([int]$accessMask)
$permissions = @()
if ($accessMask -band 1) { $permissions += "Remote Enable" }
if ($accessMask -band 2) { $permissions += "Method Execute" }
if ($accessMask -band 4) { $permissions += "Full Write" }
if ($accessMask -band 8) { $permissions += "Partial Write" }
if ($accessMask -band 16) { $permissions += "Provider Write" }
if ($accessMask -band 32) { $permissions += "Subscribe" }
if ($accessMask -band 64) { $permissions += "Reserved1" }
if ($accessMask -band 128) { $permissions += "Reserved2" }
if ($accessMask -band 256) { $permissions += "Read Security" }
if ($accessMask -band 512) { $permissions += "Write Security" }
if ($accessMask -band 1024) { $permissions += "Change Owner" }
if ($accessMask -band 2048) { $permissions += "Full Control" }
return [string]::Join(", ", $permissions)
}
function Interpret-AceType {
param ([int]$aceType)
switch ($aceType) {
0 { return "Allow" }
1 { return "Deny" }
2 { return "Audit Success" }
3 { return "Audit Failure" }
default { return "Unknown" }
}
}
function Interpret-AceFlags {
param ([int]$aceFlags)
$flags = @()
if ($aceFlags -band 1) { $flags += "Object Inherit" }
if ($aceFlags -band 2) { $flags += "Container Inherit" }
if ($aceFlags -band 4) { $flags += "No Propagate Inherit" }
if ($aceFlags -band 8) { $flags += "Inherit Only" }
if ($aceFlags -band 16) { $flags += "Inherited" }
if ($aceFlags -band 32) { $flags += "Successful Access Audit" }
if ($aceFlags -band 64) { $flags += "Failed Access Audit" }
return [string]::Join(", ", $flags)
}
foreach ($ace in $dacl) {
$sid = New-Object System.Security.Principal.SecurityIdentifier($ace.Trustee.SIDString)
$accountName = $sid.Translate([System.Security.Principal.NTAccount])
[PSCustomObject]@{
Namespace = $FullNamespace
Account = $accountName
AccessMask = $ace.AccessMask
InterpretedAccess = Interpret-AccessMask $ace.AccessMask
AceType = $ace.AceType
InterpretedAceType = Interpret-AceType $ace.AceType
AceFlags = $ace.AceFlags
InterpretedAceFlags = Interpret-AceFlags $ace.AceFlags
Inherited = $ace.IsInherited
}
}
Remove-CimSession -CimSession $cimSession
}
catch {
Write-Error "Failed to retrieve WMI permissions for namespace ${FullNamespace} on computer ${ComputerName}: $_"
}
}
# Example usage:
# Get-NameSpacePerms -Namespace "cimv2\cimv2" -ComputerName "EXCHANGE01"
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.