如果标准位置被禁止,在哪里放置PowerShell配置文件脚本



在我们的公司环境中,我在创建PowerShell配置文件脚本时遇到了困难。

为了防止用户在本地磁盘上写文档,"documents"目录被强制放在网络驱动器上。通常是"H:"(home)驱动器。

同样,禁止用户在C:WindowsSystem32.

下写入。

如果这两个都不可用,我可以把ISE配置文件脚本放在哪里?

PSVersion 5.0.10586.117

PS C:WindowsSystem32WindowsPowerShellv1.0> $HOME, $PSHOME
C:Userspwatson
C:WindowsSystem32WindowsPowerShellv1.0

参见:Help-About about_Profiles

当我没有连接到网络时,这些是$profile设置。我仍然无法在C:WindowsSystem32下写入,并且CurrentUser值无效。

PS C:WindowsSystem32WindowsPowerShellv1.0> $profile | Get-Member -Type NoteProperty | ForEach-Object {$_.ToString
()}
string AllUsersAllHosts=C:WindowsSystem32WindowsPowerShellv1.0profile.ps1
string AllUsersCurrentHost=C:WindowsSystem32WindowsPowerShellv1.0Microsoft.PowerShell_profile.ps1
string CurrentUserAllHosts=WindowsPowerShellprofile.ps1
string CurrentUserCurrentHost=WindowsPowerShellMicrosoft.PowerShell_profile.ps1
PS C:WindowsSystem32WindowsPowerShellv1.0>

一个选项是为目标创建一个快捷方式,如下所示:

%systemRoot%System32WindowsPowerShellv1.0powershell.exe -NoExit -file C:somewheremyprofile.ps1

,然后总是使用这个快捷方式来启动PowerShell。

这实际上并没有使用内置的PowerShell配置文件概念,但它是点源一个ps1文件,其行为与配置文件非常相似。

如果你想从cmd.exe启动PowerShell,创建一个与上面相同内容的批处理文件,并把它放在你的路径的某个地方(如果你有权限这样做)

最新更新