Skip to content

Commit 4b8035f

Browse files
Merge pull request #31 from phmcgann/master
Add -SkipDotNet parameter to Install-LTService function
2 parents 751a69d + ceb93ad commit 4b8035f

File tree

1 file changed

+50
-39
lines changed

1 file changed

+50
-39
lines changed

LabTech.psm1

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,9 @@ Function Install-LTService{
880880
881881
.PARAMETER Hide
882882
This will call Hide-LTAddRemove after the install.
883+
884+
.PARAMETER SkipDotNet
885+
This will disable the error checking for the .NET 3.5 and .NET 2.0 frameworks during the install process.
883886
884887
.PARAMETER Force
885888
This will disable some of the error checking on the install process.
@@ -926,6 +929,10 @@ Function Install-LTService{
926929
Update Date: 3/13/2018
927930
Purpose/Change: Added -NoWait parameter.
928931
Added minimum size requirement for agent installer to detect and skip a bad file download.
932+
933+
Update Date: 6/5/2018
934+
Purpose/Change: Added -SkipDotNet parameter.
935+
Allows for skipping of .NET 3.5 and 2.0 framework checks for installing on OS with .NET 4.0+ already installed
929936
930937
.LINK
931938
http://labtechconsulting.com
@@ -948,6 +955,7 @@ Function Install-LTService{
948955
[AllowNull()]
949956
[string]$Rename,
950957
[switch]$Hide,
958+
[switch]$SkipDotNet,
951959
[switch]$Force,
952960
[switch]$NoWait
953961
)
@@ -970,54 +978,57 @@ Function Install-LTService{
970978
Throw "Needs to be ran as Administrator"
971979
}
972980

973-
$DotNET = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse -EA 0 | Get-ItemProperty -name Version,Release -EA 0 | Where-Object { $_.PSChildName -match '^(?!S)\p{L}'} | Select-Object -ExpandProperty Version -EA 0
974-
if (-not ($DotNet -like '3.5.*')){
975-
Write-Output ".NET 3.5 installation needed."
976-
#Install-WindowsFeature Net-Framework-Core
977-
$OSVersion = [System.Environment]::OSVersion.Version
978-
979-
if ([version]$OSVersion -gt [version]'6.2'){
980-
try{
981-
If ( $PSCmdlet.ShouldProcess("NetFx3", "Enable-WindowsOptionalFeature") ) {
982-
$Install = Enable-WindowsOptionalFeature -Online -FeatureName "NetFx3" -All
983-
if ($Install.RestartNeeded) {
984-
Write-Output ".NET 3.5 installed but a reboot is needed."
981+
if (!$SkipDotNet){
982+
983+
$DotNET = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse -EA 0 | Get-ItemProperty -name Version,Release -EA 0 | Where-Object { $_.PSChildName -match '^(?!S)\p{L}'} | Select-Object -ExpandProperty Version -EA 0
984+
if (-not ($DotNet -like '3.5.*')){
985+
Write-Output ".NET 3.5 installation needed."
986+
#Install-WindowsFeature Net-Framework-Core
987+
$OSVersion = [System.Environment]::OSVersion.Version
988+
989+
if ([version]$OSVersion -gt [version]'6.2'){
990+
try{
991+
If ( $PSCmdlet.ShouldProcess("NetFx3", "Enable-WindowsOptionalFeature") ) {
992+
$Install = Enable-WindowsOptionalFeature -Online -FeatureName "NetFx3" -All
993+
if ($Install.RestartNeeded) {
994+
Write-Output ".NET 3.5 installed but a reboot is needed."
995+
}
985996
}
986997
}
987-
}
988-
catch{
989-
Write-Error "ERROR: .NET 3.5 install failed." -ErrorAction Continue
990-
if (!($Force)) { Write-Error $Install -ErrorAction Stop }
991-
}
992-
}
993-
Else{
994-
If ( $PSCmdlet.ShouldProcess("NetFx3", "Add Windows Feature") ) {
995-
Try {$Result=& "$env:windir\system32\Dism.exe" /online /get-featureinfo /featurename:NetFx3 2>''}
996-
Catch {Write-Output "Error calling Dism.exe."; $Result=$Null}
997-
If ($Result -contains "State : Enabled"){
998-
# also check reboot status, unsure of possible outputs
999-
# Restart Required : Possible
1000-
Write-Warning ".Net Framework 3.5 has been installed and enabled."
1001-
}
1002-
Else {
998+
catch{
1003999
Write-Error "ERROR: .NET 3.5 install failed." -ErrorAction Continue
1004-
If (!($Force)) { Write-Error $Result -ErrorAction Stop }
1000+
if (!($Force)) { Write-Error $Install -ErrorAction Stop }
1001+
}
1002+
}
1003+
Else{
1004+
If ( $PSCmdlet.ShouldProcess("NetFx3", "Add Windows Feature") ) {
1005+
Try {$Result=& "$env:windir\system32\Dism.exe" /online /get-featureinfo /featurename:NetFx3 2>''}
1006+
Catch {Write-Output "Error calling Dism.exe."; $Result=$Null}
1007+
If ($Result -contains "State : Enabled"){
1008+
# also check reboot status, unsure of possible outputs
1009+
# Restart Required : Possible
1010+
Write-Warning ".Net Framework 3.5 has been installed and enabled."
1011+
}
1012+
Else {
1013+
Write-Error "ERROR: .NET 3.5 install failed." -ErrorAction Continue
1014+
If (!($Force)) { Write-Error $Result -ErrorAction Stop }
1015+
}#End If
10051016
}#End If
10061017
}#End If
1007-
}#End If
10081018

1009-
$DotNET = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse | Get-ItemProperty -name Version -EA 0 | Where-Object{ $_.PSChildName -match '^(?!S)\p{L}'} | Select-Object -ExpandProperty Version
1010-
}#End If
1019+
$DotNET = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse | Get-ItemProperty -name Version -EA 0 | Where-Object{ $_.PSChildName -match '^(?!S)\p{L}'} | Select-Object -ExpandProperty Version
1020+
}#End If
10111021

1012-
If (-not ($DotNet -like '3.5.*')){
1013-
If (($Force)) {
1014-
If ($DotNet -like '2.0.*'){
1015-
Write-Error "ERROR: .NET 3.5 is not detected and could not be installed." -ErrorAction Continue
1022+
If (-not ($DotNet -like '3.5.*')){
1023+
If (($Force)) {
1024+
If ($DotNet -like '2.0.*'){
1025+
Write-Error "ERROR: .NET 3.5 is not detected and could not be installed." -ErrorAction Continue
1026+
} Else {
1027+
Write-Error "ERROR: .NET 2.0 is not detected and could not be installed." -ErrorAction Stop
1028+
}#End If
10161029
} Else {
1017-
Write-Error "ERROR: .NET 2.0 is not detected and could not be installed." -ErrorAction Stop
1030+
Write-Error "ERROR: .NET 3.5 is not detected and could not be installed." -ErrorAction Stop
10181031
}#End If
1019-
} Else {
1020-
Write-Error "ERROR: .NET 3.5 is not detected and could not be installed." -ErrorAction Stop
10211032
}#End If
10221033
}#End If
10231034

0 commit comments

Comments
 (0)