Hiya guys
After some guidance please.
I have a CSV with following details
MailboxName, PRFNAME,TempConstant
usera, a, usera.prf,TEMPLATEPRFUSER
userb, b, userb.prf,TEMPLATEPRFUSER
userc, c, userc.prf,TEMPLATEPRFUSER
Im after creating multiple copies of a prf file with the PRFNAME
Import-Csv $UsernamesCSV | % { Copy-Item "C:\TemplatePRF\Template.prf" "C:\TEST\$($_.NewPRFName)"}This creates multiple prfs named correctly based on the prfnames provided in the CSV
Now I want to search for mailboxname=TEMPLATEPRFUSER and replace to "MailboxName" from my csv.
so it will be
usera.PRF
ContentsMailboxname=user, a
userb.prf
contents
mailboxname=user, b
So the common field to replace will be TEMPALTEPRF but replace with the relevatnt mailboxname depending on prf name.
After looking around I found the following
Param (
#$List = "C:\TemplatePRF\mailbox.csv",
$Files = "c:\Test\*.prf"
)
$ReplacementList = Import-Csv $UsernamesCSV;
Get-ChildItem $Files |
ForEach-Object {
$Content = Get-Content -Path $_.FullName;
foreach ($ReplacementItem in $ReplacementList)
{
$Content = $Content.Replace($ReplacementItem.TEMPConstant, $ReplacementItem.mailboxn)
}
Set-Content -Path $_.FullName -Value $Content
}At the moment all the files will then have the content "mailboxname=" set as user,a and it does not seem to loop through the remaining and replace correctly.