Author Posts

August 2, 2013 at 7:23 am

Ok, so i have this script and everything works except that when it goes to apply the update powershell acts like it cannot find the file.

It returns the error "Failed: Exception calling "Start" with "2" argument(s): "the system cannot find the file specified"

I have verified that the file exists, the account i am using to apply it has permissions on it, I have even tried placing it locally on the machine i am running the script from and i still get the same error.

Here is my script:

function Invoke-BIOSUpdate {
[CmdletBinding()]
[OutputType([System.String])]
param(
[Parameter(ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[System.String[]]
$File,

[Parameter(ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[System.String[]]
$Arguments
)

begin {
Write-Host "BIOS Update Needed. Attempting BIOS Flash Operation..."
Write-Host "BIOS Update File: $File"
Write-Host "BIOS Update Arguments: $Arguments`n"
}
process {
try {
$install = [System.Diagnostics.Process]::Start($File,$Arguments)
$install.WaitForExit() | Out-Null
Write-Host "Restarting System"
Stop-Transcript
Restart-Computer -Force
} catch {[Exception]
Write-Host "Failed: $_"
}
}
end {}
}

Function ChangeBIOS {

$strcomputer = "computer"

$BIOS = Get-WmiObject “win32_BIOS" -computername $strcomputer

$Model = Get-wmiobject "win32_computersystem" -computername $strcomputer

#write-host "*"$Model $strcomputer"*"

If ((($Model.Model).Trim() -eq "OptiPlex 3010") -and (!($BIOS.SMBIOSBIOSVersion -eq "A09")))
{
write-Output "Computer Name: " $strComputer
write-Output "Bios: Out of Date 3010"
Invoke-BIOSUpdate "\\server\folder\Bios\Optiplex 30103010A09.exe" "-noreboot -nopause -forceit"

}
elseif ((($Model.Model).Trim() -eq "OptiPlex 360") -and (!($BIOS.SMBIOSBIOSVersion -eq "A07")))
{
write-Output "Computer Name: " $strComputer
write-Output "Bios: Out of Date 360"
Invoke-BIOSUpdate "\\server\folder\Bios\Optiplex 360360-A07.exe" "-noreboot -nopause -forceit"

}

elseif ((($Model.Model).Trim() -eq "OptiPlex 380") -and (!($BIOS.SMBIOSBIOSVersion -eq "A07")))
{
write-Output "Computer Name: " $strComputer
write-Output "Bios: Out of Date 380"
Invoke-BIOSUpdate "\\server\folder\Bios\Optiplex 380380-A07.exe" "-noreboot -nopause -forceit"

}

elseif ((($Model.Model).Trim() -eq "OptiPlex 390") -and (!($BIOS.SMBIOSBIOSVersion -eq "A10")))
{
write-Output "Computer Name: " $strComputer
write-Output "Bios: Out of Date 390"
Invoke-BIOSUpdate "\\server\folder\Bios\Optiplex 390390-A10.exe" "-noreboot -nopause -forceit"

}

}

ChangeBIOS >> "h:\myscripts\testbios.txt"

To be completely honest I am relatively new to powershell and this script is not complete by any means but im just stuck at this point and need some guidance.

Any help would be greatly appreciated!

August 2, 2013 at 8:40 am

Try replacing [System.Diagnostics.Process]::Start($File,$Arguments) with

Start-Process -filepath $File -argumentlist $Arguments

I wasn't able to replicate the file not found issue, but by using the cmdlet we will get another (hopefully useful) error.

August 2, 2013 at 9:28 am

Doing that i now get

"Failed: Cannot convert 'System.String[]' to the type 'Sytem.String' required by parameter 'FilePath' Specified method is not supported."

August 2, 2013 at 9:37 am

Righto, replace [System.String[]] with [String] . You don't need to specify System and because you aren't passing multiple items in an array so you don't need []. The error is telling you that because you are passing an array (even though it is only made up of one item) it can't process it as a single string.

August 2, 2013 at 9:51 am

This is so strange, I am now getting:

"Failed: This command cannot be run due to the error: The system cannot find the file specified"

BUT In the script where it writes output to the console

begin {
Write-Host “BIOS Update Needed. Attempting BIOS Flash Operation…”
Write-Host “BIOS Update File: $File”
Write-Host “BIOS Update Arguments: $Arguments`n”
}

It returns the file path exactly how it should be.

So i tried placing it locally on the machine at just "c:\myscripts\bios.exe" and also on the target computer in the same location.

August 2, 2013 at 9:52 am

BTW much thanks for your help.

August 2, 2013 at 11:34 am

Whenever i get a weird problem like that i go back to running the command manually, in this case

Start-Process -filepath “\\server\folder\Bios\Optiplex 360360-A07.exe” -argumentlist “-noreboot -nopause -forceit”

August 6, 2013 at 6:15 am

Just to update, the file name was causing this error all along. Still having an issue with completing the script but now at least the file will run. Thanks for all the help!