From 080034b176aba916ed0a8161a4d67cd51db77803 Mon Sep 17 00:00:00 2001 From: iRaven4522 Date: Fri, 3 Oct 2025 22:45:57 -0500 Subject: [PATCH] minor rearranging --- Computer-NameScheme.ps1 | 4 +- Install-MSOffice.ps1 | 4 +- Install-ZabbixAgent.ps1 | 2 +- MDT-JoinDomain.ps1 | 6 +- Test-MDTScript.ps1 | 142 +++++++++++++++++++++------------------- 5 files changed, 85 insertions(+), 73 deletions(-) diff --git a/Computer-NameScheme.ps1 b/Computer-NameScheme.ps1 index 63d0e67..4f2c9ea 100644 --- a/Computer-NameScheme.ps1 +++ b/Computer-NameScheme.ps1 @@ -9,11 +9,11 @@ $CompName = $env:COMPUTERNAME $ADCompOU = ([adsisearcher]"(&(objectClass=computer)(sAMAccountName=$CompName$))").FindOne().GetDirectoryEntry().distinguishedName $PCNamePrefix = ($CompName.Substring(0,$CompName.IndexOf("-"))) $PCNameSuffix = ($CompName.Substring($CompName.IndexOf("-")+1)) -# Domain Credentials to be used -. "\\berrypunch.technolog.net\PSCredentials$\Credentials-WKSDeploy.ps1" Function RenamePCTNGPrefix { Write-Host "Renaming this computer to TNG-$PCNameSuffix." + # Domain Credentials to be used + . "\\berrypunch.technolog.net\PSCredentials$\Credentials-WKSDeploy.ps1" Rename-Computer -NewName "TNG-$PCNameSuffix" -DomainCredential $DomainCredential -Restart } diff --git a/Install-MSOffice.ps1 b/Install-MSOffice.ps1 index ef5d294..f3ed791 100644 --- a/Install-MSOffice.ps1 +++ b/Install-MSOffice.ps1 @@ -4,7 +4,7 @@ Start-Transcript -Path "c:\irnh\Install-MSOffice.log" -Append -$SoftwareDeployLocation = "\\minuette2.technolog.net\SoftwareLibrary\Software\MSOffice" +$SoftwareDeployLocation = "\\minuette2.technolog.net\Software\Software\MSOffice" $ParamVersion = $args[0] # Office Install Checks @@ -18,7 +18,7 @@ $Office2024 = (Get-WmiObject -Class Win32_Product | where name -like "Microsoft Function CheckInstall { if ($null -ne $OfficeVersionInstalled) { if ($OfficeVersionInstalled -ge "16.0" ) { # Checks if currently installed Office is less than version 16 (2016) - if ($null -eq $Office2016 -and $ParamVersion -eq 2016) { + if ($null -ne $Office2016 -and $ParamVersion -eq 2016) { Write-Host "Office $ParamVersion is already installed. No action will be taken." return $true } elseif ($null -ne $Office2019 -and $ParamVersion -eq 2019) { diff --git a/Install-ZabbixAgent.ps1 b/Install-ZabbixAgent.ps1 index df99ec7..128eb6b 100644 --- a/Install-ZabbixAgent.ps1 +++ b/Install-ZabbixAgent.ps1 @@ -15,7 +15,7 @@ $ZabbixServer = "10.10.0.90" $ZabbixAgentLogFile = "$InstallFolder\zabbix_agentd.log" Function CheckZabbixInstall { - if ($ZabbixVersionInstalled -ne $null) { + if ($null -ne $ZabbixVersionInstalled) { if ($ZabbixVersionInstalled -like "$SDZabbixVersion*") { return $true } else { diff --git a/MDT-JoinDomain.ps1 b/MDT-JoinDomain.ps1 index 0b374a7..d6bee57 100644 --- a/MDT-JoinDomain.ps1 +++ b/MDT-JoinDomain.ps1 @@ -30,6 +30,10 @@ if ($CompType -like "WKS") { Write-Host "Detected computer name as TEST - domain joining to Testing WKS OU" $DomainOU = "OU=TestingWKS,OU=Workstations,DC=technolog,DC=net" } + elseif ($PCNamePrefix -like "HEADEND") { + Write-Host "Detected computer name as HEADEND - domain joining to Headend WKS OU" + $DomainOU = "OU=Headend,OU=Workstations,DC=technolog,DC=net" + } else { Write-Host "Computer name is unusual - domain joining to Standard WKS OU" $DomainOU = "OU=Workstations,DC=technolog,DC=net" @@ -46,7 +50,7 @@ if ($CompType -like "WKS") { . "$MDTPath\_Scripts\Credentials-MDTJoinDomain.ps1" Write-Host "Domain joining to Utility OU" - $DomainOU = "OU=Utility,DC=technolog,DC=net" + $DomainOU = "OU=Utility,OU=Workstations,DC=technolog,DC=net" } else { . "$MDTPath\_Scripts\Credentials-MDTJoinDomain.ps1" Write-Host "Domain joining to generic Computers OU" diff --git a/Test-MDTScript.ps1 b/Test-MDTScript.ps1 index 7fac53f..3568e35 100644 --- a/Test-MDTScript.ps1 +++ b/Test-MDTScript.ps1 @@ -1,79 +1,87 @@ -# Testing MDT bullshit -# Technolog Networks +# Script to join domain inside of MDT. +# Technolog Networks, 2024-08-12 # iRaven -$CompName = $env:COMPUTERNAME -Start-Transcript -Path "c:\$CompName-TESTScript.log" -Append - # General necessities. +$CompName = $env:COMPUTERNAME $TSEnv = New-Object -ComObject Microsoft.SMS.TSEnvironment - +$MDTPath = $Global:TSEnv.Value("DeployRoot") +Start-Transcript -Path "$MDTPath\_Logs\$CompName-JoinDomain.log" -Append $CompType = $args[0] $SubType = $args[1] -Write-Host "Username: $env:username" -Write-Host "MDT DeployRoot: $Global:TSEnv.Value("DeployRoot")" -$MDTun = [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($Global:TSEnv.Value("SMSConnectNetworkFolderAccount"))) -Write-Host "MDT UserName: $MDTun" - -Read-Host -Prompt "Balls..." - -if ($CompType -like "WKS") { - $PCNamePrefix = ($CompName.Substring(0,$CompName.IndexOf("-"))) - # Domain credentials to join WKS to domain - $MDTPath = $Global:TSEnv.Value("DeployRoot") - . "$MDTPath\_Scripts\Credentials-MDTJoinDomain.ps1" - - Write-Host "Auto-detecting computer name $CompName..." - # Filter out OUs - if ($PCNamePrefix -like "XH") { - Write-Host "Detected computer name as XH - domain joining to Personal WKS OU" - $DomainOU = "OU=Personal,OU=Workstations,DC=technolog,DC=net" - } - elseif ($PCNamePrefix -like "TNG" -or $PCNamePrefix -like "NH" -or $PCNamePrefix -like "IR") { - Write-Host "Detected computer name as TNG, NH, or IR - domain joining to Standard WKS OU" - $DomainOU = "OU=Workstations,DC=technolog,DC=net" - } - elseif ($PCNamePrefix -like "TEST") { - Write-Host "Detected computer name as TEST - domain joining to Testing WKS OU" - $DomainOU = "OU=TestingWKS,OU=Workstations,DC=technolog,DC=net" - } - else { - Write-Host "Computer name is unusual - domain joining to Standard WKS OU" - $DomainOU = "OU=Workstations,DC=technolog,DC=net" - } -} elseif ($CompType -like "Server") { - $DomainCredential = Get-Credential -Message "To join this server to the domain, enter your domain credentials." - # Filter out SubType var for server tiers - if ($SubType -ne $null) { - $DomainOU = "OU=$SubType,OU=Domain Servers,DC=technolog,DC=net" +Function CheckDomainJoin { # Check if we're already domain joined + if ((gwmi Win32_ComputerSystem).partofdomain -eq $true -and (gwmi Win32_ComputerSystem).domain -eq "technolog.net") { + write-host "Already part of the domain!" + return true } else { - $DomainOU = "OU=Domain Servers,DC=technolog,DC=net" - } -} elseif ($CompType -like "Utility") { - . "z:\_Scripts\Credentials-MDTJoinDomain.ps1" - - Write-Host "Domain joining to Utility OU" - $DomainOU = "OU=Utility,DC=technolog,DC=net" -} else { - . "z:\_Scripts\Credentials-MDTJoinDomain.ps1" - Write-Host "Domain joining to generic Computers OU" -} - - -if ([boolean](get-variable "DomainOU" -ErrorAction SilentlyContinue)) { - try { - Add-Computer -DomainName technolog.net -Credential $DomainCredential -OUPath $DomainOU -Restart - } catch { - Write-Host "Couldn't join the domain with OU $DomainOU" - } -} -else { - try { - Add-Computer -DomainName technolog.net -Credential $DomainCredential -Restart - } catch { - Write-Host "Couldn't join the domain!" + write-host "Not part of the domain yet (or joined to another)!" + return false } } +Function FilterComputerOU { + if ($CompType -like "WKS") { + New-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\LSA" -Name NetJoinLegacyAccountReuse -Value 1 + $PCNamePrefix = ($CompName.Substring(0,$CompName.IndexOf("-"))) + # Domain credentials to join WKS to domain + . "$MDTPath\_Scripts\Credentials-MDTJoinDomain.ps1" + + Write-Host "Auto-detecting computer name $CompName..." + # Filter out OUs + if ($PCNamePrefix -like "XH") { + Write-Host "Detected computer name as XH - domain joining to Personal WKS OU" + $Script.DomainOU = "OU=Personal,OU=Workstations,DC=technolog,DC=net" + } + elseif ($PCNamePrefix -like "TNG" -or $PCNamePrefix -like "NH" -or $PCNamePrefix -like "IR") { + Write-Host "Detected computer name as TNG, NH, or IR - domain joining to Standard WKS OU" + $Script.DomainOU = "OU=Generic,OU=Workstations,DC=technolog,DC=net" + } elseif ($PCNamePrefix -like "TEST") { + Write-Host "Detected computer name as TEST - domain joining to Testing WKS OU" + $Script.DomainOU = "OU=TestingWKS,OU=Workstations,DC=technolog,DC=net" + } else { + Write-Host "Computer name is unusual - domain joining to Standard WKS OU" + $Script.DomainOU = "OU=Workstations,DC=technolog,DC=net" + } + } elseif ($CompType -like "Server") { + $DomainCredential = Get-Credential -Message "To join this server to the domain, enter your domain credentials." + # Filter out SubType var for server tiers + if ($null -ne $SubType) { + $Script.DomainOU = "OU=$SubType,OU=Domain Servers,DC=technolog,DC=net" + } else { + $Script.DomainOU = "OU=Domain Servers,DC=technolog,DC=net" + } + } elseif ($CompType -like "Utility") { + . "$MDTPath\_Scripts\Credentials-MDTJoinDomain.ps1" + + Write-Host "Domain joining to Utility OU" + $Script.DomainOU = "OU=Utility,OU=Workstations,DC=technolog,DC=net" + } else { + . "$MDTPath\_Scripts\Credentials-MDTJoinDomain.ps1" + Write-Host "Domain joining to generic Computers OU" + + } +} + +Function JoinDomainOU { + # Perform domain join with filtered OU from above + if ([boolean](get-variable "DomainOU" -ErrorAction SilentlyContinue)) { + try { + Add-Computer -DomainName technolog.net -Credential $DomainCredential -OUPath $DomainOU -Restart + } catch { + Write-Host "Couldn't join the domain with OU $DomainOU" + } + } else { + try { + Add-Computer -DomainName technolog.net -Credential $DomainCredential -Restart + } catch { + Write-Host "Couldn't join the domain!" + } + } +} + +if ((CheckDomainJoin) -eq $false) { + FilterComputerOU + JoinDomainOU +} Stop-Transcript \ No newline at end of file