Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Have you guys had this problem where, when you start PowerShell from SQL Server, it throws an exception like the following?

Cannot resolve alias 'cd' because it refers to term 'Microsoft.PowerShell.Manag ement\Set-Location', which is not recognized as a cmdlet, function, operable pr ogram, or script file. Verify the term and try again. At line:1 char:140 + &{[System.Console]::Title = 'SQL Server Powershell';Convert-UrnToPath 'Server [@Name=''AIMLESS'']/Database[@Name=''AdventureWorks2008'']'|cd <<<< }


I cannot navigate around with some common aliases like pwd, cd, etc.. even though get-alias clears shows that cd is set-location and pwd is get-location.

alt text

[UPDATE] Alias cannot be set either alt text

share|improve this question

3 Answers 3

I'm pretty sure I ran across this several months ago, but can't find it anymore after a quick search. I believe the user's GAC some how got corrupted/mixed up.

Are you able to start a regular PowerShell session OK?

How you updated .NET versions?

share|improve this answer
    
Yes, I have no problem with regular PowerShell on the same machine---I actually installed Visual Studio 2010 Professional Beta 1 installed on my machine and it also installed .NET v4.0.20506 –  Sung Jul 29 '09 at 4:39
    
So... Did this problem start after you installed .NET 4? The SQL minishell may have some hardcoded configs that cause it to break here. How about trying the regular PowerShell console, then loading the SQL snapins. If that works, then there may be an issue with the SQL minishell itself. –  Marco Shaw Jul 29 '09 at 10:26
    
@Marco Shaw: I am not sure if the problem has started after installing .NET 4.0 since I never tried SQL PowerShell before installing it. But if I were to speculate that seems to be case, since that "developer" machine is the only one with VS2010 and has the trouble. From "Get-PSSnapIn", i can see that SQL snapins are loaded but let me try it again. –  Sung Jul 29 '09 at 13:28
    
I had a SQL 2008 VM, and just loaded the latest .NET 4.0 without any problems. One thing that seems odd is the error refers to "...ManagementWSet-Location...". I don't the "W". That should at least be a black-slash, I'm thinking. –  Marco Shaw Aug 2 '09 at 11:57

Are you using PowerShell Community Extensions? Unfortunately they use the default profile.ps1 file instead of Microsoft.PowerShell_profile.ps1. IF this is the case all you need to do is rename your Profile.ps1 to Microsoft.PowerShell_profile.ps1. SQLPS will not load the Microsoft.PowerShell_profile.ps1 profile only the host agnostic profile profile.ps1. There is work item for it here

http://www.codeplex.com/Pscx/WorkItem/View.aspx?WorkItemId=18417

share|improve this answer
    
I don't have PSCX installed on my machine. And actually, I don't even have a profile location - PS C:\Users\dance2die> ii (split-path $profile -Parent) Invoke-Item : Cannot find path 'C:\Users\dance2die\Documents\WindowsPowerShell' because it does not exist. At line:1 char:3 + ii <<<< (split-path $profile -Parent) –  Sung Jul 29 '09 at 4:37

It definitely sounds like a profile issue to me. I found an article(a) that talks about a similar problem caused by Powershell version 1 beta being installed at one time.

I would look through each of the files in the profile chain to see which one is remapping those aliases on you. You could then rename the profile file to test if it was the problem. I am not exactly sure how you are starting Powershell, but if SQL Server is starting Powershell, you will want to look at it's user account's profile.

This should do it...

notepad '$env:windir\system32\WindowsPowerShell\v1.0\profile.ps1'
notepad '$env:windir\system32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1'
notepad '$env:UserProfile\My Documents\WindowsPowerShell\profile.ps1'
notepad '$env:UserProfile\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'

(a) Profile.msh possible errors:

If you load the profile.msh file, and you have previously installed an earlier version of Monad, then on startup you may see a series of errors like:

set-alias : The AllScope option cannot be removed from the alias 'cat'. At C:\Documents and Settings\All Users\Documents\msh\profile.msh:9 char:10 + set-alias <<<< cat get-content

To fix this, either delete the file named ("C:\Documents and Settings\All Users\Documents\msh\profile.msh" in this example), or remove all the "set-alias" lines from it. Aliases defined in profile.msh in earlier versions of Monad are now defined internally by Monad before the profile is run; therefore, the definitions in profile.msh will generate an error attempting to redefine the alias.

http://www.latenighthacking.com/archives/reference/PowerShellDocumentationPack_rc1/Windows%20PowerShell%20RC1%20release%20notes.htm

share|improve this answer
    
Actually, now that I look at your error again, the problem is likely the script that is being ran when you click "Start Powershell". You will need to find and fix him. –  Nathan Hartley Jul 28 '09 at 14:33

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.