I have a PS script, which loops through file folders and archive some of them:
$CSV = import-csv -path C:\folder\Builds\ApplicationsMappingNew.csv
$Application = $CSV.Application
$GetAppPath = Get-ChildItem -Path $DestinationDir\Server\*
foreach($line in $GetAppPath){
$AppPath = $Line.fullname
$AppName = Split-Path $AppPath -Leaf
$RAR_Destination = "C:\folder\Builds\test1\SOA-ConfigurationManagement"+"\"+"$AppName"+"_st-FTP.rar"
Push-Location $AppPath
& "C:\Program Files (x86)\WinRAR\rar" a -r $RAR_Destination
}
And I have a CSV file, which has an Application column:
My question is - how, inside a foreach
loop, can I compare the $Appname
loop variable value with the values inside the $Application
array variable?
And, if the value of $AppName
equals a value inside the $Application
array, execute Push-Location
and execute a winrar
command. If not, skip to next element in foreach($line in $GetAppPath)
?