【发布时间】:2016-10-06 15:58:31
【问题描述】:
在我们的公司环境中,我在创建 PowerShell 配置文件脚本时遇到了困难。
为了防止用户在本地磁盘上写入文档,“文档”目录被强制位于网络驱动器上。通常是“H:”(家庭)驱动器。
同样禁止用户在C:\Windows\System32下写入。
如果这两个不可用,我可以将 ISE 配置文件脚本放在哪里?
PSVersion 5.0.10586.117
PS C:\Windows\System32\WindowsPowerShell\v1.0> $HOME, $PSHOME
C:\Users\pwatson
C:\Windows\System32\WindowsPowerShell\v1.0
另请参阅:Help-About about_Profiles
当我没有连接到网络时,这些是 $profile 设置。我仍然无法在 C:\Windows\System32 下写入,CurrentUser 值无效。
PS C:\Windows\System32\WindowsPowerShell\v1.0> $profile | Get-Member -Type NoteProperty | ForEach-Object {$_.ToString
()}
string AllUsersAllHosts=C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
string AllUsersCurrentHost=C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
string CurrentUserAllHosts=WindowsPowerShell\profile.ps1
string CurrentUserCurrentHost=WindowsPowerShell\Microsoft.PowerShell_profile.ps1
PS C:\Windows\System32\WindowsPowerShell\v1.0>
【问题讨论】:
-
据我所知,您是此环境中的用户还是管理员?为什么用户需要对脚本的写入权限?
-
@wOxxOm - 这不是微软文档所说的可以放置脚本的地方。你知道这行得通吗?
-
@Kage - 我是用户。这是我的开发机器。我有“管理员”权限,但不能在 System32 下写。
-
@Liturgist,不,它没有用,我已经删除了评论。
-
我发现我可以在
$profile.CurrentUserAllHosts放置一个profile.ps1 文件,shell 会使用它。该值采用 UNC 格式,\\SERVER\SHARE\user\My Documents...。当我没有连接到网络时,我将没有可用的配置文件。
标签: powershell