Powershell Error with Multiline Command Call - Missing Expression After Unary Operator '-'

Powershell Error with Multiline Command Call - Missing Expression After Unary Operator '-'

I've called the following command, using backticks to place the parameters on separate lines

Create-WebSite -Name $targetWebSite ` 
    -Location $targetWebSiteDir

However this is returning the following error:

- <<<< Location $targetWebSiteDir ` [<<==>>] Exception: Missing expression after unary operator '-'.

2 Answers

This turned out to be caused by a space being present after the backtick (`) character.

So,

Create-WebSite -Name $targetWebSite ` <- SPACE HERE
    -Location $targetWebSiteDir

became

Create-WebSite -Name $targetWebSite `<- NO SPACE
    -Location $targetWebSiteDir

Once I removed the space everything ran correctly.

0

I have resolved this issue by using \ at end of line or we can remove spaces. For you it could

Create-WebSite -Name $targetWebSite `\ 
    -Location $targetWebSiteDir
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.