Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In PowerShell, I type:

PS C:> sal cdp "cd 'C:\Users\ec\Documents\Visual Studio 2010\Projects'"

I get no error from this, and

PS C:> gal cdp

shows definition as: cd 'C:\Users\ec\Documents\Visual Studio 2010\Projects'

But, when I try to use cdp, I get this:

Cannot resolve alias 'cdp' because it refers to term 'cd 'C:\Users\ec\Documents\Visual Studio 2010\Projects'', which is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again. At line:1 char:4
+ cdp <<<<
 + CatergoryInfo   : ObjectNotFound (dsp:String) [], CommandNotFoundException
 + FullyQualifiedErrorId   : AliasNotResolvedException

I am guessing that this is trivially easy. So I apologize in advance if that is the case. I have googled and googled and have also read through Windows PowerShell Cookbook.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

From my understanding, aliases in piowershell do not behave like they do in unix/linux type shells. An alias is merely a shorthand way of typing a much longer command. For the functionality that you are looking for, it may be easier to eaither define a function:

function cdp { Set-Location 'C:\Users\ec\Documents\Visual Studio 2010\Projects' }

Then you can execute cdp on the line to get to the desired location. Or you can create a variable for the location and then cd to that variable name:

$cdp = 'C:\Users\ec\Documents\Visual Studio 2010\Projects'
cd $cdp

Those are the two easiest solutions to what it appears you're trying to achieve.

share|improve this answer
    
Thanks. Yes, I am trying to replicate *nix shell scripting behavior. Both of your suggestions worked for me - so I will see if I can get them to persist in some easily re-useable form. –  westsider Jun 29 '11 at 0:04
1  
Even though you haven't opened a question regarding the persistence issue, at the powershell prompt execute get-help about_profile that'll help you out with the persistence issue –  Matrix Mole Jun 29 '11 at 0:16
1  
Thanks. At the risk of running amok of etiquette, I settled on using profile.ps1 in Documents/WindowsPowerShell/ as the easiest path. That works well for my immediate needs - much like .profile on other systems. –  westsider Jun 29 '11 at 0:45
    
Well then I am an amok runner as well. Pretty much all my shell customizations go into my AllUsersAllHosts profile as well. –  EBGreen Jun 29 '11 at 13:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.