Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...with companys cutting back on training, lack of true support by makers of software, the forums are a great tool in your cyber-toolbox...."

Geography

Where in the world do Tek-Tips members come from?
markdmac (MIS)
5 Jan 07 11:01
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

dm4ever (TechnicalUser)
5 Jan 07 16:19
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

Helpful Member!  markdmac (MIS)
5 Jan 07 17:03
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

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!

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