From 015b91f83381bdd3b76de59f37d60ebf34f8292b Mon Sep 17 00:00:00 2001 From: James Ruskin Date: Thu, 18 Apr 2024 15:57:04 +0100 Subject: [PATCH] (#86) Improve Script Output As some of the changes have resulted in a lot less noise during the script(s) running, this adds a few more bits of output to show folk that progress is being made. Conversely, this also removes a few of the block-outputs at the end of scripts that tell the user to login - as we don't want them to login until they've completed the guide (see #161). --- OfflineInstallPreparation.ps1 | 2 +- Start-C4bCcmSetup.ps1 | 28 ++++++++++++---------- Start-C4bJenkinsSetup.ps1 | 6 ++--- Start-C4bNexusSetup.ps1 | 45 +++++++++++++---------------------- scripts/Get-Helpers.ps1 | 4 ++-- 5 files changed, 36 insertions(+), 49 deletions(-) diff --git a/OfflineInstallPreparation.ps1 b/OfflineInstallPreparation.ps1 index ea1ab1c..d7f8808 100644 --- a/OfflineInstallPreparation.ps1 +++ b/OfflineInstallPreparation.ps1 @@ -89,7 +89,7 @@ foreach ($Package in (Get-Content $PSScriptRoot\files\chocolatey.json | ConvertF try { if (-not (Test-Path "$($PackageWorkingDirectory)\$($Package.Name)*.nupkg") -and -not (Test-Path "$PSScriptRoot\files\$($Package.Name)*.nupkg")) { - Write-Verbose "Downloading '$($Package.Name)'" + Write-Host "Downloading '$($Package.Name)'" $Output = choco @ChocoArgs if ($LASTEXITCODE -ne 0) { $Output diff --git a/Start-C4bCcmSetup.ps1 b/Start-C4bCcmSetup.ps1 index 7c0a5bd..257430e 100644 --- a/Start-C4bCcmSetup.ps1 +++ b/Start-C4bCcmSetup.ps1 @@ -45,11 +45,12 @@ process { $PkgSrc = "$env:SystemDrive\choco-setup\packages" $Ccr = 'https://community.chocolatey.org/api/v2/' + Write-Host "Installing SQL Server Express" $chocoArgs = @('upgrade', 'sql-server-express', 'sql-server-management-studio', '-y', "--source='$Ccr'", '--no-progress') & choco @chocoArgs # https://docs.microsoft.com/en-us/sql/tools/configuration-manager/tcp-ip-properties-ip-addresses-tab - Write-Output 'SQL Server: Configuring Remote Acess on SQL Server Express.' + Write-Verbose 'SQL Server: Configuring Remote Access on SQL Server Express.' $assemblyList = 'Microsoft.SqlServer.Management.Common', 'Microsoft.SqlServer.Smo', 'Microsoft.SqlServer.SqlWmiManagement', 'Microsoft.SqlServer.SmoExtended' foreach ($assembly in $assemblyList) { @@ -81,25 +82,26 @@ process { $SqlString = (Get-ChildItem -Path 'HKLM:\Software\Microsoft\Microsoft SQL Server').Name | Where-Object { $_ -like "HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft SQL Server\MSSQL*.SQLEXPRESS" } $SqlVersion = $SqlString.Split("\") | Where-Object { $_ -like "MSSQL*.SQLEXPRESS" } - Write-Output 'SQL Server: Setting Mixed Mode Authentication.' - New-ItemProperty "HKLM:\Software\Microsoft\Microsoft SQL Server\$SqlVersion\MSSQLServer\" -Name 'LoginMode' -Value 2 -Force + Write-Verbose 'SQL Server: Setting Mixed Mode Authentication.' + $null = New-ItemProperty "HKLM:\Software\Microsoft\Microsoft SQL Server\$SqlVersion\MSSQLServer\" -Name 'LoginMode' -Value 2 -Force - Write-Output "SQL Server: Forcing Restart of Instance." + Write-Verbose "SQL Server: Forcing Restart of Instance." Restart-Service -Force 'MSSQL$SQLEXPRESS' - Write-Output "SQL Server: Setting up SQL Server Browser and starting the service." + Write-Verbose "SQL Server: Setting up SQL Server Browser and starting the service." Set-Service 'SQLBrowser' -StartupType Automatic Start-Service 'SQLBrowser' - Write-Output "Firewall: Enabling SQLServer TCP port 1433." - netsh advfirewall firewall add rule name="SQL Server 1433" dir=in action=allow protocol=TCP localport=1433 profile=any enable=yes service=any + Write-Verbose "Firewall: Enabling SQLServer TCP port 1433." + $null = netsh advfirewall firewall add rule name="SQL Server 1433" dir=in action=allow protocol=TCP localport=1433 profile=any enable=yes service=any #New-NetFirewallRule -DisplayName "Allow inbound TCP Port 1433" –Direction inbound –LocalPort 1433 -Protocol TCP -Action Allow - Write-Output "Firewall: Enabling SQL Server browser UDP port 1434." - netsh advfirewall firewall add rule name="SQL Server Browser 1434" dir=in action=allow protocol=UDP localport=1434 profile=any enable=yes service=any + Write-Verbose "Firewall: Enabling SQL Server browser UDP port 1434." + $null = netsh advfirewall firewall add rule name="SQL Server Browser 1434" dir=in action=allow protocol=UDP localport=1434 profile=any enable=yes service=any #New-NetFirewallRule -DisplayName "Allow inbound UDP Port 1434" –Direction inbound –LocalPort 1434 -Protocol UDP -Action Allow # Install prerequisites for CCM + Write-Host "Installing Chocolatey Central Management Prerequisites" $chocoArgs = @('install', 'IIS-WebServer', "--source='windowsfeatures'", '--no-progress', '-y') & choco @chocoArgs @@ -115,7 +117,7 @@ process { $chocoArgs = @('install', 'dotnet-6.0-aspnetruntime', "--version=$($Packages.Where{$_.Name -eq 'dotnet-6.0-aspnetruntime'}.Version)", '--no-progress', '--pin', '--pin-reason="Latest version compatible with chocolatey-management-database V 0.12.0"', '-y') & choco @chocoArgs - # Install CCM DB package using Local SQL Express + Write-Host "Creating Chocolatey Central Management Database" choco install chocolatey-management-database -y --package-parameters="'/ConnectionString=Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;Trusted_Connection=true;'" --no-progress # Add Local Windows User: @@ -131,7 +133,7 @@ process { $hostName += "." + $domainName } - #Install CCM Service + Write-Host "Installing Chocolatey Central Management Service" if($CertificateThumbprint){ Write-Verbose "Validating certificate is in LocalMachine\TrustedPeople Store" if($CertificateThumbprint -notin (Get-ChildItem Cert:\LocalMachine\TrustedPeople | Select-Object -Expand Thumbprint)){ @@ -153,7 +155,7 @@ process { & choco @chocoArgs } - #Install CCM Web package + Write-Host "Installing Chocolatey Central Management Website" $chocoArgs = @('install', 'chocolatey-management-web', '-y', "--package-parameters-sensitive=""'/ConnectionString:Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User ID=$DatabaseUser;Password=$DatabaseUserPw;'""", '--no-progress') & choco @chocoArgs @@ -167,7 +169,7 @@ process { } $CcmJson | ConvertTo-Json | Out-File "$env:SystemDrive\choco-setup\logs\ccm.json" - Write-Host "CCM Setup has now completed" -ForegroundColor Green + Write-Host "Chocolatey Central Management Setup has now completed" -ForegroundColor Green $ErrorActionPreference = $DefaultEap Stop-Transcript diff --git a/Start-C4bJenkinsSetup.ps1 b/Start-C4bJenkinsSetup.ps1 index e7167b3..b225ce6 100644 --- a/Start-C4bJenkinsSetup.ps1 +++ b/Start-C4bJenkinsSetup.ps1 @@ -38,10 +38,11 @@ process { $chocoArgs = @('install', 'temurin21jre', '-y', '--no-progress', "--params='/ADDLOCAL=FeatureJavaHome'") & choco @chocoArgs - # Enviornment variable used to disbale jenkins instal login prompts + # Environment variable used to disable jenkins install login prompts [Environment]::SetEnvironmentVariable('JAVA_OPTS', '-Djenkins.install.runSetupWizard=false', 'Machine') # Install Jenkins + Write-Host "Installing Jenkins" $chocoArgs = @('install', 'jenkins', '-y', '--no-progress') & choco @chocoArgs @@ -132,9 +133,6 @@ process { $JenkinsJson | ConvertTo-Json | Out-File "$env:SystemDrive\choco-setup\logs\jenkins.json" Write-Host 'Jenkins setup complete' -ForegroundColor Green - Write-Host "Login to Jenkins at: $($JenkinsJson.JenkinsUri)" -ForegroundColor Green - Write-Host 'Initial default Jenkins admin user password:' -ForegroundColor Green - Write-Host "Admin Password is '$($JenkinsJson.JenkinsPw)'" -ForegroundColor Green $ErrorActionPreference = $DefaultEap Stop-Transcript diff --git a/Start-C4bNexusSetup.ps1 b/Start-C4bNexusSetup.ps1 index b2eb944..982a30a 100644 --- a/Start-C4bNexusSetup.ps1 +++ b/Start-C4bNexusSetup.ps1 @@ -39,17 +39,19 @@ process { . .\scripts\Get-Helpers.ps1 # Install base nexus-repository package + Write-Host "Installing Sonatype Nexus Repository" $chocoArgs = @('install', 'nexus-repository', '-y' ,'--no-progress', "--package-parameters='/Fqdn:localhost'") & choco @chocoArgs #Build Credential Object, Connect to Nexus + Write-Host "Configuring Sonatype Nexus Repository" $securePw = (Get-Content 'C:\programdata\sonatype-work\nexus3\admin.password') | ConvertTo-SecureString -AsPlainText -Force $Credential = [System.Management.Automation.PSCredential]::new('admin',$securePw) Connect-NexusServer -Hostname localhost -Credential $Credential #Drain default repositories - Get-NexusRepository | Remove-NexusRepository -Force + $null = Get-NexusRepository | Remove-NexusRepository -Force #Enable NuGet Auth Realm Enable-NexusRealm -Realm 'NuGet API-Key Realm' @@ -91,19 +93,20 @@ process { choco source add -n 'ChocolateyInternal' -s "$((Get-NexusRepository -Name 'ChocolateyInternal').url)/index.json" --priority 1 # Install a non-IE browser for browsing the Nexus web portal. - # Edge sometimes fails install due to latest Windows Updates not being installed. - # In that scenario, Google Chrome is installed instead. - choco install microsoft-edge -y - if ($LASTEXITCODE -eq 0) { - if (Test-Path 'HKLM:\SOFTWARE\Microsoft\Edge') { - $RegArgs = @{ - Path = 'HKLM:\SOFTWARE\Microsoft\Edge\' - Name = 'HideFirstRunExperience' - Type = 'Dword' - Value = 1 - Force = $true + if (-not (Test-Path 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe')) { + Write-Host "Installing Microsoft Edge, to allow viewing the Nexus site" + choco install microsoft-edge -y + if ($LASTEXITCODE -eq 0) { + if (Test-Path 'HKLM:\SOFTWARE\Microsoft\Edge') { + $RegArgs = @{ + Path = 'HKLM:\SOFTWARE\Microsoft\Edge\' + Name = 'HideFirstRunExperience' + Type = 'Dword' + Value = 1 + Force = $true + } + $null = Set-ItemProperty @RegArgs } - Set-ItemProperty @RegArgs } } @@ -127,22 +130,6 @@ process { } $NexusJson | ConvertTo-Json | Out-File "$env:SystemDrive\choco-setup\logs\nexus.json" - $finishOutput = @" - ############################################################## - - Nexus Repository Setup Completed - Please login to the following URL to complete admin account setup: - - Server Url: 'http://localhost:8081' (this will change once you add a certificate) - Chocolatey Repo: "$((Get-NexusRepository -Name 'ChocolateyInternal').url)/" - NuGet ApiKey: $NugetApiKey - Nexus 'admin' user password: $($Credential.GetNetworkCredential().Password) - - ############################################################## -"@ - - Write-Host "$finishOutput" -ForegroundColor Green - $ErrorActionPreference = $DefaultEap Stop-Transcript } \ No newline at end of file diff --git a/scripts/Get-Helpers.ps1 b/scripts/Get-Helpers.ps1 index 4d61704..14f36a6 100644 --- a/scripts/Get-Helpers.ps1 +++ b/scripts/Get-Helpers.ps1 @@ -1600,7 +1600,7 @@ ALTER ROLE [$DatabaseRole] ADD MEMBER [$Username] "@ } - Write-Output "Adding $UserName to $DatabaseName with the following permissions: $($DatabaseRoles -Join ', ')" + Write-Host "Adding $UserName to $DatabaseName with the following permissions: $($DatabaseRoles -Join ', ')" Write-Debug "running the following: \n $addUserSQLCommand" $Connection = New-Object System.Data.SQLClient.SQLConnection $Connection.ConnectionString = "server='$DatabaseServer';database='master';$DatabaseServerPermissionsOptions" @@ -1608,7 +1608,7 @@ ALTER ROLE [$DatabaseRole] ADD MEMBER [$Username] $Command = New-Object System.Data.SQLClient.SQLCommand $Command.CommandText = $addUserSQLCommand $Command.Connection = $Connection - $Command.ExecuteNonQuery() + $null = $Command.ExecuteNonQuery() $Connection.Close() }