Friday, August 24, 2007

Loading PowerShell scripts at startup

If you want to execute a lot of custom scripts/functions when PowerShell starts up, you can either put them all in your startup profile, or use the method below.

Assuming you have a startup profile named Microsoft.PowerShell_Profile.ps1 in:

%UserProfile%\\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile

Create a subdirectory called something like Includes and place all your custom script files in this directory. Finally add the following code into the startup profile:

foreach ($f in get-childitem $(join-path $(split-path $profile -Parent) "Includes"))
{
. $f.fullname
}


Now, each time PowerShell is started, it will automatically execute all your customer shell scripts/functions.

No comments:

Can't RDP? How to enable / disable virtual machine firewall for Azure VM

Oh no!  I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore.  I did ...