GPPrefs are great – but in true MS fashion – they are very much a bolt-on from when they were acquired many years ago – and the ability to script reading values (let alone creation) is somewhere limited due to this.
This dude made a fantastic script to document GPPref drive mappings here
You should be able to go to the link above for the original script, i have a slightly updated version below, which outputs the content to a CSV instead of to screen.
<#
.SYNOPSIS
The script finds the GPP Drive Maps in your domain.
.NOTES
File Name: Get-GPPDriveMaps.ps1
Author : Johan Dahlbom, johan[at]dahlbom.eu
The script are provided “AS IS” with no guarantees, no warranties, and it confer no rights.
#>
#Import the required module GroupPolicy
try
{
Import-Module GroupPolicy
}
catch
{
throw “Module GroupPolicy not Installed”
}
$GPO = Get-GPO -All
foreach ($Policy in $GPO){
$GPOID = $Policy.Id
$GPODom = $Policy.DomainName
$GPODisp = $Policy.DisplayName
if (Test-Path “\\$($GPODom)\SYSVOL\$($GPODom)\Policies\{$($GPOID)}\User\Preferences\Drives\Drives.xml”)
{
$DriveXML = Get-Content “\\$($GPODom)\SYSVOL\$($GPODom)\Policies\{$($GPOID)}\User\Preferences\Drives\Drives.xml”
foreach ( $drivemap in $DriveXML.Drives.Drive ) {
$GPOName = $GPODisp
$DriveLetter = $drivemap.Properties.Letter + “:”
$DrivePath = $drivemap.Properties.Path
$DriveAction = $drivemap.Properties.action.Replace(“U”,”Update”).Replace(“C”,”Create”).Replace(“D”,”Delete”).Replace(“R”,”Replace”)
$DriveLabel = $drivemap.Properties.label
$DrivePersistent = $drivemap.Properties.persistent.Replace(“0″,”False”).Replace(“1″,”True”)
$DriveFilterGroup = $drivemap.Filters.FilterGroup.Name
Add-Content -Value “$GPOName,$DriveLetter,$DrivePath,$DriveAction,$DriveLabel,$DrivePersistent,$DriveFilterGroup” -Path C:\Temp\GPODriveMaps.csv
}
}
}
In addition, i used this script as a base to make one that will document printer mappings from GPPrefs
<#
.SYNOPSIS
The script finds the GPP Printer Maps in your domain.
.NOTES
File Name: Get-GPPPrinterMaps.ps1
The script are provided “AS IS” with no guarantees, no warranties, and it confer no rights.
#>
#Import the required module GroupPolicy
try
{
Import-Module GroupPolicy -ErrorAction Stop
}
catch
{
throw “Module GroupPolicy not Installed”
}
$GPO = Get-GPO -All
foreach ($Policy in $GPO){
$GPOID = $Policy.Id
$GPODom = $Policy.DomainName
$GPODisp = $Policy.DisplayName
if (Test-Path “\\$($GPODom)\SYSVOL\$($GPODom)\Policies\{$($GPOID)}\User\Preferences\Printers\Printers.xml”)
{
foreach ( $PrinterMap in $PrinterXML.Printers.SharedPrinter) {
$GPOName = $GPODisp
$PrinterName = $PrinterMap.name
$PrinterPath = $PrinterMap.Properties.path
$PrinterAction = $PrinterMap.Properties.action.Replace(“U”,”Update”).Replace(“C”,”Create”).Replace(“D”,”Delete”).Replace(“R”,”Replace”)
$PrinterDefault = $PrinterMap.Properties.default.Replace(“0″,”False”).Replace(“1″,”True”)
$PrinterFilterGroup = $PrinterMap.Filters.FilterGroup.name
Add-Content -Value “$GPOName,$PrinterName,$PrinterPath,$PrinterAction,$PrinterDefault,$PrinterFilterGroup” -Path C:\Temp\GPOPrinterMaps.csv
}
}
}