Trying to figure out a way to export all GPO’s to a CSV so they can at some point be imported in to another domain as part of an MSP’s standard deployment methods via script instead of GUI.
Install-Module -Name GPRegistryPolicy -force
get-gpo -all | select DisplayName
#Let’s say for this example there are only three GPO’s
GPOTest_01
GPOProd_01
GPOFinance_01
Loop through all GPO’s
ForEach($GPO in $GPOList)
{
$gpoGuid = (Get-GPO -Name $GPO).Id.ToString()
$domainController = ‘DC01’
$domainName = ‘mycorp.com’
$registryPolPath = “\$domainController\sysvol$domainName\Policies{$gpoGuid}\Machine”
Get-ChildItem -Path $registryPolPath
$RegPolPath = Join-Path -Path $registryPolPath -ChildPath ‘registry.pol’
Parse-PolFile -Path $regPolPath
$regKeyInfo = Parse-PolFile -Path $regPolPath
}
CSV Output:
“DisplayName”,“KeyName”,“ValueName”,“ValueType”,“ValueData”
“GPOTest_01”,“HKLM\Software\Policies\Microsoft\W32time\Parameters”,“NtpServer”,“REG_SZ”,“time.windows.com,0x9”
“GPOTest_01”,“HKLM\Software\Policies\Microsoft\W32time\Parameters”,“Type”,“REG_SZ”,“NT5DS”
"KeyName : Software\Policies\Microsoft\W32time\Parameters
ValueName : NtpServer
ValueType : REG_SZ
ValueLength : 42
ValueData : time_windows_com,0x9
KeyName : Software\Policies\Microsoft\W32time\Parameters
ValueName : Type
ValueType : REG_SZ
ValueLength : 12
ValueData : NT5DS
$gpoName = ‘GPOTest’
New-GPO -Name $gpoName -Comment ‘GPO Test Automation’
$gpRegParams = @{
Name = $gpoName
Key = “HKLM$($regKeyInfo.KeyName)”
ValueName = $regKeyInfo.ValueName
Type = $regKeyInfo.ValueType
Value = $regKeyInfo.ValueData
}
Set-GPRegistryValue @gpRegParams