diff --git a/Horizon Tools/KIS Pool Checker - v1.5.docx b/Horizon Tools/KIS Pool Checker - v1.5.docx new file mode 100644 index 0000000..b0c5ac4 Binary files /dev/null and b/Horizon Tools/KIS Pool Checker - v1.5.docx differ diff --git a/Horizon Tools/KISPoolChecker.cfg b/Horizon Tools/KISPoolChecker.cfg new file mode 100644 index 0000000..095e9e5 --- /dev/null +++ b/Horizon Tools/KISPoolChecker.cfg @@ -0,0 +1,4 @@ +HorizonServer=test.server.com +SMTPServer=smtp.server.com +SMTPFrom=sender@server.com +SMTPTo="test ","test2 " \ No newline at end of file diff --git a/Horizon Tools/KISPoolChecker.ps1 b/Horizon Tools/KISPoolChecker.ps1 new file mode 100644 index 0000000..02e608c --- /dev/null +++ b/Horizon Tools/KISPoolChecker.ps1 @@ -0,0 +1,230 @@ +<# +KISPoolChecker.ps1 - Horizon Pool Monitoring Script +Version: 1.5 +Written by: Charlie Silverman + +Purpose: Detects Horizon pools that have provisioning disabled and sends e-mail to recipients. +Command Line Options: + + -credential - Configure and store Horizon server credentials. This will only store the credentials under the + current logged in user. + -test - Output results to the screen and do not send e-mail. + -help - Display command help. +#> +$ScriptName = "KISPoolChecker.ps1" +$ScriptVersion = "1.5.1" +$test = $false +$debug = $false +$now = Get-Date +$mypath = Split-Path $MyInvocation.MyCommand.Path -Parent +$configFile = $mypath + "\KISPoolChecker.cfg" +$logFile = $mypath + "\KISPoolChecker.log" + +# Process command line parameters +for ( $i = 0; $i -lt $args.count; $i++ ) { + Switch ($args[$i]) { + "-credential" { + $credential = Get-Credential + $credential | Export-Clixml -path $env:USERPROFILE\User-Horizon.cred + Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "Credential entry stored`r`n`r`n" + exit + } + "-smtpcredential" { + $credential = Get-Credential + $credential | Export-Clixml -path $env:USERPROFILE\User-SMTP.cred + Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "Credential entry stored`r`n`r`n" + exit + } + "-test" { + $test = $true + Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "Test flag set" + } + "-debug" { + $debug = $true + Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "Debug flag set" + } + "-help" { + Write-Host + Write-Host + Write-Host "**********************************************************" -ForegroundColor Yellow + Write-Host "** **" -ForegroundColor Yellow + Write-Host "** KISPoolChecker.ps1 - Horizon Pool Monitoring Script **" -Foregroundcolor Yellow + Write-Host "** Version: $ScriptVersion **" -Foregroundcolor Yellow + Write-Host "** Written by: Charlie Silverman **" -Foregroundcolor Yellow + Write-Host "** **" -ForegroundColor Yellow + Write-Host "**********************************************************" -ForegroundColor Yellow + Write-Host + Write-Host "Purpose: Detects Horizon pools that have provisioning disabled and sends e-mail to recipients." + Write-Host "Command Line Options:" + Write-Host + Write-Host " -credential - Configure and store Horizon server credentials. This will only store the credentials under" + Write-Host " the current logged in user." + Write-Host " -smtpcredential - (Optional) Configure and store SMTP server credentials. This will only store the credentials" + Write-Host " under the current logged in user." + Write-Host " -test - Output results to the screen and do not send e-mail." + Write-Host " -help - Display command help." + Write-Host + Write-Host + Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "Help info requested" + exit + } + } +} + +# Read configuration file +try { + $inifile = Get-Content($configFile) -ErrorAction Stop | ConvertFrom-StringData -ErrorAction SilentlyContinue +} Catch { + Write-Host "Error reading from $configFile configuration file." -Backgroundcolor Red -ForegroundColor Yellow + Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "ERROR: Unable to read config file $configFile`r`n`r`n" + exit +} +$orgName = $inifile.OrganizationName +$hzServer = $inifile.HorizonServer +$mailServer = $inifile.SMTPServer +$mailFrom = $inifile.SMTPFromconnec.B +$mailTo = $inifile.SMTPTo +$mailSSL = $false +$mailPort = 25 +if (Test-Path Variable:\$inifile.SMTPSSL) { + if ($inifile.SMTPSSL.ToLower() -eq "true") { + $mailSSL = $true + } + if ($inifile.SMTPPort -ne $null) { + $mailPort = $inifile.SMTPPort + } +} +$logFile = $mypath + "\KISPoolChecker.log" + +# Reformat email recipient list +$mtlist = $mailTo -split "," +$mailRecipients = @() +for ( $i = 0; $i -lt $mtlist.count; $i++ ) { + $mailRecipients += $mtlist[$i].Trim(); +} + +Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "*** Script initiated $now" + +# Load Credentials +$credential = import-clixml -path $env:USERPROFILE\User-Horizon.cred +try { + $mailCredential = import-clixml -path $env:USERPROFILE\User-SMTP.cred -ErrorAction Stop +} catch { + $mailCredential = $null +} + +# Log into Horizon +try { + $horizon = Connect-HVServer -server $hzServer -Credential $credential + If ($debug) { + Write-Host "Connected to Horizon Server $hzServer" + } + Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "Connected to Horizon Server $hzServer" +} catch { + Write-Host "ERROR: Failed to connect to Horizon Server $hzServer" -Backgroundcolor Red -ForegroundColor Yellow + If ($debug) { + Write-Host "Connected to Horizon Server $hzServer" + } + Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "ERROR: Failed to connect to Horizon Server $hzServer`r`n`r`n" +} +$Services1 = $Global:DefaultHVServers.ExtensionData + +# Get Horizon pool list +$pools = Get-HVPool + +$results = "" +If ($debug) { + Write-Host "Inspecting pools" +} +Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "Inspecting pools" +# Check each pool for enabled, automated pools with provisioning disabled +foreach ($pool in $pools) { + $poolName = $pool.Base.Name + $poolType = $pool.Type + $poolEnabled = $pool.DesktopSettings.Enabled + $provisioningEnabled = $pool.AutomatedDesktopData.VirtualCenterProvisioningSettings.EnableProvisioning + $poolError = $pool.AutomatedDesktopData.ProvisioningStatusData.LastProvisioningError + $poolErrorTime = $pool.AutomatedDesktopData.ProvisioningStatusData.LastProvisioningErrorTime + if (($poolType -eq "AUTOMATED") -and !$provisioningEnabled -and $poolEnabled) { + $results = $results + "Pool " + $poolName + " has provisioning disabled.`r`n" + $results = $results + "-- Last error: " + $poolError + "`r`n" + $results = $results + "-- Error Time: " + $poolErrortime + "`r`n" + If ($debug) { + Write-Host "Found pool $poolName with provisioning disabled" + Write-Host "-- Last error: " + $poolError + Write-Host "-- Error Time: " + $poolErrortime + } + Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "Found pool $poolName with provisioning disabled" + Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "-- Last error: $poolError" + Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "-- Error Time: $poolErrortime" + } +} + +# Output test results or send e-mail +if ($test) { + if ($results -ne "") { + Write-Host Results: + Write-Host $results + } else { + Write-Host No pools found with provisioning disabled. + } +} else { + if ($results -ne "") { + try { + $smtpCred = "" + $smtpSSL = "" + If ($mailCredential -ne $null) { + $smtpCred = " -credential $mailCredential" + } + if ($mailSSL -eq $true) { + $smtpSSL = " -UseSsl" + } + $results = $orgName + "KIS Pool Checker v" + $ScriptVersion + "`r`n`r`n" + $results + $results = $results + "`r`n`r`n" + $now + if ($debug) { + If ($mailCredential -ne $null) { + if ($mailSSL -eq $true) { + Write-Host Send-MailMessage -SmtpServer $mailServer -UseSSL -Port $mailPort -credential $mailCredential -From $mailFrom -To $mailRecipients -subject "$orgName KIS Pool Checker - Pool Provisioing Disabled" -body $results -ErrorAction Stop + } else { + Write-Host Send-MailMessage -SmtpServer $mailServer -Port $mailPort -credential $mailCredential -From $mailFrom -To $mailRecipients -subject "$orgName KIS Pool Checker - Pool Provisioing Disabled" -body $results -ErrorAction Stop + } + } else { + if ($mailSSL -eq $true) { + Write-Host Send-MailMessage -SmtpServer $mailServer -UseSSL -Port $mailPort -From $mailFrom -To $mailRecipients -subject "$orgName KIS Pool Checker - Pool Provisioing Disabled" -body $results -ErrorAction Stop + } else { + Write-Host Send-MailMessage -SmtpServer $mailServer -Port $mailPort -From $mailFrom -To $mailRecipients -subject "$orgName KIS Pool Checker - Pool Provisioing Disabled" -body $results -ErrorAction Stop + } + } + } + If ($mailCredential -ne $null) { + if ($mailSSL -eq $true) { + Send-MailMessage -SmtpServer $mailServer -UseSSL -Port $mailPort -credential $mailCredential -From $mailFrom -To $mailRecipients -subject "$orgName KIS Pool Checker - Pool Provisioing Disabled" -body $results -ErrorAction Stop + } else { + Send-MailMessage -SmtpServer $mailServer -Port $mailPort -credential $mailCredential -From $mailFrom -To $mailRecipients -subject "$orgName KIS Pool Checker - Pool Provisioing Disabled" -body $results -ErrorAction Stop + } + } else { + if ($mailSSL -eq $true) { + Send-MailMessage -SmtpServer $mailServer -UseSSL -Port $mailPort -From $mailFrom -To $mailRecipients -subject "$orgName KIS Pool Checker - Pool Provisioing Disabled" -body $results -ErrorAction Stop + } else { + Send-MailMessage -SmtpServer $mailServer -Port $mailPort -From $mailFrom -To $mailRecipients -subject "$orgName KIS Pool Checker - Pool Provisioing Disabled" -body $results -ErrorAction Stop + } + } + If ($debug) { + Write-Host "E-mail sent successfully to $mailTo" + } + Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "E-mail sent successfully to $mailTo" + } catch { + Write-Host "Error: Unable to send e-mail." -Backgroundcolor Red -ForegroundColor Yellow + Write-Host $_.Exception.Message -Backgroundcolor Red -ForegroundColor Yellow + If ($debug) { + Write-Host "ERROR: Unable to send e-mail`r`n" + } + Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "ERROR: Unable to send e-mail`r`n`r`n" + Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject $_.Exception.Message + } + } else { + Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "No pools with issues found. No e-mail sent.`r`n`r`n" + } +} +$now = Get-Date +Out-File -FilePath $logFile -Encoding ASCII -Append -InputObject "*** Script completed $now`r`n`r`n" diff --git a/Windows Tools/IOC_Checker.ps1 b/Windows Tools/IOC_Checker.ps1 new file mode 100644 index 0000000..0daa6a1 --- /dev/null +++ b/Windows Tools/IOC_Checker.ps1 @@ -0,0 +1,35 @@ +$scriptVersion = "1.0.0" +$scriptDate = "2025-08-19" + +# Display Script Banner +Write-Host "--------------------------------------------------" -ForegroundColor White +Write-Host "Windows IOC & Encryption Checker" -ForegroundColor Green +Write-Host "Version $($scriptVersion) ($($scriptDate))" -ForegroundColor Green +Write-Host "Written by Charlie Silverman" -ForegroundColor Green +Write-Host "--------------------------------------------------" -ForegroundColor White + +Write-Host "Scanning for IOCs... " -NoNewLine +$fileList = @("crackmapexec", "kerbrute", "Anydesk", "IamBatMan", "stealer_cli_v2", "rclone", "nmap", "netscan", "mimikatz", "vmxojj", "zfewtu", "xigglo", "qfvtwz", "gkoou", "ofczqp", "videotomp3setup", "amd64.exe", "BaTrCk.exe", "232.bat", "tdsskiller.bat", "killdeff.bat", "logdel.bat", "bdfd47.lock", "processhacker.exe", "PCHunter64.exe", "win_locker.exe", "win_locker.ex_", "netscan.exe", "Syncovery.exe") +$searchDirectory = "C:\" +$files = Get-ChildItem -Path $searchDirectory -Recurse -Include $fileList | Select-Object FullName, LastWriteTime +if ($files.Count -gt 0) { + $files | Export-Csv -Path "C:\IOCScan.csv" -NoTypeInformation + Write-Host "$($files.Count) matching files found." -ForegroundColor Yellow -BackgroundColor Red + Write-Host "File list written to C:\IOCScan.csv" +} else { + Write-Host "No IOCs found." -ForegroundColor Green +} + +$drives = Get-PsDrive | Where-Object {$_.Root -like "?:\" -and $_.Used -gt 0} | Select-Object Root +foreach ($drive in $drives) { + $dpath = $drive.Root + Write-Host "Scanning drive $dpath for encrypted files.... " -NoNewLine + $foundfiles = Get-ChildItem -Path $dpath -Recurse -Include "*akira*" + if ($foundfiles.Count -gt 0) { + $foundfiles | Export-Csv -Path "C:\EncryptedFiles-$($dpath[0]).csv" + Write-Host "Found $($foundfiles.Count) encrypted files." -backgroundcolor Red -ForegroundColor Yellow + Write-Host "Encrypted file list exported to C:\EncryptedFiles-$($dpath[0]).csv" + } else { + Write-Host "No encrypted files found" -ForegroundColor Green + } +} \ No newline at end of file diff --git a/Windows Tools/IntuneAssessment.ps1 b/Windows Tools/IntuneAssessment.ps1 new file mode 100644 index 0000000..bf905df --- /dev/null +++ b/Windows Tools/IntuneAssessment.ps1 @@ -0,0 +1,172 @@ +<# +.SYNOPSIS + Intune Readiness Assessment Script + +.DESCRIPTION + Collects the minimum required device information for an Intune deployment: + - Computer Name + - Serial Number + - Manufacturer + - Model + - Windows Edition + - Windows Build + - TPM Status + - Secure Boot Status + - Domain Join Status + - Entra ID Join Status + - Primary User + - BitLocker Status + - Installed Applications Count + - Antivirus Product + +.NOTES + Run as Administrator for best results. +#> + +# Stop running if script is not run as Administrator +if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { + Write-Host "ERROR: Script must be run as administrator" -ForegroundColor Yellow -BackgroundColor Red -NoNewLine + Write-Host + Write-Host "Operation aborted." + exit +} + +# Get basic computer information +$ComputerSystem = Get-CimInstance Win32_ComputerSystem +$BIOS = Get-CimInstance Win32_BIOS +$OS = Get-CimInstance Win32_OperatingSystem + +# Computer Name +$ComputerName = $env:COMPUTERNAME + +# Serial Number +$SerialNumber = $BIOS.SerialNumber + +# Manufacturer and Model +$Manufacturer = $ComputerSystem.Manufacturer +$Model = $ComputerSystem.Model + +# Windows Information +$WindowsEdition = (Get-ComputerInfo).OsName +$WindowsBuild = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select-Object DisplayVersion).DisplayVersion + +# TPM Information +try { + $TPM = Get-Tpm + if ($TPM.TpmPresent) { + $TPMStatus = "Present" + $TPMVersion = ($TPM.ManufacturerVersion) + } + else { + $TPMStatus = "Not Present" + $TPMVersion = "N/A" + } +} +catch { + $TPMStatus = "Unknown" + $TPMVersion = "Unknown" +} + +# Secure Boot +try { + $SecureBoot = Confirm-SecureBootUEFI +} +catch { + $SecureBoot = "Unsupported/Legacy BIOS" +} + +# Domain Join Status +$DomainJoined = $ComputerSystem.PartOfDomain + +# Entra ID Join Status +$AzureADJoined = "Unknown" + +try { + $DsReg = dsregcmd /status + + if ($DsReg -match "AzureAdJoined\s*:\s*YES") { + $AzureADJoined = "Yes" + } + elseif ($DsReg -match "AzureAdJoined\s*:\s*NO") { + $AzureADJoined = "No" + } +} +catch { + $AzureADJoined = "Unable to Determine" +} + +# Primary User +$PrimaryUser = (Get-CimInstance Win32_ComputerSystem).UserName + +# BitLocker Status +try { + $BitLockerVolume = Get-BitLockerVolume -MountPoint "C:" + $BitLockerStatus = $BitLockerVolume.ProtectionStatus + + switch ($BitLockerStatus) { + 1 { $BitLockerStatus = "Protected" } + 0 { $BitLockerStatus = "Not Protected" } + default { $BitLockerStatus = "Unknown" } + } +} +catch { + $BitLockerStatus = "Unknown" +} + +# Installed Applications Count +try { + $AppCount = ( + Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* , + HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* ` + -ErrorAction SilentlyContinue | + Where-Object { $_.DisplayName } | + Measure-Object + ).Count +} +catch { + $AppCount = "Unknown" +} + +# Antivirus Product +try { + $AV = Get-CimInstance ` + -Namespace "root\SecurityCenter2" ` + -ClassName AntiVirusProduct ` + -ErrorAction Stop + + $AntivirusProduct = ($AV.displayName -join "; ") +} +catch { + $AntivirusProduct = "Not Detected" +} + +# Create Output Object +$Results = [PSCustomObject]@{ + ComputerName = $ComputerName + SerialNumber = $SerialNumber + Manufacturer = $Manufacturer + Model = $Model + WindowsEdition = $WindowsEdition + WindowsBuild = $WindowsBuild + TPMStatus = $TPMStatus + TPMVersion = $TPMVersion + SecureBootEnabled = $SecureBoot + DomainJoined = $DomainJoined + AzureADJoined = $AzureADJoined + PrimaryUser = $PrimaryUser + BitLockerStatus = $BitLockerStatus + InstalledApps = $AppCount + AntivirusProduct = $AntivirusProduct +} + +# Display Results +$Results | Format-List + +# Export Results +$OutputFile = "$env:PUBLIC\Documents\Intune_Readiness_$ComputerName.csv" + +$Results | Export-Csv -Path $OutputFile -NoTypeInformation + +Write-Host "" +Write-Host "Assessment complete." -ForegroundColor Green +Write-Host "Results exported to: $OutputFile" -ForegroundColor Cyan diff --git a/Windows Tools/KISGPOExport.ps1 b/Windows Tools/KISGPOExport.ps1 new file mode 100644 index 0000000..a88ef5d --- /dev/null +++ b/Windows Tools/KISGPOExport.ps1 @@ -0,0 +1,161 @@ +## +## KISGPOExport.ps1 - Export GPOs for an OU to file +## +## Created by Charlie Silverman - Keep IT Simple +## +## Version History: +## 1.1.0 - Added history +## 1.5.0 - Changed to put exported GPOs into a subfolder based on the OU name. +## 2.0.0 - Added functionality to process all parent OUs. Added help function. + +param ( + [switch]$Help = $false, + [switch]$Parents = $false +) + +function prettyPrintOU($ou) { + $myparts = $ou.split("/") + $result = "" + for ($counter = $myparts.length - 1; $counter -gt 0; --$counter) { + $result += "OU=" + $myparts[$counter] + "," + } + $domainparts = $myparts[0].split(".") + for ($counter = 0; $counter -lt $domainparts.length; ++$counter) { + $result += "DC=" + $domainparts[$counter] + if ($counter -lt $domainparts.length - 1) { $result += "," } + } + return $result +} + +$ScriptName = $MyInvocation.MyCommand.Path +$ScriptDate = Get-Item $ScriptName | select LastWriteTime +$ScriptDate = $ScriptDate.LastWriteTime +$ScriptVersion = "2.0.0" + +Write-Host "`r`n" +Write-Host "--------------------------------------------------------------" -ForegroundColor Gray +Write-Host " KISGPOExport.ps1" -ForegroundColor Green -NoNewLine +Write-Host " - Group Policy Export Script" -ForegroundColor White +Write-Host " Version $ScriptVersion - $ScriptDate" -ForegroundColor White +Write-Host " Written by" -ForegroundColor White -NoNewLine +Write-Host " Charlie Silverman - Keep IT Simple" -ForegroundColor Green +Write-Host "--------------------------------------------------------------" -ForegroundColor Gray +if ($Help) { + Write-Host + Write-Host "Purpose: Export Group Policy Objects to HTML for a given OU." + Write-Host "Command Syntax:" + Write-Host " KISGPOExport.ps1 (-parents) (-help)`n" -foregroundcolor green + Write-Host "Command Line Options:" + Write-Host + Write-Host -NoNewLine " -parents " -foregroundcolor Green + Write-Host "- Export GPOs for all parent OUs as well." + Write-Host -NoNewLine " -help " -foregroundcolor Green + Write-Host "- Display command help." +} + +$OUList = Get-ADOrganizationalUnit -Filter * -Properties CanonicalName | Select-Object CanonicalName | Sort-Object -Property CanonicalName +$prev = "" +$depth = 1 +$domainname = $OUList[0].CanonicalName.split("/")[0] +$lastpos = 5 +$toppos = 1 +$selected = 0 +$displaypage = 25 +$datestamp = Get-Date -Format FileDate +#$bottompos = $toppos + 19 +while ($selected -eq 0) { + Write-Host "`nSelect an OU to scan for linked GPOs:`n" + Write-Host "Domain: $domainname" + For ($x = $toppos-1; $x -lt $toppos + $displaypage - 1; $x++) { + if ($x -ge $OUList.length) { break } + $thisOU = $OUList[$x].CanonicalName + $OUParts = $thisOU.split("/"); + $spacing = " |" * ($OUParts.length - 2) + $spacing = "$spacing |__" + if ($depth -lt $OUParts.length - 1) { + $spacing = " |" * ($OUParts.length - 2) + $spacing += " |__" + } + $position = ([string]($x+1)).PadLeft(3) + ":" + Write-Host $position -NoNewLine -ForegroundColor Yellow + Write-Host "$spacing $($OUParts[$OUParts.length - 1])" + # for ($y = 1; $y -lt $OUParts.length; $y++ { + $depth = $OUParts.length + } + $selected = Read-Host -Prompt 'Select line number or P for Previous page, N for next page, or Q to quit [N]' + switch($selected.toLower()) { + "n" { + if ($toppos + $displaypage -lt $OUList.length) { + $toppos += $displaypage + if ($toppos -gt $OUList.length) { $toppos = $OUList.length - 1 } + } + $selected = 0 + } + "p" { + $toppos -= $displaypage + if ($toppos -lt 1) { $toppos = 1 } + $selected=0 + } + "q" { + exit + } + } + try { + $selected = [int]$selected + } catch { + $selected = 0 + } +} + +$selectedOU = prettyPrintOU($OUList[$selected-1].CanonicalName) +While (([regex]::Matches($selectedOU, "," )).count -gt 1) { + Write-Host "`n`nProcessing GPOs in $selectedOU`n" + $myou = Get-ADOrganizationalunit $selectedOU + $CNParts = $selectedOU.split(",") + $folderpath = ""; + for ($x = $CNParts.length - 1; $x -ge 0; --$x) { + $folderpath = "$folderpath\$($CNParts[$x])" + } + if (-not (Test-Path -Path "$pwd$folderpath")) { + $result = New-Item -ItemType Directory -Path "$pwd$folderpath" + } + $gpolist = $myou | Select-Object -ExpandProperty LinkedGroupPolicyObjects + $x = 1 + if ($gpolist -is [string]) { + $gpoguid = $gpolist.split("}")[0].split("{")[1] + try { + $thisgpo = Get-GPO -Guid $gpoguid + Write-Host "Exporting GPO " -NoNewLine -ForegroundColor DarkGray + Write-Host $thisgpo.DisplayName -NoNewLine + Write-Host "..." -NoNewLine -ForegroundColor DarkGray + Get-GPOReport -Guid $gpoguid -ReportType 'HTML' -Path "$pwd\$domainname - $($thisgpo.DisplayName) - 20230530.html" + Write-Host " Complete" -ForegroundColor Green + } catch { + Write-Host "ERROR PROCESSING" + } + } else { + Write-Host "There are a total of $($gpolist.length) GPOs linked to $selectedOU" + for ($x = 0; $x -lt $gpolist.length; ++$x) { + $thisgpo = [string]$gpolist[$x] + $gpoguid = $thisgpo.split("}")[0].split("{")[1] + try { + $thisgpo = Get-GPO -Guid $gpoguid + Write-Host "Exporting GPO " -NoNewLine -ForegroundColor DarkGray + Write-Host $thisgpo.DisplayName -NoNewLine + Write-Host "..." -NoNewLine -ForegroundColor DarkGray + + Get-GPOReport -Guid $gpoguid -ReportType 'HTML' -Path "$pwd$folderpath\$domainname - $($thisgpo.DisplayName) - $datestamp.html" + Write-Host " Complete" -ForegroundColor Green + } catch { + Write-Host "ERROR PROCESSING" + } + } + } + if ($Parents) { + $selectedOU = ($myou.distinguishedname -split ',', 2)[1] + } else { + $selectedOU = "" + } +} +Write-Host "`nOperation complete." +Write-Host "$x policies exported to HTML and stored in $pwd$folderpath"