Friday, April 5, 2013

Perminantly add Snap-Ins to your Powershell

In this article I will give a quick little script that will add your powershell snap-ins to you profile so that everytime you launch ISE they will auto load!

if (!(test-path $profile.AllUsersAllHosts)) {new-item -type file -path $profile.AllUsersAllHosts -force} powershell_ise $profile.AllUsersAllHosts #Add the following code to the script file and save your changes: $ver = $host | select version if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"} if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" } This particular script will load the SharePoint snap-ins, but you can switch those last two lines for whatever snap-ins you wish.

For instance: ((Get-PSSnapin "Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin" -ErrorAction SilentlyContinue) -eq $null) { Add-PSSnapin "Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin" } This would add the Exchange snapin instead of the SharePoint.

Micosoft has a snap-in for just about every solution they produce, and 3rd parties are beginning to put out snap-ins as well. The easiest way to find yours would be to simply google "Add-PSSnapin Name"

4 comments:

  1. No problem! If there is anything in particular you are looking for just let me know...

    ReplyDelete
  2. Looks like this is way above my paygrade :)

    ReplyDelete
    Replies
    1. No doubt, powershell is way too much power for a Cop to be handling!

      Delete