2

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 enter image description here

4

1 回答 1

3

无论出于何种原因,您的字符串都包含双引号,所以这当然不起作用。删除它们,您应该会很好:

$logFolder = $settings.get_Item("LogFolder") -replace '^"|"$'
mkdir $logFlder

不过,您可能应该修复读取设置的代码。

另一种方法是使用Invoke-Expression,但我不推荐它。最好避免它。

于 2012-06-16T07:49:10.047 回答