![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||