title: how to merge multiple scripts and use functions to show output
body: <p>A couple of you (Shay especially!) helped me yesterday and I have managed to come up with multiple scripts and am now merging them into one. </p>
  
  <p>The problem is that I have put them all into "Functions" and one function relies on the successful check on a hotfix - if the hotfix is not installed then the script has to stop right there and then - that is the first check the script does. How do I get the next function to call the successful output of the hotfix function?</p>
  
  <p>Also I have no idea how to call the functions - ie at the bottom I put the name of the functions one line after each other but ended up looping over and over! </p>
  
  <p>hope someone can assist.</p>
  
  <pre><code>Write-Host "=================================="
  Write-Host "Pre-Staging Script for DFSR Server"
  Write-Host "=================================="
  
  Function Service
  {
      Write-Host "=================================="
      Write-Host "Checking Service Installation"
      Write-Host "=================================="
  
      write-host "This will check if Hotfix KB979808 is installed." -ForegroundColor Black -BackgroundColor Cyan
      write-host "This is required for Windows Server 2008 R2 Robocopying"  -ForegroundColor Black -BackgroundColor Cyan
      Write-Host ""
  
      $hotfix1 = Get-HotFix -id KB979808 -ErrorAction SilentlyContinue
  
          If($hotfix1)
          {
              Write-Host "Hotfix is installed you may proceed" -foregroundcolor "green"
              Write-Host ""
          }
      else
          {
          Write-Host "Hotfix is NOT installed - Please ensure you install this hotfix BEFORE" -ForegroundColor "red"
          Write-host "Copying any data" -foregroundcolor "red"
          Write-Host ""
          }
  }
  
  Function Robocopy ($hotfix1)
   {
      Write-Host "============="
      Write-Host "Robocopy Data" 
      Write-Host "============="
  
      $Source = Read-Host "Please enter path of SOURCE"
      $Destination = Read-Host "Please enter path of TARGET"
  
      $Output = Read-Host "Please enter where to place output file eg c:\temp\COPY.log"
  
      robocopy $Source $Target /b /e /copyall /r:1 /xd dfsrprivate /log:$Output /tee
   }
  
  Function Comparision
  {
      Write-Host "==============================================="
      Write-Host "Checking Directory Count and Folder comparision" -ErrorAction SilentlyContinue -BackgroundColor Cyan -ForegroundColor Black
      Write-Host "==============================================="
      Write-Host ""
  
      $Source = Read-Host "Please enter Source directory to check"
      $Target = Read-Host "Please enter Target directory to check"
      Write-Host ""
      If($source -and (Test-Path -Path $source -PathType Container))
      {
          "There are $(@(Get-ChildItem $Source).Count) items in the '$Source' directory"  
      }
      Else
      {
          Write-Host "Please enter a directory"
          }
          If($source -and (Test-Path -Path $Target -PathType Container))
          {
              "There are $(@(Get-ChildItem $Target).Count) items in the '$Target' directory"  
      }
      Else
      {
          Write-Host "Please enter a directory"
      }
  
      Write-Host ""
      $child1 = Get-ChildItem -Path $Source -Recurse -Force
      $child2 = Get-ChildItem -Path $Target -Recurse -Force
  
      Compare-Object $child1 -DifferenceObject $child2 -Property Name
  
      Write-Host ""
      Write-Host "NOTE:" -BackgroundColor Cyan -ForegroundColor Black
      Write-Host "Any symbols with '=&gt;' mean that the file Does NOT exist in SOURCE but is in the Target" -BackgroundColor Cyan -ForegroundColor Black
      Write-Host "Any symbols with '&lt;=' mean that the file Does NOT exist in TARGET but is in the Source" -BackgroundColor Cyan -ForegroundColor Black
  }
  </code></pre>