Powershell自动执行脚本之profile
AI摘要
由
Deepseek提供支持
四中不同的profile脚本
Powershell支持四种可以用来初始化任务的profile脚本。应用之前要弄清楚你的初始化是当前用户个人使用,还是所有用户。如果是个人使用,可以使用”当前用户profile”,但是如果你的初始化任务是针对所有用户,可是使用”所有用户profile”。
| Profile | 描述 | 位置 |
|---|---|---|
| 所有用户 | 所有用户共有的profile | $pshome\profile.ps1 |
| 所有用户(私有) | powershell.exe 中验证 | $pshome\Microsoft.PowerShell_profile.ps1 |
| 当前用户 | 当前用户的profile | $((Split-Path $profile -Parent)+ “\profile.ps1”) |
| 当前用户(私有) | 当前用户的profile;只在Powershell.exe中验证 | $profile |
我们注意到上面的四种profile有两个private。一旦声明为private,只有个microsoft的Powershell自身才会去调用,不会对其它引用powershell的组件有效。
创建自己的profile
Profile脚本并不是强制性的,换言之,profile可有可无。下面会很方便的创建自己的profile。在控制台执行:
notepad $((Split-Path $profile -Parent) + "\profile.ps1")
如果不存在profile默认会创建,在打开的记事本中输入:
Set-Alias edit notepad.exe
也就是给notepad添加edit别名,保存关闭,之后重启控制台,输入:
edit $((Split-Path $profile -Parent) + "\profile.ps1")
控制台会调用记事本打开之前的profile,可见edit别名已经生效。
创建全局profile
创建全局的profile也是很容易的,如上,只是文件的位置稍有改变;需要注意的是,创建全局profile需要管理员权限,没有管理员权限,该文件或者文件夹拒绝访问。
温馨提示 : 非特殊注明,否则均为©李联华的博客网原创文章,本站文章未经授权禁止任何形式转载;来自:俄亥俄州·哥伦布 ,欢迎您的访问!
文章链接:https://www.lilianhua.com/the-profile-of-powershells-automated-script-execution.html
文章链接:https://www.lilianhua.com/the-profile-of-powershells-automated-script-execution.html

