Powershell error

I keep getting this error:

PowerCLI C:\> "test.ps1" -AfterDate 08/21/2012 -FileName C:\Report.txt
You must provide a value expression on the right-hand side of the '-' operator.
At line:1 char:13
+ "test.ps1" - <<<< AfterDate 08/21/2012 -FileName C:\Report.txt
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx
    + FullyQualifiedErrorId : ExpectedValueExpression

I've changed the date several times. I'm assuming this is realated to the format of the date but I can't seem to get it to work.
Who is Participating?
dicconbConnect With a Mentor Commented:
Try .\test.ps1 with no quotes, ie:
.\test.ps1 -AfterDate 08/21/2012 -FileName C:\Report.txt

Open in new window

If quotes are required (eg if there are spaces in the file name), put an ampsersand in front, ie:
& ".\test.ps1" -AfterDate 08/21/2012 -FileName C:\Report.txt

Open in new window

The reason for the original error is that powershell is interpreting "test.ps1" as a string rather than the name of a script that it should execute.


Try taking the quotes out from around script filename.


xmouserAuthor Commented:
That's how I started:

Suggestion [3,General]: The command test.ps1 was not found, but does exist in th
e current location. Windows PowerShell doesn't load commands from the current lo
cation by default. If you trust this command, instead type ".\test.ps1". See "ge
t-help about_Command_Precedence" for more details.

That's why I put the quotes around it.

Also tried it with ".\test.ps1"
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

If I read (and count) it correctly it has to do with the "/" in the date.
xmouserAuthor Commented:
The script as posted at MS has it in the format that I'm using. There the example was 09/09/09. How should it be?
xmouserAuthor Commented:
I'm getting this:

PowerCLI C:\> & ".\test.ps1" -AfterDate 08/21/2012 -FileName C:\Report.txt
Missing closing ')' in expression.
At C:\test.ps1:40 char:12
+             <<<< [String]
    + CategoryInfo          : ParserError: (CloseParenToken:TokenId) [], Parse
    + FullyQualifiedErrorId : MissingEndParenthesisInExpression
slidingfoxConnect With a Mentor Commented:
Looks like your missing an ')' around line 40 of your script.
Thanks for the points,

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.