Create Folder for Script
mkdir c:\Scripts
Share this Folder
New-SmbShare `
-Name "Scripts" `
-Path "c:\Scripts" `
-ReadAccess "everyone"
Enable permission
icacls "C:\Scripts" /grant "*S-1-1-0:(OI)(CI)(M)"
Create the logon script
Set-Content -Path C:\Scripts\mapDrive.bat `
-Value 'net use U: \\server\Scripts /persistent:yes' `
-Encoding ASCII
Verify the script
type C:\Scripts\mapDrive.bat
Load the Group Policy module
Import-Module GroupPolicy
Create the GPO for "Map Drive"
New-GPO -Name "Map Drive"
Link the GPO to the correct OU
New-GPLink `
-Name "Map Drive" `
-Target "OU=Team,DC=server,DC=kh"
Add the Logon Script to GPO "Map Drive"
$gpo = Get-GPO "Map Drive"
$guid = $gpo.Id
$path = "\\server.kh\SYSVOL\server.kh\Policies\{$guid}\User\Scripts"
New-Item "$path\Logon" -ItemType Directory -Force
Copy-Item "C:\Scripts\mapDrive.bat" "$path\Logon"
@"
[Logon]
0CmdLine=mapDrive.bat
0Parameters=
"@ | Set-Content "$path\Scripts.ini"