0

Simple issue, I'm trying to run the following command:

$d = ((Get-Date).AddMonths(-1)).ToString('MMM')
$filepath = "<<PATH>>\EOM " + $d + " " + $d.Year
New-Item $filepath -type directory

Path works correctly, that is a parameter set by an external program.

I can't get it to recognise the " " + $d.Year in the path, it just stops after $d. Is there an easy way I can get it to read the whole file path? At the moment It keeps creating a new folder ...\EOM Sep without the year.

1 Answer 1

1

There is no Year property of $d as you explicitly cast it to a string with ToString('MMM') Also instead of trying to concatenate spaces use a string format:

$d = ((Get-Date).AddMonths(-1))
$filepath = "<<PATH>>\EOM {0} {1}" -f $d.ToString('MMM'),$d.Year
New-Item $filepath -type Directory
Sign up to request clarification or add additional context in comments.

Comments

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.