1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# Imports CSV, runs foreach condition, runs archive database move using key columns # Variable to folder location of csv file $inputCSV="C:\Scripts\EVMigration\EastBatch1.csv" # Variable to Import CSV using the cmdlet import-csv using the location variable created above $list=Import-Csv $inputCSV # Start a foreach condition to loop through the CSV imported. Foreach ($user in $list) #Condition to be ran - Example is a new mailbox move request { New-MoveRequest -Identity $user.LegacyDN -ArchiveTargetDatabase $user.ArchiveTargetDatabase -badItemLimit '20' -WarningAction "SilentlyContinue" -ArchiveOnly } |
Example:
1 2 3 4 5 6 7 |
# Imports CSV, runs foreach condition, runs archive database move using key columns $inputCSV="C:\Scripts\EVMigration\EastBatch1.csv" $list=Import-Csv $inputCSV Foreach ($user in $list) { New-MoveRequest -Identity $user.LegacyDN -ArchiveTargetDatabase $user.ArchiveTargetDatabase -badItemLimit '20' -WarningAction "SilentlyContinue" -ArchiveOnly } |
Exporting a foreach to CSV Example
1 2 3 4 5 6 |
# Imports CSV and runs foreach condition loop $test = import-csv \\sf1\user1\shared\elau\a.csv $list = @() foreach ($user in $test) {$list+= Get-Mailbox -id $user.legacydn | Select-Object primary*} $list | Export-CSV \\sf1\user1\shared\elau\output2.csv |