重命名PowerShell中的扩展文件错误

时间:2019-07-23 07:33:39

标签: powershell

我想更改文件的扩展名。当我从PowerShell ISE执行代码时,它可以工作。但是当我在WinPE下执行它时,它返回此错误:

+ ... Found = $Job | Rename-Item -NewName { $_.Name.Replace('.que','.pro')}
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (P:\JOB\FS190723...WQ6BT602-A1.que:String) [Rename-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : RenameItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.RenameItemCommand

此输出在重命名文件之前。为了确保连接准备就绪,并且文件存在。

Connection Ready
P:\JOB\FS190723AG_1062E59622CA_AAA111222-A1.que
[xml]$Config_File = Get-Content .\ConfigUnit.xml
function PRO_JOB {
    if (Check_Connection_PRISM) {
        Write-Host "Connection Ready"
        $Job_Path = $Config_File.Automation_ConfigUnit.Path.JOB_Path
        $Job = Get-ChildItem -Path "$Job_Path\*$b_SN`_$b_MAC*.que"
        Write-Host $Job
        pause
        Write-Host "Rename file .que to .pro"
        $Job_Found = $Job | Rename-Item -NewName { $_.Name.Replace('.que','.pro')}
    }

0 个答案:

没有答案