Lets say you have a idea for a new function that you would like to implement in Window's PowerShell. In this case I made a Unix like whoami command:
function whoami
{
[System.Security.Principal.WindowsIdentity]::GetCurrent().Name
}
when in PowerShell it returned for me: mss/wandrus. Simple enough. Now to get the command to be usable every time an new PowerShell is opened.
Type within PowerShell: Get-Variable profile | Format-List
This should give you the information on what file and directory path are needed to place your custom scripts. In this case I was given:
C:\Document and Settings\wandrus\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Which meant that I had to create a new folder (WindowsPowerShell) and a new script file in notepad (Microsoft.PowerShell_profile.ps1) where I've place my function.
No comments:
Post a Comment