Skip to content

Commit

Permalink
New version of the Installer PS Wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
DeploymentBunny committed Nov 19, 2016
1 parent b157c38 commit c1b525a
Showing 1 changed file with 196 additions and 0 deletions.
196 changes: 196 additions & 0 deletions Tools/Install-Wrapper/Invoke-Install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
Function Get-OSVersion([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-SMSTSENV{
try
{
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
Write-Output "$ScriptName - tsenv is $tsenv "
$MDTIntegration = "YES"

#$tsenv.GetVariables() | % { Write-Output "$ScriptName - $_ = $($tsenv.Value($_))" }
}
catch
{
Write-Output "$ScriptName - Unable to load Microsoft.SMS.TSEnvironment"
Write-Output "$ScriptName - Running in standalonemode"
$MDTIntegration = "NO"
}
Finally
{
if ($MDTIntegration -eq "YES"){
$Logpath = $tsenv.Value("LogPath")
$LogFile = $Logpath + "\" + "$ScriptName.txt"

}
Else{
$Logpath = $env:TEMP
$LogFile = $Logpath + "\" + "$ScriptName.txt"
}
}
}
Function Start-Logging{
start-transcript -path $LogFile -Force
}
Function Stop-Logging{
Stop-Transcript
}
Function Invoke-Exe{
[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-Msi{
[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-Msu{
[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
#[xml]$Settings = Get-Content "$ScriptDir\Settings.xml"

$SOURCEROOT = "$SCRIPTDIR\Source"
$LANG = (Get-Culture).Name
$OSV = $Null
$ARCHITECTURE = $env:PROCESSOR_ARCHITECTURE

#Try to Import SMSTSEnv
. Import-SMSTSENV

#Start Transcript Logging
. Start-Logging

#Detect current OS Version
. Get-OSVersion -osv ([ref]$osv)

#Output base info
Write-Output ""
Write-Output "$ScriptName - ScriptDir: $ScriptDir"
Write-Output "$ScriptName - SourceRoot: $SOURCEROOT"
Write-Output "$ScriptName - ScriptName: $ScriptName"
Write-Output "$ScriptName - OS Name: $osv"
Write-Output "$ScriptName - OS Architecture: $ARCHITECTURE"
Write-Output "$ScriptName - Current Culture: $LANG"
Write-Output "$ScriptName - Integration with MDT(LTI/ZTI): $MDTIntegration"
Write-Output "$ScriptName - Log: $LogFile"

#Determine what to do

switch ($osv)
{
'Windows Server 2012 R2'{Invoke-Msu -MSU """$ScriptDir\Source\Win8.1AndW2K12R2-KB3134758-x64.msu""" -Arguments "/quiet /norestart" -Verbose}
Default {}
}

. Stop-Logging

0 comments on commit c1b525a

Please sign in to comment.