diff --git a/Audit.ps1 b/Audit.ps1 new file mode 100644 index 0000000..16fbb7e --- /dev/null +++ b/Audit.ps1 @@ -0,0 +1,72 @@ +param() + +$Computers = Get-ADComputer -Filter { enabled -eq $true } -Properties ms-Mcs-AdmPwd,OperatingSystem,LastLogonTimeStamp,msLaps-EncryptedPassword + +#.CSS Style +$Header = '' + +#.Header +$Precontent = "

LAPS (Local Admin Password Solution)

" +$Precontent += "

Rapport d'avancement du déploiement du "+ (Get-Date -format "dd/MM/yyyy - HH:mm:ss") + "

" + +#.Grabing collection +[System.Collections.Generic.List[PSObject]]$result = @() +foreach ($cptr in $Computers) +{ + $LapsSet = $false + $LapsType = $null + + if ($cptr.'ms-Mcs-AdmPwd' -or $cptr.'msLaps-EncryptedPassword') + { + $LapsSet = $true + + if ($cptr.'ms-Mcs-AdmPwd') + { + $LapsType = "Legacy" + } + + if ($cptr.'msLaps-EncryptedPassword') + { + switch($LapsType) + { + "Legacy" { $LapsType += ' & Modern' } + Default { $LapsType = "Modern" } + } + } + } + + $object = [PSCustomObject][ordered]@{ + ComputerName = $cptr.sAMAccountName + OS = $Cptr.OperatingSystem + LAPS = $LapsSet + Type = $LapsType + LastLogon = [DateTime]::FromFileTime($cptr.LastLogonTimeStamp) + } + + $result.Add($object) + +} + +#.Exporting Result as html report +$TotalCptr = $Computers.Count - @(Get-ADDomainController -Filter *).count # @ in case of only one DC +$LapsDone = ($result | Where-Object { $_.LAPS -eq $true }).count +$LapsToDo = ($result | Where-Object { $_.LAPS -eq $False }).count +$LapsCover = [int]($LapsDone / $TotalCptr * 100) + +$Precontent += '

' +$Precontent += "

Progression : $LapsCover% - [fait = $LapsDone] [reste à faire = $LapsToDo]

" +$Precontent += '

' + +$reportHtml = $result | ConvertTo-Html -Fragment -PreContent $Precontent -Property @('ComputerName','OS','LAPS','Type','LastLogon') + +# $PSScriptRoot to export script in the same path in case of scheduled task +ConvertTo-Html -Body $reportHtml -Head $Header | Out-File $PSScriptRoot\LAPS-DailyReport-Laps.html -Force + +$result | Select-Object ComputerName,OS,LAPS,Type,LastLogon | Export-Csv $PSScriptRoot\LAPS-DailyReport-Laps.csv -Delimiter ";" -NoTypeInformation -Force \ No newline at end of file