在我们的企业环境中,我在创建PowerShell配置文件脚本时遇到了困难。
为了防止用户在本地磁盘上写文档," Documents"目录被强制在网络驱动器上。通常是" 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
另请参阅:帮助 - 关于about_Profiles
当我未连接到网络时,这些是$个人资料设置。我仍然无法在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>
答案 0 :(得分:0)
一种选择是使用如下目标创建快捷方式:
%systemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoExit -file C:\somewhere\myprofile.ps1
然后始终使用此快捷方式启动PowerShell。
这实际上并没有使用内置的PowerShell配置文件概念,但它是一个点源ps1文件,其行为与配置文件非常相似。
如果您想从cmd.exe启动PowerShell,请创建一个与上述内容相同的批处理文件,并将其放在路径中的某个位置(如果您有权这样做)