WSMan Config issue?.

Tagged: 

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Harrison Alexander Harrison Alexander 3 years, 3 months ago.

  • Author
    Posts
  • #12547
    Profile photo of Harrison Alexander
    Harrison Alexander
    Participant

    Hello-

    I am running into a problem when I am piping computer names into a function I put together

    I have a list of 88 computers names saved as in a text file. The first 31 come back with the correct data and then the script stalls. Could this WSMan Config issue?

    He is the code I am working with.

    Any Help would be greatly Appreciated

    ipcsv .\computer.csv | get-eddyinventory | exxport.csv .\inv.csv

    function Test-PsRemoting 
    { 
         [CmdletBinding()]            
     Param             
       (                       
        [Parameter(Mandatory=$true,
                   Position=0,                          
                   ValueFromPipeline=$true,            
                   ValueFromPipelineByPropertyName=$true)]   
            $computername 
        ) 
        
        try 
        { 
            $errorActionPreference = "Stop" 
            $result = Invoke-Command -ComputerName $computername { 1 } 
        } 
        catch 
        { 
            Write-Verbose $_ 
            return $false 
        } 
        
        ## I've never seen this happen, but if you want to be 
        ## thorough…. 
        if($result -ne 1) 
        { 
            Write-Verbose "Remoting to $computerName returned an unexpected result." 
            return $false 
        } 
        
        $true    
    }
    
    Function Get-EddyInventory {
    # $b | select @{n="computername";e={$_.name}} | Get-EddyInventory 
     [CmdletBinding()]            
     Param             
       (                       
        [Parameter(Mandatory=$true,
                   Position=0,                          
                   ValueFromPipeline=$true,            
                   ValueFromPipelineByPropertyName=$true)]            
        [Object]$Object,
        [String]$Parameter
        )#End Param  
      Begin            
    {            
      $ErrorActionPreference = "SilentlyContinue"
              
    }#Begin  
               
       Process            
    {
    
           trap {
       $computer | out-file c:\errors.txt -append
       continue
      }
    
        $Object | ForEach-Object {
             if ($Parameter)
                {
                    $Computer = $_."$Parameter"
                    $test = Test-PsRemoting -computername $Computer
    
                }
            elseif ($_.ComputerName)
                {
                    $Computer = $_.ComputerName    
                    $test = Test-PsRemoting -computername $Computer
                }
            else    
                {
                    $Computer = $_
                    $test = Test-PsRemoting -computername $Computer
                }
          
            
            if ($test -eq $true)
                {
                $os = Get-WMIObject -Class win32_operatingsystem  -comp $Computer  -ea stop
                $cs = Get-WmiObject -Class win32_computersystem -comp $Computer    -ea stop
                $bios =Get-WmiObject -Class Win32_BIOS -Computername $Computer     -ea Stop
    
                $data = new-object psobject
                $data | add-member noteproperty 'Computer Name' $cs.name
                $data | add-member noteproperty 'User Name' $cs.Username
                $data | add-member noteproperty 'Operating System' $os.caption
                $data | add-member noteproperty 'Install Date' $os.ConvertToDateTime($os.installdate)
                $data | add-member noteproperty 'Model' $cs.model
                $data | add-member noteproperty 'Servie Tag' $bios.SerialNumber
                $data | add-member noteproperty 'RAM' ($CS.TotalPhysicalMemory/1GB -AS [INT])
    
                write $data 
                   
                    
                }
             else
                {
       $computer | out-file c:\errors.txt -append
                }
        }#Foreach-Object (Computers)
        
    } 
    } 
     
  • #12549
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Try removing or commenting out that $ErrorActionPreference = "SilentlyContinue" line, and you may get some more information about what's going wrong.

    On a side note, WSMAN and PSRemoting have nothing to do with Get-WmiObject, which uses the older DCOM protocol. A successful result from your Test-PsRemoting function is not an indicator that the WMI calls will be successful; the firewall may be blocking the RPC port, for example.

  • #12550
    Profile photo of Harrison Alexander
    Harrison Alexander
    Participant

    Thanks for the reply

    I am successfully getting back half the list of computers that I am piping into the function, with all the data from the WMI queries, it just seems to "freeze" halfway thru the list. For the most part they are all very similar dell models.

  • #12551
    Profile photo of Harrison Alexander
    Harrison Alexander
    Participant

    I will com-met it out and let you know you thank you

  • #12552
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    Why are you testing remoting in this scenario?

    These 3 lines are the core of your script

    $os = Get-WMIObject -Class win32_operatingsystem -comp $Computer -ea stop
    $cs = Get-WmiObject -Class win32_computersystem -comp $Computer -ea stop
    $bios =Get-WmiObject -Class Win32_BIOS -Computername $Computer -ea Stop

    You are using Get-WmiObject which uses DCOM to access the remote computer. DCOM is an older technology that has nothing to do with WSMAN and remoting. The alternative is to wrap the WMI calls in Invoke-Command or better still create a CIM session to the remote machine and use the CIM cmdlets

    For the ones that fail try a WMI call from the command line – if DCOM access is disabled you'll get an error

  • #12555
    Profile photo of Harrison Alexander
    Harrison Alexander
    Participant

    ok I'll give that a try.. thank you Richard

You must be logged in to reply to this topic.