Questions tagged «cmdlet»

17
如何获取正在执行的cmdlet的当前目录
这应该是一个简单的任务,但是我已经看过几次尝试如何成功获取到执行的cmdlet所在目录的路径。例如,当我执行时C:\temp\myscripts\mycmdlet.ps1有一个设置文件时,C:\temp\myscripts\settings.xml我希望能够存储C:\temp\myscripts在中的变量中mycmdlet.ps1。 这是一种可行的解决方案(尽管有点麻烦): $invocation = (Get-Variable MyInvocation).Value $directorypath = Split-Path $invocation.MyCommand.Path $settingspath = $directorypath + '\settings.xml' 另一个人建议此解决方案仅在我们的测试环境中有效: $settingspath = '.\settings.xml' 我非常喜欢后一种方法,而不是每次都必须将文件路径解析为参数,但我无法使其在我的开发环境中正常工作。我该怎么办?它与PowerShell的配置有关吗?
202 powershell  cmdlet 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.