|
|
|
@ -42,15 +42,34 @@ $includesubfeatures = Get-Attr $params "include_sub_features" $false | ConvertTo
|
|
|
|
$includemanagementtools = Get-Attr $params "include_management_tools" $false | ConvertTo-Bool
|
|
|
|
$includemanagementtools = Get-Attr $params "include_management_tools" $false | ConvertTo-Bool
|
|
|
|
$source = Get-Attr $params "source" $false
|
|
|
|
$source = Get-Attr $params "source" $false
|
|
|
|
|
|
|
|
|
|
|
|
If ($state -eq "present") {
|
|
|
|
# Determine which cmdlets we need to work with. Then we can set options appropriate for the cmdlet
|
|
|
|
if ($source)
|
|
|
|
$installWF= $false
|
|
|
|
{
|
|
|
|
$addWF = $false
|
|
|
|
if (!(test-path $source))
|
|
|
|
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
Fail-Json $result "Failed to find source path $source"
|
|
|
|
# We can infer uninstall/remove if install/add cmdlets exist
|
|
|
|
}
|
|
|
|
if (Get-Command "Install-WindowsFeature" -ErrorAction SilentlyContinue) {
|
|
|
|
|
|
|
|
$addCmdlet = "Install-WindowsFeature"
|
|
|
|
|
|
|
|
$removeCmdlet = "Uninstall-WindowsFeature"
|
|
|
|
|
|
|
|
$installWF = $true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
elseif (Get-Command "Add-WindowsFeature" -ErrorAction SilentlyContinue) {
|
|
|
|
|
|
|
|
$addCmdlet = "Add-WindowsFeature"
|
|
|
|
|
|
|
|
$removeCmdlet = "Remove-WindowsFeature"
|
|
|
|
|
|
|
|
$addWF = $true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
throw [System.Exception] "Not supported on this version of Windows"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch {
|
|
|
|
|
|
|
|
Fail-Json $result $_.Exception.Message
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
If ($state -eq "present") {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Base params to cover both Add/Install-WindowsFeature
|
|
|
|
$InstallParams = @{
|
|
|
|
$InstallParams = @{
|
|
|
|
"Name"=$name;
|
|
|
|
"Name"=$name;
|
|
|
|
"Restart"=$Restart;
|
|
|
|
"Restart"=$Restart;
|
|
|
|
@ -58,48 +77,39 @@ If ($state -eq "present") {
|
|
|
|
"ErrorAction"="SilentlyContinue"
|
|
|
|
"ErrorAction"="SilentlyContinue"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($IncludeManagementTools -eq $true)
|
|
|
|
# IncludeManagementTools and source are options only for Install-WindowsFeature
|
|
|
|
{
|
|
|
|
if ($installWF) {
|
|
|
|
$InstallParams.add("IncludeManagementTools",$includemanagementtools)
|
|
|
|
|
|
|
|
}
|
|
|
|
if ($source) {
|
|
|
|
|
|
|
|
if (!(test-path $source)) {
|
|
|
|
if ($source)
|
|
|
|
Fail-Json $result "Failed to find source path $source"
|
|
|
|
{
|
|
|
|
|
|
|
|
$InstallParams.add("Source",$source)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
If (Get-Command "Install-WindowsFeature" -ErrorAction SilentlyContinue) {
|
|
|
|
|
|
|
|
$featureresult = Install-WindowsFeature @InstallParams
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ElseIf (Get-Command "Add-WindowsFeature" -ErrorAction SilentlyContinue) {
|
|
|
|
|
|
|
|
if ($IncludeManagementTools)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$InstallParams.Remove("IncludeManagementTools")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$featureresult = Add-WindowsFeature @InstallParams
|
|
|
|
|
|
|
|
|
|
|
|
$InstallParams.add("Source",$source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Else {
|
|
|
|
|
|
|
|
Fail-Json $result "Not supported on this version of Windows"
|
|
|
|
if ($IncludeManagementTools) {
|
|
|
|
|
|
|
|
$InstallParams.add("IncludeManagementTools",$includemanagementtools)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
$featureresult = Invoke-Expression "$addCmdlet @InstallParams"
|
|
|
|
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
catch {
|
|
|
|
Fail-Json $result $_.Exception.Message
|
|
|
|
Fail-Json $result $_.Exception.Message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ElseIf ($state -eq "absent") {
|
|
|
|
ElseIf ($state -eq "absent") {
|
|
|
|
try {
|
|
|
|
|
|
|
|
If (Get-Command "Uninstall-WindowsFeature" -ErrorAction SilentlyContinue) {
|
|
|
|
$UninstallParams = @{
|
|
|
|
$featureresult = Uninstall-WindowsFeature -Name $name -Restart:$restart -ErrorAction SilentlyContinue
|
|
|
|
"Name"=$name;
|
|
|
|
}
|
|
|
|
"Restart"=$Restart;
|
|
|
|
ElseIf (Get-Command "Remove-WindowsFeature" -ErrorAction SilentlyContinue) {
|
|
|
|
"ErrorAction"="SilentlyContinue"
|
|
|
|
$featureresult = Remove-WindowsFeature -Name $name -Restart:$restart -ErrorAction SilentlyContinue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Else {
|
|
|
|
try {
|
|
|
|
Fail-Json $result "Not supported on this version of Windows"
|
|
|
|
$featureresult = Invoke-Expression "$removeCmdlet @UninstallParams"
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
catch {
|
|
|
|
Fail-Json $result $_.Exception.Message
|
|
|
|
Fail-Json $result $_.Exception.Message
|
|
|
|
|