From 76f1e79161eaf3018833202557f670efaa24395f Mon Sep 17 00:00:00 2001 From: Gramzon Date: Mon, 13 Jan 2025 16:02:43 +0100 Subject: [PATCH] Changed scripts --- activedir.ps1 | 72 ++++++++++++++++++++++++++++ addtodomain.ps1 | 27 +++++++++++ psremote.ps1 | 21 ++++++++ timelang.ps1 | 33 +++++++++++-- usersetup.ps1 | 27 +++++++++++ winget driver install and update.ps1 | 3 ++ 6 files changed, 179 insertions(+), 4 deletions(-) create mode 100644 activedir.ps1 create mode 100644 addtodomain.ps1 create mode 100644 psremote.ps1 create mode 100644 usersetup.ps1 diff --git a/activedir.ps1 b/activedir.ps1 new file mode 100644 index 0000000..370f1b4 --- /dev/null +++ b/activedir.ps1 @@ -0,0 +1,72 @@ +#install active directory. +# THIS SCRIPT MUST BE RUN AS ADMINISTRATOR ON DC1 + +#language, time and timezone settings: +# Se hvilke språkpakker (capabilities) som er tilgjengelige og evt. installert: +Get-WindowsCapability -Online -Name Language* | + Where-Object { $_.Name -like '*nb-NO*' } | + Format-Table -Autosize + +# Installer Bokmål grunnpakke: +Add-WindowsCapability -Online -Name Language.Basic~~~nb-NO~0.0.1.0 + +# (Valgfritt) Installer OCR / TextToSpeech / Handwriting / Speech om ønskelig: +# Add-WindowsCapability -Online -Name Language.OCR~~~nb-NO~0.0.1.0 +# Add-WindowsCapability -Online -Name Language.TextToSpeech~~~nb-NO~0.0.1.0 +# Add-WindowsCapability -Online -Name Language.Handwriting~~~nb-NO~0.0.1.0 +# Add-WindowsCapability -Online -Name Language.Speech~~~nb-NO~0.0.1.0 + + + +<# Checklist: + - Windows Update is up to date + - Time zone is correct + - Computer name is correct + - IP address is correct (non relevant for this lab) + - Keyboard layout is correct (Norwegian) +#> + +# variable containing the computer name +$env:DC1 +# If you want to change the computer name, you can use the Rename-Computer cmdlet +# $newcompname = Read-host "Skriv inn ønsket hostname på maskinen" +# Rename-Computer -Newname $newcompname -Restart -Force + +# Check what features are installed +Get-WindowsFeature | Where-Object {$_. installstate -eq "installed"} + + +# Install Active Directory Domain Services (AD DS) +# Needs to be run as Administrator +Install-WindowsFeature AD-Domain-Services, DNS -IncludeManagementTools +$Password = Read-Host -Prompt 'Enter Password' -AsSecureString +Set-LocalUser -Password $Password Administrator + +$Params = @{ + DomainMode = 'WinThreshold' + DomainName = 'RohanIT.sec' + DomainNetbiosName = 'RohanIT' + ForestMode = 'WinThreshold' + InstallDns = $true + NoRebootOnCompletion = $true + SafeModeAdministratorPassword = $Password + Force = $true +} + +# Install AD DS with the parameters defined above +Install-ADDSForest @Params +Restart-Computer +# Log in as Administrator@YourDomanName.whatever with password from above +# Test our domain +Get-ADRootDSE +# The Get-ADRootDSE cmdlet gets the object that represents the root of the directory information tree of a directory server. +# This tree provides information about the configuration and capabilities of the directory server, +# such as the distinguished name for the configuration container, the current time on the directory server, +# and the functional levels of the directory server and the domain. +# +Get-ADForest +# The Get-ADForest cmdlet gets the Active Directory forest specified by the parameters. +Get-ADDomain +# The Get-ADDomain cmdlet gets the Active Directory domain specified by the parameters. +# Any computers joined the domain? +Get-ADComputer -Filter * | Select-Object DNSHostName \ No newline at end of file diff --git a/addtodomain.ps1 b/addtodomain.ps1 new file mode 100644 index 0000000..e1afb50 --- /dev/null +++ b/addtodomain.ps1 @@ -0,0 +1,27 @@ +# THIS SCRIPT MUST BE RUN AS ADMINISTRATOR ON SRV1, CLI1 and MGR +<# CHECKLIST: + - Windows Update is up to date + - Time zone is correct + - Set-TimeZone -id 'W. Europe Standard Time' + - Computer name is correct + - IP address is correct (non relevant for this lab) + - Keyboard layout is correct (Norwegian) +#> + +# VM's for the lab needs DC1 IP-address as DNS server (must be done on VM's: SRV1, CLI1 and MGR) +# Why? Because the DNS server is the only one that knows about the domain +$ipaddressdc1 = "192.168.x.x" # IP-address of DC1 +Get-NetAdapter | Set-DnsClientServerAddress -ServerAddresses $ipaddressdc1 + +# Check if configuration is correct +# Find DNS Servers . . . . . . . . . . . : IP.ADR.TIL.DC (192.168.x.x) +ipconfig /all + +# Add the computer to the domain +$domainName = "RohanIT.sec" # replace with your domain name (e.g. InfraIT.sec) + +$cred = Get-Credential -UserName "Wormtongue@$domainName" -Message 'Provide credentials for a domain admin' +Add-Computer -Credential $cred -DomainName $domainName -PassThru -Verbose +Restart-Computer + +# When restarted, the computer will be joinedto the domain, and you can log in with a domain admin or user account \ No newline at end of file diff --git a/psremote.ps1 b/psremote.ps1 new file mode 100644 index 0000000..7b93239 --- /dev/null +++ b/psremote.ps1 @@ -0,0 +1,21 @@ +# TEST PSREMOTE: Connect-PSRemoting -ComputerName FROM MGR TO WORKSTATIONS/SERVERS IN DOMAIN +Enter-PSSession -ComputerName dc1 +Enter-PSSession -ComputerName srv1 +Enter-PSSession -ComputerName cl1 + +# Install PowerShell 7.x on remote machine. +# Enable-PSRemoting -Force <- This command must be run as administrator on remote machine if PSRemote dont work. +$session = New-PSSession -ComputerName dc1 -ConfigurationName PowerShell.7 +Copy-Item -Path "C:\install\PowerShell-7.4.0-win-x64.msi" -Destination "C:\install" -ToSession $session +Invoke-Command -Session $session -ScriptBlock { + Start-Process "msiexec.exe" -ArgumentList "/i C:\install\PowerShell-7.4.0-win-x64.msi /quiet /norestart" -Wait +} +Invoke-Command -Session $session -ScriptBlock { $PSVersionTable } + + +# IF PSREMOTE DONT WORK, THIS COMMANDS MUST BE RUN AS ADMINISTRATOR ON VM'S WITH WINDOWS 10/11 +# Enable PSRemote: Enable-PSRemoting -Force +Enable-PSRemoting -Force +winrm set winrm/config/service/auth '@{Kerberos="true"}' +# List auth: +winrm get winrm/config/service/auth \ No newline at end of file diff --git a/timelang.ps1 b/timelang.ps1 index d5c99ae..0e14d42 100644 --- a/timelang.ps1 +++ b/timelang.ps1 @@ -1,5 +1,30 @@ #language, time and timezone settings: -Set-TimeZone -Id "UTC+1" -Confirm -Set-SystemLanguage no-NB -Set-WinSystemLocale no-NB -Set-WinUserLanguageList -LanguageList no-NB \ No newline at end of file +#language, time and timezone settings: +# Se hvilke språkpakker (capabilities) som er tilgjengelige og evt. installert: +Get-WindowsCapability -Online -Name Language* | + Where-Object { $_.Name -like '*nb-NO*' } | + Format-Table -Autosize + +# Installer Bokmål grunnpakke: +Add-WindowsCapability -Online -Name Language.Basic~~~nb-NO~0.0.1.0 + +# (Valgfritt) Installer OCR / TextToSpeech / Handwriting / Speech om ønskelig: +# Add-WindowsCapability -Online -Name Language.OCR~~~nb-NO~0.0.1.0 +# Add-WindowsCapability -Online -Name Language.TextToSpeech~~~nb-NO~0.0.1.0 +# Add-WindowsCapability -Online -Name Language.Handwriting~~~nb-NO~0.0.1.0 +# Add-WindowsCapability -Online -Name Language.Speech~~~nb-NO~0.0.1.0 + +# Sett Windows sin brukerliste for språk +# (NB: -Force hindrer bekreftelsesdialog): +Set-WinUserLanguageList -LanguageList nb-NO -Force + +# Sett system-lokale: +Set-WinSystemLocale nb-NO + +# Sett kultur (valutafomat, dato/klokkeslett osv.): +Set-Culture nb-NO + +# Sett standard grensesnittspråk for UI (f.eks. "Press any key to continue"): +Set-WinUILanguageOverride nb-NO + + diff --git a/usersetup.ps1 b/usersetup.ps1 new file mode 100644 index 0000000..e1e2f46 --- /dev/null +++ b/usersetup.ps1 @@ -0,0 +1,27 @@ +# THIS SCRIPT MUST BE RUN AS ADMINISTRATOR ON DC1 + +# Define new user parameters +$username = "Wormtongue" # Change this to the desired username +$Password = Read-Host -Prompt 'Enter Password' -AsSecureString +$userPrincipalName = $username + "@" # Change to your domain +$displayName = "" # Change this to the desired display name +$description = "" # Change this to a suitable description +$path = "CN=Users,DC=,DC=" # Change the path to the appropriate path in your AD structure +# My path in the video CN=Users,DC=InfraIT,DC=sec (CN stands for Common Name, and DC stands for Domain Component) +# Users is a container in the root of the domain and not a OU (Organizational Unit) + +# Create the new user +New-ADUser -Name $displayName ` + -GivenName $username ` + -UserPrincipalName $userPrincipalName ` + -SamAccountName $username ` + -AccountPassword $password ` + -DisplayName $displayName ` + -Description $description ` + -Path $path ` + -Enabled $true + +# Add the new user to the Domain Admins group +Add-ADGroupMember -Identity "Domain Admins" -Members $username + +Write-Host "User $username created and added to Domain Admins group." \ No newline at end of file diff --git a/winget driver install and update.ps1 b/winget driver install and update.ps1 index 3deb6d5..57f2fea 100644 --- a/winget driver install and update.ps1 +++ b/winget driver install and update.ps1 @@ -25,3 +25,6 @@ foreach ($driver in $drivers) { } Write-Output "All drivers have been updated." + +#install chocolatey +Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) \ No newline at end of file