2016-06-22 5 views
2

Win10 및 Powershell 5.0을 새로 설치했습니다. 나는 update-help를 실행했고 대부분 잘 동작한다. 그러나 Get-Command는 일반 모드인지 상승 모드인지에 관계없이 null 참조 예외를 반환합니다. 나는 또한 -noprofile을 사용하여 Run from Powershell을 실행하려고 시도했지만 사용자와 상승 모드에서 여전히 동일한 오류가 발생합니다. 여기에 몇 가지 추가 정보는 다음과 같습니다Powershell 5.0/Windows 10 Get-Command Null 참조 예외

PS Z:\> Get-WmiObject Win32_OperatingSystem | Select-Object -Property Version, ServicePackMajorVersion, ServicePackMinorVersion 

Version ServicePackMajorVersion ServicePackMinorVersion 
------- ----------------------- ----------------------- 
10.0.10586      0      0 

PS Z:\> $PSVersionTable 

Name       Value 
----       ----- 
PSVersion      5.0.10586.122 
PSCompatibleVersions   {1.0, 2.0, 3.0, 4.0...} 
BuildVersion     10.0.10586.122 
CLRVersion      4.0.30319.42000 
WSManStackVersion    3.0 
PSRemotingProtocolVersion  2.3 
SerializationVersion   1.1.0.1 

PS Z:\> get-command 
>> TerminatingError(Get-Command): "Object reference not set to an instance of an object." 
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 
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 

PS Z:\> $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, Boolean& isDuplicate) 
          at Microsoft.PowerShell.Commands.GetCommandCommand.AccumulateMatchingCommands(IEnumerable`1 commandNames) 
          at System.Management.Automation.CommandProcessor.ProcessRecord() 
TargetObject   : 
CategoryInfo   : NotSpecified: (:) [Get-Command], NullReferenceException 
FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GetCommandCommand 
ErrorDetails   : 
InvocationInfo  : System.Management.Automation.InvocationInfo 
ScriptStackTrace  : at <ScriptBlock>, <No file>: line 1 
PipelineIterationInfo : {} 



PS Z:\> $error[0].line 
PS Z:\> $error[0].exception | format-list * -force 


Message  : Object reference not set to an instance of an object. 
Data   : {} 
InnerException : 
TargetSite  : Boolean IsCommandMatch(System.Management.Automation.CommandInfo ByRef, Boolean ByRef) 
StackTrace  : at Microsoft.PowerShell.Commands.GetCommandCommand.IsCommandMatch(CommandInfo& current, Boolean& isDuplicate) 
        at Microsoft.PowerShell.Commands.GetCommandCommand.AccumulateMatchingCommands(IEnumerable`1 commandNames) 
        at System.Management.Automation.CommandProcessor.ProcessRecord() 
HelpLink  : 
Source   : System.Management.Automation 
HResult  : -2147467261 

사용자와 높은 모드 모두에서 갱신 도움을 실행 한 후, 내가 PowerShell에서했던 다음 일은 내가 '돈 때문에이 문제가 발생하는 경우 SQL Power Doc 그래서 난 잘 모르겠어요 설치했다 설치 전에 Get-Command를 사용하여 호출하십시오. 이 오류없이 작동 -

Set-ExecutionPolicy RemoteSigned -Force 

New-Item -type directory -path "$([Environment]::GetFolderPath([Environment+SpecialFolder]::MyDocuments))\WindowsPowerShell\Modules" 

Set-Location "$([Environment]::GetFolderPath([Environment+SpecialFolder]::MyDocuments))\WindowsPowerShell" 

내가 가져-명령에 대한 도움말을 실행합니다 :

PS Z:\> help get-command 

NAME 
    Get-Command 

SYNOPSIS 
    Gets all commands. 


SYNTAX 
    Get-Command [[-ArgumentList] [<Object[]>]] [-All] [-FullyQualifiedModule [<ModuleSpecification[]>]] [-ListImported] [-Module [<String[]>]] [-Noun [<String[]>]] [-ParameterName [<String[]>]] [-ParameterType [<PSTypeName[]>]] [-ShowCommandInfo] [-Syntax] [-TotalCount 
    [<Int32>]] [-Verb [<String[]>]] [<CommonParameters>] 

    Get-Command [[-Name] [<String[]>]] [[-ArgumentList] [<Object[]>]] [-All] [-CommandType {Alias | Function | Filter | Cmdlet | ExternalScript | Application | Script | Workflow | Configuration | All}] [-FullyQualifiedModule [<ModuleSpecification[]>]] [-ListImported] 
    [-Module [<String[]>]] [-ParameterName [<String[]>]] [-ParameterType [<PSTypeName[]>]] [-ShowCommandInfo] [-Syntax] [-TotalCount [<Int32>]] [<CommonParameters>] 


DESCRIPTION 
    The Get-Command cmdlet gets all commands that are installed on the computer, including cmdlets, aliases, functions, workflows, filters, scripts, and applications. Get-Command gets the commands from Windows PowerShell modules and snap-ins and commands that were 
    imported from other sessions. To get only commands that have been imported into the current session, use the ListImported parameter. 

    Without parameters, a Get-Command command gets all of the cmdlets, functions, workflows and aliases installed on the computer. A Get-Command * command gets all types of commands, including all of the non-Windows-PowerShell files in the Path environment variable 
    ($env:path), which it lists in the "Application" command type. 

    A Get-Command command that uses the exact name of the command (without wildcard characters) automatically imports the module that contains the command so you can use the command immediately. To enable, disable, and configure automatic importing of modules, use the 
    $PSModuleAutoLoadingPreference preference variable. For more information, see about_Preference_Variables (http://go.microsoft.com/fwlink/?LinkID=113248). 

    Get-Command gets its data directly from the command code, unlike Get-Help, which gets its information from help topics. 

    In Windows PowerShell 2.0, Get-Command gets only commands in current session. It does not get commands from modules that are installed, but not imported. To limit Get-Command in Windows PowerShell 3.0 and later to commands in the current session, use the 
    ListImported parameter. 

    Starting in Windows PowerShell 5.0, results of the Get-Command cmdlet display a Version column by default; a new Version property has been added to the CommandInfo class. 


RELATED LINKS 
    Online Version: http://go.microsoft.com/fwlink/p/?linkid=289583 
    Export-PSSession 
    Get-Help 
    Get-Member 
    Get-PSDrive 
    Import-PSSession 
    about_Command_Precedence 

REMARKS 
    To see the examples, type: "get-help Get-Command -examples". 
    For more information, type: "get-help Get-Command -detailed". 
    For technical information, type: "get-help Get-Command -full". 
    For online help, type: "get-help Get-Command -online" 

사람이 분명 아무것도 보이지 않음 동안

내가이 명령을 실행, 설치? 어떤 도움을 주셔서 감사합니다.

+0

분명히하기 : Windows 10 OS를 새로 설치했지만 수동으로 PowerShell 5.0을 설치하려고하지 않았습니까? PS 5에는 10이 나온 이래로? – gravity

+1

맞습니다. – SFAgitator

+1

'Modules' 디렉토리의 이름을 임시로 바꾼 다음'Get-Command'를 다시 실행하여 수정했는지 확인하는 것이 좋습니다. 당신이 모듈을 추가 한 것을 본 후에, 나는 그것이 관련이 있다고 내기하고 있습니다. 그것이 문제를 해결하지 못한다면 복원하여 알려주십시오 ...;) – gravity

답변

3

Modules 디렉토리를 임시로 바꾼 다음 Get-Command을 다시 실행하여 문제가 해결되었는지 확인하는 것이 좋습니다.

(이 솔루션처럼 질문에 위의 코멘트 당, 그것은 보인다.) 저도 같은 문제를 가지고 있기 때문에

0

난 그냥이 질문을 우연히 발견했다. SQL Powerdoc 솔루션과 함께 제공되는 모듈 RDS-Manager와 관련이 있다고 생각합니다. RDS.Manager는 TechNet 갤러리에서 제공합니다. http://gallery.technet.microsoft.com/ScriptCenter/e8c3af96-db10-45b0-88e3-328f087a8700/

모듈 폴더에서 전체 폴더를 제거했으며 모든 것이 정상이었습니다. RDS 모듈이 추가되었으며 NullReference Exception이 다시있었습니다.

+0

이상하게도, RDS 모듈을 제거하고 추가 한 후에 잘 동작합니다. –