【发布时间】:2021-05-01 06:11:09
【问题描述】:
我习惯于在自动化脚本中使用%~dp0,以确保无论部署文件夹放在哪里都能找到我的文件。
%~dp0 在 PowerShell 中效果不佳,$PSScriptRoot 和 $PSCommandPath 对用户不友好
我可以让这段代码卸载并安装应用程序而不会出现任何问题。问题是我必须声明并不总是正确的文件位置。
很好,但必须声明位置。
$RmvAppName = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "chrome"}
$RmvAppName.Uninstall() | Out-Null
Start-Process msiexec.exe -ArgumentList '/i c:\deploy\microsoft\edge.msi /passive ALLUSERS=1' | Out-Null
如果我尝试使用对我不起作用的位置变量。我试过Set-Location、Get-Location、$PSScriptRoot、$PSCommandPath,但没有任何效果。我只是在 PowerShell 中寻找能够为我提供 %~dp0 的功能和 PowerShell 的强大功能的东西。
不好!
$RmvAppName = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "chrome"}
$location = Get-Location
$RmvAppName.Uninstall() | Out-Null
#Start-Process msiexec.exe -ArgumentList '/i $(location)\edge.msi /passive ALLUSERS=1'
提前感谢大家的帮助。
【问题讨论】:
标签: powershell-3.0 powershell-4.0