我是PowerShell的新手,并了解cmdlet如何工作的细节。我有三条路,我想确保它们都有斜杠。下面的代码应该检查每个代码并附加一个\如果不存在,但它不会自己更改变量本身。
# append trailing slash if not present
$engineXCopyPath, $engineXBackupPath, $enlistmentBuildTargetPath | ForEach-Object {
if(!$_.EndsWith("\")) {
$_ += "\"
}
}
感谢您的帮助!
答案 0 :(得分:1)
以这种方式尝试:
# append trailing slash if not present
$engineXCopyPath, $engineXBackupPath, $enlistmentBuildTargetPath =
$engineXCopyPath, $engineXBackupPath, $enlistmentBuildTargetPath | ForEach-Object {
if(!$_.EndsWith("\")) {
$_ + "\"
}
else {
$_ # keep the original value if appending isn't needed
}
}