Skip to content

Commit 4290292

Browse files
committed
Update ServerInventory.ps1
Fix issue with local group membership displaying large table for domain controllers.
1 parent fa3e7b2 commit 4290292

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

ServerInventory.ps1

+10-6
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,17 @@ Get-WmiObject win32_StartupCommand -ComputerName $name | select caption,descrip
108108
$localusers = Get-WmiObject win32_UserAccount -ComputerName $name -Filter "LocalAccount='$True'" | select Name,SID,PasswordExpires,Disabled,Lockout | ConvertTo-html -Body "<H2> Local Users </H2>" >> "$filepath\$name.html"
109109

110110
###local user group membershipe
111-
$adsi = [ADSI]"WinNT://$env:COMPUTERNAME"
112-
$adsi.Children | where {$_.SchemaClassName -eq 'user'} | Foreach-Object {
111+
###Check if machine is a domain controller first to prevent large unreadable table
112+
Import-Module servermanager
113+
$Domaincontroller = get-windowsfeature | where {$_.Name -eq "ADDS-Domain-Controller" -and $_.installed -eq $true}
114+
if ($Domaincontroller -eq $null){
115+
$adsi = [ADSI]"WinNT://$env:COMPUTERNAME"
116+
$adsi.Children | where {$_.SchemaClassName -eq 'user'} | Foreach-Object {
113117
$groups = $_.Groups() | Foreach-Object {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
114118
$_ | Select-Object @{n='UserName';e={$_.Name}},@{n='Groups';e={$groups -join ';'}}
115-
} | ConvertTo-html -Body "<H2> Local User Group Memberships </H2>" >> "$filepath\$name.html"
116-
119+
} | ConvertTo-html -Body "<H2> Local User Group Memberships </H2>" >> "$filepath\$name.html"
120+
}
121+
Else{}
117122
# MotherBoard: Win32_BaseBoard # You can Also select Tag,Weight,Width
118123
Get-WmiObject -ComputerName $name Win32_BaseBoard | Select Name,Manufacturer,Product,SerialNumber,Status | ConvertTo-html -Body "<H2> MotherBoard Information</H2>" >> "$filepath\$name.html"
119124

@@ -260,5 +265,4 @@ $schtasks | ConvertTo-Html -Body "<H2>Scheduled Tasks</H2>" >> "$filepath\$name.
260265

261266
####Send Email if required
262267
If ($sendemail -eq $true){
263-
Send-MailMessage -To $to -Subject $subject -From $from $subject -SmtpServer $smtp -Priority "High" -BodyAsHtml -Attachments "$filepath\$name.html"
264-
}
268+
Send-MailMessage -To $to -Subject $subject -From $from $subject -SmtpServer $smtp -Priority "High" -BodyAsHtml -Attachments "$filepath\$name.html"}

0 commit comments

Comments
 (0)