【发布时间】:2016-05-12 10:24:42
【问题描述】:
我正在 PowerShell 中创建一个脚本,该脚本应该找到用户的 UPM 文件夹并将 .old 附加到它(以促进配置文件重建)。
下面的sn-p是我的代码:
# Rename the UPM profile
Exit-PSSession
cd '\\SYLX-FS-01\D$\UPMProfiles'
$UPMPath = "$target.upm"
$UPMOld = "$target.upm.old"
if (Test-Path $UPMPath -IsValid) {
if (Test-Path $UPMOld -IsValid) {
Remove-Item $UPMOld
Rename-Item $UPMPath -NewName $UPMOld
Write-Host "Renamed UPMProfile"
} else {
Rename-Item $UPMPath -NewName $UPMOld
Write-Host "Renamed UPMProfile"
}
} else {
# Write-Host "UPM Profile not found, no action has been taken on the file server."
$UPM = "False"
}
每次我运行它都会返回一个找不到文件的错误。
删除项目:找不到路径 '\\SYLX-FS-01\D$\UPMProfiles\bill.odwyer.upm.old' 因为它不存在。 在行:8 字符:20 + 删除项目据我所知,如果
$UPMPath存在,它应该只转到第 8 行,如果不存在,那么它应该跳到else。我错过了什么?
【问题讨论】:
标签: powershell