ISE Load and execute Script on Start-up

To load and execute a script when ISE starts, add the following to the SharePoint profile

Note: Use this snippet of code to open your profile

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

Add the following into the file, save it, and restart ISE

function psedit {
    if(test-path $filename -PathType Leaf) {
        $file = Get-ChildItem $filename
        if($file.PSProvider.Name -eq "Filesystem") {
            Start-Process PowerShell_ISE -ArgumentList $file
        else {
            Write-Error "Wrong PSProvider: $($File.PSProvider.Name)"
    else {
        write-error "Bad path: $filename"
<# .SYNOPSIS Opens a file in PowerShell ISE for editing.
   .DESCRIPTION Accepts one or more file (as paths) and then checks them to make sure the path exists and it's a file. If any of the files are not already open in PowerShell ISE, the file is opened in a new tab.
   .EXAMPLE PSEdit $Filename Opens the file at $filename in the PowerShell ISE
   .EXAMPLE Get-ChildItem C:\Scripts\ProjectGenesis\*.ps1 | PSEdit Opens all PS1 files in the Project Genesis folder for editing. .LINK
#Declare the file you want to edit into a variable (optional)
$FilePath = "C:\Scripts\MyProfile.ps1"
#Run the file
PSEdit $FilePath
#Execute the file
$Tempstringholdingcode = Get-Content $FilePath -Raw
Invoke-Expression $Tempstringholdingcode

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s