Import GPO using CSV

by Sep 26, 2014

Hi Masters,

I have created PS script that nicely handling GPO links(import etc.) that working well, but
Do you have any ideia or give a hint, How can I develop this script better or simplier? Any idea would be appreciated

# The script:

Import-module ActiveDirectory
Import-Module GroupPolicy

$LogFile = "C:logimgpo.txt"

set-content $LogFile $NULL

# Importing csv
$gpo = import-csv c:data.csv -Delimiter ";" -Encoding UTF8 -header DIR,OU

# Loop and Importing GPO folders
foreach($dat in $gpo.dir) {Import-GPO –BackupGPOName $dat –TargetName $dat -path C:Applications -MigrationTable "C:GPO.table" –CreateIfNeeded | Out-File $LogFile -append}

# Loop and Importing new and set GPlinks
foreach($datn in $gpo.OU) {New-GPLink –name $datn –target $datn | Out-File $LogFile -append}
foreach($dats in $gpo.OU) {Set-GPLink –name $dats –target $dats –LinkEnabled Yes –Order 1 | Out-File $LogFile -append}

###############################################################################
The data.CSV file contains:

#DIR;OU
Application;OU=Application,OU=Servers,DC=life,DC=ad,DC=lifecomp,DC=com
Application01;OU=Application01,OU=Servers,DC=life,DC=ad,DC=lifecomp,DC=com
Application02;OU=Application02,OU=Servers,DC=life,DC=ad,DC=lifecomp,DC=com
Application03;OU=Application03,OU=Servers,DC=life,DC=ad,DC=lifecomp,DC=com
###############################################################################