Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Idea
- #Replace values
- #Give a CSV with old value, new value
- #Replace a single value
- #
- #
- Function Update-OCSXML {
- param(
- $BuddyListFile="A:\Export-Updated.xml",
- $NameMatchingFile="C:\Users\sowen\Dropbox\Docs\foxDeploy.com\Contoso\Contoso - Source Disabled Users with OCS Accounts - Disable OCS - 20141002.csv",
- $OutFile = ("A:\temp\" + (get-date -UFormat %Y%m%d_%H%M) + "_UpdatedOSCSXML.xml")
- )
- begin{
- $i=0
- Write-host "Importing contents of `$BuddyListFile......" -NoNewline
- $FileInMemory = Get-Content $BuddyListFile
- Write-host "[OK]" -ForegroundColor Green
- $starttime = get-date
- if ($NameMatchingFile){
- Write-host "Importing contents of `$NameMatchingFile..." -NoNewline #I'm doing two Where's instead of one, this makes it faster somehow
- $NameMatchingFile = import-csv $NameMatchingFile | ? {$_."msRTCSIP-PrimaryUserAddress"}| ? {$_.mail} |select @{Name=‘Source‘;Expression={$_.'msRTCSIP-PrimaryUserAddress'}},@{Name=‘Target‘;Expression={$_.mail}}
- Write-host "[OK]" -ForegroundColor Green
- }
- #EndOfBeginning
- }
- process{
- if ($NameMatchingFile){
- ForEach ($name in $NameMatchingFile){
- $i++
- $nowTime = get-date
- $projectedTime = ($nowTime - $startTime).Seconds / $i * ($NameMatchingFile.Count - $i)
- if ($projectedTime -gt [math]::Abs(60)){$projectedText = ([math]::Round(($projectedTime / 60),2), " minutes" -join " ")}
- ELSE{$projectedText = (([math]::Round($projectedTime,2))," seconds" -join " ")}
- $percent = [math]::Round(($i/($NameMatchingFile.count)*100),2)
- Write-Progress -Activity ("Processing record $i of " + $NameMatchingFile.Count + "| Projected time remaining: $projectedText") -PercentComplete $percent -Status "$percent`% Completed" -CurrentOperation ("Replacing " + $name.Source + " with " +$name.Target +"...")
- #Replace $nameA with $nameB
- $FileInMemory = $FileInMemory -replace $name.Source,$name.Target
- $lastTime = $nowTime
- }
- }
- #EndOfProcess
- }
- end{
- #Remove references to ContosoAd
- Write-host ("Replacing Contosoad.Contoso.com with Contoso.com..." ) -NoNewline
- $FileInMemory = $FileInMemory -replace 'Contosoad.Contoso.com','Contoso.com'
- Write-host "[OK]" -ForegroundColor Green
- "Outputting file $Outfile"
- $FileInMemory | Out-File $OutFile
- }
- #EndOfFunction
- }
- Update-OCSXML
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement