Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Create-RemoteMappedDrive {
- [Cmdletbinding()]
- Param(
- [Parameter(Mandatory=$True)]
- [string]$UserName,
- [Parameter(Mandatory=$True)]
- [string]$DriveLetter,
- [Parameter(Mandatory=$True)]
- [string]$Path,
- [Parameter(Mandatory=$True)]
- [string]$ComputerName
- )
- $SID = (Get-ADUser -Identity $UserName).SID
- $ModifiedPath = $Path.Replace('\','\\')
- $RegKey =@"
- Windows Registry Editor Version 5.00
- [HKEY_USERS\$SID\Network\$DriveLetter]
- "RemotePath"="$ModifiedPath"
- "UserName"=dword:00000000
- "ProviderName"="Microsoft Windows Network"
- "ProviderType"=dword:00020000
- "ConnectionType"=dword:00000001
- "DeferFlags"=dword:00000004
- "@
- Invoke-Command -ComputerName $ComputerName -ScriptBlock {
- If (!(Test-Path c:\Temp)) {mkdir c:\Temp}
- $Using:Regkey | Out-file c:\temp\DriveMap.reg
- Regedit /s c:\temp\DriveMap.reg
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment