Package a suite of powershell cmdlets for quick deployment on any machine?
I have a series of cmdlets that I wrote that help me in my day-to-day work, and I would like to have them readily available on any new machine I might be working on.
I'm thinking that it would be great if I had some script/executable on a remote share that I could execute from 开发者_高级运维any machine I'm temporarily working on that would start a new instance of powershell with all of my scripts already loaded in the environment.
I'm thinking it's either a matter of creating a new snapin (I might be overcomplicating this) or maybe I can get away with simply loading a remotely located .ps1 library of functions from powershell running on one of these machines I'm working on.
Any suggestions / best practice recommendations?
You want to create a PowerShell Module. Modules are deployable via Xcopy, no dll registration or anything funky. You can set all kinds of options for your module using a Module Manifest. This will give you versioning, prerequisites, what hosts you can run your module on, and a variety of other options as well. In PowerShell, check out
PS> Help about_module
PS> get-command new-modulemanifest
I think a module might be what you're looking for.
I'd just create a PowerShell script (.PS1) file and import all modules I need in that. Then, on the remote machine, I'd simply run this new PS1 file from a remote share. However, when laoding modules / scripts from a remote source, you may have to modify the local PowerShell.exe.config or PowerShell_ise.exe.config files to add:
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v2.0" />
<process>
<rollForward enabled="false" />
</process>
</startup>
<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>
</configuration>
These files don't exist by default. You will have to create them under C:\Windows\System32\WindowsPowerShell\v1.0\
精彩评论