problem with _ when running script in powershell
am trying to create users by importing their details saved in csv format. please find below the script
Import-csv xyz.csv | foreach { New-Mailbox -name $_.FirstName -Alias $_.FirstName -FirstName $_.FirstName -LastName $_.LastName -UserPrincipalname "$($_.FirstName)@test.com" -OrganizationalUnit Users -Password $Password -Database "Mailbox Database" -ResetPasswordOnNextLogon $True }
but it keeps giving me the following error. you must provide a value expression on the right-hand side of the '-f' operator
.You must provide a value expression on the right-hand side of the '-f' operator.At script1.ps1:2 char:16+ $_.FirstName -Fi <<<< rstName $_.FirstName -LastName $_.LastName -UserPrincipalname
how do i handle the _ symbol whenrunning powershell scripts?
October 3rd, 2008 5:15pm
Backtick (') is escape character in powershell.
you can read more about it here: http://technet.microsoft.com/en-us/library/bb978698.aspx
Free Windows Admin Tool Kit Click here and download it now
October 4th, 2008 3:12am
the page has been removed or no longer available. at what point should i use the ' character
October 4th, 2008 11:45am
Sorry the site was down when you must have checked. The page is working now and you can check it for examples.
Free Windows Admin Tool Kit Click here and download it now
October 5th, 2008 7:22pm
Put your powershell code in single line insead of spanning into multiple lines and check... I just tested and worked for me.
Code Snippet
Import-csv xyz.csv | foreach { New-Mailbox -name $_.FirstName -Alias $_.FirstName -FirstName $_.FirstName -LastName $_.LastName -UserPrincipalname "$($_.FirstName)@test.com" -OrganizationalUnit Users -Password $Password -Database "Mailbox Database" -ResetPasswordOnNextLogon $True }
October 7th, 2008 8:05pm