title: In Powershell, how to create a directory using IP address into a remote computer using do-while loop
body: <p>Please help me. I'm trying trying to create a PowerShell script using do-while loop as follows: </p>
  
  <ol>
  <li>Ask user for folder name (foldername) and target IP Address (targetipaddress)</li>
  <li>If "foldername" does not exist, then create "foldername" in "C:\" drive </li>
  <li>Using "targetipaddress" as the part of target path, copy the contents from a sub folder of network drive path,"S:\" and paste into the "foldername" in the "C:\" path.  </li>
  <li>If user enters "quit", then script finishes. </li>
  </ol>
  
  <p>My code below: </p>
  
  <pre><code>$var = "welcome to IP address and folder creation world"
  echo $var
  
  # create foldername until user type "quit"
  $output = (command)
  do { 
  
  $foldername = Read-Host "enter folder name "
  $targetipaddress = Read-Host "enter target ip address "
  
  # create folder name only if it does not exist
  function createFolder {
  $path = "\\$targetipaddress\C$\$foldername "
  If (!(Test-Path $path))
  { 
        New-Item -ItemType Directory -Force $path
  }
  
  } # end of function createFolder
  
  # copy contents from a sub folder of a network drive path and
  # and paste them onto "C:\" drive path using "targetipaddress" and "foldername"
  
  function copyContents {
   Copy-Item S:\sourcefolder\subfolder\*.*  \\$targetipaddress\C$\$foldername\ -Recurse
   }
  
   } while ($foldername = "quit") # end of do-while loop
  </code></pre>