Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #######################################
- # CHANGE THE BELOW SETTINGS AS REQUIRED
- #######################################
- # Set the target hostname here
- $hostName = 'HostName'
- # Set the name of the share from the target hostname here
- $shareName = 'ShareName'
- # Set the desired drive letter for the mapped location here
- $mappedDriveLetter = 'K'
- # Set the domain here
- $domain = 'DomainName'
- # Set the username here
- $userName = 'UserName'
- # Set the password here
- $password = 'Password'
- ###################################
- # DO NOT MODIFY ANYTHING BELOW HERE
- ###################################
- $ipAddress = [System.Net.Dns]::GetHostEntry($hostName).AddressList[0]
- if ($domain.Length -eq 0 -or $userName.Length -eq 0 -or $password.Length -eq 0)
- {
- New-PSDrive -Name $mappedDriveLetter –PSProvider FileSystem –Root “\\$ipAddress\$shareName” -Credential $env:USERDOMAIN\$env:USERNAME –Persist
- }
- else
- {
- $password = $password|ConvertTo-SecureString -AsPlainText -Force
- $auth = $userName + '@' + $domain
- $credential = New-Object System.Management.Automation.PsCredential($auth, $password)
- New-PSDrive –Name $mappedDriveLetter –PSProvider FileSystem –Root “\\$ipAddress\$shareName” -Credential $credential –Persist
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement