diff --git a/Set-SslSecurity.ps1 b/Set-SslSecurity.ps1 index 407ece2..104e7aa 100644 --- a/Set-SslSecurity.ps1 +++ b/Set-SslSecurity.ps1 @@ -119,7 +119,7 @@ process { Write-Verbose "Starting up Nexus" Start-Service nexus - Write-Warning "Waiting to give Nexus time to start up" + Write-Warning "Waiting to give Nexus time to start up on 'https://${SubjectWithoutCn}:8443'" [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::tls12 do { $response = try { diff --git a/Start-C4bCcmSetup.ps1 b/Start-C4bCcmSetup.ps1 index def4da6..1cbc97e 100644 --- a/Start-C4bCcmSetup.ps1 +++ b/Start-C4bCcmSetup.ps1 @@ -47,7 +47,7 @@ process { & 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) { @@ -79,25 +79,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 @@ -113,8 +114,8 @@ 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 - choco install chocolatey-management-database -y -s $PkgSrc --package-parameters="'/ConnectionString=Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;Trusted_Connection=true;'" --no-progress + 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: $DatabaseUser = $DatabaseCredential.UserName @@ -129,7 +130,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)){ @@ -139,7 +140,7 @@ process { } else { Write-Verbose "Certificate has been successfully found in correct store" - $chocoArgs = @('install','chocolatey-management-service','-y',"--source='$PkgSrc'","--package-parameters-sensitive='/ConnectionString:Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User Id=$DatabaseUser;Password=$DatabaseUserPw'") + $chocoArgs = @('install', 'chocolatey-management-service', '-y', "--package-parameters-sensitive='/ConnectionString:Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User Id=$DatabaseUser;Password=$DatabaseUserPw'") & choco @chocoArgs Set-CcmCertificate -CertificateThumbprint $CertificateThumbprint @@ -147,12 +148,12 @@ process { } else { - $chocoArgs = @('install', 'chocolatey-management-service', '-y', "--source='$PkgSrc'", "--package-parameters-sensitive=`"/ConnectionString:'Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User ID=$DatabaseUser;Password=$DatabaseUserPw;'`"", '--no-progress') + $chocoArgs = @('install', 'chocolatey-management-service', '-y', "--package-parameters-sensitive=`"/ConnectionString:'Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User ID=$DatabaseUser;Password=$DatabaseUserPw;'`"", '--no-progress') & choco @chocoArgs } - #Install CCM Web package - $chocoArgs = @('install', 'chocolatey-management-web', '-y', "--source='$PkgSrc'", "--package-parameters-sensitive=""'/ConnectionString:Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User ID=$DatabaseUser;Password=$DatabaseUserPw;'""", '--no-progress') + 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 $CcmSvcUrl = choco config get centralManagementServiceUrl -r @@ -165,7 +166,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 61bc52f..b225ce6 100644 --- a/Start-C4bJenkinsSetup.ps1 +++ b/Start-C4bJenkinsSetup.ps1 @@ -12,8 +12,7 @@ C4B Quick-Start Guide Jenkins setup script param( # Hostname of your C4B Server [string]$HostName = $env:ComputerName, - # Repo where you're installing Jenkins from, usually CCR - [string]$Source = 'https://community.chocolatey.org/api/v2/', + # API key of your Nexus repo, for Chocolatey Jenkins jobs to use [string]$NuGetApiKey = $(Get-Content "$env:SystemDrive\choco-setup\logs\nexus.json" | ConvertFrom-Json).NuGetApiKey ) @@ -36,14 +35,15 @@ process { . .\scripts\Get-Helpers.ps1 # Install temurin21jre to meet JRE>11 dependency of Jenkins - $chocoArgs = @('install', 'temurin21jre', '-y', "--source='$Source'", '--no-progress', "--params='/ADDLOCAL=FeatureJavaHome'") + $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 - $chocoArgs = @('install', 'jenkins', '-y', "--source='$Source'", '--no-progress') + Write-Host "Installing Jenkins" + $chocoArgs = @('install', 'jenkins', '-y', '--no-progress') & choco @chocoArgs Write-Host "Giving Jenkins 30 seconds to complete background setup..." -ForegroundColor Green @@ -133,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 3ddf4cd..f25b531 100644 --- a/Start-C4bNexusSetup.ps1 +++ b/Start-C4bNexusSetup.ps1 @@ -39,10 +39,12 @@ process { . .\scripts\Get-Helpers.ps1 # Install base nexus-repository package - $chocoArgs = @('install','nexus-repository','-y',"--source='https://community.chocolatey.org/api/v2/'",'--no-progress',"--package-parameters='/Fqdn:localhost'") + 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) @@ -90,26 +92,22 @@ 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. - $null = choco install microsoft-edge -y --source="'https://community.chocolatey.org/api/v2/'" - 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 } } - else { - Write-Warning "Microsoft Edge install was not succesful." - Write-Host "Installing Google Chrome as an alternative." - choco install googlechrome -y --source="'https://community.chocolatey.org/api/v2/'" - } # Add Nexus port 8081 access via firewall $FwRuleParams = @{ @@ -131,22 +129,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/Start-C4bSetup.ps1 b/Start-C4bSetup.ps1 index 9febb4a..0238840 100644 --- a/Start-C4bSetup.ps1 +++ b/Start-C4bSetup.ps1 @@ -64,7 +64,10 @@ param( # Only used in Unattend mode for the SSL setup script. [Parameter(ParameterSetName='Unattended')] [string] - $Thumbprint + $Thumbprint, + + # If provided, shows all Chocolatey output. Otherwise, blissful quiet. + [switch]$ShowChocoOutput ) if ($host.name -ne 'ConsoleHost') { @@ -73,6 +76,10 @@ if ($host.name -ne 'ConsoleHost') { break } +if ($ShowChocoOutput) { + $global:PSDefaultParameterValues["Invoke-Choco:InformationAction"] = "Continue" +} + if ($env:CHOCO_QSG_DEVELOP){ $QsRepo = "https://github.com/chocolatey/choco-quickstart-scripts/archive/refs/heads/develop.zip" } diff --git a/scripts/Get-Helpers.ps1 b/scripts/Get-Helpers.ps1 index 47110f6..d1cc249 100644 --- a/scripts/Get-Helpers.ps1 +++ b/scripts/Get-Helpers.ps1 @@ -624,7 +624,7 @@ function New-NexusNugetHostedRepository { } Write-Verbose $($Body | ConvertTo-Json) - Invoke-Nexus -UriSlug $FullUrlSlug -Body $Body -Method POST + $null = Invoke-Nexus -UriSlug $FullUrlSlug -Body $Body -Method POST } } @@ -745,7 +745,7 @@ function New-NexusRawHostedRepository { } Write-Verbose $($Body | ConvertTo-Json) - Invoke-Nexus -UriSlug $urislug -Body $Body -Method POST + $null = Invoke-Nexus -UriSlug $urislug -Body $Body -Method POST } @@ -882,7 +882,7 @@ function Enable-NexusRealm { $body = $collection Write-Verbose $($Body | ConvertTo-Json) - Invoke-Nexus -UriSlug $urislug -BodyAsArray $Body -Method PUT + $null = Invoke-Nexus -UriSlug $urislug -BodyAsArray $Body -Method PUT } } @@ -1599,7 +1599,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" @@ -1607,7 +1607,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() }