Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Shorten This Code

$
0
0

So I've got a script testing a few program by starting them, checking that they run and then closing them. So here's my code so far:

Powershell
functiontestApps{$arrApps,$arrFriendlyApps=getArrApps$i=0foreach($itemin$arrApps){Start-Process$item-ErrorActionSilentlyContinue$shortItem=getShortItem$itemStart-Sleep2if(!(Get-Process-Name$shortItem-ErrorActionSilentlyContinue)){$errorMessage="Software Test: $item failed to launch"pauseScript$errorMessage}else{$crntFrApp=$arrFriendlyApps[$i]Write-Host"$tab Software Test: $crntFrApp launched successfully"|Add-Content$outLogPath-ErrorActionSilentlyContinueStop-Process-Name$shortItem}$i++}}#works out which programs need to be tested and returns an array with the exe names and one with user friendly namesfunctiongetArrApps{$retValStandard='C:\...

Viewing all articles
Browse latest Browse all 15370

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>