Reputation: 12318
I found this interesting behavior. Why could this happen
I am using the cmdlet New-Item for create a folder. If I write something like this it works
New-Item "D:\logeando9091" -type directory
I have a variable of type string. It contains the value of the path where I want the new folder.
Why when Use New-Item with this variable it fails?
New-Item $settings.get_Item("LogFolder") -type directory
Here is a screenshot
Upvotes: 2
Views: 2770
Reputation: 354446
Your string contains double quotes around it, for whichever reason, so of course this doesn't work. Remove them and you should be good:
$logFolder = $settings.get_Item("LogFolder") -replace '^"|"$'
mkdir $logFlder
You should probably fix the code that reads the setting, though.
Another way would be using Invoke-Expression
but I wouldn't recommend it. Better to avoid it.
Upvotes: 3