title: Extracting each ZIP files in folder A to a separate folders (Folders are manually created and they existed)
body: <p>I have PowerShell 4.0 and windows server 2012 R2. I want to extract ZIP files (84 files) to a separate folders. I create a script that work fine but it is hard-coded and the code is too long to troubleshoot. I want to reduce the code by parameterizing the script to reduce the numbers of lines of code. Can anyone help me with this?  Here is my script:</p>
  
  <pre><code>Function Get-ShortName {
  begin {
  $fso = New-Object -ComObject Scripting.FileSystemObject }
  process {
  If ($_.psiscontainer) {
  $fso.getfolder($_.fullname).ShortName }
  ELSE {
  $fso.getfile($_.fullname).ShortName }
  } }
  
  #Formatting today's date
  $TodayDate = (Get-Date).ToString('DTyyMMdd')
  
  #Formatting the first day of the month
  $Year = (get-date).Year
  $Month = (get-date).Month
  $FirstDayMth = Get-Date -Year $Year -Month $Month -Day 1
  $FirstDayOfMonth = $FirstDayMth.ToString('DTyyMMdd')
  
  #Download Nightly and Monthly files
  Get-ChildItem -Path "C:\users\in\FileZIP*_nightly.$TodayDate" -Recurse | Copy-Item -Destination "C:\data_files\Provisioning_Files" -Force -Verbose 
  Get-ChildItem -Path "C:\users\in\FileZIP*_monthly.$FirstDayOfMonth" -Recurse | Copy-Item -Destination "C:\data_files\Provisioning_Files" -Force -Verbose
  
  #Unzip files
  Add-Type --AssemblyName System.IO.Compression.FileSystem
  function Unzip {
  param([string]$zipfile, [string]$outpath)
  [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) }
  
  #Check if files exist
  $checkprovfiles = Get-ChildItem -Path C:\data_files\Provisioning_Files -File
  if ($checkprovfiles.Count -eq 84 ) {
  echo "Files have been downloaded SUCCESSFULLY. Now we need to Extract them"
  
  Get files shortname
  $files = Get-ChildItem "C:\data_files\Provisioning_Files\*.*" | Get-Shortname
  Foreach ($file in $files) {
  if ($file -eq "FileZIP1_nightly.$TodayDate") {
  echo 'Start extracting FileZIP1 nightly files'
  Unzip ""C:\data_files\Provisioning_Files\FileZIP1_nightly.$TodayDate" "C:\data_files\Extracted_files\FILEZIP1_Nightly_Monthly_Extracted\"
  echo 'Finish extracting FileZIP1 nightly files' }
  
  if ($file -eq "FileZIP1_monthly.$FirstDayOfMonth") {
  echo 'Start extracting FileZIP1 monthly files'
  Unzip ""C:\data_files\Provisioning_Files\FileZIP1_monthly.$FirstDayOfMonth") "C:\data_files\Extracted_files\FILEZIP1_Nightly_Monthly_Extracted\" 
  echo 'Finish extracting FileZIP1 monthly files'
  
  if ($file -eq "FileZIP2_nightly.$TodayDate") {
  echo 'Start extracting FileZIP2 nightly files'
  Unzip "C:\data_files\Provisioning_Files\FileZIP2_nightly.$TodayDate" "C:\data_files\Extracted_files\FILEZIP2_Nightly_Monthly_Extracted\"
  echo 'Finish extracting FileZIP2 nightly files'
  
  if ($file -eq "FileZIP2_monthly.$FirstDayOfMonth") {
  echo 'Start extracting FileZIP2 monthly files'
  Unzip ""C:\data_files\Provisioning_Files\FileZIP2_monthly.$FirstDayOfMonth") "C:\data_files\Extracted_files\FILEZIP2_Nightly_Monthly_Extracted\"
  echo 'Finish extracting SFileZIP2 monthly files' }
  .
  .
  .
  if ($file -eq "FileZIP84_nightly.$TodayDate") {
  echo 'Start extracting FileZIP84 nightly files'
  Unzip "C:\data_files\Provisioning_Files\FileZIP84_nightly.$TodayDate" "C:\data_files\Extracted_files\FILEZIP84_Nightly_Monthly_Extracted\"
  echo 'Finish extracting FileZIP84 nightly files' }
  }
  else {
  echo "Provisionning files are incomplete or could not be found on ." 
  EXIT }
  </code></pre>
  
  <p>I repeated the IF statement 84 times and I dont want to do that. It is hard to troubleshoot. I want to reduce the if statement and I don't know how to do it. Can anyone help me or have a suggestion to do the script another way?</p>