diff --git a/Tools/Install-Wrapper/Invoke-Install.ps1 b/Tools/Install-Wrapper/Invoke-Install.ps1 index b8cb09d..70be9e7 100644 --- a/Tools/Install-Wrapper/Invoke-Install.ps1 +++ b/Tools/Install-Wrapper/Invoke-Install.ps1 @@ -1,13 +1,168 @@ -<# - Generic installer Wrapper +<# + Install Wrapper 2.0 + Author: Mikael Nystrom + http://www.deploymentbunny.com #> [cmdletbinding(SupportsShouldProcess=$True)] -Param -( - $Role="None" +Param( ) +Function Get-VIAOSVersion([ref]$OSv){ + $OS = Get-WmiObject -Class Win32_OperatingSystem + Switch -Regex ($OS.Version) + { + "6.1" + {If($OS.ProductType -eq 1) + {$OSv.value = "Windows 7 SP1"} + Else + {$OSv.value = "Windows Server 2008 R2"} + } + "6.2" + {If($OS.ProductType -eq 1) + {$OSv.value = "Windows 8"} + Else + {$OSv.value = "Windows Server 2012"} + } + "6.3" + {If($OS.ProductType -eq 1) + {$OSv.value = "Windows 8.1"} + Else + {$OSv.value = "Windows Server 2012 R2"} + } + "10" + {If($OS.ProductType -eq 1) + {$OSv.value = "Windows 10"} + Else + {$OSv.value = "Windows Server 2016"} + } + DEFAULT { "Version not listed" } + } +} +Function Import-VIASMSTSENV{ + try{ + $tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment + Write-Output "$ScriptName - tsenv is $tsenv " + $MDTIntegration = $true + + #$tsenv.GetVariables() | % { Write-Output "$ScriptName - $_ = $($tsenv.Value($_))" } + } + catch{ + Write-Output "$ScriptName - Unable to load Microsoft.SMS.TSEnvironment" + Write-Output "$ScriptName - Running in standalonemode" + $MDTIntegration = $false + } + Finally{ + if ($MDTIntegration -eq $true){ + $Logpath = $tsenv.Value("LogPath") + $LogFile = $Logpath + "\" + "$ScriptName.txt" + } + Else{ + $Logpath = $env:TEMP + $LogFile = $Logpath + "\" + "$ScriptName.txt" + } + } + Return $MDTIntegration +} +Function Start-VIALogging{ + Start-Transcript -path $LogFile -Force +} +Function Stop-VIALogging{ + Stop-Transcript +} +Function Invoke-VIAExe{ + [CmdletBinding(SupportsShouldProcess=$true)] + + param( + [parameter(mandatory=$true,position=0)] + [ValidateNotNullOrEmpty()] + [string] + $Executable, + + [parameter(mandatory=$false,position=1)] + [string] + $Arguments + ) + + if($Arguments -eq "") + { + Write-Verbose "Running Start-Process -FilePath $Executable -ArgumentList $Arguments -NoNewWindow -Wait -Passthru" + $ReturnFromEXE = Start-Process -FilePath $Executable -NoNewWindow -Wait -Passthru + }else{ + Write-Verbose "Running Start-Process -FilePath $Executable -ArgumentList $Arguments -NoNewWindow -Wait -Passthru" + $ReturnFromEXE = Start-Process -FilePath $Executable -ArgumentList $Arguments -NoNewWindow -Wait -Passthru + } + Write-Verbose "Returncode is $($ReturnFromEXE.ExitCode)" + Return $ReturnFromEXE.ExitCode +} +Function Invoke-VIAMsi{ + [CmdletBinding(SupportsShouldProcess=$true)] + + param( + [parameter(mandatory=$true,position=0)] + [ValidateNotNullOrEmpty()] + [string] + $MSI, + + [parameter(mandatory=$false,position=1)] + [string] + $Arguments + ) + + #Set MSIArgs + $MSIArgs = "/i " + $MSI + " " + $Arguments + + if($Arguments -eq "") + { + $MSIArgs = "/i " + $MSI + + + } + else + { + $MSIArgs = "/i " + $MSI + " " + $Arguments + + } + Write-Verbose "Running Start-Process -FilePath msiexec.exe -ArgumentList $MSIArgs -NoNewWindow -Wait -Passthru" + $ReturnFromEXE = Start-Process -FilePath msiexec.exe -ArgumentList $MSIArgs -NoNewWindow -Wait -Passthru + Write-Verbose "Returncode is $($ReturnFromEXE.ExitCode)" + Return $ReturnFromEXE.ExitCode +} +Function Invoke-VIAMsu{ + [CmdletBinding(SupportsShouldProcess=$true)] + + param( + [parameter(mandatory=$true,position=0)] + [ValidateNotNullOrEmpty()] + [string] + $MSU, + + [parameter(mandatory=$false,position=1)] + [string] + $Arguments + ) + + #Set MSIArgs + $MSUArgs = $MSU + " " + $Arguments + + if($Arguments -eq "") + { + $MSUArgs = $MSU + + + } + else + { + $MSUArgs = $MSU + " " + $Arguments + + } + + Write-Verbose "Running Start-Process -FilePath wusa.exe -ArgumentList $MSUArgs -NoNewWindow -Wait -Passthru" + $ReturnFromEXE = Start-Process -FilePath wusa.exe -ArgumentList $MSUArgs -NoNewWindow -Wait -Passthru + Write-Verbose "Returncode is $($ReturnFromEXE.ExitCode)" + Return $ReturnFromEXE.ExitCode +} + # Set Vars $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $ScriptName = Split-Path -Leaf $MyInvocation.MyCommand.Path @@ -17,19 +172,16 @@ $LANG = (Get-Culture).Name $OSV = $Null $ARCHITECTURE = $env:PROCESSOR_ARCHITECTURE -#Import function library -Import-Module "$ScriptDir\VIAInstall.psm1" -ErrorAction Stop -WarningAction Stop - #Try to Import SMSTSEnv -. Import-SMSTSENV +. Import-VIASMSTSENV #Start Transcript Logging -. Start-Logging +. Start-VIALogging #Detect current OS Version -. Get-OSVersion -osv ([ref]$osv) +. Get-VIAOSVersion -osv ([ref]$osv) -#Output base info +#Output more info Write-Output "" Write-Output "$ScriptName - ScriptDir: $ScriptDir" Write-Output "$ScriptName - SourceRoot: $SOURCEROOT" @@ -54,10 +206,11 @@ if($MDTIntegration -eq "YES"){ Write-Output "$ScriptName - OSDComputername: $TSOSDComputerName" } + #Custom Code Starts-------------------------------------- #Custom Code Ends-------------------------------------- -. Stop-Logging \ No newline at end of file +. Stop-VIALogging \ No newline at end of file diff --git a/Tools/Install-Wrapper/VIAInstall.psm1 b/Tools/Install-Wrapper/VIAInstall.psm1 deleted file mode 100644 index cd696fb..0000000 --- a/Tools/Install-Wrapper/VIAInstall.psm1 +++ /dev/null @@ -1,164 +0,0 @@ -<# - Functions used for the Installer Scripts - Version: 1.0 - Date: 2016-11-20 - Author: Mikael Nystrom -#> - -Function Get-VIAOSVersion([ref]$OSv){ - $OS = Get-WmiObject -Class Win32_OperatingSystem - Switch -Regex ($OS.Version) - { - "6.1" - {If($OS.ProductType -eq 1) - {$OSv.value = "Windows 7 SP1"} - Else - {$OSv.value = "Windows Server 2008 R2"} - } - "6.2" - {If($OS.ProductType -eq 1) - {$OSv.value = "Windows 8"} - Else - {$OSv.value = "Windows Server 2012"} - } - "6.3" - {If($OS.ProductType -eq 1) - {$OSv.value = "Windows 8.1"} - Else - {$OSv.value = "Windows Server 2012 R2"} - } - "10" - {If($OS.ProductType -eq 1) - {$OSv.value = "Windows 10"} - Else - {$OSv.value = "Windows Server 2016"} - } - DEFAULT { "Version not listed" } - } -} -Function Import-VIASMSTSENV{ - try - { - $tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment - Write-Output "$ScriptName - tsenv is $tsenv " - $MDTIntegration = $true - - #$tsenv.GetVariables() | % { Write-Output "$ScriptName - $_ = $($tsenv.Value($_))" } - } - catch - { - Write-Output "$ScriptName - Unable to load Microsoft.SMS.TSEnvironment" - Write-Output "$ScriptName - Running in standalonemode" - $MDTIntegration = $false - } - Finally - { - if ($MDTIntegration -eq $true){ - $Logpath = $tsenv.Value("LogPath") - $LogFile = $Logpath + "\" + "$ScriptName.log" - - } - Else{ - $Logpath = $env:TEMP - $LogFile = $Logpath + "\" + "$ScriptName.log" - } - } -} -Function Start-VIALogging{ - start-transcript -path $LogFile -Force -} -Function Stop-VIALogging{ - Stop-Transcript -} -Function Invoke-VIAExe{ - [CmdletBinding(SupportsShouldProcess=$true)] - - param( - [parameter(mandatory=$true,position=0)] - [ValidateNotNullOrEmpty()] - [string] - $Executable, - - [parameter(mandatory=$false,position=1)] - [string] - $Arguments - ) - - if($Arguments -eq "") - { - Write-Verbose "Running Start-Process -FilePath $Executable -ArgumentList $Arguments -NoNewWindow -Wait -Passthru" - $ReturnFromEXE = Start-Process -FilePath $Executable -NoNewWindow -Wait -Passthru - }else{ - Write-Verbose "Running Start-Process -FilePath $Executable -ArgumentList $Arguments -NoNewWindow -Wait -Passthru" - $ReturnFromEXE = Start-Process -FilePath $Executable -ArgumentList $Arguments -NoNewWindow -Wait -Passthru - } - Write-Verbose "Returncode is $($ReturnFromEXE.ExitCode)" - Return $ReturnFromEXE.ExitCode -} -Function Invoke-VIAMsi{ - [CmdletBinding(SupportsShouldProcess=$true)] - - param( - [parameter(mandatory=$true,position=0)] - [ValidateNotNullOrEmpty()] - [string] - $MSI, - - [parameter(mandatory=$false,position=1)] - [string] - $Arguments - ) - - #Set MSIArgs - $MSIArgs = "/i " + $MSI + " " + $Arguments - - if($Arguments -eq "") - { - $MSIArgs = "/i " + $MSI - - - } - else - { - $MSIArgs = "/i " + $MSI + " " + $Arguments - - } - Write-Verbose "Running Start-Process -FilePath msiexec.exe -ArgumentList $MSIArgs -NoNewWindow -Wait -Passthru" - $ReturnFromEXE = Start-Process -FilePath msiexec.exe -ArgumentList $MSIArgs -NoNewWindow -Wait -Passthru - Write-Verbose "Returncode is $($ReturnFromEXE.ExitCode)" - Return $ReturnFromEXE.ExitCode -} -Function Invoke-VIAMsu{ - [CmdletBinding(SupportsShouldProcess=$true)] - - param( - [parameter(mandatory=$true,position=0)] - [ValidateNotNullOrEmpty()] - [string] - $MSU, - - [parameter(mandatory=$false,position=1)] - [string] - $Arguments - ) - - #Set MSIArgs - $MSUArgs = $MSU + " " + $Arguments - - if($Arguments -eq "") - { - $MSUArgs = $MSU - - - } - else - { - $MSUArgs = $MSU + " " + $Arguments - - } - - Write-Verbose "Running Start-Process -FilePath wusa.exe -ArgumentList $MSUArgs -NoNewWindow -Wait -Passthru" - $ReturnFromEXE = Start-Process -FilePath wusa.exe -ArgumentList $MSUArgs -NoNewWindow -Wait -Passthru - Write-Verbose "Returncode is $($ReturnFromEXE.ExitCode)" - Return $ReturnFromEXE.ExitCode -} \ No newline at end of file