Windows Tip Sheet

Jog Your Memory with PowerShell

Try this tip if you're as forgetful as I am when trying to remember what functions reside in your profile script.

In my continuing series on some nifty tricks you can do with PowerShell, here's another quick tip for getting the most from your PowerShell profile script. PowerShell automatically populates a variable called $profile with the file name and path of your profile script. Want to see your profile again? Just type:

PS C:\> get-content $profile | more

I often can't remember the exact name of a function in my profile, so I can use an expression like this to jog my memory:

PS C:\> get-content $profile | select-string "Function" -casesensitive

I use the -casesensitive switch because I'm pretty good about using Function in my declarations. This prevents any other lines with the word "function" from being returned.

Another way to leverage $profile is to edit the file. The PowerShell Community Extensions have a section in their profile script where you can specify the name of an editor. But all you have to do is use:

PS C:\> notepad $profile

Tech Help -- Just An
E-Mail Away

Got a Windows, Exchange or virtualization question or need troubleshooting help? Or maybe you want a better explanation than provided in the manuals? Describe your dilemma in an e-mail to the MCPmag.com editors at editor@mcpmag.com; the best questions get answered in this column and garner the questioner with a nifty Redmond T-shirt.

When you send your questions, please include your full first and last name, location, certifications (if any) with your message. (If you prefer to remain anonymous, specify this in your message, but submit the requested information for verification purposes.)

If you edit your profile, you can easily reload it by typing:

PS C:\> . $profile

You may get errors if your profile reloads any snapins or type extensions but you can safely ignore the error messages. Any new or edited functions will be available which is all that matters anyway.

About the Author

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at Petri.com, and a frequent speaker at technology conferences and user groups.

comments powered by Disqus
Most   Popular

SharePoint Watch

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.