Need Help with Powershell Advance Function

This topic contains 2 replies, has 2 voices, and was last updated by  Mariusz Serwin 3 years, 6 months ago.

  • Author
    Posts
  • #13685

    Mariusz Serwin
    Participant

    Hi , I'm new to Powershell and I'm working on script to gather some hardware information .
    Script works fine only for single computer but is coming up with an error when I'm trying to get information's from multiple remote computers .

    Method invocation failed because [System.Object[]] doesn't contain a method named 'op_Division'.
    At C:\HwInfops1.ps1:46 char:2
    + $HWHashTabel =[ordered]@{
    + ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (op_Division:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

    param (
    [Parameter(Mandatory=$true)]
    [string[]]$computername
    )

    I have Parameter $computername set to accept multiple computers .
    Can anyone help me please .
    Script is attached as TXT file .

  • #13687

    Kevin Hopcroft
    Participant

    you will need a loop.

    either
    foreach($computer in $computername)
    {
    $BIOS = Get-WmiObject win32_bios -computername $computer
    ...............
    ...............
    $HDDinfo
    }

    or

    $computername | foreach-object {
    $BIOS = Get-WmiObject win32_bios -computername $_
    ...............
    ...............
    $HDDinfo
    }

    Kevin

  • #13722

    Mariusz Serwin
    Participant

    Thank you Kevin . That solved the issue .

You must be logged in to reply to this topic.