Skip to content

Commit 645e4b4

Browse files
authored
Merge pull request #99 from gesbeckj/dev
xComputer: Added Description
2 parents e98a911 + af4395f commit 645e4b4

5 files changed

Lines changed: 476 additions & 132 deletions

File tree

DSCResources/MSFT_xComputer/MSFT_xComputer.psm1

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ function Get-TargetResource
3333

3434
[Parameter()]
3535
[System.String]
36-
$WorkGroupName
36+
$WorkGroupName,
37+
38+
[Parameter()]
39+
[System.String]
40+
$Description
3741
)
3842

3943
Write-Verbose -Message "Getting computer state for '$($Name)'."
@@ -64,6 +68,7 @@ function Get-TargetResource
6468
Credential = [ciminstance]$convertToCimCredential
6569
UnjoinCredential = [ciminstance]$convertToCimUnjoinCredential
6670
WorkGroupName = (Get-CimInstance -Class 'Win32_ComputerSystem').Workgroup
71+
Description = (Get-CimInstance -Class 'Win32_OperatingSystem').Description
6772
}
6873

6974
$returnValue
@@ -98,7 +103,11 @@ function Set-TargetResource
98103

99104
[Parameter()]
100105
[System.String]
101-
$WorkGroupName
106+
$WorkGroupName,
107+
108+
[Parameter()]
109+
[System.String]
110+
$Description
102111
)
103112

104113
Assert-DomainOrWorkGroup -DomainName $DomainName -WorkGroupName $WorkGroupName
@@ -108,6 +117,14 @@ function Set-TargetResource
108117
$Name = $env:COMPUTERNAME
109118
}
110119

120+
if ($PSBoundParameters.ContainsKey('Description'))
121+
{
122+
Write-Verbose -Message "Setting computer description to '$($Description)'."
123+
$win32OperatingSystemCimInstance = Get-CimInstance -ClassName Win32_OperatingSystem
124+
$win32OperatingSystemCimInstance.Description = $Description
125+
Set-CimInstance -InputObject $win32OperatingSystemCimInstance
126+
}
127+
111128
if ($Credential)
112129
{
113130
if ($DomainName)
@@ -274,7 +291,11 @@ function Test-TargetResource
274291

275292
[Parameter()]
276293
[System.String]
277-
$WorkGroupName
294+
$WorkGroupName,
295+
296+
[Parameter()]
297+
[System.String]
298+
$Description
278299
)
279300

280301
Write-Verbose -Message 'Validate desired Name is a valid name'
@@ -285,6 +306,15 @@ function Test-TargetResource
285306
return $false
286307
}
287308

309+
if ($PSBoundParameters.ContainsKey('Description'))
310+
{
311+
Write-Verbose -Message 'Checking if description is corerect'
312+
if ($Description -ne (Get-CimInstance -Class 'Win32_OperatingSystem').Description)
313+
{
314+
return $false
315+
}
316+
}
317+
288318
Assert-DomainOrWorkGroup -DomainName $DomainName -WorkGroupName $WorkGroupName
289319

290320
if ($DomainName)
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[ClassVersion("1.0.1.0"), FriendlyName("xComputer")]
22
class MSFT_xComputer : OMI_BaseResource
33
{
4-
[key] string Name;
5-
[write] string DomainName;
6-
[write] string JoinOU;
7-
[read] string CurrentOU;
8-
[write,EmbeddedInstance("MSFT_Credential")] String Credential;
9-
[write,EmbeddedInstance("MSFT_Credential")] String UnjoinCredential;
10-
[write] string WorkGroupName;
4+
[Key, Description("The desired computer name")] String Name;
5+
[Write, Description("The name of the domain to join")] String DomainName;
6+
[Write, Description("The distinguished name of the organizational unit that the computer account will be created in")] String JoinOU;
7+
[Read, Description("A read-only property that specifies the organizational unit that the computer account is currently in")] String CurrentOU;
8+
[Write, EmbeddedInstance("MSFT_Credential"), Description("Credential to be used to join or leave domain")] String Credential;
9+
[Write, EmbeddedInstance("MSFT_Credential"), Description("Credential to be used to join or leave domain")] String UnjoinCredential;
10+
[Write, Description("The name of the workgroup")] String WorkGroupName;
11+
[Write, Description("The value assigned here will be set as the local computer description")] String Description;
1112
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<#
2+
.EXAMPLE
3+
This example will set the computer description
4+
#>
5+
Configuration Example
6+
{
7+
param
8+
(
9+
[Parameter()]
10+
[System.String[]]
11+
$NodeName = 'localhost'
12+
)
13+
14+
Import-DscResource -Module xComputerManagement
15+
16+
Node $NodeName
17+
{
18+
xComputer NewDescription
19+
{
20+
Name = 'localhost'
21+
Description = 'This is my computer.'
22+
}
23+
}
24+
}

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ xComputer resource has following properties:
5353
* Credential: Credential to be used to join or leave domain
5454
* CurrentOU: A read-only property that specifies the organizational unit that
5555
the computer account is currently in
56+
* Description: The value assigned here will be set as the local computer description
5657

5758
### xComputer Examples
5859

@@ -61,6 +62,7 @@ xComputer resource has following properties:
6162
* [Set the Name while staying on the Domain](/Examples/xComputer/3-RenameComputerInDomain.ps1)
6263
* [Set the Name while staying on the Workgroup](/Examples/xComputer/4-RenameComputerInWorkgroup.ps1)
6364
* [Switch from a Domain to a Workgroup](/Examples/xComputer/5-UnjoinDomainAndJoinWorkgroup.ps1)
65+
* [Set a Description for the Workstation](/Examples/xComputer/6-SetComputerDescriptionInWorkgroup.ps1)
6466

6567
## xOfflineDomainJoin
6668

@@ -202,6 +204,9 @@ xVirtualMemory has the following properties:
202204

203205
### Unreleased
204206

207+
* xComputer: Added parameter to set the local computer description along with documentation
208+
and unit tests for this change.
209+
205210
### 2.1.0.0
206211

207212
* xComputer: Changed comparison that validates if we are in the correct AD

0 commit comments

Comments
 (0)