Hi all,
I have a script which I am running from within a .bat file.
.bat file contents are:
@echo off powershell.exe -executionpolicy bypass -command "& 'c:\temp\McAfee_PL8_update_all.ps1'" exit
for some reason the .bat file does not exit therefor in my main script the for each loop cannot continue…
contents below of: McAfee_PL8_update_all.ps1
# 01 McAfee PL8 fresh install locations for x64 machines: $x64_agent_1 = Test-Path 'c:\Program Files\McAfee\Agent\CmdAgent.exe' $x64_update_1 = Test-Path 'c:\Program Files (x86)\McAfee\VirusScan Enterprise\mcupdate.exe' # 02 McAfee PL8 upgrade install locations for x64 machines: $x64_agent_2 = Test-Path 'c:\Program Files (x86)\McAfee\Common Framework\CmdAgent.exe' $x64_update_2 = Test-Path 'c:\Program Files (x86)\McAfee\VirusScan Enterprise\mcupdate.exe' # 03 McAfee PL7 install locations for x86 machines: $x86_agent_1 = Test-Path 'c:\Program Files\McAfee\Common Framework\CmdAgent.exe' $x86_update_1 = Test-Path 'c:\Program Files\McAfee\VirusScan Enterprise\mcupdate.exe' # 04 McAfee PL8 upgrade from PL7 locations for x86 machines: $x86_agent_2 = Test-Path 'c:\Program Files\McAfee\agent\CmdAgent.exe' $x86_update_2 = Test-Path 'c:\Program Files\McAfee\VirusScan Enterprise\mcupdate.exe' # 05 not used yet #$x86_x64_1 = Test-Path 'C:\Program Files\McAfee\Agent\CmdAgent.exe' #01 Variables used (Fresh PL8 install for x64): if (($x64_agent_1 -eq 'True') -and ($x64_update_1 -eq 'True')) { cd 'c:\Program Files (x86)\McAfee\VirusScan Enterprise' .\mcupdate.exe /update /quiet wait-event -Timeout 30 cd 'C:\Program Files\McAfee\Agent' .\cmdagent.exe -p wait-event -Timeout 15 .\cmdagent.exe -f wait-event -Timeout 15 .\cmdagent.exe -c wait-event -Timeout 15 .\cmdagent.exe -e } #02 Variables used (PL8 upgrade for x64): Elseif (($x64_agent_2 -eq 'True') -and ($x64_update_2 -eq 'True')) { cd 'c:\Program Files (x86)\McAfee\VirusScan Enterprise' .\mcupdate.exe /update /quiet wait-event -Timeout 30 cd 'c:\Program Files (x86)\McAfee\Common Framework' .\cmdagent.exe /p wait-event -Timeout 15 .\cmdagent.exe /f wait-event -Timeout 15 .\cmdagent.exe /c wait-event -Timeout 15 .\cmdagent.exe /e } #03 Variables used (Fresh PL7 install for x86): Elseif (($x86_agent_1 -eq 'True') -and ($x86_update_1 -eq 'True')) { cd 'c:\Program Files\McAfee\VirusScan enterprise' .\mcupdate.exe /update /quiet wait-event -Timeout 30 cd 'c:\Program Files\McAfee\Common Framework' .\cmdagent.exe /p wait-event -Timeout 15 .\cmdagent.exe /f wait-event -Timeout 15 .\cmdagent.exe /c wait-event -Timeout 15 .\cmdagent.exe /e } #04 Variables used (PL8 upgrade for x86): Elseif (($x86_agent_2 -eq 'True') -and ($x86_update_2 -eq 'True')) { cd 'c:\Program Files\McAfee\VirusScan enterprise' .\mcupdate.exe /update /quiet wait-event -Timeout 30 cd 'c:\Program Files\McAfee\Agent' .\cmdagent.exe -p wait-event -Timeout 15 .\cmdagent.exe -f wait-event -Timeout 15 .\cmdagent.exe -c wait-event -Timeout 15 .\cmdagent.exe -e } break
main script that I run for the above:
# variables listed below $remotecomputers = Get-Content c:\temp\remotecomputers1.txt $sourcefile1 = "C:\Temp\mcafee_update.bat" $sourcefile2 = "C:\temp\PsExec.exe" $sourcefile3 = "C:\Temp\McAfee_PL8_update_all.ps1" # This section will Run the batch File foreach ($computer in $remotecomputers) { $destination = "\\$computer\c$\Temp" # This Section will Ping machine to ensure its online if((Test-Connection -Computername $computer -BufferSize 16 -Count 1 -quiet)) # This will Copy files to machine and create the destination folder if it does not exist {if (!(Test-Path -path $destination)) { New-Item $destination -Type Directory } Copy-Item -Path $sourcefile1, $sourcefile2, $sourcefile3 -Destination $destination -Force Invoke-Command -scriptblock {C:\temp\PsExec.exe -h -s \\$computer cmd /c "C:\Temp\McAfee_update.bat"} } }
I do apologies if im doing something completely wrong but i’m still learning this all.