This is the PS code to silently install the VLC Player. I have also added event and local logging, just as demonstrated logging segments.
* if you have trouble with the backtick being recognized as multi-line, just delete it and join the subsequent line.
Code
#define variables $strUser = "SCCM" $appSetup = "setup.exe" $silent =" /S /V/qn" $Source = "VLC Player 2.2.2" $TimeFormat = 'yyyy/MM/dd hh:mm:ss tt' #create event log source new-eventlog -Logname Application -source $Source -ErrorAction ` SilentlyContinue $logstamp = (get-date).toString($TimeFormat) ; $logstamp + ` " Created event log source.">>log.txt #install application Clear-Host Write-Host "Starting Setup..." cmd /c ($appSetup + $silent) $logstamp = (get-date).toString($TimeFormat) ; $logstamp + ` " Launched setup.exe.">>log.txt $logstamp = (get-date).toString($TimeFormat) ; $logstamp + ` " Exit code: " + $LastExitCode>>log.txt If ($LastExitCode -eq 0) { #write event log Clear-Host Write-Host "Writing event log..." $startTime = Get-date $startLog = $strUser + ': VLC Player COMPLETED SUCCESSFULLY ' ` + $startTime Write-Eventlog -Logname Application -Message $startLog -Source ` $Source -id 777 -entrytype Information -Category 0 $logstamp = (get-date).toString($TimeFormat) ; $logstamp + ` " Installed successfully!">>log.txt #exiting Clear-Host Write-Host "Installed successfully! Exiting now..." Start-Sleep -s 4 $logstamp = (get-date).toString($TimeFormat) ; $logstamp + ` " Exiting...">>log.txt } Else { #write event log Clear-Host Write-Host "Writing event log..." $startTime = Get-date $startLog = $strUser + ': VLC Player FAILED SETUP ' + $startTime Write-Eventlog -Logname Application -Message $startLog ` -Source $Source -id 777 -entrytype Information -Category 0 $logstamp = (get-date).toString($TimeFormat) ; $logstamp ` + " Failed setup!">>log.txt #exiting Clear-Host Write-Host "Failed setup! Exiting now..." Start-Sleep -s 4 $logstamp = (get-date).toString($TimeFormat) ; $logstamp + ` " Exiting...">>log.txt }
The wrapper or launch file
This can be used as the main deploy script to wrap and deploy through desktop management software (i.e., SCCM, LANDesk, Altiris, etc.). This should be compiled into one, nice EXE with the resource files.
Code
@echo on title SCCM Installation color 0b cls set CurDir=%CD% set PSPath=C:\Windows\System32\WindowsPowerShell\v1.0 %PSPath%\powershell.exe -Command "Set-ExecutionPolicy RemoteSigned" %PSPath%\powershell.exe -file "%CurDir%\script.ps1" ping -n 10 127.0.0.1>nul exit /b 0