Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Exporting User Objects to a CSV file ready for importing again?

$
0
0

Hi All,

I am extremely new to powershell but I am working on a script to export user objects from AD - effectively taking a backup of them and then I would like to be able to restore them using csvde or something from the CSV.  The trouble is the export-csv puts all stuff about activeroles server etc in it and my csvde command does not work when importing the CSV file.  Please can you provide assistance as to why this occurs? I can only think the Export-CSV command is doing something 'clever' with the user object.

My Code:

Add-PSSnapin quest.activeroles.admanagement | Out-Null
Connect-QADService | Out-Null

$Users = Get-QADUser -SearchRoot 'OU=SwattosUsers,DC=swatto,DC=home' -Sizelimit 0
foreach ($User in $Users)
{
$Username = $User.sAMAccountName
$Date = Get-Date -f dd.MM.yy_hh.mm.ss
[string]$Foldername = "$Username.$Date"
New-Item -Path c:\ArchivedUsers -ItemType Directory -Name $Foldername | Out-Null
$User | export-CSV "c:\ArchivedUsers\$Foldername\$Username.csv" -NoTypeInformation
}
Read-Host

Thanks for any help you can provide


Viewing all articles
Browse latest Browse all 8583

Trending Articles