如何尽可能简单地为工作中的所有同事设置默认powershell配置文件?
我想要实现什么? 我有一个ps1文件,里面有我所有的函数。在第一步中,我想将其转换为ps模块。那么我想有以下几点:如何尽可能简单地为工作中的所有同事设置默认powershell配置文件?,powershell,powershell-module,Powershell,Powershell Module,我想要实现什么? 我有一个ps1文件,里面有我所有的函数。在第一步中,我想将其转换为ps模块。那么我想有以下几点: #set path for profile_loader.ps1 $path = "\\server\share\folderwithscripts"; #call profile_loader.ps1 . "$path" 同事得到一个脚本或蝙蝠,他必须运行一次。这将把他的模块环境路径$Env:PSModulePath设置为每个人都可以访问的网络驱动器上的路径 将custom
#set path for profile_loader.ps1
$path = "\\server\share\folderwithscripts";
#call profile_loader.ps1
. "$path"
- 同事得到一个脚本或蝙蝠,他必须运行一次。这将把他的模块环境路径
设置为每个人都可以访问的网络驱动器上的路径$Env:PSModulePath
- 将custom profile.ps1复制并粘贴到导入模块的用户
%userprofile%\Documents\WindowsPowershell
- 现在,每个用户的shell中都应该有我提供的powershell脚本
profile.ps1
文件):
然后这个profile\u loader.ps1
baisly只加载成吨的脚本(ps1文件),如下所示:
。“\\server\share\path to otherscript.ps1
一行接一行
我不喜欢它,而且它对于我未来想要建立的其他25位同事来说太复杂了
问题
实现这一点的最佳方法是什么?一个好的旧.bat文件,它可以将ps1文件复制并通过ps1文件进入他们的用户配置文件?或者有更好的方法吗?作为一个擦除了他们的
$profile
并设置为“公司默认值”的人,看在上帝的份上,不要这样做
如果必须的话,我建议您只创建一个概要文件,您希望每个人都能将您的所有模块放在一个共享位置,比如安全锁定的Sysadmin文件夹
请在您的计算机上编辑$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)"
}
在您的机器上运行此命令,将您的灵魂粉碎$profile
发送给可能有自己设置的同事
# 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
}
如果这只是为了让您的同事可以获得您创建的模块,那么设置如何?这样,他们就可以安装您发布的任何模块,并轻松获得更新。前期工作更多,但无需处理文件共享和批处理脚本,并且随着您添加用户和模块,可以更好地扩展。非常感谢。我将我接受这个问题。