作为一个拥有
$profile
抹去并设置为“公司违约”,为上帝的爱,不要。
如果必须这样做,那么我建议您只创建一个概要文件,让每个人都在共享位置拥有所有模块,比如安全锁定的Sysadmin文件夹。
做
psedit $proile.AllUsersAllHosts
在您的计算机上,修改它,然后用您自己的强制配置文件创建一个包含所有要销毁的主机名的文本文件把这个放进去,让它在默认情况下导入您的模块。
# Checks your server share for any PSM1 files, could change to include PS1 as well I suppose. Long name because its in a $Profile so ¯\_(ã)_/¯
$ModulePathWithLongNameBecauseSomeoneMayUseThisInAnActualScript = Get-ChildItem -file -Recurse "\\server\share\" -Include "*.psm1"
# Sets module path for other adhoc module calls if they dont want to restart their Powershell
$env:PSModulePath = $env:PSModulePath + ";\\server\share\"
# Imports all PSM1 files from the ModulePath*
Foreach($psm in $ModulePathWithLongNameBecauseSomeoneMayUseThisInAnActualScript){
Import-Module "$($ModulePath.FullName)"
}
把这个放在你的机器上让你的灵魂崩溃
$配置文件
你的同事可能有自己的设置。
# Get a list of machines that your staff will use and throw them into a txt or csv etc.
$PCsForForcedProfile = Get-Content "\\server\share\PleaseNo.txt"
Foreach($Colleague in $PCsForForcedProfile){
Copy-Item "C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1" "\\$Colleague\C$\Windows\System32\WindowsPowerShell\v1.0\" -force
}