0

I wrote this script to run a command on all of the computers in the Computers.txt file to update the bios using the HP bios utility. it looks like its not running the names from the txt and i just don't know what to do anymore...

$targets = Get-Content '\\52gkux-fs-001v\FRD-Admins\SCOO\03 - Scripts\Bazooka Blast\Targets\Computers.txt'
#List of computers to target

ForEach ($Computer in $targets){
#loops through each computer in your computer list
if (Test-Connection $computer -count 1 -Quiet )
{         
    Invoke-Expression -Command "\\52gkux-hc-001v\LogonScripts\Modules\BIOS\sp93030\BiosConfigUtility.exe /set:\\52gkux-hc-001v\LogonScripts\Modules\BIOS\sp93030\hpBios.txt /cspwdfile:\\52gkux-hc-001v\LogonScripts\Modules\BIOS\sp93030\password.bin  /log"
}

else  #means we had a bad ping
{
    #Report the reason for the bad ping based on WMI ping error code
    if ($reply.statuscode -eq $null)   #null status code means no DNS entry was found.  Delete that shit from ADUC (unless it's the three-star's laptop...)                 
    {                   
        $PingResponse = "No DNS Entry"
        $pingIPaddress = $null
        }
        #Report the reason for the bad ping based on WMI ping error code    
        if ($reply.statuscode -eq "11010")
        {
            #Ping timeouts still return the IP address from DNS        
            $pingIPaddress = $reply.IPV4Address.ipaddresstostring
            $PingResponse = "Request Timed Out"
        }
        #Report the reason for the bad ping based on WMI ping error code    
        if ($reply.statuscode -eq "11003")
        {
            $pingIPaddress = $reply.IPV4Address.ipaddresstostring
            $PingResponse = "Unable to reach host"
        }
    }
    $ResultProps = @{
        ComputerName =  $strComputer
        PingResponse =  $PingResponse
        ErrorCode = $ReturnCode
    }
    $return = New-Object PSObject -Property $ResultProps
    return $return
}
Benjamin Hubbard
  • 2,797
  • 22
  • 28
blakey108
  • 1
  • 2
  • 2
    The `Invoke-Command` cmdlet runs commands on a local or remote computer while `Invoke-Expression` cmdlet evaluates or runs a specified string as a command entirely **locally**. FYI, _I don't advise you to update the bios remotely_. – JosefZ Nov 26 '19 at 15:24
  • 1
    As an aside: [`Invoke-Expression` should generally be avoided](https://blogs.msdn.microsoft.com/powershell/2011/06/03/invoke-expression-considered-harmful/); definitely [don't use it to invoke an external program](https://stackoverflow.com/a/57966347/45375). – mklement0 Nov 26 '19 at 15:39
  • Also, remove the `return` keyword if you want the loop to continue – Mathias R. Jessen Nov 26 '19 at 16:42

0 Answers0