<# .Synopsis Get following from local computer: UserName, ComputerName, SiteName, DomainShortName, DomainDNSName, ForestDNSName, PDCRoleOwner, SchemaRoleOwner, IsNativeMode .DESCRIPTION This script gets the attributes from the ADSystemInfo com object. .EXAMPLE Get-ADSystemInfo .LINK https://technet.microsoft.com/en-us/library/ee198776.aspx .NOTES A. Kaplan 9/6/17 added com object cleanup, moved to advanced function #> function Get-ADSystemInfo{ [CmdletBinding()] Param () Begin { $properties = @( 'UserName', 'ComputerName', 'SiteName', 'DomainShortName', 'DomainDNSName', 'ForestDNSName', 'PDCRoleOwner', 'SchemaRoleOwner', 'IsNativeMode' ) $ads = New-Object -ComObject ADSystemInfo $type = $ads.GetType() $hash = @{} } Process{ foreach($p in $properties){ $hash.Add($p,$type.InvokeMember($p,'GetProperty', $Null, $ads, $Null)) } } End { [pscustomobject]$hash [System.Runtime.Interopservices.Marshal]::ReleaseComObject($ads) | Out-Null [System.GC]::Collect() [System.GC]::WaitForPendingFinalizers() } }