From 925307554fe1728438dcf4196a7e1f29dced88ae Mon Sep 17 00:00:00 2001 From: abrown38 Date: Sat, 14 Sep 2024 15:53:47 +0100 Subject: [PATCH] This actually maps a drive!!! --- .../templates/mapped_drive.ps1.j2 | 30 ++++++++----------- .../roles/win_domain_controller/vars/main.yml | 3 +- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/ansible/roles/win_domain_controller/templates/mapped_drive.ps1.j2 b/ansible/roles/win_domain_controller/templates/mapped_drive.ps1.j2 index 3a9ce73..f4c5baf 100644 --- a/ansible/roles/win_domain_controller/templates/mapped_drive.ps1.j2 +++ b/ansible/roles/win_domain_controller/templates/mapped_drive.ps1.j2 @@ -1,25 +1,21 @@ $gp_name = "Map Study Drive" -New-GPO -Name $gp_name +New-GPO -Name $gp_name -comment "Registry Keys To Map Study Drive" -$gp = Get-GPO -Name $gp_name -$gp_id = $gp.Id +$map_regkey = "HKEY_CURRENT_USER\Network\{{ study_data_letter }}" +$label_regkey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2\##{{ win_project }}#{{ share_name }}" -$create_date = Get-Date -Format "yyyy-MM-dd HH:mm:ss" +Set-GPRegistryValue -Name "$gp_name" -ValueName "ConnectFlags" -key "$map_regkey" -Value 0 -Type DWord +Set-GPRegistryValue -Name "$gp_name" -ValueName "ConnectionType" -key "$map_regkey" -Value 1 -Type DWord +Set-GPRegistryValue -Name "$gp_name" -ValueName "DeferFlags" -key "$map_regkey" -Value 4 -Type DWord +Set-GPRegistryValue -Name "$gp_name" -ValueName "ProviderFlags" -key "$map_regkey" -Value 1 -Type DWord +Set-GPRegistryValue -Name "$gp_name" -ValueName "ProviderName" -key "$map_regkey" -Value "Microsoft Windows Network" -Type String +Set-GPRegistryValue -Name "$gp_name" -ValueName "ProviderType" -key "$map_regkey" -Value 131072 -Type DWord +Set-GPRegistryValue -Name "$gp_name" -ValueName "RemotePath" -key "$map_regkey" -Value "{{ study_data_dfs }}" -Type String +Set-GPRegistryValue -Name "$gp_name" -ValueName "UserName" -key "$map_regkey" -Value "" -Type String -$xml_path = "{{ policy_path }}\{$gp_id}\User\Preferences\Drives" -New-Item -ItemType Directory -Force $xml_path - -$data = @" - - - - - - -"@ - -$data | Out-File $xml_path\Drives.xml -Encoding utf8 -Force +Set-GPRegistryValue -Name "$gp_name" -ValueName "_LabelFromDesktopINI" -key "$labe_regkey" -Value "" -Type String +Set-GPRegistryValue -Name "$gp_name" -ValueName "_LabelFromReg" -key "$label_regkey" -Value "{{ study_data_label }}" -Type String $DomainInfo = Get-ADDomain $DomainOU = $DomainInfo.DistinguishedName diff --git a/ansible/roles/win_domain_controller/vars/main.yml b/ansible/roles/win_domain_controller/vars/main.yml index 71d11ec..9c68342 100644 --- a/ansible/roles/win_domain_controller/vars/main.yml +++ b/ansible/roles/win_domain_controller/vars/main.yml @@ -8,7 +8,8 @@ script_dir: C:\eidf mapped_drive_script: mapped_drive.ps1 mapped_drive_script_tmpl: mapped_drive.ps1.j2 -study_data_dfs: \\{{ win_project }}\Study_Data +share_name: Study_Data +study_data_dfs: \\{{ win_project }}\{{ share_name }} study_data_label: Study Data study_data_letter: S