From 8f2a04e82e96297286b05ebf7706ec2c725c70e0 Mon Sep 17 00:00:00 2001 From: cfinlay Date: Thu, 23 Jan 2025 15:22:28 +0000 Subject: [PATCH] simplifing process --- ansible/roles/win_client/files/logon.ps1 | 28 ------------- .../files/OpenStackADBuildv7.5.3.ps1 | 7 +--- .../win_domain_controller/files/logon.ps1 | 5 +++ .../win_domain_controller/tasks/dc-logon.yml | 39 ------------------- 4 files changed, 6 insertions(+), 73 deletions(-) delete mode 100644 ansible/roles/win_client/files/logon.ps1 create mode 100644 ansible/roles/win_domain_controller/files/logon.ps1 delete mode 100644 ansible/roles/win_domain_controller/tasks/dc-logon.yml diff --git a/ansible/roles/win_client/files/logon.ps1 b/ansible/roles/win_client/files/logon.ps1 deleted file mode 100644 index f552d70..0000000 --- a/ansible/roles/win_client/files/logon.ps1 +++ /dev/null @@ -1,28 +0,0 @@ -$bashProfilePath = Join-Path $HOME ".bash_profile" - -$condaPath = "C:\tools\miniforge3\Scripts\conda.exe" - -$requiredLine = 'eval "$(''/C/tools/miniforge3/Scripts/conda.exe'' ''shell.bash'' ''hook'')"' - -if (Test-Path $condaPath) { - Write-Host "Miniforge3 is installed at $condaPath" - - if (Test-Path $bashProfilePath) { - $currentContent = Get-Content -Path $bashProfilePath -ErrorAction SilentlyContinue - - if ($currentContent -contains $requiredLine) { - Write-Host "The required line is already present in .bash_profile" - } else { - Add-Content -Path $bashProfilePath -Value $requiredLine - Write-Host "The required line has been added to .bash_profile" - } - } else { - Set-Content -Path $bashProfilePath -Value $requiredLine -Force - Write-Host ".bash_profile created with the required line" - } - - Set-ItemProperty -Path $bashProfilePath -Name Attributes -Value ([System.IO.FileAttributes]::Hidden) - Write-Host ".bash_profile is set to hidden" -} else { - Write-Host "Miniforge3 is not installed. Exiting." -} diff --git a/ansible/roles/win_domain_controller/files/OpenStackADBuildv7.5.3.ps1 b/ansible/roles/win_domain_controller/files/OpenStackADBuildv7.5.3.ps1 index 9b7d7d4..e76218e 100644 --- a/ansible/roles/win_domain_controller/files/OpenStackADBuildv7.5.3.ps1 +++ b/ansible/roles/win_domain_controller/files/OpenStackADBuildv7.5.3.ps1 @@ -412,12 +412,7 @@ New-GPLink -Name "Chrome" -Target $workbenchou #New-GPLink -Name "firewall" -Target $workbenchou #Logon Script Reg Keys -Import-Module GroupPolicy -if (!(Get-GPLink -Name "User Logon Script" -Target "OU=YourOU,DC=yourdomain,DC=local" -ErrorAction SilentlyContinue)) { -New-GPLink -Name "User Logon Script" -Target "OU=YourOU,DC=yourdomain,DC=local" -} -Set-GPRegistryValue -Name "User Logon Script" -Key "HKCU\Environment" -ValueName "LogonScript" -Type String -Value "C:\\eidf\\logon.ps1" -Set-GPRegistryValue -Name "User Logon Script" -Key "HKLM\Software\Policies\Microsoft\Windows\PowerShell" -ValueName "ExecutionPolicy" -Type String -Value "Unrestricted" +New-ItemProperty -Path "Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name "CreateBashProfile" -Value "powershell.exe -ExecutionPolicy Bypass -File C:\eidf\logon.ps1" -PropertyType String #add entry for WSUS diff --git a/ansible/roles/win_domain_controller/files/logon.ps1 b/ansible/roles/win_domain_controller/files/logon.ps1 new file mode 100644 index 0000000..fadf979 --- /dev/null +++ b/ansible/roles/win_domain_controller/files/logon.ps1 @@ -0,0 +1,5 @@ +$bashProfilePath = Join-Path $HOME ".bash_profile" +$requiredLine = 'eval "$(''/C/tools/miniforge3/Scripts/conda.exe'' ''shell.bash'' ''hook'')"' + +Add-Content -Path $bashProfilePath -Value $requiredLine +Set-ItemProperty -Path $bashProfilePath -Name Attributes -Value ([System.IO.FileAttributes]::Hidden) diff --git a/ansible/roles/win_domain_controller/tasks/dc-logon.yml b/ansible/roles/win_domain_controller/tasks/dc-logon.yml deleted file mode 100644 index 359ee58..0000000 --- a/ansible/roles/win_domain_controller/tasks/dc-logon.yml +++ /dev/null @@ -1,39 +0,0 @@ ---- -- name: Set Reg Keys - tags: - - logon - block: - - name: Configure Windows Logon Script via GPO - tasks: - - name: Create a new Group Policy Object (GPO) - ansible.windows.win_shell: - command: | - Import-Module GroupPolicy - if (!(Get-GPO -Name "User Logon Script" -ErrorAction SilentlyContinue)) { - New-GPO -Name "User Logon Script" -Domain "yourdomain.local" - } - ignore_errors: true - - - name: Link GPO to Organizational Unit (OU) - ansible.windows.win_shell: - command: | - Import-Module GroupPolicy - if (!(Get-GPLink -Name "User Logon Script" -Target "OU=YourOU,DC=yourdomain,DC=local" -ErrorAction SilentlyContinue)) { - New-GPLink -Name "User Logon Script" -Target "OU=YourOU,DC=yourdomain,DC=local" - } - - - name: Configure the logon script in GPO - ansible.windows.win_shell: - command: | - Import-Module GroupPolicy - Set-GPRegistryValue -Name "User Logon Script" -Key "HKCU\Environment" -ValueName "LogonScript" -Type String -Value "C:\\eidf\\logon.ps1" - - - name: Allow PowerShell scripts to execute - ansible.windows.win_shell: - command: | - Import-Module GroupPolicy - Set-GPRegistryValue -Name "User Logon Script" -Key "HKLM\Software\Policies\Microsoft\Windows\PowerShell" -ValueName "ExecutionPolicy" -Type String -Value "Unrestricted" - - - name: Force Group Policy update on clients - ansible.windows.win_command: - command: gpupdate /Force