Get-Content Error

This topic contains 6 replies, has 3 voices, and was last updated by Profile photo of Roger Goins Roger Goins 2 years, 6 months ago.

  • Author
    Posts
  • #15427
    Profile photo of Roger Goins
    Roger Goins
    Participant

    Hello, I'm getting this error when I try to run Get-Content.
    Get-Content : Cannot bind argument to parameter 'Path' because it is an empty array.
    At line:1 char:1
    + Get-Content
    + ~~~~~~~~~~~
    + CategoryInfo : InvalidData: (:) [Get-Content], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyArrayNotAllowed,Microsoft.PowerShell.Commands.GetContentCommand

    I first noticed the problem when I tried using Show-Command. The error for that is:
    get-command : Object reference not set to an instance of an object.
    At line:1 char:3
    + @(get-command -CommandType Cmdlet,Function,Script,ExternalScript,Work ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Get-Command], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GetCommandCommand

    I get the same errors using console or ISE. Same thing using elevated for both. Any thoughts???

  • #15428
    Profile photo of Roger Goins
    Roger Goins
    Participant

    Sorry, I forgot to add that I also tried opening the console with the -NoProfile option. I still receive the error.

  • #15430
    Profile photo of Roger Goins
    Roger Goins
    Participant

    Mike, thanks for the quick reply. Unfortuneatly, I pasted the wrong command. It's Get-Command, not Get-Content. Hate when I do that. You can see the error I get with Show-Command after my typo earlier. Here's the error for 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

  • #15434
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    Roger,

    Please check out my post on another thread where we are discussing the Get-Command error as well. The Microsoft KB article might be relevant if you have SQL Server 2008/2008 R2 components installed.

    Best,
    Daniel

  • #15449
    Profile photo of Roger Goins
    Roger Goins
    Participant

    Daniel, I have SQL Server Express 2012 installed. I'll double check this though just in case. Thanks

    Mike, the command, as you suggested, "Get-Command -name Get-Module", works. I tried "Show-Command Get-Module" and the worked as well. However, if I try Get-Command or Show-Command with no parameters, I still get the error.

  • #15429
    Profile photo of Mike F Robbins
    Mike F Robbins
    Participant

    The Get-Content cmdlet gets the contents of a file. The Path parameter is a mandatory parameter and must be specified otherwise you'll receive that error:

    
    PS C:\> help Get-Content -Parameter path
    
    -Path 
        Specifies the path to an item. Get-Content gets the content of the item. Wildcards are permitted. The parameter
        name ("Path" or "FilePath") is optional.
    
        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?       true (ByPropertyName)
        Accept wildcard characters?  true
    
    PS C:\>
    
  • #15431
    Profile photo of Mike F Robbins
    Mike F Robbins
    Participant

    If you run Get-Command on a particular cmdlet, do you receive the same error? Example:

    
    Get-Command -Name Get-Module
    

    If that runs without error, give this a try to see if it's cmdlets in a particular module that's causing the issue:

    
    Get-Module -ListAvailable | ForEach-Object {
        Write-Output "*** Module Name: $($_.Name) ***"
        Get-Command -Module $_.Name
    }
    

You must be logged in to reply to this topic.