Powershell function issue
Error I'm getting is the following
Missing closing '}' in statement block.
I'm using this to automate adding user to a .dat file which has hundreds
of user's for one of our systems. I was task with taking this part over
and well I don't like to do anything manually. So I wrote a script to do
95% of it for me and it removes user's just fine. But this function I'm
trying here adds the user in 2 different specific places to keep it nice
and net. I'm still learning powershell so any direction would be great and
you wont hurt my feelings I'm no pro nor novice here.
Function Add{
$username = Read-Host "User to add to REP01-02 Printing"
$LOCreportADD1 = "\\rep01\E$\orant\Report60\Server\cgicmd.dat"
$LOCreportADD2 = "\\rep02\e$\orant\Report60\Server\cgicmd.dat"
$Username1 = $username+": "
$prd = "prd: "
$userid = "userid="
$henation = "/henation@rmsprd %*"
$Text1 = get-content $LOCreportADD1
$Text2 = get-content $LOCreportADD2
$NewText1 = @()
foreach ($Line in $Text1) {
if ($Line -eq "Insert new user1") {
$Line = $Line.Replace("Insert new user1 \", "Insert new user1 \")
$NewText1 += $Line
$NewText1 += $username1+$userid+$username+$henation
}
Elseif ($Line -eq "New User2") {
$Line = $Line.Replace("New User2 \", "New User2 \")
$NewText12 += $Line
$NewText12 += $username+$prd+$userid+$username+$henation
}
$NewText1 | Set-Content $LOCreportADD1
}
No comments:
Post a Comment