Advertisement
Guest User

MapShare.ps1

a guest
Aug 24th, 2017
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #######################################
  2. # CHANGE THE BELOW SETTINGS AS REQUIRED
  3. #######################################
  4.  
  5. # Set the target hostname here
  6. $hostName = 'HostName'
  7.  
  8. # Set the name of the share from the target hostname here
  9. $shareName = 'ShareName'
  10.  
  11. # Set the desired drive letter for the mapped location here
  12. $mappedDriveLetter = 'K'
  13.  
  14. # Set the domain here
  15. $domain = 'DomainName'
  16.  
  17. # Set the username here
  18. $userName = 'UserName'
  19.  
  20. # Set the password here
  21. $password = 'Password'
  22.  
  23. ###################################
  24. # DO NOT MODIFY ANYTHING BELOW HERE
  25. ###################################
  26. $ipAddress = [System.Net.Dns]::GetHostEntry($hostName).AddressList[0]
  27. if ($domain.Length -eq 0 -or $userName.Length -eq 0 -or $password.Length -eq 0)
  28. {
  29.     New-PSDrive -Name $mappedDriveLetter –PSProvider FileSystem –Root “\\$ipAddress\$shareName-Credential $env:USERDOMAIN\$env:USERNAME –Persist
  30. }
  31. else
  32. {
  33.     $password = $password|ConvertTo-SecureString -AsPlainText -Force
  34.     $auth = $userName + '@' + $domain
  35.     $credential = New-Object System.Management.Automation.PsCredential($auth, $password)
  36.     New-PSDrive –Name $mappedDriveLetter –PSProvider FileSystem –Root “\\$ipAddress\$shareName-Credential $credential –Persist
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement