Guest User

Create-RemoteMappedDrive

a guest
Jul 21st, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Create-RemoteMappedDrive {
  2.    
  3.     [Cmdletbinding()]
  4.     Param(
  5.           [Parameter(Mandatory=$True)]
  6.           [string]$UserName,
  7.  
  8.           [Parameter(Mandatory=$True)]
  9.           [string]$DriveLetter,
  10.  
  11.           [Parameter(Mandatory=$True)]
  12.           [string]$Path,
  13.  
  14.           [Parameter(Mandatory=$True)]
  15.           [string]$ComputerName
  16.  
  17.     )
  18.  
  19.     $SID = (Get-ADUser -Identity $UserName).SID
  20.  
  21.     $ModifiedPath = $Path.Replace('\','\\')
  22.  
  23.     $RegKey =@"
  24. Windows Registry Editor Version 5.00
  25.  
  26. [HKEY_USERS\$SID\Network\$DriveLetter]
  27. "RemotePath"="$ModifiedPath"
  28. "UserName"=dword:00000000
  29. "ProviderName"="Microsoft Windows Network"
  30. "ProviderType"=dword:00020000
  31. "ConnectionType"=dword:00000001
  32. "DeferFlags"=dword:00000004
  33. "@
  34.  
  35.       Invoke-Command -ComputerName $ComputerName -ScriptBlock {
  36.       If (!(Test-Path c:\Temp)) {mkdir c:\Temp}
  37.       $Using:Regkey | Out-file c:\temp\DriveMap.reg
  38.       Regedit /s c:\temp\DriveMap.reg
  39.       }
  40.  
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment