I have created a script that will search all GPO's in the domain and parse only those which have Drive Map settings and writes the information to a .csv file. I have tried to figure out a way to get the GPOApplyOrder to no avail. The closest I have come to any sort of reasonable output is
"@{GPOSettingOrder=}", which is better than the nothing I had been getting. I think it would be really helpful if I could sort on the appy order so I could see the flow of the applied settings. Here is what I have.
# ==============================================================================================
#
# NAME: GetGPO_DriveMappings.ps1
#
# AUTHOR: Mike
# DATE: 6/17/2014
# Updated: 7/29/2014
#
# COMMENT: This script will get all the GPO's in the domain. It will parse only the GPO's that have drive map settings.
# The results are written to GetGPO_DriveMappings.csv
# This script is written to be run from the domain that the GPO(s) is in.
#
# NOTE: The script will not perform any group provisioning.
# ==============================================================================================
# set Variables and load assemblies
ImportSystemModules
Import-Module GroupPolicy
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$ScriptPath = "R:\Procedural Instructions\Scripts\Get AD Object Info"
# Get drive map settings from all GPOs.
Function Get-DriveMappings
{
# File listing the drive mappings via GPO.
$ExportFile = "GetGPO_DriveMappings.csv"
# Creates .csv file for logging.
$Header = "GPO Name,Drive Letter,Action,Apply Order,Drive Path,Group,OU,User"
Set-Content -Path $ScriptPath\$ExportFile -Value $Header
$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")
{
[xml]$DriveXML = Get-Content "\\$($GPODom)\SYSVOL\$($GPODom)\Policies\{$($GPOID)}\User\Preferences\Drives\Drives.xml"
ForEach ( $MapDrive in $DriveXML.Drives.Drive )
{
$GPOName = $GPODisp
$DriveLetter = $MapDrive.Properties.Letter + ":"
$DrivePath = $MapDrive.Properties.Path
$DriveAction = $MapDrive.Properties.action.Replace("U","Update").Replace("C","Create").Replace("D","Delete").Replace("R","Replace")
$GPOApplyOrder = $MapDrive | Select GPOSettingOrder
$Filters = $MapDrive.Filters
$FilterOrgUnit = $null
$FilterGroup = $null
$FilterUser = $null
ForEach ($FilterGroup in $Filters.FilterGroup)
{
$FilterGroupName = $FilterGroup.Name
ForEach ($FilterOrgUnit in $Filters.FilterOrgUnit)
{
$FilterOrgUnitName = $FilterOrgUnit.Name
$FilterOrgUnitName = $FilterOrgUnitName -Replace (",",";")
ForEach ($FilterUser in $Filters.FilterUser)
{
$FilterUserName = $FilterUser.Name
$ExportText = "$GPOName,$DriveLetter,$DriveAction,$GPOApplyOrder,$DrivePath,$FilterGroupName,$FilterOrgUnitName,$FilterUserName"
Add-Content -Path $ScriptPath\$ExportFile -value $ExportText
}
}
}
}
}
}
}
# --End of Function: Get-DriveMappings--------------------------
# Notifying that the scripted finished.
Function Script-Finished
{
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[Windows.Forms.MessageBox]::Show(“Script completed successfully”,"GetGPO_DriveMappings.ps", [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
}
# --End of Function: Script-Finished--------------------------
# Main Code:
# Execute the functions
$ErrorActionPreference="SilentlyContinue"
Get-DriveMappings
Script-Finished
$ErrorActionPreference="Stop"
Thanks to all in advance.