daily pastebin goal
56%
SHARE
TWEET

Create a temporary folder in powershell

anonit Jan 21st, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $TempDirectoryValid=$false
  2. $AttemptCount=0
  3. while (!($TempDirectoryValid) -and ($AttemptCount -lt 5))
  4. {
  5.     # Set random directory to the users temp directory plus a random number
  6.     $RandomDirectoryName=get-random
  7.     $TemporaryLocation=$env:TEMP+"\"+$RandomDirectoryName
  8.     # if the temporary path already exists / exit with error
  9.     $AttemptCount++
  10.     if (!(Test-Path -path $TemporaryLocation))
  11.     {
  12.         # Create the temporary location
  13.         new-item $TemporaryLocation -type directory
  14.         $TempDirectoryValid=$true
  15.     }
  16. }
  17. if ($AttemptCount -gt 4)
  18. {
  19.     write-error "Temp folder creation attempted 5 times, failed"
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top