Good Afternoon,
I am trying to write a script to install software. The script is below:
$ComputerName = Read-Host -Prompt "Please Enter The Computer Name"
$Software = Read-Host -Prompt "Please Enter The Software Name"
switch ($Software)
{
Java {$Software = "C:\Script\Java.msi"}
Atom {$Software = "C:\Script\AtomSetup.exe"}
Notepad {$Software = "C:\Script\notepad.exe"}
Default {Throw No Software Match found for $software}
}
$session = New-PSSession -ComputerName $ComputerName
Copy-Item -Path $Software -Destination C:\Script -Recurse -Verbose -ToSession $session
$session | Remove-PSSession
Invoke-Command -ComputerName $ComputerName -Credential (Get-Credential) -ScriptBlock {start-process -Filepath $software -ArgumentList '/silent' -wait
Remove-Item -Path $software -Force
}
I am getting the error message below.
Cannot validate argument on parameter 'FilePath'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. + CategoryInfo : InvalidData: (:) [Start-Process], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StartProcessCommand + PSComputerName : testPC
Cannot bind argument to parameter 'Path' because it is null. + CategoryInfo : InvalidData: (:) [Remove-Item], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RemoveItemCommand + PSComputerName : testPC
Any help would be appreciated
Default {Throw "No Software Match found for $software"}
(missing double quotes). Read and follow about_Throw:THROWING A STRING.