Wednesday, November 18, 2015

Create PowerShell ISE Enabled for SharePoint

2013

Are you tired of typing in …

Add-PSSnapin Microsoft.SharePoint.PowerShell

How to Add PowerShell cmdlets for Sharepoint to ISE

Note that if you are using SharePoint 2013 running on Server 2012 use the following updated steps

Start by making sure ISE is loaded

(HINT) Get-WindowsFeature will display entire list

image

If ISE is not added then add by

Running powershell as local administrator

import-module servermanager
add-windowsfeature powershell-ise


image
Note that in this example it is already loaded.

Create ISE Profile

Now you need to create a profile (this has changed)

image

To create a profile for the current user use:

if (!(test-path $profile ))
{new-item -type file -path $profile -force}

To edit the new profile use:

psEdit $profile

image

Then type the following in the ISE Scripting Pane and click Save.

add-pssnapin microsoft.sharepoint.powershell

Test ISE with SharePoint commands

Close/Open ISE and give it a test, now you have ISE enabled with SharePoint

image

image

Technet Reference

To create a new profile you need to decide from one of 4 scenarios listed below.

To create a new “Current user, Windows PowerShell ISE” profile, run this command:

if (!(test-path $profile ))
{new-item -type file -path $profile -force}

To create a new “All users, Windows PowerShell ISE” profile, run this command:

if (!(test-path $profile.AllUsersCurrentHost))
{new-item -type file -path $profile.AllUsersCurrentHost -force}

To create a new “Current user, All Hosts” profile, run this command:

if (!(test-path $profile.CurrentUserAllHosts))
{new-item -type file -path $profile.CurrentUserAllHosts -force}

To create a new “All users, All Hosts” profile, type:

if (!(test-path $profile.AllUsersAllHosts))
{new-item -type file -path $profile.AllUsersAllHosts-force}

To edit a profile

  1. To open the profile, run the command psedit with the variable that specifies the profile you want to edit. For example, to open the “Current user, Windows PowerShell ISE” profile, type: psEdit $profile
  2. Add some items to your profile. The following are a few examples to get you started:
    • To change the default background color of the Console Pane to blue, in the profile file type: $psISE.Options.OutputPaneBackground = 'blue' . For more information about the $psISE variable, see The ISE Scripting Object Model.
    • To change font size to 20, in the profile file type: $psISE.Options.FontSize =20
  3. To save your profile file, on the File menu, click Save. Next time you open the Windows PowerShell ISE, your customizations are applied.

 

2010

So you want to use the ISE with SharePoint.  First add ISE feature then create a new profile by completing the following steps:

ADD ISE
Running powershell as local administrator

import-module servermanager
add-windowsfeature powershell-ise

(HINT) Get-WindowsFeature will display entire list

ADD Profile
Running powershell as sharepoint administrator
Powershell_ISE
Test-Path $profile (if true jump to Open ISO Profile step below)
New-Item $profile -ItemType file –Force
 
Close current untitled ps1 and open new file created
Open ISE Profile > Open > look in documents for microsoft.powershellies_profile.ps1

add-pssnapin microsoft.sharepoint.powershell

Save File and test by closing ISE and relaunch

(HINT) get-psnapin to display that have been added
(HINT) get-psnapin -registered to display all but ...

Give access to DB use the following powershell from a privileged user shell

$spcdb = get-spcontentdatabase wss_content_intranet
Add-spshelladmin -username contoso\sp_admin -database $spcdb


Reference - Scripting Wife - ISE Profiles
http://blogs.technet.com/b/heyscriptingguy/archive/2011/09/13/the-scripting-wife-creates-a-powershell-ise-profile.aspx

http://blogs.msdn.com/b/kaevans/archive/2011/11/14/add-microsoft-sharepoint-powershell-snap-in-to-all-powershell-windows.aspx

No comments:

Post a Comment