【发布时间】:2019-10-25 20:24:37
【问题描述】:
PowerShell 的$env:username 和[environment]::username 有什么区别以及为什么它们可能会返回不同的用户? (我知道还有其他方法可以获取当前用户)
一些背景:
我有一个在发布目标上运行 PowerShell 脚本的 Azure 管道。管道代理配置为在特定服务帐户下运行。该 PowerShell 脚本的一部分使用 $env:username 分配权限。但是,权限被分配给本地管理员帐户。如果我将脚本更改为使用[environment]::username,则会为正确的服务帐户用户授予权限。
【问题讨论】:
标签: powershell