Reputation: 422
At First: Sorry for my Bad Englisch.
The Question:
NameOfUser
with the $User.Username entry of the csv File
b) Replace the Word EmailUser
with the $User.Email entry of the csv File
c) write a new file with the new Content to \UNC\Username\New-html-file.htmMy Problem: If i only Change one thing, Name or Email Adresse, the Output Works. If i put a second -replace into the foreach-object part, the output results in an error. I have to change 5 different Entrys and hope that i can fix it in one get-content | ..... step.
A Part of the Script:
$userfile = import-csv \\the-fileserver\User.csv
foreach ($User in $Userfile) {
Get-Content \\the-fileserver\File.htm | foreach-object {
$_ -replace 'Username', $User.Name
$_ -replace 'email-adresse', $User.Email
} | set-content -path $NewHTMFile
Problem: Each line appears 2 (or more equal to the -replace entries) Times in the $NewHTMFile :(
Thanks in Advance Daniel
Upvotes: 1
Views: 284
Reputation: 68293
Not tested, but I think this shouild work, and avoid a some chewing in the disk drive:
$userfile = import-csv \\the-fileserver\User.csv
$HTML = Get-Content '\\the-fileserver\File.htm'
foreach ($User in $Userfile)
{
$HTML -replace 'Username', $User.Name -replace 'email-adresse', $User.Email |
set-content -path $NewHTMFile
}
Upvotes: 1
Reputation: 60928
try
...
Get-Content \\the-fileserver\File.htm | foreach-object {
$_ -replace 'Username', $User.Name -replace 'email-adresse', $User.Email }
...
Upvotes: 1