Forum Discussion
bala08yuvaraj
Oct 14, 2024Copper Contributor
Powershell GPO
Need a gpo script to find the value of multiple policy settings For example Computer Configuration\Windows Settings\Security Settings\Local Policies\User Rights Assignment Computer Configuratio...
sdtslmn
Nov 04, 2024MCT
# Define the policies you want to retrieve
$policiesToRetrieve = @(
"SeInteractiveLogonRight", # Log on locally
"SeDenyInteractiveLogonRight" # Deny log on locally
)
# Temporary file path for secedit export
$tempFilePath = "$env:TEMP\gpo_security_config.inf"
# Run secedit to export security settings
secedit /export /cfg $tempFilePath /quiet
# Check if the file was created successfully
if (Test-Path -Path $tempFilePath) {
# Initialize a hashtable to store policy values
$policyValues = @{}
# Read and parse the INF file
foreach ($line in Get-Content -Path $tempFilePath) {
foreach ($policy in $policiesToRetrieve) {
if ($line -match "^$policy\s*=\s*(.+)$") {
$policyValues[$policy] = $matches[1].Trim()
}
}
}
# Display the retrieved policy values
foreach ($policy in $policyValues.Keys) {
Write-Output "$policy: $($policyValues[$policy])"
}
# Cleanup - Remove the temporary file
Remove-Item -Path $tempFilePath -Force
} else {
Write-Output "Failed to export security configuration."
}