E-Mail 'Windows PowerShell Aliases' To A Friend

Email a copy of 'Windows PowerShell Aliases' to a friend

* Required Field






Separate multiple entries with a comma. Maximum 5 entries.



Separate multiple entries with a comma. Maximum 5 entries.


E-Mail Image Verification

Loading ... Loading ...

Comments

By Kevin Kelleher on November 5th, 2007 at 8:45 am

I think it would be helpful for those us with a unix background to make it clear that PowerScript aliases are aliases for single words. I didn’t realize this at first, and couldn’t understand why I couldn’t redefine “ls” as “get-childitem -force -name”.

By Roy Pardee on May 30th, 2008 at 2:13 pm

Ach–thanks Kevin! I’ve been surfing around for a while now looking for multi-word examples & trying different combinations of single/double quotes & escapes & such and having no luck.

I guess it’s *functions* that I need to be able to do multi-word commands?

I don’t know if having My Documents redirected to the D: drive has anything to do with it, but the Profile.ps1 results in the following for me:

Incomplete string token.
At line:1 char:14
+ . ‘F:\Jim`’s D <<<< ocuments\WindowsPowerShell\profile.ps1′

I am new to this, when i tried to set the execution policy i got this. i am running this on windwos vista business;is that expectied ?

Set-ExecutionPolicy : Access to the

registry key ‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft
.PowerShell’ is denied.
At line:1 char:20
+ Set-ExecutionPolicy <<<< unrestricted

Set-ExecutionPolicy : Access to the
registry key ‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft
.PowerShell’ is denied.
At line:1 char:20
+ Set-ExecutionPolicy <<<< unrestricted

I get the same thing as Joe. Any way to fix this?

Set-ExecutionPolicy : Access to the registry key ‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft
.PowerShell’ is denied.
At line:1 char:20
+ set-executionpolicy <<<< unrestricted
+ CategoryInfo : NotSpecified: (:) [Set-ExecutionPolicy], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetExecutionPolicyComma
nd

Apologies, the command is slightly different.

Luke
You have to execute the set-executionpolicy as admin. if you are on Vists, try run as administrator

\\Greg

Here’s my question – I have my home directory redirected to a network path and everytime PS tries to load my profile, it prompts with this:

Run only scripts that you trust[...] Do you want to run H:\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1?
[D] Do not run [R] Run once [S] Suspend [?] Help (default is “D”):

other than signing the script, is there a way around it?

\\Greg

Thanks for the email, Jesse.

Adding my AD domain to the local intranet sites
in IE did the trick. Add it as file://*.mydomain.com

Excellent!

\\Greg

Your tutorial is awesome, thx a lot :)

By Bingo Little on March 16th, 2009 at 3:13 am

Great tutorial! Thanks.

Q: Does PS remember the ExecutionPolicy across sessions? How?

None of the following commands: dir, ls, gci, or Get-ChildItem produce any result. Is my PowerShell not installed and configured correctly? I am running on an XP Pro machine.

John

This is embarassing to say, but here goes. The reason no result was produced is that the folder was empty. Adding a sample file to the folder and running the commands again produced a listing o fthe sample file.

I love the tutorials so far! I ran into a problem though!
I’m trying to run:

export-alias -path Aliases.txt

and i’m getting:

Export-Alias : Unknown error “-1″.
At line:1 char:13
+ export-alias <<<< -path aliases.txt

I’ve tried everything, but i’m getting the same error! Can anyone tell me what I can do? Thanks!

Nice! great tutorial. I hope I will understand more about PowerShells for my profession. Excellent! :)

@Drew

Kindly try this one:

PS D:\MyScripts> Export-Alias
cmdlet Export-Alias at command pipeline position 1
Supply values for the following parameters:
path[0]:aliases.txt
path[1]:

PS D:\MyScripts>
PS D:\MyScripts> dir <– check whether your txt file has been created.

Thanks.
-Arjay

As already mentioned the Vista executionPolicy errors can be corrected by running as administrator. You can do this from the start menu by right clicking on powershell and choosing Run As Administrator. Or alternatively, if you’ve set up a desktop shortcut for powershell, right click on the the icon, choose properties, then choose the shortcut tab in the properties window. On that tab, click the advanced button and check the Run as administrator box in the resulting advanced properties window.
Of course, all this assumes you’ve logged on as an admin user in the first place.

Bingo Little: Try typing “Get-Help Set-ExecutionPolicy -Full”

In the “NOTES” section of the help text it explains that “the new user preference is written to the registry and remains unchanged until you change it.”

Great tutorials.. I have been using the virtual labs from MS and these are by far much easier to understand and follow. Thank you so much for your hard work on these..

This is really good! a few years ago I slogged through a few chapters of a book on PS and found it interesting but kind of obtuse. Your Tutorial is very elegent and makes practical sense!

Excelllent! very elegant and simple. Thank You.

i love this tutorial. thanks

Great tutorial indeed – but I have a problem!

I want to start the Powershell through the commandline by typing ‘ps’ instead of ‘powershell’.

Any way of doing that?

make a batchfile.

start cmd

echo powershell > ps.bat

ps

should start powershell

Great tutorials!
What if I want keep profile in my working directory (somewhere on D:) and open PowerShell with customised-personalised profile? Is it possible?

@Dennis
I open powershell with ps directly from run (Win-logo R)
In the registry create new key at
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ps.exe
with value
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

does the trick?

:Dennis
I open powershell with ps directly from run (Win-logo R)
In the registry create new key at
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ps.exe
with value
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

does the trick?

At first the “Run as Administrator” technique didn’t work for me. I guess it does for many out there but if not, as a permanent fix you can add the permission in directly via the windows registry. It’s pretty easy and eliminates the need to “run as admin”.

See http://kyleclegg.com/powershell/

Hope this helps someone!

By Peter Wood on March 15th, 2011 at 6:17 am

Great tutorial! Thanks for the help!

Dont bother hacking the registry.

Right click the powershell shortcut on your desktop. Click advanced, click run as administrator.

Works for most any shortcut.

Thanks so much!

I am hopeless and this series is brilliant.

Cheers

Worked great for me!

Excellent Tutorial!

get-service name PowerShellProTutorial

Bill

Have you ever seen the behavior where you have the default start folder set but it changes to C:\Windows\system32 when you Run as Administrator?

It was really great and fun by learning powershell step by step. I love it just because its not theory but practical. It helps me a lot in my project. Thank you so much :)
I have a doubt..
by setting alias thru profile.. how many alias can be added(user defined)?? can u explain adding more alias to the profile?

I have the same issue as Lori. The “Start in” is ignored when running as Administrator. Also noticed the “$Path” variable no longer seems to be populated. I removed the ‘run as’ and it now respects the ‘Start in’, but $Path is still not set. Also, when Run As Adminitstator, it kept prompting st startup asking me if I wanted to allow the program to make changes to the computer. Win7 Pro 64.

This is how you would do a cd alias. Place the code in your profile file:

function exampleDir {Set-Location C:\Users\Hugo\Example}

Set-Alias cdExample exampleDir

Note:

The name of the alias cannot be the same than the function name.

Regards,

Robert

It’s amazing to me that seting the powershell to unrestricted usage is persistant beyond the life of your session – which is inherently dumb.
Seems like there should be a $profile type of variable when the shell closes, then you can set the shell to unrestricted when being used and back to restricted when it closes.

when i add the microsoft.powershell_profile.ps1 and start up powershell, it just sits there after the copyright notice. I checked syntax in the file, made it blank, and still the same. When I rename the file, it opens right up, so I know it’s actually reading the file… Any ideas?

Win7, running as admin….

@orschiro/Robert – thank you so much for that tip! brilliant!

By Steven Kitterman on July 10th, 2012 at 8:37 am

Thanks for your tutorials. I am brand-new to Powershell and still have a lot of gaps to fill, but so far I feel I am learning. Thank you for making these tutorials easy to understand and follow.

Thanks very much for these tutorials. I have a suggestion: If you’re going down the command-line route, then drop notebook and use vim. You’ll never look back…

For those with the problem opening in c:\windows\system32 when run as administrator from a shortcut, do this.

Go to properties of shortcut, on shortcut tab under target, add this to the end of the target:
-NoExit -Command “cd f:\MyScripts”

of course, change the f:\MyScripts to the path you wish to use.

Click apply, and run it. Should now open starting in your custom home target.

In response to Sanfords question about ExecutionPolicy only elevated to unrestricted during session, there is a way to do it.

Add this-> -ExecutionPolicy Unrestricted

to the end of target in the properties/shortcut tab on the shortcut you run ps from.

Thanks! You made this easy. Read through all these tutorials in an afternoon and I am already up to speed to manage my Sharepoint server with Powershell (I’m already a .Net developer) Yeah! Don’t have to change 100 report data sources by hand. It will be fun seeing what else it can do to help me manage my custom Sharepoint environments.

learning a lot here, thank you.

Excellent tutorial. This works when I alias to an executable. How do I set up aliases to a directory?

example: I want to type:

mike and have pwoershell go to directory c:\Mike

I tried generating an alias and modifying the resultant working file, but, no luck so far.

When doing this I had a small issue regarding the user of “notepad” as it constantly was not recognized as an operable program and all that good stuff. Only solution to this that I(newbie) could find was to do “start notepad $profile” instead. But then again I’m not exactly experienced at coding so I wouldn’t know much about any tricks or fix. Just in case someone has the same problem as I had/have.

Also, great tutorials, I guess you’re never in here anymore as it starts to get ancient, but it’s easy to follow and really useful. I really appreciate it.

Sorry to be French but shortly after the image 3.10 you enter the following text:

” Viola! your profile has loaded successfully and your alias is working.”

I am sure it was a typo but just in case, It’s Voila not Viola! viola actually means ” (someone) rapped….”

Cheers,

Stéphane

 

Leave a Comment