From cf6406fc66bdbb99ecc4fd6ea977e796176d7b3c Mon Sep 17 00:00:00 2001 From: Joel Porgand Date: Wed, 5 Dec 2018 10:53:46 +1000 Subject: [PATCH 1/5] fix grammer --- PSHTML-AD.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PSHTML-AD.ps1 b/PSHTML-AD.ps1 index 40978e3..2c99522 100644 --- a/PSHTML-AD.ps1 +++ b/PSHTML-AD.ps1 @@ -561,7 +561,7 @@ $GroupMembershipTable.add($objmem) Organizational Units ############################> -#Get all OU's' +#Get all OUs' $OUs = Get-ADOrganizationalUnit -filter * -properties * $OUwithLinked = 0 @@ -622,14 +622,14 @@ If (($OUTable).count -eq 0) #OUs with no GPO Linked $obj1 = [PSCustomObject]@{ - 'Name' = "OU's with no GPO's linked" + 'Name' = "OUs with no GPOs linked" 'Count' = $OUwithnoLink } $OUGPOTable.add($obj1) $obj2 = [PSCustomObject]@{ - 'Name' = "OU's with GPO's linked" + 'Name' = "OUs with GPOs linked" 'Count' = $OUwithLinked } From f50efbd9367a450a77eccb7aae00a61186464d6f Mon Sep 17 00:00:00 2001 From: Joel Porgand Date: Fri, 7 Dec 2018 10:29:50 +1000 Subject: [PATCH 2/5] fix enterprise admin query when not running from root domain --- PSHTML-AD.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSHTML-AD.ps1 b/PSHTML-AD.ps1 index fdae876..1c223e7 100644 --- a/PSHTML-AD.ps1 +++ b/PSHTML-AD.ps1 @@ -342,7 +342,7 @@ foreach ($DomainAdminMember in $DomainAdminMembers) } #Get Enterprise Admins -$EnterpriseAdminsMembers = Get-ADGroupMember "Enterprise Admins" +$EnterpriseAdminsMembers = Get-ADGroupMember "Enterprise Admins" -Server $ForestObj.SchemaMaster foreach ($EnterpriseAdminsMember in $EnterpriseAdminsMembers) { From 4d7fb3fe1459996bc0602322ebc1e02e7677ca0f Mon Sep 17 00:00:00 2001 From: Joel Porgand Date: Fri, 7 Dec 2018 14:45:10 +1000 Subject: [PATCH 3/5] OS enumeration --- PSHTML-AD.ps1 | 138 +++++++++----------------------------------------- 1 file changed, 25 insertions(+), 113 deletions(-) diff --git a/PSHTML-AD.ps1 b/PSHTML-AD.ps1 index 1c223e7..05c9e14 100644 --- a/PSHTML-AD.ps1 +++ b/PSHTML-AD.ps1 @@ -1114,14 +1114,23 @@ $ComputersProtected = 0 $ComputersNotProtected = 0 $ComputerEnabled = 0 $ComputerDisabled = 0 -$Server2016 = 0 -$Server2012 = 0 -$Server2012R2 = 0 -$Server2008R2 = 0 -$Windows10 = 0 -$Windows8 = 0 -$Windows7 = 0 -$Server2012R2 = 0 +#Only search for versions of windows that exist in the Environment +$WindowsRegex = "(Windows (Server )?(\d+|XP)?( R2)?).*" +$OsVersions = $Computers | Select-Object OperatingSystem -unique | ForEach-Object { + if ($_.OperatingSystem -match $WindowsRegex ){ + return $matches[1] + } else { + #return $_.OperatingSystem + } +} | Select-Object -unique | Sort-Object + +$OsObj = [PSCustomObject]@{} + +$OsVersions | ForEach-Object { + + $OsObj | Add-Member -Name $_ -Value 0 -Type NoteProperty + +} foreach ($Computer in $Computers) { @@ -1162,47 +1171,11 @@ foreach ($Computer in $Computers) $ComputersTable.Add($obj) - if ($Computer.OperatingSystem -like "*Server 2016*") - { - - $Server2016++ - } - - elseif ($Computer.OperatingSystem -like "*Server 2012 R2*") + if ($Computer.OperatingSystem -match $WindowsRegex) { - - $Server2012R2++ - } - - elseif ($Computer.OperatingSystem -like "*Server 2012*") - { - - $Server2012++ - } - - elseif ($Computer.OperatingSystem -like "*Server 2008 R2*") - { - - $Server2008R2++ - } - - elseif ($Computer.OperatingSystem -like "*Windows 10*") - { - - $Windows10++ - } - - elseif ($Computer.OperatingSystem -like "*Windows 8*") - { - - $Windows8++ - } - - elseif ($Computer.OperatingSystem -like "*Windows 7*") - { - - $Windows7++ + $OsObj."$($matches[1])"++ } + } If (($ComputersTable).Count -eq 0) @@ -1214,77 +1187,16 @@ If (($ComputersTable).Count -eq 0) } } -#Data for TOP Computers data table -$objULic = [PSCustomObject]@{ - - 'Total Computers' = $Computers.Count - "Server 2016" = $Server2016 - "Server 2012 R2" = $Server2012R2 - "Server 2012" = $Server2012 - "Server 2008 R2" = $Server2008R2 - "Windows 10" = $Windows10 - "Windows 8" = $Windows8 - "Windows 7" = $Windows7 -} - -$TOPComputersTable.Add($objULic) - #Pie chart breaking down OS for computer obj -$objULic = [PSCustomObject]@{ - - 'Name' = "Server 2016" - "Count" = $Server2016 -} - -$GraphComputerOS.Add($objULic) - -$objULic = [PSCustomObject]@{ - - 'Name' = "Server 2012 R2" - "Count" = $Server2012R2 -} - -$GraphComputerOS.Add($objULic) - -$objULic = [PSCustomObject]@{ - - 'Name' = "Server 2012" - "Count" = $Server2012 -} - -$GraphComputerOS.Add($objULic) - -$objULic = [PSCustomObject]@{ - - 'Name' = "Server 2008 R2" - "Count" = $Server2008R2 +$OsObj.PSObject.Properties | ForEach-Object { + $GraphComputerOS.Add([PSCustomObject]@{'Name' = $_.Name;"Count" =$_.Value}) } -$GraphComputerOS.Add($objULic) - -$objULic = [PSCustomObject]@{ - - 'Name' = "Windows 10" - "Count" = $Windows10 -} - -$GraphComputerOS.Add($objULic) - -$objULic = [PSCustomObject]@{ - - 'Name' = "Windows 8" - "Count" = $Windows8 -} - -$GraphComputerOS.Add($objULic) +#Data for TOP Computers data table +$OsObj | Add-Member -Name 'Total Computers' -Value $Computers.Count -Type NoteProperty -$objULic = [PSCustomObject]@{ - - 'Name' = "Windows 7" - "Count" = $Windows7 -} +$TOPComputersTable.Add($OsObj) -$GraphComputerOS.Add($objULic) #Data for protected Computers pie graph $objULic = [PSCustomObject]@{ From 5fc05c0033de039d1ccd02ee6a921caa9f8eee64 Mon Sep 17 00:00:00 2001 From: Joel Porgand Date: Fri, 7 Dec 2018 15:11:29 +1000 Subject: [PATCH 4/5] fix typo --- PSHTML-AD.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSHTML-AD.ps1 b/PSHTML-AD.ps1 index 05c9e14..58fa788 100644 --- a/PSHTML-AD.ps1 +++ b/PSHTML-AD.ps1 @@ -1120,7 +1120,7 @@ $OsVersions = $Computers | Select-Object OperatingSystem -unique | ForEach-Objec if ($_.OperatingSystem -match $WindowsRegex ){ return $matches[1] } else { - #return $_.OperatingSystem + return $_.OperatingSystem } } | Select-Object -unique | Sort-Object From 0490ab089b231736c4b53799e318fd3b41c164dc Mon Sep 17 00:00:00 2001 From: Joel Porgand Date: Fri, 7 Dec 2018 15:36:38 +1000 Subject: [PATCH 5/5] bleh --- PSHTML-AD.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSHTML-AD.ps1 b/PSHTML-AD.ps1 index 58fa788..51b75e9 100644 --- a/PSHTML-AD.ps1 +++ b/PSHTML-AD.ps1 @@ -1119,7 +1119,7 @@ $WindowsRegex = "(Windows (Server )?(\d+|XP)?( R2)?).*" $OsVersions = $Computers | Select-Object OperatingSystem -unique | ForEach-Object { if ($_.OperatingSystem -match $WindowsRegex ){ return $matches[1] - } else { + } elseif ($_.OperatingSystem -ne $null) { return $_.OperatingSystem } } | Select-Object -unique | Sort-Object