0
votes

I am trying to install one client's software by using PowerShell silent scripting. Below is the script which I have created and its not working and throwing errors like below:

Cannot validate argument on parameter 'ArgumentList'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any null values and then try the command again

Is the below line correct or any mistake in this Here I am getting issue.

$Args = @("/S", "/L1033", -INSTALL_TYPE=PRESERVE_VERSION, START_MENU=AStartMenuFolder\Software\production\)

Full script:

$INSTALLDIR = "C:\Software\Software.exe"
$Args = @("/S", "/L1033", -INSTALL_TYPE=PRESERVE_VERSION, START_MENU=AStartMenuFolder\Software\production\)
$logfile = "D:\BACKUP\Install_Logfile.txt"
$ErrorActionPreference = 'Stop'
try {
    $exitcode = (Start-Process $Installer -ArgumentList $Args -NoNewWindow -Wait -Passthru).ExitCode    
    if ($exitcode -eq 0) {
        [System.Windows.MessageBox]::Show('Installation Completed Successfully')
    } else {
        [System.Windows.MessageBox]::Show('Installation Failled')
    }
} catch {
    "$_" | Out-File $logfile -Append
    {[System.Windows.MessageBox]::Show('Installation Failled')}
}

Edit:

$Installer = "C:\OTE\OTE.exe"
$params = @("/S", "/L1033", "-INSTALL_TYPE=PRESERVE_VERSION", "-START_MENU=AStartMenuFolder\OTE\production\")
$logfile = "C:\Install_Logfile.txt"
$ErrorActionPreference = 'Stop'

& $Installer @params
if ($LastExitCode -eq 0) {
    [Windows.MessageBox]::Show('Installation Completed Successfully')
} else {
    "$_" | out-file $logfile -append
    [Windows.MessageBox]::Show('Installation Failled')
}

In the above script I am getting the error like below,

Cannot validate argument on parameter 'ArgumentList'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any null values and then try the command again.

2
Put all $args element in quotes. This line should throw an error at the moment - guiwhatsthat
Its not showing any message also..the message box code is correct rite..? - Meghana
Run only this line of code in your ise $Args=@("/S", "/L1033", -INSTALL_TYPE=PRESERVE_VERSION, START_MENU=AStartMenuFolder\Software\production) , it will throw an error - guiwhatsthat

2 Answers

2
votes

There are several things you may want to fix in your code:

  • $args is an automatic variable. Don't try to overwrite it. Use a different variable name, e.g. $params. As others have already mentioned, put the parameters in quotes when defining the array.
  • Unless you have specific reasons to use Start-Process it's easier to use the call operator and splatting.
  • External programs don't throw PowerShell exceptions, so using try/catch on them is pointless.
  • PowerShell automatically records the exit code of an external program in the automatic variable $LastExitCode.
$installer = 'C:\Software\Software.exe'
$params = '/S', '/L1033', '-INSTALL_TYPE=PRESERVE_VERSION',
          'START_MENU=AStartMenuFolder\Software\production'

& $Installer @params
if ($LastExitCode -eq 0) {
    [Windows.MessageBox]::Show('Installation Completed Successfully')
} else {
    [Windows.MessageBox]::Show('Installation Failled')
}
0
votes

Your items need to be within quotes when creating an array:

$Args=@("/S", "/L1033", "-INSTALL_TYPE=PRESERVE_VERSION", "START_MENU=AStartMenuFolder\Software\production\")