Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Loading Powershell Snapins in your Profile

Reply
 
Old 09-02-2007   #1 (permalink)
Hal Rottenberg


 
 

Loading Powershell Snapins in your Profile

Loading Powershell Snapins in your Profile
http://halr9000.com/article/425

I’ve recently started to sync my Powershell profile between my work and home
PCs. What I quickly found out however, was that I had some Powershell snapins
installed on one computer, but not the other. Here’s a bit of script which I
came up with to handle things cleanly.

1: $snapins = “psmsi”, # Windows Installer PowerShell Extensions
2: “PshX-SAPIEN”, # AD cmdlets from Sapien
3: “GetGPObjectPSSnapIn”, # GPO management
4: “PowerPad”, # mini-editor
5: “Quest.ActiveRoles.ADManagement”, # more AD stuff
6: “Microsoft.Office.OneNote”
7: $snapins | ForEach-Object {
8: if ( Get-PSSnapin -Registered $_ -ErrorAction SilentlyContinue ) {
9: Add-PSSnapin $_
10: }
11: }

In lines 1-6 you see I’m building an array called $snapins. Each one of these
is the exact name of the snapin as seen when you run ‘get-pssnapin -r’ at the
prompt.

Line 7: I use a foreach-object loop to iterate through each item in the array.

Line 8: Get-PsSnapin takes as an optional parameter the name of a snapin, so
this If block evaluates to true if the current snapin in the loop (that’s using
the $_ automatic variable) is indeed installed.

Line 9: If it’s true…I add the snapin to the current session using the
Add-PsSnapin cmdlet.

Hope you find this useful!
--

Hal Rottenberg
blog: http://halr9000.com
powershell category:
http://halr9000.com/article/category...ng/powershell/

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Profile loading problem General Discussion
Vista and Roaming Profile: error when loading...temp profile used Vista General
Loading Profile During Start Up Vista performance & maintenance
Book: Professional Windows PowerShell Programming: Snapins, Cmdlets,Hosts and Providers (Paperback) by Wrox PowerShell
Building MMC Snapins on top of PowerShell CmdLets PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46