SifHelper.psm1
#Requires -RunAsAdministrator #Requires -Modules PKI,WebAdministration Set-StrictMode -Version Latest # Pass verbose on if required $verboseSetting = $false if ($PSBoundParameters.ContainsKey('Verbose')) { $verboseSetting = $PSBoundParameters["Verbose"] } $whatifSetting = $false if ($PSBoundParameters.ContainsKey('WhatIf')) { $whatifSetting = $PSBoundParameters["WhatIf"] } $DestinationFolder = Split-Path $PSScriptRoot -Parent $filename = "SifHelper.{0:yyMMdd}" -f (Get-Date) $counter = 2 $fullPath = Join-Path $DestinationFolder "$filename.log" while (Test-Path $fullPath) { $fullPath = Join-Path $DestinationFolder "$filename ($($counter)).log" $counter++ } Start-Transcript -Path $fullpath -IncludeInvocationHeader try { $nugetPackageProvider = Get-PackageProvider -Name NuGet -Force -Verbose:$verboseSetting -ErrorAction Stop if (!$nugetPackageProvider) { Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Confirm:$false -Verbose:$verboseSetting } # TODO remove the module imports for PKI and WebAdministration.. should be done in module .PSD1 if (!(Get-Module PKI)) { Import-Module PKI -ErrorAction Stop -Verbose:$verboseSetting } if (!(Get-Module WebAdministration) -or (!(Get-PSDrive IIS -ErrorAction SilentlyContinue -Verbose:$verboseSetting))) { Get-Module WebAdministration | Remove-Module -Force -Confirm:$false Import-Module WebAdministration -ErrorAction Stop -Force -Verbose:$verboseSetting } $SitecoreGalleryUrl = "https://sitecore.myget.org/F/sc-powershell/api/v2" if (-not(Get-PSRepository -name SitecoreGallery)) { Register-PSRepository -Name SitecoreGallery -SourceLocation $SitecoreGalleryUrl -InstallationPolicy Trusted -Verbose:$verboseSetting } ("SitecoreInstallFramework", "SqlServer") | ForEach-Object -Verbose:$verboseSetting { if ((Get-InstalledModule -Name $_ -Verbose:$verboseSetting -ErrorAction SilentlyContinue)) { Update-Module $_ -Confirm:$false -Verbose:$verboseSetting -Force } else { Install-Module $_ -Confirm:$false -AllowClobber -SkipPublisherCheck -Force -Verbose:$verboseSetting } if (!(Get-Module $_)) { Write-Warning "Module '$_' is not loaded!" Import-Module $_ -Force -Verbose:$verboseSetting } } $scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path $privates = Join-Path -Path $scriptRoot -ChildPath 'Private' $publics = Join-Path -Path $scriptRoot -ChildPath 'Public' Get-ChildItem -Path $privates -Filter '*.psm1' | ForEach-Object { Import-Module $_.FullName -Force -Verbose:$verboseSetting } Get-ChildItem -Path $publics -Filter '*.psm1;*.ps1' | ForEach-Object { Import-Module $_.FullName -Global -Force -Verbose:$verboseSetting } # Dot source to scope # Private must be sourced first - usage in public functions during load ('Private' , 'Public') | ForEach-Object { Get-ChildItem -Path (Join-Path $scriptRoot $_) -Include *.ps1 -Exclude *.Tests.ps1 -File -Recurse | ForEach-Object { try { . $_.FullName } catch { Write-Warning $_.Exception.Message } } } # Export Public functions from the module Get-ChildItem (Join-Path $scriptRoot Public) -Include *.ps1 -Exclude *.Tests.ps1 -File -Recurse | ForEach-Object { Export-ModuleMember -Function $_.BaseName } Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) choco upgrade webdeploy -y -f choco upgrade sql2014-dacframework -y -f choco upgrade sql2016-dacframework -y -f choco upgrade urlrewrite -y -f # $webpicmd = Join-Path $env:ProgramFiles 'Microsoft\Web Platform Installer\webpicmd.exe' # $products = ('UrlRewrite2', 'DACFx') -join ',' # & $webpicmd /Install /Products:$products /AcceptEula /SuppressReboot } catch { Write-Error $_ throw } finally { Stop-Transcript } |