Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpdateServicesComputerTargetGroup: (new resource) Computer Target Group Creation / Deletion #60

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added UpdateServicesComputerTargetGroup Resource including:
- Resource
- Unit Tests
- Example
- Update to ReadMe File

### Changed

- Updated inital offline package sync WSUS.cab.
- Updated ImitateUpdateServicesModule Module to meet style guidelines

### Fixed

- Changed RequiredModules / Pester module version to '4.10.1' - as existing tests are incompatible with pester 5.

## [1.2.0] - 2020-05-18

Expand Down
6 changes: 6 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ Windows Server 2008 R2 SP1, Windows Server 2012 and Windows Server 2012 R2.
* **CleanupLocalPublishedContentFiles**: Cleanup local published content files.
* **TimeOfDay** Time of day to start cleanup.

**UpdateServicesComputerTargetGroup** resource has following properties:

* **Ensure**: An enumerated value that describes if the Computer Target Group exists.
* **Name**: Name of the Computer Target Group.
* **Path**: Path to the Computer Target Group in the format 'Parent/Child'.

**UpdateServicesServer** resource has following properties:

* **Ensure**: An enumerated value that describes if WSUS is configured.
Expand Down
2 changes: 1 addition & 1 deletion RequiredModules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

InvokeBuild = 'latest'
PSScriptAnalyzer = 'latest'
Pester = 'latest'
Pester = '4.10.1'
Plaster = 'latest'
ModuleBuilder = '1.0.0'
ChangelogManagement = 'latest'
Expand Down
189 changes: 156 additions & 33 deletions Tests/Helpers/ImitateUpdateServicesModule.psm1
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
function Get-WsusServer {
function Get-WsusServer
{
$WsusServer = [pscustomobject] @{
Name = 'ServerName'
}
}

$ApprovalRule = [scriptblock]{
$ApprovalRule = [pscustomobject]@{
Name = 'ServerName'
Enabled = $true
$ApprovalRule = [pscustomobject] @{
Name = 'ServerName'
Enabled = $true
}

$ApprovalRule | Add-Member -MemberType ScriptMethod -Name GetUpdateClassifications -Value {
$UpdateClassification = [pscustomobject]@{
$UpdateClassification = [pscustomobject] @{
Name = 'Update Classification'
ID = [pscustomobject]@{
ID = [pscustomobject] @{
GUID = '00000000-0000-0000-0000-0000testguid'
}
}
return $UpdateClassification
}
return $UpdateClassification
}

$ApprovalRule | Add-Member -MemberType ScriptMethod -Name GetCategories -Value {
$Products = [pscustomobject]@{
$Products = [pscustomobject] @{
Title = 'Product'
}
$Products | Add-Member -MemberType ScriptMethod -Name Add -Value {}
return $Products
}

$ApprovalRule | Add-Member -MemberType ScriptMethod -Name GetComputerTargetGroups -Value {
$ComputerTargetGroups = [pscustomobject]@{
$ComputerTargetGroups = [pscustomobject] @{
Name = 'Computer Target Group'
}
$ComputerTargetGroups | Add-Member -MemberType ScriptMethod -Name Add -Value {}
Expand All @@ -46,34 +47,155 @@ function Get-WsusServer {
return $ApprovalRule
}

$ComputerTargetGroups = [scriptblock]{
$ComputerTargetGroups = @(
[pscustomobject] @{
Name = 'All Computers'
Id = [pscustomobject] @{
GUID = '4be27a8d-b969-4a8a-9cae-ec6b3a282b0b'
}
},
[pscustomobject] @{
Name = 'Servers'
Id = [pscustomobject] @{
GUID = '14adceba-ddf3-4299-9c1a-e4cf8bd56c47'
}
ParentTargetGroup = [pscustomobject] @{
Name = 'All Computers'
Id = [pscustomobject] @{
GUID = '4be27a8d-b969-4a8a-9cae-ec6b3a282b0b'
}
}
ChildTargetGroup = [pscustomobject] @{
Name = 'Web'
Id = [pscustomobject] @{
GUID = 'f4aa59c7-e6a0-4e6d-97b0-293d00a0dc60'
}
}
},
[pscustomobject] @{
Name = 'Web'
Id = [pscustomobject] @{
GUID = 'f4aa59c7-e6a0-4e6d-97b0-293d00a0dc60'
}
ParentTargetGroup = [pscustomobject] @{
Name = 'Servers'
Id = [pscustomobject] @{
GUID = '14adceba-ddf3-4299-9c1a-e4cf8bd56c47'
}
ParentTargetGroup = [pscustomobject] @{
Name = 'All Computers'
Id = [pscustomobject] @{
GUID = '4be27a8d-b969-4a8a-9cae-ec6b3a282b0b'
}
}
}
},
[pscustomobject] @{
Name = 'Workstations'
Id = [pscustomobject] @{
GUID = '31742fd8-df6f-4836-82b4-b2e52ee4ba1b'
}
ParentTargetGroup = [pscustomobject] @{
Name = 'All Computers'
Id = [pscustomobject] @{
GUID = '4be27a8d-b969-4a8a-9cae-ec6b3a282b0b'
}
}
},
[pscustomobject] @{
Name = 'Desktops'
Id = [pscustomobject] @{
GUID = '2b77a9ce-f320-41c7-bec7-9b22f67ae5b1'
}
ParentTargetGroup = [pscustomobject] @{
Name = 'Workstations'
Id = [pscustomobject] @{
GUID = '31742fd8-df6f-4836-82b4-b2e52ee4ba1b'
}
ParentTargetGroup = [pscustomobject] @{
Name = 'All Computers'
Id = [pscustomobject] @{
GUID = '4be27a8d-b969-4a8a-9cae-ec6b3a282b0b'
}
}
}
}
)

foreach ($ComputerTargetGroup in $ComputerTargetGroups)
{
Add-Member -InputObject $ComputerTargetGroup -MemberType ScriptMethod -Name Delete -Value {}

Add-Member -InputObject $ComputerTargetGroup -MemberType ScriptMethod -Name GetParentTargetGroup -Value {
return $this.ParentTargetGroup
}

if ($null -ne $ComputerTargetGroup.ParentTargetGroup)
{
Add-Member -InputObject $ComputerTargetGroup.ParentTargetGroup -MemberType ScriptMethod -Name GetParentTargetGroup -Value {
return $this.ParentTargetGroup
}
}

if ($null -ne $ComputerTargetGroup.ChildTargetGroup)
{
Add-Member -InputObject $ComputerTargetGroup -MemberType ScriptMethod -Name GetChildTargetGroups -Value {
return $this.ChildTargetGroup
}

Add-Member -InputOBject $ComputerTargetGroup.ChildTargetGroup -MemberType ScriptMethod -Name Delete -Value {}
}
}

return $ComputerTargetGroups
}

$WsusServer | Add-Member -MemberType ScriptMethod -Name CreateComputerTargetGroup -Value {
param
(
[Parameter(Mandatory = $true)]
[string]
$Name,

[Parameter(Mandatory = $true)]
[object]
$ComputerTargetGroup
)
{
Write-Output $Name
Write-Output $ComputerTargetGroup
}
}

$WsusServer | Add-Member -MemberType ScriptMethod -Name GetInstallApprovalRules -Value $ApprovalRule

$WsusServer | Add-Member -MemberType ScriptMethod -Name CreateInstallApprovalRule -Value $ApprovalRule

$WsusServer | Add-Member -MemberType ScriptMethod -Name GetUpdateClassification -Value {}
$WsusServer | Add-Member -MemberType ScriptMethod -Name GetComputerTargetGroups -Value {}

$WsusServer | Add-Member -MemberType ScriptMethod -Name GetComputerTargetGroups -Value $ComputerTargetGroups

$WsusServer | Add-Member -MemberType ScriptMethod -Name DeleteInstallApprovalRule -Value {}

$WsusServer | Add-Member -MemberType ScriptMethod -Name GetSubscription -Value {
$Subscription = [pscustomobject]@{
$Subscription = [pscustomobject] @{
SynchronizeAutomaticallyTimeOfDay = '04:00:00'
NumberOfSynchronizationsPerDay = 24
SynchronizeAutomatically = $true
}
$Subscription | Add-Member -MemberType ScriptMethod -Name StartSynchronization -Value {}
$Subscription | Add-Member -MemberType ScriptMethod -Name GetUpdateClassifications -Value {
$UpdateClassification = [pscustomobject]@{
Name = 'Update Classification'
ID = [pscustomobject]@{
GUID = '00000000-0000-0000-0000-0000testguid'
}
$UpdateClassification = [pscustomobject] @{
Name = 'Update Classification'
ID = [pscustomobject] @{
GUID = '00000000-0000-0000-0000-0000testguid'
}
}
return $UpdateClassification
}
$Subscription | Add-Member -MemberType ScriptMethod -Name GetUpdateCategories -Value {
$Categories = [pscustomobject]@{
$Categories = [pscustomobject] @{
Title = 'Category'
}
return $Categories
Expand All @@ -93,21 +215,21 @@ function Get-WsusServer {
AllUpdateLanguagesEnabled = $true
}
$Configuration | Add-Member -MemberType ScriptMethod -Name GetEnabledUpdateLanguages -Value {}
return $Configuration
return $Configuration
}

$WsusServer | Add-Member -MemberType ScriptMethod -Name GetUpdateClassifications -Value {
$UpdateClassification = [pscustomobject]@{
Name = 'Update Classification'
ID = [pscustomobject]@{
GUID = '00000000-0000-0000-0000-0000testguid'
}
$UpdateClassification = [pscustomobject] @{
Name = 'Update Classification'
ID = [pscustomobject]@{
GUID = '00000000-0000-0000-0000-0000testguid'
}
}
return $UpdateClassification
}

$WsusServer | Add-Member -MemberType ScriptMethod -Name GetUpdateCategories -Value {
$Categories = [pscustomobject]@{
$Categories = [pscustomobject] @{
Title = 'Category'
}
return $Categories
Expand All @@ -116,10 +238,11 @@ function Get-WsusServer {
return $WsusServer
}

function Get-WsusClassification {
$WsusClassification = [pscustomobject]@{
Classification = [pscustomobject]@{
ID = [pscustomobject]@{
function Get-WsusClassification
{
$WsusClassification = [pscustomobject] @{
Classification = [pscustomobject] @{
ID = [pscustomobject] @{
Guid = '00000000-0000-0000-0000-0000testguid'
}
}
Expand Down
Loading