考慮以下PowerShell代碼:PowerShell的找不到文件
IF(Test-Path -Path "C:\Windows\System32\File123")
{Remove-Item -Force -Path "C:\Windows\System32\File123"}
如果該代碼已在x86 PowerShell控制檯執行,下面的錯誤引發的Get-ChildItem:找不到路徑「C:\ Windows \ System32下\ File123',因爲它不存在。
但是,當代碼在x64 Powershell控制檯中運行時,該命令的行爲與預期相同。
是否有解決此問題的任何腳本化方法?
您可以使用'$ env:Processor_Architecture'查看答案中顯示的Powershell是x86還是x64。然後,你可以從'c:\ windows \ sysWOW64'(x86下的x64 env),'c:\ windows \ sysnative'(x86下的x64)或'c:\ windows \ system32'中選擇適當的'system32'每個env都是原生的)。 – Vesper