Skip to content

Commit

Permalink
Merge pull request #53 from PowerShell/dev
Browse files Browse the repository at this point in the history
Release of version 2.6.0.0 of xWindowsUpdate
  • Loading branch information
kwirkykat authored Mar 8, 2017
2 parents ce18fe2 + b06aa32 commit 0d389dd
Show file tree
Hide file tree
Showing 19 changed files with 838 additions and 451 deletions.
4 changes: 4 additions & 0 deletions .MetaTestOptIn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"Common Tests - Validate Markdown Files",
"Common Tests - Validate Example Files"
]
30 changes: 30 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
codecov:
notify:
require_ci_to_pass: no
# dev should be the baseline for reporting
branch: dev

comment:
layout: "reach, diff"
behavior: default

coverage:
range: 50..80
round: down
precision: 0

status:
project:
default:
# Set the overall project code coverage requirement to 70%
target: 70
patch:
default:
# Set the pull request requirement to not regress overall coverage by more than 5%
# and let codecov.io set the goal for the code changed in the patch.
target: auto
threshold: 5

# MSFT_xMicrosoftUpdate is deprecated
ignore:
- "DscResources/MSFT_xMicrosoftUpdate/MSFT_xMicrosoftUpdate.psm1"
21 changes: 16 additions & 5 deletions DscResources/MSFT_xMicrosoftUpdate/MSFT_xMicrosoftUpdate.psm1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
function Write-DeprecatedMessage
{
Write-Warning -Message 'xMicrosoftUpdate is deprecated. Please use xWindows Update Agent'
}

function Get-TargetResource
{
[CmdletBinding()]
Expand All @@ -10,6 +15,8 @@ function Get-TargetResource
$Ensure
)

Write-DeprecatedMessage
Write-Verbose -Message "Getting Windows Update Agent services..."
#Get the registered update services
$UpdateServices = (New-Object -ComObject Microsoft.Update.ServiceManager).Services

Expand All @@ -18,12 +25,14 @@ function Get-TargetResource
}

#Check if the microsoft update service is registered
if($UpdateServices | where {$_.ServiceID -eq '7971f918-a847-4430-9279-4a52d1efe18d'})
if($UpdateServices | Where-Object {$_.ServiceID -eq '7971f918-a847-4430-9279-4a52d1efe18d'})
{
Write-Verbose -Message "Microsoft Update Present..."
$returnValue.Ensure = 'Present'
}
Else
{
Write-Verbose -Message "Microsoft Update Absent..."
$returnValue.Ensure = 'Absent'
}

Expand All @@ -42,7 +51,7 @@ function Set-TargetResource
$Ensure
)


Write-DeprecatedMessage
Switch($Ensure)
{
'Present'
Expand All @@ -51,7 +60,7 @@ function Set-TargetResource
{
Try
{
Write-Verbose "Enable the Microsoft Update setting"
Write-Verbose -Message "Enable the Microsoft Update setting"
(New-Object -ComObject Microsoft.Update.ServiceManager).AddService2('7971f918-a847-4430-9279-4a52d1efe18d',7,"")
Restart-Service wuauserv -ErrorAction SilentlyContinue
}
Expand All @@ -68,7 +77,7 @@ function Set-TargetResource
{
Try
{
Write-Verbose "Disable the Microsoft Update setting"
Write-Verbose -Message "Disable the Microsoft Update setting"
(New-Object -ComObject Microsoft.Update.ServiceManager).RemoveService('7971f918-a847-4430-9279-4a52d1efe18d')
}
Catch
Expand All @@ -81,9 +90,10 @@ function Set-TargetResource
}
}


function Test-TargetResource
{
# Verbose messages are written in Get.
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSDSCUseVerboseMessageInDSCResource", "")]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand All @@ -95,6 +105,7 @@ function Test-TargetResource
)

#Output the result of Get-TargetResource function.

$Get = Get-TargetResource -Ensure $Ensure

If($Ensure -eq $Get.Ensure)
Expand Down
4 changes: 4 additions & 0 deletions DscResources/MSFT_xMicrosoftUpdate/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Description

The resource is responsible for ensuring that Windows Update Agent
configuration for using Microsoft Update.
32 changes: 17 additions & 15 deletions DscResources/MSFT_xWindowsUpdate/MSFT_xWindowsUpdate.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Data LocalizedData
TestingEnsure = Testing whether hotfix is {0}.
InvalidPath=The specified Path ({0}) is not in a valid format. Valid formats are local paths, UNC, and HTTP.
InvalidBinaryType=The specified Path ({0}) does not appear to specify an MSU file and as such is not supported.
ValidateStandardArgumentsPathwasPath = Validate-StandardArguments, Path was {0}.
TestStandardArgumentsPathWasPath = Test-StandardArguments, Path was {0}.
NeedToDownloadFileFromSchemeDestinationWillBeDestName = Need to download file from {0}, destination will be {1}.
TheUriSchemeWasUriScheme = The uri scheme was {0}.
MountSharePath=Mount share to get media.
Expand Down Expand Up @@ -61,7 +61,7 @@ function Get-TargetResource
)
Set-StrictMode -Version latest

$uri, $kbId = Validate-StandardArguments -Path $Path -Id $Id
$uri, $kbId = Test-StandardArguments -Path $Path -Id $Id

Write-Verbose $($LocalizedData.GettingHotfixMessage -f ${Id})

Expand All @@ -88,7 +88,7 @@ Function Trace-Message
}
}

Function Throw-InvalidArgumentException
Function New-InvalidArgumentException
{
param(
[string] $Message,
Expand All @@ -104,6 +104,8 @@ Function Throw-InvalidArgumentException
# The Set-TargetResource cmdlet
function Set-TargetResource
{
# should be [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "DSCMachineStatus")], but it doesn't work
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "")]
[CmdletBinding()]
Param
(
Expand Down Expand Up @@ -133,13 +135,13 @@ function Set-TargetResource

Write-Verbose "$($LocalizedData.LogNotSpecified -f ${Log})"
}
$uri, $kbId = Validate-StandardArguments -Path $Path -Id $Id
$uri, $kbId = Test-StandardArguments -Path $Path -Id $Id



if($Ensure -eq 'Present')
{
$filePath = Validate-Path -uri $uri -Credential $Credential
$filePath = Test-WindowsUpdatePath -uri $uri -Credential $Credential
Write-Verbose "$($LocalizedData.StartKeyWord) $($LocalizedData.ActionInstallUsingwsusa)"

Start-Process -FilePath 'wusa.exe' -ArgumentList "`"$filepath`" /quiet /norestart /log:`"$Log`"" -Wait -NoNewWindow -ErrorAction SilentlyContinue
Expand Down Expand Up @@ -209,7 +211,7 @@ function Test-TargetResource
)
Set-StrictMode -Version latest
Write-Verbose "$($LocalizedData.TestingEnsure -f ${Ensure})"
$uri, $kbId = Validate-StandardArguments -Path $Path -Id $Id
$uri, $kbId = Test-StandardArguments -Path $Path -Id $Id

# This is not the correct way to test to see if an update is applicable to a machine
# but, WUSA does not currently expose a way to ask.
Expand All @@ -227,7 +229,7 @@ function Test-TargetResource

}

Function Validate-StandardArguments
Function Test-StandardArguments
{
param(
[string]
Expand All @@ -238,33 +240,33 @@ Function Validate-StandardArguments
)
Set-StrictMode -Version latest

Trace-Message ($LocalizedData.ValidateStandardArgumentsPathwasPath -f $Path)
Trace-Message ($LocalizedData.TestStandardArgumentsPathWasPath -f $Path)
$uri = $null
try
{
$uri = [uri] $Path
}
catch
{
Throw-InvalidArgumentException ($LocalizedData.InvalidPath -f $Path) 'Path'
New-InvalidArgumentException ($LocalizedData.InvalidPath -f $Path) 'Path'
}

if(-not @('file', 'http', 'https') -contains $uri.Scheme)
{
Trace-Message ($Localized.TheUriSchemeWasUriScheme -f $uri.Scheme)
Throw-InvalidArgumentException ($LocalizedData.InvalidPath -f $Path) 'Path'
New-InvalidArgumentException ($LocalizedData.InvalidPath -f $Path) 'Path'
}

$pathExt = [System.IO.Path]::GetExtension($Path)
Trace-Message ($LocalizedData.ThePathExtensionWasPathExt -f $pathExt)
if(-not @('.msu') -contains $pathExt.ToLower())
{
Throw-InvalidArgumentException ($LocalizedData.InvalidBinaryType -f $Path) 'Path'
New-InvalidArgumentException ($LocalizedData.InvalidBinaryType -f $Path) 'Path'
}

if(-not $Id)
{
Throw-InvalidArgumentException ($LocalizedData.NeedsMoreInfo -f $Path) 'Id'
New-InvalidArgumentException ($LocalizedData.NeedsMoreInfo -f $Path) 'Id'
}
else
{
Expand All @@ -276,7 +278,7 @@ Function Validate-StandardArguments
}
else
{
Throw-InvalidArgumentException ($LocalizedData.InvalidIdFormat -f $Path) 'Id'
New-InvalidArgumentException ($LocalizedData.InvalidIdFormat -f $Path) 'Id'
}
}
elseif($id -match '[0-9]+')
Expand All @@ -287,7 +289,7 @@ Function Validate-StandardArguments
}
else
{
Throw-InvalidArgumentException ($LocalizedData.InvalidIdFormat -f $Path) 'Id'
New-InvalidArgumentException ($LocalizedData.InvalidIdFormat -f $Path) 'Id'
}
}
}
Expand All @@ -296,7 +298,7 @@ Function Validate-StandardArguments
}


function Validate-Path
function Test-WindowsUpdatePath
{
<#
.SYNOPSIS
Expand Down
4 changes: 4 additions & 0 deletions DscResources/MSFT_xWindowsUpdate/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Description

The resource is responsible for ensuring that a MSU
(Standalone Windows Update) is installed.
44 changes: 33 additions & 11 deletions DscResources/MSFT_xWindowsUpdateAgent/MSFT_xWindowsUpdateAgent.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ function Get-WuaWrapper {
Write-Warning 'Got an error a request timed out (http status 408 or equivalent) when WU was communicating with the update service. Handling the error.'
return $ExceptionReturnValue
}
# 0x8024402f -2145107921 WU_E_PT_ECP_SUCCEEDED_WITH_ERRORS External cab file processing completed with some errors. wuerror.h
-2145107921 {
# No retry needed
Write-Warning 'Got an error that CAB processing completed with some errors.'
return $ExceptionReturnValue
}
default {
throw
}
Expand Down Expand Up @@ -203,21 +209,35 @@ function Invoke-WuaInstallUpdates
function Set-WuaAuNotificationLevel
{
param(
[ValidateSet('Not Configured','Disabled','Notify before download','Notify before installation','Scheduled installation')]
[ValidateSet('Not Configured','Disabled','Notify before download','Notify before installation','Scheduled installation','ScheduledInstallation')]
[string]
$notificationLevel
)
$intNotificationLevel = Get-WuaAuNotificationLevelInt -notificationLevel $notificationLevel

$settings = Get-WuaAuSettings
$settings.NotificationLevel = $intNotificationLevel
$settings.Save()
}

function Get-WuaAuNotificationLevelInt {
param(
[ValidateSet('Not Configured','Disabled','Notify before download','Notify before installation','Scheduled installation','ScheduledInstallation')]
[string]
$notificationLevel
)
$intNotificationLevel =0
switch ($notificationLevel) {
'Not Configured' { $intNotificationLevel = 0 }
'Disabled' { $intNotificationLevel = 1 }
'Notify before download' { $intNotificationLevel = 2 }
'Notify before installation' { $intNotificationLevel = 3 }
'Scheduled installation' { $intNotificationLevel = 4 }

switch -Regex ($notificationLevel) {
'^Not\s*Configured$' { $intNotificationLevel = 0 }
'^Disabled$' { $intNotificationLevel = 1 }
'^Notify\s*before\s*download$' { $intNotificationLevel = 2 }
'^Notify\s*before\s*installation$' { $intNotificationLevel = 3 }
'^Scheduled\s*installation$' { $intNotificationLevel = 4 }
default { throw 'Invalid notification level'}
}
$settings = Get-WuaAuSettings
$settings.Save()

return $intNotificationLevel
}

function Get-WuaSystemInfo
Expand Down Expand Up @@ -291,12 +311,12 @@ function Test-SearchResult
$SearchResult
)

if(!(@($SearchResult | get-member |select -ExpandProperty Name) -contains 'Updates'))
if(!(@($SearchResult | get-member |Select-Object -ExpandProperty Name) -contains 'Updates'))
{
Write-Verbose 'Did not find updates on SearchResult'
return $false
}
if(!(@(Get-Member -InputObject $SearchResult.Updates |select -ExpandProperty Name) -contains 'Count'))
if(!(@(Get-Member -InputObject $SearchResult.Updates |Select-Object -ExpandProperty Name) -contains 'Count'))
{
Write-Verbose 'Did not find count on updates on SearchResult'
return $false
Expand Down Expand Up @@ -388,6 +408,8 @@ function Get-TargetResource

function Set-TargetResource
{
# should be [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "DSCMachineStatus")], but it doesn't work
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "")]
[CmdletBinding(SupportsShouldProcess=$true)]
param
(
Expand Down
4 changes: 4 additions & 0 deletions DscResources/MSFT_xWindowsUpdateAgent/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Description

The resource is responsible for configuring
the Windows Update Agent on the node.
18 changes: 18 additions & 0 deletions Examples/Resources/xHotfix/1-Sample_xWindowsUpdateFromPath.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<#
.EXAMPLE
This sample looks at installing a particular windows update. However, the path and ID properties can be changed
as per the hotfix that you want to install
#>

Configuration Example
{
Import-DscResource -ModuleName xWindowsUpdate

xHotfix m1
{
Path = "c:\WindowsBlue-KB2937982-x64.msu"
Id = "KB2937982"
Ensure="Present"
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<#
# This sample looks at installing a particular windows update. However, the URI and ID properties can be changed
# as per the hotfix that you want to install
#>
.EXAMPLE
This sample looks at installing a particular windows update. However, the URI and ID properties can be changed
as per the hotfix that you want to install
#>

Configuration DownloadHotfixFromURI
Configuration Example
{
Import-DscResource -module xWindowsUpdate

xHotfix m1
{
Path = 'http://hotfixv4.microsoft.com/Microsoft%20Office%20SharePoint%20Server%202007/sp2/officekb956056fullfilex64glb/12.0000.6327.5000/free/358323_intl_x64_zip.exe'
Expand All @@ -14,6 +16,3 @@ Configuration DownloadHotfixFromURI
}

}
DownloadHotfixFromURI

Start-DscConfiguration -path ./DownloadHotfixFromURI -wait -Verbose
Loading

0 comments on commit 0d389dd

Please sign in to comment.