Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $TempDirectoryValid=$false
- $AttemptCount=0
- while (!($TempDirectoryValid) -and ($AttemptCount -lt 5))
- {
- # Set random directory to the users temp directory plus a random number
- $RandomDirectoryName=get-random
- $TemporaryLocation=$env:TEMP+"\"+$RandomDirectoryName
- # if the temporary path already exists / exit with error
- $AttemptCount++
- if (!(Test-Path -path $TemporaryLocation))
- {
- # Create the temporary location
- new-item $TemporaryLocation -type directory
- $TempDirectoryValid=$true
- }
- }
- if ($AttemptCount -gt 4)
- {
- write-error "Temp folder creation attempted 5 times, failed"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement