@JRV helped me yesterday with a script to install various .exe's using a PS script. I have made some additions and modifications to have the script also delete the directory after the process completes, and I have added some Read-Host parameters. I am having a problem with only one of these Read-Host Parameters that I can not get to work properly. Here is the script:
$sourcefile = Read-Host 'Enter the full path to the .exe/.msi being installed ie. \\Server\Folder\Java.exe'
$textfile = Read-Host 'Enter the full path to the location of text file containing the list of computers needing the .exe/.msi'
$computers = Get-Content $textfile
$process = Read-Host 'Enter the name of the .exe/.msi being installed ie. Java.exe'
$arglist = Read-Host 'Enter the switches to be used ie. /s /qn'
$sb={
Start-Process 'C:\Temp\$process' -ArgumentList '$arglist' -verb runas -Wait}
foreach ($computer in $computers){Write-Host "Processing computer: $computer" -ForegroundColor green
Try{
$destinationFolder="\\$computer\C$\Temp"
if(!(Test-Path -path $destinationFolder)){
New-Item $destinationFolder -Type Directory -ErrorAction stop}
Copy-Item -Path $sourcefile -Destination $destinationFolder -ErrorAction stop
Invoke-Command -ComputerName $computer -ScriptBlock $sb -ErrorAction stop}
Catch{Write-Host $_ -ForegroundColor red -BackgroundColor white}
}
Start-Sleep -s 10
foreach ($computer in $computers){Write-Host "Cleaning up: $computer" -ForegroundColor green
$Folder="\\$computer\C$\Temp"
if(Test-Path $Folder){
Remove-Item $Folder -Recurse -ErrorAction stop}}The error I'm getting I believe comes from the line:
$sb={
Start-Process 'C:\Temp\$process' -ArgumentList '$arglist' -verb runas -Wait}It looks like the script can't find the file 'C:\Temp\jre-7u25-windows-x64.exe' where 'jre-7u25-windows-x64.exe' is entered when prompted for the $process. I know that everything else works because I can log into the remote machine and watch the directory be created, the file coppied, and then deleted.
If I replace the 'C:\Temp\$Process' with 'C:\Temp\jre-7u25-windows-x64.exe' then the script works. But, I would like to input the name of the .exe without modifying the script. The errors I'm getting are:
Processing computer: computer1 Directory: \\computer1\C$ Mode LastWriteTime Length Name ---- ------------- ------ ---- d---- 8/27/2013 9:00 AM Temp This command cannot be executed due to the error: The system cannot find the file specified. Processing computer: computer2 Directory: \\computer2\C$ Mode LastWriteTime Length Name ---- ------------- ------ ---- d---- 8/27/2013 9:00 AM Temp This command cannot be executed due to the error: The system cannot find the file specified.Cleaning up: computer1 Cleaning up: computer2