To get this working, you must first create a profile:
- At the powershell command prompt, run Test-Path $Profile. If the result is true, then you have created a profile. To see the path to your profile, just type $Profile.
- If the result is false, run this command to create a profile:
- New-Item -Path $Profile -Type File -Force.
- I've no idea how to create it an a location you desire (I back mine up in place), but this will create a file like: C:\Users\[you]\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
- Open your profile in the Powershell ISE. Create functions to your heart's desire. Of course you have access to all of powershell's built in commands as well.
- If you get an error saying you can't run scripts, run this command: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned More info here.
function start-git
{
Set-Location C:\Dev
. "C:\Program Files\Git\bin\bash.exe" #note the dot
}
If you want to pass parameters into your function, you can do that like:
function compare-files([string]$s1, [string]$s2)
{
. "C:\Program Files (x86)\WinMerge\WinMergeU.exe" $s1 $s2
}
If you want to group related functions in a separate script, you reference it like this:
######### WhateverFunctions.psm1
function whatever {}
Export-ModuleMember -function whatever
########## profile
Import-Module C:\WhateverFunctions.psm1
No comments:
Post a Comment