17 lines
981 B
PowerShell
17 lines
981 B
PowerShell
#Variables
|
|
$OutputDirectory = "$Env:windir\temp"
|
|
$CSVOutput1 = "$Env:windir\temp\$env:computername Local Users.csv"
|
|
$CSVOutput2 = "$Env:windir\temp\$env:computername Users in Local Administrators Group.csv"
|
|
|
|
#Create output directory if it doesn't exist
|
|
If ((Test-Path $OutputDirectory) -eq $False) { New-Item -ItemType directory -Path $OutputDirectory }
|
|
|
|
#Remove existing CSV output files to prevent possible issues(just in case)
|
|
If ((Test-Path $CSVOutput1 -ErrorAction SilentlyContinue) -eq $True) { Remove-Item $CSVOutput1 -Force }
|
|
If ((Test-Path $CSVOutput2 -ErrorAction SilentlyContinue) -eq $True) { Remove-Item $CSVOutput2 -Force }
|
|
|
|
#To see if the local user(s) are enabled
|
|
Get-LocalUser | Select-Object Enabled, Name | Export-Csv -Path $CSVOutput1 -Append -NoType
|
|
|
|
#To find all the users in the local Administrators group on a computer, domain and local users
|
|
Get-LocalGroupMember -Group "Administrators" | Select-Object Name | Export-Csv -Path $CSVOutput2 -Append -NoType |