by Stevo at 2012-09-10 00:34:21
I have a bizare issue with PS 3 ISE. When i start up ISE, the Commands Pane appears after all my Profiles is loaded but without any commands listed. Also when i run Show-Command i get this error:by poshoholic at 2012-09-10 04:38:15
PS C:\Scripts> Show-Command
get-command : Object reference not set to an instance of an object.
At line:1 char:3
+ @(get-command -CommandType Cmdlet,Function,Script,ExternalScript,Workflow),@(get …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: ([Get-Command], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GetCommandCommand
Has anyone seen this or does anyone know why im getting this?
Help greatly appreciated.
I haven’t seen that before, but you should be able to troubleshoot it.by Stevo at 2012-09-10 06:08:42
1. If you launch PowerShell.exe with the -noprofile switch, can you invoke Show-Command without running into that error?
2. If you launch PowerShell_ISE.exe with the -noprofile switch, do you still see the error?
If either of those works without raising the error, you may want to identify which part of your profile is causing this to raise an error by commenting out the entire thing and then uncommenting parts of it until you find the root cause. If launching either of those causes the error to reproduce, more troubleshooting will be necessary, in which case the following details will be important:
1. OS version/SP version (Get-WmiObject Win32_OperatingSystem | Select-Object -Property Version,ServicePackMajorVersion,ServicePackMinorVersion)
2. PowerShell version details ($PSVersionTable).
3. Have you ever installed a Community Preview or Release Preview version of PowerShell 3.0 on this system?
4. What other PowerShell-related software do you have installed (modules, snapins, 3rd party products, etc).?
Thanks,
This error only happens when running PS ISE as an Admin.by DonJ at 2012-09-10 06:57:00
Running PS ISE without admin elevation then everything is fine and the Show-Command and Command Pane works.
Running PS as an Admin it works fine and i can run Show-Command.
Name Value
---- -----
WSManStackVersion 3.0
PSCompatibleVersions {1.0, 2.0, 3.0}
SerializationVersion 1.1.0.1
BuildVersion 6.2.9200.16398
PSVersion 3.0
CLRVersion 4.0.30319.269
PSRemotingProtocolVersion 2.2
I have not installed any Community Previews on this machine.
The Profile for this PS ISE is empty so nothing else is being run at start up.
Its very wierd.
Check the contents of the PSMODULEPATH environment variable. Once you’ve launched the shell, as admin, run GC ENV]. What’s it say?by Stevo at 2012-09-10 23:19:17
PS C:\Scripts> gc Env:\PSModulePathby poshoholic at 2012-09-11 05:26:35
C:\Users%username%\Documents\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules<br>
and nothing else!
Thanks for the answers to the troubleshooting questions. Nothing seems out of the ordinary in the ones I asked, nor in PSModulePath.by Stevo at 2012-09-13 04:22:05
I went back to your original message, and the bug does not appear to be in Show-Command, but instead it appears to be happening in Get-Command. Looking at your original error, It indicates that Get-Command (internally the GetCommandCommand class) is raising a null reference exception:PS C:\Scripts> Show-Command
get-command : Object reference not set to an instance of an object.
At line:1 char:3
+ @(get-command -CommandType Cmdlet,Function,Script,ExternalScript,Workflow),@(get …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: ([Get-Command], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GetCommandCommand
I’d like to see the details about that error. Immediately after you get that error in PowerShell, can you share the output of the following:$error[0] | Format-List * -Force
$error[0].Line
$error[0].Exception | Format-List * -Force
That output may help highlight what the true issue is here.
Also when you open PowerShell ISE as an administrator, can you invoke Get-Command without any issues?
For the details you provided such as PSModulePath, are those what you see you open PowerShell ISE as administrator? And what modules do you have installed in your administrator’s Documents\WindowsPowerShell\Modules folder?
Lastly, if you rename your Documents\WindowsPowerShell\Modules folder as something else temporarily, and then open PowerShell ISE as administrator and invoke Show-Command (or Get-Command, presuming you get an error with that as well), do you still see the error?
Hi Kirk and Don,by poshoholic at 2012-09-13 05:47:18
Thanks for helping me out with this. I did some more investigating into this and it appeared to be my admin profile that was corrupted.
After deleting the profiles and regkeys and then profile re-creation this issue was resolved.
Keep up the good work and Don, great books (PS Month of Lunches 3 and PS in Depth)
Thanks for circling back to let us know that the issue is resolved.by Stevo at 2012-09-16 23:48:55
Hi, aplogies but my issue has reared its ugly head again. This is the output from what you asked me last:by Stevo at 2012-09-16 23:54:29
PS C:\Scripts> Show-Command
get-command : Object reference not set to an instance of an object.
At line:1 char:3
+ @(get-command -CommandType Cmdlet,Function,Script,ExternalScript,Workflow),@(get …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: ([Get-Command], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GetCommandCommand
PS C:\Scripts> $error[0] | Format-List * -Force
PSMessageDetails :
Exception : System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.PowerShell.Commands.GetCommandCommand.IsCommandMatch(CommandInfo& current)
at Microsoft.PowerShell.Commands.GetCommandCommand.AccumulateMatchingCommands(IEnumerable1 commandNames)<br> at Microsoft.PowerShell.Commands.GetCommandCommand.AccumulateMatchingCommands()<br> at Microsoft.PowerShell.Commands.GetCommandCommand.ProcessRecord()<br> at System.Management.Automation.Cmdlet.DoProcessRecord()<br> at System.Management.Automation.CommandProcessor.ProcessRecord()<br>TargetObject : <br>CategoryInfo : NotSpecified: (:) [Get-Command], NullReferenceException<br>FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GetCommandCommand<br>ErrorDetails : <br>InvocationInfo : System.Management.Automation.InvocationInfo<br>ScriptStackTrace : at <ScriptBlock>, <No file>: line 1<br> at <ScriptBlock>, <No file>: line 1<br>PipelineIterationInfo : {}<br><br>PS C:\Scripts> $error[0].Line<br><br>PS C:\Scripts> $error[0].Exception | Format-List * -Force<br><br>Message : Object reference not set to an instance of an object.<br>Data : {}<br>InnerException : <br>TargetSite : Boolean IsCommandMatch(System.Management.Automation.CommandInfo ByRef)<br>StackTrace : at Microsoft.PowerShell.Commands.GetCommandCommand.IsCommandMatch(CommandInfo& current)<br> at Microsoft.PowerShell.Commands.GetCommandCommand.AccumulateMatchingCommands(IEnumerable
1 commandNames)
at Microsoft.PowerShell.Commands.GetCommandCommand.AccumulateMatchingCommands()
at Microsoft.PowerShell.Commands.GetCommandCommand.ProcessRecord()
at System.Management.Automation.Cmdlet.DoProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
HelpLink :
Source : System.Management.Automation
PS C:\Scripts> Get-Command
Get-Command : Object reference not set to an instance of an object.
At line:1 char:1
+ Get-Command
+ ~~~~~~~~~~~
+ CategoryInfo : NotSpecified: ([Get-Command], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GetCommandCommand
Your help is greatly appreciated
The only modules i have on my profile for ISE is:by poshoholic at 2012-09-17 07:46:26
ActiveDirectory
Quest.ActiveRoles.ADManagement
Ok, so that confirms that the issue is indeed Get-Command, since it causes this error. Let’s focus on Get-Command and confirm a few more things:by Stevo at 2012-09-18 01:16:18
1. When you run Get-Command in non-elevated PowerShell (native console, not ISE), do you get this error?
2. When you run Get-Command in elevated PowerShell (native console, not ISE), do you get this error?
3. When you run Get-Command in non-elevated PowerShell ISE, do you get this error?
For these tests, make sure you launch PowerShell.exe or PowerShell_ISE.exe with the /noprofile switch so that you’re starting from as clean a state as possible.
Hi Kirk,by poshoholic at 2012-09-18 06:09:48
For question 1 no i dont get this error.
For question 2 no i dont get this error.
For question 3 no i dont get this error.
I have a feeling that this could be caused by the Quest Cmdlets as i have opened up the ISE with another admin credentials without Quest cmdlets and it appears to work correctly.
Try the following then:by Stevo at 2012-09-19 03:57:44
1. Open ISE in an elevated session using the -NoProfile switch. This will help eliminate your profile from the equation. If you don’t get the error, then something’s up with your profile. In this scenario, assuming you don’t get the error, manually load the Quest cmdlets and then see if you get the error.
2. If you do identify the problem is your profile, back up your profile and then create a new profile. Bring items in your profile in one at a time until you identify what the culprit is.
FWIW, I have the Quest AD cmdlets installed and while I’m not loading them in my profile, I can load them in ISE elevated and then call Get-Command and it works.
Hi Kirk,by poshoholic at 2012-09-19 06:55:39
I have carried out what you have advised and it looks like the Quest Cmdlets are the culprit.
Without them on my admin profile all works fine and i can load them in manually and Get-Command works fine.
With them on my profile they are somehow breaking Get-Command and Show-Command.
I will put in a problem with Quest and see what they say.
Thanks Alot Kirk
I’m glad you identified the root cause. Just for my own knowledge, what were you doing with the Quest cmdlets inside of your profile? Simply invoking Add-PSSnapin Quest.ActiveRoles.ADManagement? I have tried that locally and it works fine in both 32-bit and 64-bit PowerShell ISE when elevated. I am not currently domain joined, just using a standalone server.by Stevo at 2012-09-19 07:06:21
Also, if you remove the Quest AD cmdlet usage from your profile but then do it manually in ISE, does that work?
Yes i was just invoking the Add pssnapin along with import-module activedirectory.
After removing the pssnapin and just load it manually everything works fine. Maybe there is an issue with the version of quest cmdlets and PSISE v3?
I have sent them an email with all the details. Iff i get a reply i will comment on here for all.
Many thanks again