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

Changing value in Array on the fly

$
0
0

Hi

Thanks for looking at my issue. I'm trying to setup a function that looks at the best DB to stick a mailbox in (this is a general PowerShell question though don't worry I'm not in the wrong forum).

So I've got a daily report that pushes out CSV that has Name, MbCount, MBSizeTotal, MBBlocks, MBBlocks free

So we have quotas and a block is just 1Gb and we want 500Gb DB's so each DB is made up of 500 Blocks. Just a way to logically assign them.

So I want to do this in a function

Import-CSV on the above CSV

Sort by most blocks free set that to bestDB and bestArcDB then in a for each loop setup a move request with the bestDB and bestArcDB values.

this is the bit I'm not sure what to do. I then need to break the Mailbox into blocks (most will be within quota) and Archive into blocks (totalGB divided by 1Gb) then have to change the value in that CSV for the next run on the ForEach loop. 

Does that make sense?

This is what I have so far. I'm guessing the right way to do it is to write back to the value in the $moveDetails array and then after done write to an after processing csv file to preserve the original one.

 

$dateToday=Get-Date-Format yyMMdd
$dbmap=import-csv"DBMap-$datetoday.csv"
$mbdbs=$dbmap | Where-Object { $_.Database-like"DAG01*"-or$_.Database-like"DAG02*" }
$arcdbs=$dbmap | Where-Object { $_.Database-like"DAG03*" }
$dbMapbestMB=$mbdbs | Sort -Descending"Blocks Free" | Select -First 1

#Setup new batch
$movefile="D:\Exchange2013\Migration\Batches\UK2013-2.csv"
$moveDetails=Import-Csv$movefile
$batchName= (Get-ChildItem$movefile).BaseName
$moveLogFile="D:\Exchange2013\Migration\Batches\MoveLogs\MoveLog-$batchName.txt"

ForEach ($movein$moveDetails){
New-MoveRequest-Identity$($move.Mailbox) -BatchName$($batchName) -TargetDatabase$($move.MBDB) -ArchiveTargetDatabase$($move.ArcDB)`
-BadItemLimit 50 -CompleteAfter"05/11/16 02:00"-ErrorAction Silent

Write-Output"Moving $($move.Mailbox) to $($move.MBDB) and Archive to $($move.ArcDB) in Batch $($batchName) " | Out-file$moveLogFile-Append
}

Viewing all articles
Browse latest Browse all 6937

Trending Articles