1

I'm having issues with the following PS script:

New-Item -name $InfoLog -path $LogPath -Name ("Info Log - ",$DateStamp," - ",$TimeStamp) -type file

It gives me the error-

Cannot bind parameter because parameter 'Name' is specified more than once. To provide multiple values to parameters that can accept multiple values, use the array syntax. For example, "-parameter value1,value2,value3".

Any ideas? I also tried it without the parentheses.

1
  • Does "New-Item" only accept one parameter for name? If so how can I make it so I can write out a file with the date and time as well as a string? Commented Jun 27, 2014 at 21:19

1 Answer 1

5

All PowerShell cmdlets accept only one argument per parameter. However, you passed two arguments to the -Name parameter of New-Item:

New-Item -name $InfoLog -path $LogPath -Name ("Info Log - ",$DateStamp," - ",$TimeStamp) -type file
# One argument ^^^^^^^^     Another argument ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Because this is an illegal function call, PowerShell is raising your error.


It looks like you meant to write this:

New-Item -Path $LogPath -Name "Info Log - $DateStamp - $TimeStamp" -Type File

The variables in the string "Info Log - $DateStamp - $TimeStamp" will be expanded into the values that they represent:

PS > $a = 123   
PS > $b = "abc"
PS > "$a -- $b"
123 -- abc

PS > 
Sign up to request clarification or add additional context in comments.

1 Comment

Ah! What a dumb mistake! Can't believe I missed that. Thank you, sorry for the waste of time. I have to wait 5 mins to give you the correct answer.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.