×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

PS Profiles

PS Profiles

PS Profiles

(OP)
I am curious if others are also using the PowerShell profiles to create aliases or configure their PS environment?

Are people even aware of this capability?  For example, I like the vbscript Now function and would prefer to use Now instead of Get-Date and I don't want to set up an alias each time I launch PowerShell.  I would also like to have instant access to just the date and time separately.  So, I have edited my Profile to set this up for me at launch.

To edit your profile go to My Documents\PowerShell and edit the file Microsoft.PowerShell_profile.ps1 with notepad.  Here is the contents of my file:

CODE

Set-Alias Now Get-Date
$Date = Get-Date -Format M/d/yyyy
$Time = Get-Date -Format hh:mm:ss

If the file does not already exist you will need to create it.  

First determine if the Profile is created with

CODE

Get-Content $Profile

If you get an error then create the profile file and add data to it all in one shot.

CODE

Add-Content $Profile -value "Set-Alias Now Get-Date"
Add-Content $Profile -value "$Date = Get-Date -Format M/d/yyyy"
Add-Content $Profile -value "$Time = Get-Date -Format hh:mm:ss"

Note that in order for profiles to work you have to have configured PowerShell security to execute scripts.  To do that you need to execute the command:
Set-ExecutionPolicy -executionPolicy Unrestricted

Note that the above will allow all scripts to be run, if you use signed scripts then don't use the Unrestricted switch and instead use AllSigned.  I suggest everyone look at the options with Help Set-ExecutionPolicy.

I want to point out also that it is possible from within a PS Session to export/import your Aliases.  Use caution when doing this.  By default ALL aliases will be exported or imported.  You will then get a bunch of errors when the default aliases try to remap themselves at launch/import.  It is however possible to export named aliases instead of all aliases.  This is the preferred method to avoid unnecessary errors.

I hope you find this post helpful.  

Regards,

Mark

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

RE: PS Profiles

I've seen people refer to profiles, but haven't seen to many examples on setting one up.  I also read of someone who created, for example, a function profile where he kept his functions and was able to import it into his regular profile.  Have you tried this? What do you think of that approach of having a profile that perhaps contains functions only and another that contains aliases and so on and then import them to a main profile?

dm4ever
--------------------------------------------------------------------------------
My approach to things: K.I.S.S - Keep It Simple Stupid

RE: PS Profiles

(OP)
I don't care much for that idea only because the whole reason to use a profile is to make it easy for you to standardize shortcuts. In an enterprise I would want to be able to standardize all of my servers aliases and functions so my scripts can work on any system without further action.

I hope you find this post helpful.  

Regards,

Mark

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close