title: Use values from a function and pass it to another function
body: <p>I have the below two functions and I want the SOURCE and TARGET of the ROBOCOPY function used within the Comparision function. Can anyone tell me how to do this please. Thanks.</p>
  
  <pre><code>Write-Host "==================================" -ForegroundColor Magenta -BackgroundColor White
  Write-Host "Pre-Staging Script for DFSR Server" -ForegroundColor Magenta -BackgroundColor White
  Write-Host "==================================" -ForegroundColor Magenta -BackgroundColor White
  Write-Host ""
  Function GetHot-Fix
  {
                  Write-Host "==================================" -ForegroundColor Magenta -BackgroundColor White
                  Write-Host "Checking Service Installation" -ForegroundColor Magenta -BackgroundColor White
                  Write-Host "==================================" -ForegroundColor Magenta -BackgroundColor White
                  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 ""
  
                  Get-HotFix -id KB979808 -ErrorAction SilentlyContinue
  
  }
  
  Function Start-MyRobocopy($source,$Target)
  {
                  Write-Host "=============" -ForegroundColor Magenta -BackgroundColor White
                  Write-Host "Robocopy Data" -ForegroundColor Magenta -BackgroundColor White
                  Write-Host "=============" -ForegroundColor Magenta -BackgroundColor White
                  Write-Host ""
  
                  $Source = Read-Host "Please enter path of SOURCE"
  
                  If ($Source -and (Test-Path -Path $Source -PathType Container))
                  {
                                  $Target = Read-Host "Please enter path of TARGET"
                  }
                  Else
                  {
                  Write-Host "Please enter a directory"
                  }
                                  If ($Target -and (Test-Path -Path $Target -PathType Container))
                                  {
                                  $Output = Read-Host "Please enter where to place output file eg c:\temp\COPY.log"
                                  }
                                  Else
                                  {
                                  Write-Host "Please enter a directory"
                                  }
  
  
  robocopy.exe $Source $Target /b /e /copyall /r:1 /xd dfsrprivate /log:$Output /tee
  }
  Function Comparision
  {
                  Write-Host ""
                  Write-Host ""     
                  Write-Host "===============================================" -ForegroundColor Magenta -BackgroundColor White
                  Write-Host "Checking Directory Count and Folder comparision" -ErrorAction SilentlyContinue -ForegroundColor Magenta -BackgroundColor White
                  Write-Host "===============================================" -ForegroundColor Magenta -BackgroundColor White
                  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
  }
  
  
  $hotfix = GetHot-Fix
  If ($hotfix) {
                  Write-Host "Hotfix installed" -BackgroundColor Green -ForegroundColor Black
                  Write-Host ""
                  Write-Host "Proceeding with Robocopy...."
                  Write-Host "............................"
                  Write-Host ""
                  Start-MyRobocopy
                  }
  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 ""
                                  return
                  }
  
  Comparision
  </code></pre>