Share via

need help with script

lupinlicious 141 Reputation points
2022-08-30T17:06:55.08+00:00

Hello,

I have the following script that will look up the computer model (based on a folder structures with computer models) and copy the executable from the folder to the script directory.
Old Dell computers have a different name for the BIOS executable comparing to newer Dell computers, therefore I'm copying the name of the file from the executable.

         New-PSDrive -Name "A" -Root $scriptDirectory -Persist -PSProvider "FileSystem"  

        #Create Model Variable  
        $ComputerModel = Get-WmiObject -Class Win32_computersystem | Select-Object -ExpandProperty Model  
          
        #Copy Bios Installer to the root of the package  
        Copy-Item -Path "$scriptDirectory\Files\$ComputerModel\*.exe" -Destination "$Scriptdirectory\Files"  
  
        #Get Bios File Name (Uses the Bios EXE file in the same folder)  
        $BiosFileName = Get-ChildItem -Path "$scriptDirectory\Files\$ComputerModel\" -Filter *.exe -Recurse -Verbose | Select -ExpandProperty Name  
  
        #Get Bios File Name  
        $BiosLogFileName = Get-ChildItem -Path "$scriptDirectory\Files\$ComputerModel\" -Filter *.exe -Verbose | Select -ExpandProperty BaseName  
  
        #Set Command Arguments for Bios Update  
        $cmds = "/s /l=$LogPath\$BiosLogFileName"  
  
        $Process = Start-Process "$scriptDirectory\Files\$BiosFileName" "$cmds" -Wait -PassThru   
     
          

When the scripts run I can see from the script directory it has succeeded with the copying, but it fails to start the process. I tried with a numerous ways to execute this, like:

 Execute-Process "$scriptDirectory\Files\$BiosFileName" "$cmds" -Wait  
   
$Process = Start-Process "$scriptDirectory\Files\$BiosFileName.exe" "$cmds" -Wait -PassThru   
   
Execute-Process -Path "$scriptDirectory\Files\$BiosFileName" "$cmds" -Wait -PassThru  
          
 Execute-Process -Path "$scriptDirectory\Files\$BiosFileName.exe" "$cmds" -Wait -PassThru  
   
$Process = Start-Process -FilePath "$scriptDirectory\Files\$BiosFileName" "$cmds" -Wait -PassThru   
          
 $Process = Start-Process "$scriptDirectory\Files\$BiosFileName" -Filter *.exe "$cmds" -Wait -PassThru  

The BDD.log tells me "returned an unexpected return code: 60002 (and continues with the rest of the things)

Or an error pops up with "FullyQualifiedErrorId : InvalidOperatonException,Microsoft.Powershell.Commands,StartProcessCommand and points me to $Process = Start-Process

How shall I type this?

Thaaank you!

Windows for business | Windows Client for IT Pros | Devices and deployment | Set up, install, or upgrade
Windows for business | Windows Server | User experience | PowerShell

1 answer

Sort by: Most helpful
  1. jpaulo 6 Reputation points
    2022-08-30T17:30:02.98+00:00

    Hello @lupinlicious

    The script is failiing because you're trying to pass the argument of the process alongside the FilePath.
    You must separate one from another with the parameter -ArgumentList

    Please try the following cmdlet in your script

    $Process = Start-Process -FilePath "$scriptDirectory\Files\$BiosFileName"  -ArgumentList $cmds -Wait -PassThru   
    

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.