mirror of
https://github.com/PowerShell/PSDscResources
synced 2026-06-21 13:45:29 +00:00
Merge pull request #166 from PowerShell/dev
Release of version 2.12.0.0 of PSDscResources
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
[
|
||||
"Common Tests - Validate Module Files",
|
||||
"Common Tests - Validate Script Files",
|
||||
"Common Tests - Relative Path Length"
|
||||
]
|
||||
@@ -36,7 +36,7 @@
|
||||
Change to [x] for each task in the task list that applies to your PR.
|
||||
For those task that don't apply to you PR, leave those as is.
|
||||
-->
|
||||
- [ ] Added an entry under the Unreleased section of the change log in the README.md.
|
||||
- [ ] Added an entry under the Unreleased section in the CHANGELOG.md.
|
||||
Entry should say what was changed, and how that affects users (if applicable).
|
||||
- [ ] Resource documentation added/updated in README.md.
|
||||
- [ ] Resource parameter descriptions added/updated in README.md, schema.mof
|
||||
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
# Change log for PsDscResources
|
||||
|
||||
## Unreleased
|
||||
|
||||
## 2.12.0.0
|
||||
|
||||
* Ports style fixes that were recently made in xPSDesiredStateConfiguration
|
||||
on test related files.
|
||||
* Ports most of the style upgrades from xPSDesiredStateConfiguration that have
|
||||
been made in files in the DscResources folder.
|
||||
* Ports fixes for the following issues:
|
||||
[Issue #505](https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/505)
|
||||
[Issue #590](https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/590)
|
||||
Changes to test helper Enter-DscResourceTestEnvironment so that it only
|
||||
updates DSCResource.Tests when it is longer than 120 minutes since
|
||||
it was last pulled. This is to improve performance of test execution
|
||||
and reduce the likelihood of connectivity issues caused by inability to
|
||||
pull DSCResource.Tests.
|
||||
* Fixes issue where MsiPackage Integration tests fail if the test HttpListener
|
||||
fails to start. Moves the test HttpListener objects to dynamically assigned,
|
||||
higher numbered ports to avoid conflicts with other services, and also checks
|
||||
to ensure that the ports are available before using them. Adds checks to
|
||||
ensure that no outstanding HTTP server jobs are running before attempting to
|
||||
setup a new one. Also adds additional instrumentation to make it easier to
|
||||
troubleshoot issues with the test HttpListener objects in the future.
|
||||
Specifically fixes
|
||||
[Issue #142](https://github.com/PowerShell/PSDscResources/issues/142)
|
||||
* Improved speed of Test-IsNanoServer function
|
||||
* Remove the Byte Order Mark (BOM) from all affected files
|
||||
* Opt-in to 'Validate Module Files' and 'Validate Script Files' common meta-tests
|
||||
* Opt-in to 'Common Tests - Relative Path Length' common meta-test
|
||||
* Fix README markdownlint validation failures
|
||||
* Move change log from README.md to CHANGELOG.md
|
||||
|
||||
## 2.11.0.0
|
||||
|
||||
* Fix Custom DSC Resource Kit PSSA Rule Failures
|
||||
|
||||
## 2.10.0.0
|
||||
|
||||
* Fixed CompanyName typo - Fixes [Issue #100](https://github.com/PowerShell/PSDscResources/issues/100)
|
||||
* Update LICENSE file to match the Microsoft Open Source Team
|
||||
standard - Fixes [Issue #120](https://github.com/PowerShell/PSDscResources/issues/120).
|
||||
* Update `CommonResourceHelper` unit tests to meet Pester 4.0.0
|
||||
standards ([issue #129](https://github.com/PowerShell/PSDscResources/issues/129)).
|
||||
* Update `ResourceHelper` unit tests to meet Pester 4.0.0
|
||||
standards ([issue #129](https://github.com/PowerShell/PSDscResources/issues/129)).
|
||||
* Ported fixes from [xPSDesiredStateConfiguration](https://github.com/PowerShell/xPSDesiredStateConfiguration):
|
||||
* xArchive
|
||||
* Fix end-to-end tests.
|
||||
* Update integration tests to meet Pester 4.0.0 standards.
|
||||
* Update end-to-end tests to meet Pester 4.0.0 standards.
|
||||
* Update unit and integration tests to meet Pester 4.0.0 standards.
|
||||
* Wrapped all path and identifier strings in verbose messages with
|
||||
quotes to make it easier to identify the limit of the string when
|
||||
debugging.
|
||||
* Refactored date/time checksum code to improve testability and ensure
|
||||
tests can run on machines with localized datetime formats that are not
|
||||
US.
|
||||
* Fix 'Get-ArchiveEntryLastWriteTime' to return `[datetime]`.
|
||||
* Improved verbose logging to make debugging path issues easier.
|
||||
* Added .gitattributes file to ensure CRLF settings are configured correctly
|
||||
for the repository.
|
||||
* Updated '.vscode\settings.json' to refer to AnalyzerSettings.psd1 so that
|
||||
custom syntax problems are highlighted in Visual Studio Code.
|
||||
* Fixed style guideline violations in `CommonResourceHelper.psm1`.
|
||||
* Updated 'appveyor.yml' to meet more recent standards.
|
||||
* Removed OS image version from 'appveyor.yml' to use default image
|
||||
([Issue #127](https://github.com/PowerShell/PSDscResources/issues/127)).
|
||||
* Removed code to install WMF5.1 from 'appveyor.yml' because it is already
|
||||
installed in AppVeyor images ([Issue #128](https://github.com/PowerShell/PSDscResources/issues/128)).
|
||||
* Removed .vscode from .gitignore so that Visual Studio code environment
|
||||
settings can be committed.
|
||||
* Environment
|
||||
* Update tests to meet Pester 4.0.0 standards ([issue #129](https://github.com/PowerShell/PSDscResources/issues/129)).
|
||||
* Group
|
||||
* Update tests to meet Pester 4.0.0 standards ([issue #129](https://github.com/PowerShell/PSDscResources/issues/129)).
|
||||
* Fix unit tests to run on Nano Server.
|
||||
* Refactored unit tests to enclude Context fixtures and change functions
|
||||
to Describe fixtures.
|
||||
* GroupSet
|
||||
* Update tests to meet Pester 4.0.0 standards ([issue #129](https://github.com/PowerShell/PSDscResources/issues/129)).
|
||||
|
||||
## 2.9.0.0
|
||||
|
||||
* Added Description and Parameter description for composite resources
|
||||
|
||||
## 2.8.0.0
|
||||
|
||||
* Archive
|
||||
* Added handling of directory archive entries that end with a foward slash
|
||||
* Removed formatting of LastWriteTime timestamp and updated comparison of timestamps to handle dates in different formats
|
||||
* WindowsProcess
|
||||
* Fix unreliable tests
|
||||
* Updated Test-IsNanoServer to return false if Get-ComputerInfo fails
|
||||
* Registry
|
||||
* Fixed bug when using the full registry drive name (e.g. HKEY\_LOCAL\_MACHINE) and using a key name that includes a drive with forward slashes (e.g. C:/)
|
||||
|
||||
## 2.7.0.0
|
||||
|
||||
* MsiPackage
|
||||
* Parse installation date from registry using invariant culture.
|
||||
* Fix a bug in unit test failing, when regional setting differs from English-US.
|
||||
|
||||
## 2.6.0.0
|
||||
|
||||
* Archive
|
||||
* Fixed a minor bug in the unit tests where sometimes the incorrect DateTime format was used.
|
||||
* Added MsiPackage
|
||||
|
||||
## 2.5.0.0
|
||||
|
||||
* Enable codecov.io code coverage reporting
|
||||
* Group
|
||||
* Added support for domain based group members on Nano server.
|
||||
* Added the Archive resource
|
||||
* Update Test-IsNanoServer cmdlet to properly test for a Nano server rather than the core version of PowerShell
|
||||
* Registry
|
||||
* Fixed bug where an error was thrown when running Get-DscConfiguration if the registry already existed
|
||||
|
||||
## 2.4.0.0
|
||||
|
||||
* Cleaned User
|
||||
* Updated User to have non-dependent unit tests.
|
||||
* Ported fixes from [xPSDesiredStateConfiguration](https://github.com/PowerShell/xPSDesiredStateConfiguration):
|
||||
* WindowsProcess: Minor updates to integration tests
|
||||
* Registry: Fixed support for forward slashes in registry key names
|
||||
* Group:
|
||||
* Group members in the "NT Authority", "BuiltIn" and "NT Service" scopes should now be resolved without an error. If you were seeing the errors "Exception calling ".ctor" with "4" argument(s): "Server names cannot contain a space character."" or "Exception calling ".ctor" with "2" argument(s): "Server names cannot contain a space character."", this fix should resolve those errors. If you are still seeing one of the errors, there is probably another local scope we need to add. Please let us know.
|
||||
* The resource will no longer attempt to resolve group members if Members, MembersToInclude, and MembersToExclude are not specified.
|
||||
* Added Environment
|
||||
|
||||
## 2.3.0.0
|
||||
|
||||
* Updated manifest to include both WindowsOptionalFeature and WindowsOptionalFeatureSet instead of just WindowsOptionalFeature twice
|
||||
|
||||
## 2.2.0.0
|
||||
|
||||
* WindowsFeature:
|
||||
* Added Catch to ignore RuntimeException when importing ServerManager module. This solves the issue described [here](https://social.technet.microsoft.com/Forums/en-US/9fc314e1-27bf-4f03-ab78-5e0f7a662b8f/importmodule-servermanager-some-or-all-identity-references-could-not-be-translated?forum=winserverpowershell).
|
||||
* Updated unit tests.
|
||||
* Added WindowsProcess
|
||||
* CommonTestHelper:
|
||||
* Added Get-AppVeyorAdministratorCredential.
|
||||
* Added Set-StrictMode -'Latest' and $errorActionPreference -'Stop'.
|
||||
* Service:
|
||||
* Updated resource module, unit tests, integration tests, and examples to reflect the changes made in xPSDesiredStateConfiguration.
|
||||
* Group:
|
||||
* Updated resource module, examples, and integration tests to reflect the changes made in xPSDesiredStateConfiguration.
|
||||
* Added Script.
|
||||
* Added GroupSet, ServiceSet, WindowsFeatureSet, WindowsOptionalFeatureSet, and ProcessSet.
|
||||
* Added Set-StrictMode -'Latest' and $errorActionPreference -'Stop' to Group, Service, User, WindowsFeature, WindowsOptionalFeature, WindowsPackageCab.
|
||||
* Fixed bug in WindowsFeature in which is was checking the 'Count' property of an object that was not always an array.
|
||||
* Cleaned Group and Service resources and tests.
|
||||
* Added Registry.
|
||||
|
||||
## 2.1.0.0
|
||||
|
||||
* Added WindowsFeature.
|
||||
|
||||
## 2.0.0.0
|
||||
|
||||
* Initial release of PSDscResources.
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Tests if the current machine is a Nano server.
|
||||
#>
|
||||
@@ -8,21 +8,24 @@ function Test-IsNanoServer
|
||||
[CmdletBinding()]
|
||||
param ()
|
||||
|
||||
$isNanoServer = $false
|
||||
$serverLevelsRegKey = 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Server\ServerLevels'
|
||||
|
||||
if (Test-CommandExists -Name 'Get-ComputerInfo')
|
||||
if (Test-Path -Path $serverLevelsRegKey)
|
||||
{
|
||||
$computerInfo = Get-ComputerInfo -ErrorAction 'SilentlyContinue'
|
||||
$serverLevels = Get-ItemProperty -Path $serverLevelsRegKey
|
||||
|
||||
if ($null -ne $computerInfo)
|
||||
if ($serverLevels.NanoServer -eq 1)
|
||||
{
|
||||
$computerIsServer = 'Server' -ieq $computerInfo.OsProductType
|
||||
|
||||
if ($computerIsServer)
|
||||
{
|
||||
$isNanoServer = 'NanoServer' -ieq $computerInfo.OsServerLevel
|
||||
}
|
||||
$isNanoServer = $true
|
||||
}
|
||||
else
|
||||
{
|
||||
$isNanoServer = $false
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$isNanoServer = $false
|
||||
}
|
||||
|
||||
return $isNanoServer
|
||||
@@ -43,7 +46,8 @@ function Test-CommandExists
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.String] $Name
|
||||
[System.String]
|
||||
$Name
|
||||
)
|
||||
|
||||
$command = Get-Command -Name $Name -ErrorAction 'SilentlyContinue'
|
||||
@@ -52,13 +56,13 @@ function Test-CommandExists
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates and throws an invalid argument exception
|
||||
Creates and throws an invalid argument exception.
|
||||
|
||||
.PARAMETER Message
|
||||
The message explaining why this error is being thrown
|
||||
The message explaining why this error is being thrown.
|
||||
|
||||
.PARAMETER ArgumentName
|
||||
The name of the invalid argument that is causing this error to be thrown
|
||||
The name of the invalid argument that is causing this error to be thrown.
|
||||
#>
|
||||
function New-InvalidArgumentException
|
||||
{
|
||||
@@ -77,9 +81,9 @@ function New-InvalidArgumentException
|
||||
)
|
||||
|
||||
$argumentException = New-Object -TypeName 'ArgumentException' `
|
||||
-ArgumentList @($Message, $ArgumentName)
|
||||
-ArgumentList @($Message, $ArgumentName)
|
||||
$newObjectParams = @{
|
||||
TypeName = 'System.Management.Automation.ErrorRecord'
|
||||
TypeName = 'System.Management.Automation.ErrorRecord'
|
||||
ArgumentList = @($argumentException, $ArgumentName, 'InvalidArgument', $null)
|
||||
}
|
||||
$errorRecord = New-Object @newObjectParams
|
||||
@@ -89,13 +93,14 @@ function New-InvalidArgumentException
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates and throws an invalid operation exception
|
||||
Creates and throws an invalid operation exception.
|
||||
|
||||
.PARAMETER Message
|
||||
The message explaining why this error is being thrown
|
||||
The message explaining why this error is being thrown.
|
||||
|
||||
.PARAMETER ErrorRecord
|
||||
The error record containing the exception that is causing this terminating error
|
||||
The error record containing the exception that is causing this terminating
|
||||
error.
|
||||
#>
|
||||
function New-InvalidOperationException
|
||||
{
|
||||
@@ -120,18 +125,17 @@ function New-InvalidOperationException
|
||||
elseif ($null -eq $ErrorRecord)
|
||||
{
|
||||
$invalidOperationException = New-Object -TypeName 'InvalidOperationException' `
|
||||
-ArgumentList @($Message)
|
||||
-ArgumentList @( $Message )
|
||||
}
|
||||
else
|
||||
{
|
||||
$invalidOperationException = New-Object -TypeName 'InvalidOperationException' `
|
||||
-ArgumentList @($Message, $ErrorRecord.Exception)
|
||||
-ArgumentList @( $Message, $ErrorRecord.Exception )
|
||||
}
|
||||
|
||||
$newObjectParams = @{
|
||||
TypeName = 'System.Management.Automation.ErrorRecord'
|
||||
ArgumentList = @( $invalidOperationException.ToString(), 'MachineStateIncorrect',
|
||||
'InvalidOperation', $null )
|
||||
TypeName = 'System.Management.Automation.ErrorRecord'
|
||||
ArgumentList = @( $invalidOperationException.ToString(), 'MachineStateIncorrect', 'InvalidOperation', $null )
|
||||
}
|
||||
|
||||
$errorRecordToThrow = New-Object @newObjectParams
|
||||
@@ -144,7 +148,8 @@ function New-InvalidOperationException
|
||||
Falls back to en-US strings if the machine's culture is not supported.
|
||||
|
||||
.PARAMETER ResourceName
|
||||
The name of the resource as it appears before '.strings.psd1' of the localized string file.
|
||||
The name of the resource as it appears before '.strings.psd1' of the localized
|
||||
string file.
|
||||
For example:
|
||||
For WindowsOptionalFeature: MSFT_WindowsOptionalFeature
|
||||
For Service: MSFT_ServiceResource
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@{
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'GroupSet.schema.psm1'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
$errorActionPreference = 'Stop'
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
# Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock
|
||||
@@ -19,7 +19,7 @@ Import-Module -Name $script:resourceSetHelperFilePath
|
||||
|
||||
.PARAMETER Ensure
|
||||
Specifies whether or not the set of groups should exist.
|
||||
|
||||
|
||||
Set this property to Present to create or modify a set of groups.
|
||||
Set this property to Absent to remove a set of groups.
|
||||
|
||||
@@ -37,25 +37,25 @@ Configuration GroupSet
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true, HelpMessage="The names of the groups for which you want to ensure a specific state.")]
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$GroupName,
|
||||
|
||||
[Parameter( HelpMessage="Indicates whether the groups exist. Set this property to Absent to ensure that the groups do not exist. Setting it to Present (the default value) ensures that the groups exist.")]
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure,
|
||||
|
||||
[Parameter( HelpMessage="Use this property to add members to the existing membership of the group. The value of this property is an array of strings of the form Domain\UserName. If you set this property in a configuration, do not use the Members property. Doing so will generate an error.")]
|
||||
[String[]]
|
||||
[Parameter()]
|
||||
[System.String[]]
|
||||
$MembersToInclude,
|
||||
|
||||
[Parameter( HelpMessage="Use this property to remove members from the existing membership of the groups. The value of this property is an array of strings of the form Domain\UserName. If you set this property in a configuration, do not use the Members property. Doing so will generate an error.")]
|
||||
[String[]]
|
||||
[Parameter()]
|
||||
[System.String[]]
|
||||
$MembersToExclude,
|
||||
|
||||
[Parameter( HelpMessage="The credentials required to access remote resources. Note: This account must have the appropriate Active Directory permissions to add all non-local accounts to the group; otherwise, an error will occur.")]
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.Management.Automation.PSCredential]
|
||||
[System.Management.Automation.Credential()]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
$errorActionPreference = 'Stop'
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
<#
|
||||
@@ -81,27 +81,27 @@ if (-not (Test-IsNanoServer))
|
||||
#>
|
||||
function Get-TargetResource
|
||||
{
|
||||
[OutputType([Hashtable])]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Destination,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Validate = $false,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('SHA-1', 'SHA-256', 'SHA-512', 'CreatedDate', 'ModifiedDate')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Checksum = 'ModifiedDate',
|
||||
|
||||
[Parameter()]
|
||||
@@ -257,26 +257,26 @@ function Set-TargetResource
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Destination,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Validate = $false,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('SHA-1', 'SHA-256', 'SHA-512', 'CreatedDate', 'ModifiedDate')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Checksum = 'ModifiedDate',
|
||||
|
||||
[Parameter()]
|
||||
@@ -285,7 +285,7 @@ function Set-TargetResource
|
||||
$Credential,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Force = $false
|
||||
)
|
||||
|
||||
@@ -422,32 +422,32 @@ function Set-TargetResource
|
||||
#>
|
||||
function Test-TargetResource
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Destination,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Validate = $false,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('SHA-1', 'SHA-256', 'SHA-512', 'CreatedDate', 'ModifiedDate')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Checksum = 'ModifiedDate',
|
||||
|
||||
[Parameter()]
|
||||
@@ -456,7 +456,7 @@ function Test-TargetResource
|
||||
$Credential,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Force = $false
|
||||
)
|
||||
|
||||
@@ -491,11 +491,11 @@ function Test-TargetResource
|
||||
#>
|
||||
function New-Guid
|
||||
{
|
||||
[OutputType([Guid])]
|
||||
[OutputType([System.Guid])]
|
||||
[CmdletBinding()]
|
||||
param ()
|
||||
|
||||
return [Guid]::NewGuid()
|
||||
return [System.Guid]::NewGuid()
|
||||
}
|
||||
|
||||
<#
|
||||
@@ -515,7 +515,7 @@ function Invoke-NewPSDrive
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[Hashtable]
|
||||
[System.Collections.Hashtable]
|
||||
$Parameters
|
||||
)
|
||||
|
||||
@@ -541,7 +541,7 @@ function Mount-PSDriveWithCredential
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
@@ -618,7 +618,7 @@ function Assert-PathExistsAsLeaf
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path
|
||||
)
|
||||
|
||||
@@ -646,7 +646,7 @@ function Assert-DestinationDoesNotExistAsFile
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Destination
|
||||
)
|
||||
|
||||
@@ -678,7 +678,7 @@ function Open-Archive
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path
|
||||
)
|
||||
|
||||
@@ -753,7 +753,7 @@ function Get-ArchiveEntries
|
||||
#>
|
||||
function Get-ArchiveEntryFullName
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
@@ -821,13 +821,13 @@ function Close-Stream
|
||||
#>
|
||||
function Test-ChecksumIsSha
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Checksum
|
||||
)
|
||||
|
||||
@@ -845,13 +845,13 @@ function Test-ChecksumIsSha
|
||||
#>
|
||||
function ConvertTo-PowerShellHashAlgorithmName
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$DscHashAlgorithmName
|
||||
)
|
||||
|
||||
@@ -874,13 +874,13 @@ function ConvertTo-PowerShellHashAlgorithmName
|
||||
#>
|
||||
function Test-FileHashMatchesArchiveEntryHash
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$FilePath,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
@@ -890,7 +890,7 @@ function Test-FileHashMatchesArchiveEntryHash
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$HashAlgorithmName
|
||||
)
|
||||
|
||||
@@ -1115,7 +1115,7 @@ function Get-ArchiveEntryLastWriteTime
|
||||
#>
|
||||
function Test-FileMatchesArchiveEntryByChecksum
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
@@ -1131,7 +1131,7 @@ function Test-FileMatchesArchiveEntryByChecksum
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Checksum
|
||||
)
|
||||
|
||||
@@ -1187,13 +1187,13 @@ function Test-FileMatchesArchiveEntryByChecksum
|
||||
#>
|
||||
function Test-ArchiveEntryIsDirectory
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ArchiveEntryName
|
||||
)
|
||||
|
||||
@@ -1219,23 +1219,23 @@ function Test-ArchiveEntryIsDirectory
|
||||
#>
|
||||
function Test-ArchiveExistsAtDestination
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ArchiveSourcePath,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Destination,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('SHA-1', 'SHA-256', 'SHA-512', 'CreatedDate', 'ModifiedDate')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Checksum
|
||||
)
|
||||
|
||||
@@ -1370,7 +1370,7 @@ function Copy-ArchiveEntryToDestination
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$DestinationPath
|
||||
)
|
||||
|
||||
@@ -1449,21 +1449,21 @@ function Expand-ArchiveToDestination
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ArchiveSourcePath,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Destination,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('SHA-1', 'SHA-256', 'SHA-512', 'CreatedDate', 'ModifiedDate')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Checksum,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Force = $false
|
||||
)
|
||||
|
||||
@@ -1564,12 +1564,12 @@ function Remove-DirectoryFromDestination
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$Directory,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Destination
|
||||
)
|
||||
|
||||
@@ -1623,17 +1623,17 @@ function Remove-ArchiveFromDestination
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ArchiveSourcePath,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Destination,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('SHA-1', 'SHA-256', 'SHA-512', 'CreatedDate', 'ModifiedDate')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Checksum
|
||||
)
|
||||
|
||||
@@ -1699,7 +1699,7 @@ function Remove-ArchiveFromDestination
|
||||
{
|
||||
$parentDirectory = Split-Path -Path $archiveEntryFullName -Parent
|
||||
|
||||
while (-not [String]::IsNullOrEmpty($parentDirectory))
|
||||
while (-not [System.String]::IsNullOrEmpty($parentDirectory))
|
||||
{
|
||||
$directoriesToRemove += $parentDirectory
|
||||
$parentDirectory = Split-Path -Path $parentDirectory -Parent
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Localized MSFT_Archive.strings.psd1
|
||||
# Localized MSFT_Archive.strings.psd1
|
||||
|
||||
ConvertFrom-StringData @'
|
||||
RetrievingArchiveState = Retrieving the state of the archive with path "{0}" and destination "{1}"...
|
||||
|
||||
@@ -29,22 +29,22 @@ $script:maxUserEnvVariableLength = 255
|
||||
#>
|
||||
function Get-TargetResource
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([Hashtable])]
|
||||
[CmdletBinding()]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Process', 'Machine')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
$Target = ('Process', 'Machine')
|
||||
[System.String[]]
|
||||
$Target = ('Process', 'Machine')
|
||||
)
|
||||
|
||||
|
||||
$valueToReturn = $null
|
||||
|
||||
if ($Target -contains 'Machine')
|
||||
@@ -60,13 +60,13 @@ function Get-TargetResource
|
||||
{
|
||||
$valueToReturn = Get-ProcessEnvironmentVariable -Name $Name
|
||||
}
|
||||
|
||||
|
||||
$environmentResource = @{
|
||||
Name = $Name
|
||||
Value = $null
|
||||
Ensure = 'Absent'
|
||||
}
|
||||
|
||||
|
||||
if ($null -eq $valueToReturn)
|
||||
{
|
||||
Write-Verbose -Message ($script:localizedData.EnvVarNotFound -f $Name)
|
||||
@@ -84,7 +84,7 @@ function Get-TargetResource
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates, modifies, or removes an environment variable.
|
||||
|
||||
|
||||
.PARAMETER Name
|
||||
The name of the environment variable to create, modify, or remove.
|
||||
|
||||
@@ -117,34 +117,34 @@ function Set-TargetResource
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNull()]
|
||||
[String]
|
||||
$Value = [String]::Empty,
|
||||
|
||||
[System.String]
|
||||
$Value = [System.String]::Empty,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Path = $false,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Process', 'Machine')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$Target = ('Process', 'Machine')
|
||||
)
|
||||
|
||||
$valueSpecified = ($Value -ne [String]::Empty)
|
||||
|
||||
$valueSpecified = ($Value -ne [System.String]::Empty)
|
||||
$currentValueFromMachine = $null
|
||||
$currentValueFromProcess = $null
|
||||
$currentPropertiesFromMachine = $null
|
||||
@@ -162,7 +162,7 @@ function Set-TargetResource
|
||||
{
|
||||
$currentValueFromMachine = $currentPropertiesFromMachine.$Name
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$currentPropertiesFromMachine = Get-ItemProperty -Path $script:envVarRegPathMachine -Name $Name -ErrorAction 'SilentlyContinue'
|
||||
@@ -192,8 +192,8 @@ function Set-TargetResource
|
||||
|
||||
if ($Ensure -eq 'Present')
|
||||
{
|
||||
$createMachineVariable = ((-not $setMachineVariable) -or ($null -eq $currentPropertiesFromMachine) -or ($currentValueFromMachine -eq [String]::Empty))
|
||||
$createProcessVariable = ((-not $setProcessVariable) -or ($null -eq $currentValueFromProcess) -or ($currentValueFromProcess -eq [String]::Empty))
|
||||
$createMachineVariable = ((-not $setMachineVariable) -or ($null -eq $currentPropertiesFromMachine) -or ($currentValueFromMachine -eq [System.String]::Empty))
|
||||
$createProcessVariable = ((-not $setProcessVariable) -or ($null -eq $currentValueFromProcess) -or ($currentValueFromProcess -eq [System.String]::Empty))
|
||||
|
||||
if ($createMachineVariable -and $createProcessVariable)
|
||||
{
|
||||
@@ -214,7 +214,7 @@ function Set-TargetResource
|
||||
#>
|
||||
|
||||
Set-EnvironmentVariable -Name $Name -Value $Value -Target $Target
|
||||
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.EnvVarCreated -f $Name, $Value)
|
||||
return
|
||||
}
|
||||
@@ -234,15 +234,15 @@ function Set-TargetResource
|
||||
# Check if an empty, whitespace or semi-colon only string has been specified. If yes, return unchanged.
|
||||
$trimmedValue = $Value.Trim(';').Trim()
|
||||
|
||||
if ([String]::IsNullOrEmpty($trimmedValue))
|
||||
if ([System.String]::IsNullOrEmpty($trimmedValue))
|
||||
{
|
||||
Write-Verbose -Message ($script:localizedData.EnvVarPathUnchanged -f $Name, $currentValueToDisplay)
|
||||
return
|
||||
return
|
||||
}
|
||||
|
||||
if (-not $Path)
|
||||
{
|
||||
# For non-path variables, simply set the specified $Value as the new value of the specified
|
||||
# For non-path variables, simply set the specified $Value as the new value of the specified
|
||||
# variable $Name for the given $Target
|
||||
|
||||
if (($setMachineVariable -and ($Value -cne $currentValueFromMachine)) -or `
|
||||
@@ -280,7 +280,7 @@ function Set-TargetResource
|
||||
if ($setProcessVariable)
|
||||
{
|
||||
$valueUnchanged = Test-PathsInValue -ExistingPaths $currentValueFromProcess -QueryPaths $trimmedValue -FindCriteria 'All'
|
||||
|
||||
|
||||
if ($currentValueFromProcess -and -not $valueUnchanged)
|
||||
{
|
||||
$updatedValue = Add-PathsToValue -CurrentValue $currentValueFromProcess -NewValue $trimmedValue
|
||||
@@ -303,10 +303,10 @@ function Set-TargetResource
|
||||
if ($machineVariableRemoved -and $processVariableRemoved)
|
||||
{
|
||||
# Variable not found, condition is satisfied and there is nothing to set/remove, return
|
||||
Write-Verbose -Message ($script:localizedData.EnvVarNotFound -f $Name)
|
||||
Write-Verbose -Message ($script:localizedData.EnvVarNotFound -f $Name)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if ((-not $ValueSpecified) -or (-not $Path))
|
||||
{
|
||||
<#
|
||||
@@ -323,7 +323,7 @@ function Set-TargetResource
|
||||
# Check if an empty string or semi-colon only string has been specified as $Value. If yes, return unchanged as we don't need to remove anything.
|
||||
$trimmedValue = $Value.Trim(';').Trim()
|
||||
|
||||
if ([String]::IsNullOrEmpty($trimmedValue))
|
||||
if ([System.String]::IsNullOrEmpty($trimmedValue))
|
||||
{
|
||||
Write-Verbose -Message ($script:localizedData.EnvVarPathUnchanged -f $Name, $currentValueToDisplay)
|
||||
return
|
||||
@@ -334,7 +334,7 @@ function Set-TargetResource
|
||||
if ($setMachineVariable)
|
||||
{
|
||||
$finalPath = $null
|
||||
|
||||
|
||||
if ($currentValueFromMachine)
|
||||
{
|
||||
<#
|
||||
@@ -346,7 +346,7 @@ function Set-TargetResource
|
||||
$finalPath = Remove-PathsFromValue -CurrentValue $currentValueFromMachine -PathsToRemove $trimmedValue
|
||||
}
|
||||
|
||||
if ([String]::IsNullOrEmpty($finalPath))
|
||||
if ([System.String]::IsNullOrEmpty($finalPath))
|
||||
{
|
||||
Remove-EnvironmentVariable -Name $Name -Target @('Machine')
|
||||
Write-Verbose -Message ($script:localizedData.EnvVarRemoved -f $Name)
|
||||
@@ -359,13 +359,13 @@ function Set-TargetResource
|
||||
{
|
||||
Set-EnvironmentVariable -Name $Name -Value $finalPath -Target @('Machine')
|
||||
Write-Verbose -Message ($script:localizedData.EnvVarPathUpdated -f $Name, $currentValueFromMachine, $finalPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($setProcessVariable)
|
||||
{
|
||||
$finalPath = $null
|
||||
|
||||
|
||||
if ($currentValueFromProcess)
|
||||
{
|
||||
<#
|
||||
@@ -377,7 +377,7 @@ function Set-TargetResource
|
||||
$finalPath = Remove-PathsFromValue -CurrentValue $currentValueFromProcess -PathsToRemove $trimmedValue
|
||||
}
|
||||
|
||||
if ([String]::IsNullOrEmpty($finalPath))
|
||||
if ([System.String]::IsNullOrEmpty($finalPath))
|
||||
{
|
||||
Remove-EnvironmentVariable -Name $Name -Target @('Process')
|
||||
Write-Verbose -Message ($script:localizedData.EnvVarRemoved -f $Name)
|
||||
@@ -398,7 +398,7 @@ function Set-TargetResource
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Tests if the environment variable is in the desired state.
|
||||
|
||||
|
||||
.PARAMETER Name
|
||||
The name of the environment variable to test.
|
||||
|
||||
@@ -426,36 +426,36 @@ function Set-TargetResource
|
||||
function Test-TargetResource
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
param
|
||||
(
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNull()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Value,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Path = $false,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Process', 'Machine')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$Target = ('Process', 'Machine')
|
||||
)
|
||||
|
||||
$valueSpecified = $PSBoundParameters.ContainsKey('Value') -and ($Value -ne [String]::Empty)
|
||||
|
||||
$valueSpecified = $PSBoundParameters.ContainsKey('Value') -and ($Value -ne [System.String]::Empty)
|
||||
$currentValueFromMachine = $null
|
||||
$currentValueFromProcess = $null
|
||||
$currentPropertiesFromMachine = $null
|
||||
@@ -473,7 +473,7 @@ function Test-TargetResource
|
||||
{
|
||||
$currentValueFromMachine = $currentPropertiesFromMachine.$Name
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$currentPropertiesFromMachine = Get-ItemProperty -Path $script:envVarRegPathMachine -Name $Name -ErrorAction 'SilentlyContinue'
|
||||
@@ -500,7 +500,7 @@ function Test-TargetResource
|
||||
{
|
||||
$currentValueToDisplay = $currentValueFromProcess
|
||||
}
|
||||
|
||||
|
||||
if (($checkMachineTarget -and ($null -eq $currentPropertiesFromMachine)) -or ($checkProcessTarget -and ($null -eq $currentValueFromProcess)))
|
||||
{
|
||||
# Variable not found
|
||||
@@ -513,7 +513,7 @@ function Test-TargetResource
|
||||
Write-Verbose ($script:localizedData.EnvVarFound -f $Name, $currentValueToDisplay)
|
||||
return ($Ensure -eq 'Present')
|
||||
}
|
||||
|
||||
|
||||
if (-not $Path)
|
||||
{
|
||||
# For this non-path variable, make sure that the specified $Value matches the current value.
|
||||
@@ -538,7 +538,7 @@ function Test-TargetResource
|
||||
{
|
||||
if (-not (Test-PathsInValue -ExistingPaths $currentValueFromMachine -QueryPaths $Value -FindCriteria 'All'))
|
||||
{
|
||||
# If the control reached here some part of the specified path ($Value) was not found in the existing variable, return failure
|
||||
# If the control reached here some part of the specified path ($Value) was not found in the existing variable, return failure
|
||||
Write-Verbose ($script:localizedData.EnvVarFoundWithMisMatchingValue -f $Name, $currentValueToDisplay, $Value)
|
||||
return $false
|
||||
}
|
||||
@@ -548,7 +548,7 @@ function Test-TargetResource
|
||||
{
|
||||
if (-not (Test-PathsInValue -ExistingPaths $currentValueFromProcess -QueryPaths $Value -FindCriteria 'All'))
|
||||
{
|
||||
# If the control reached here some part of the specified path ($Value) was not found in the existing variable, return failure
|
||||
# If the control reached here some part of the specified path ($Value) was not found in the existing variable, return failure
|
||||
Write-Verbose ($script:localizedData.EnvVarFoundWithMisMatchingValue -f $Name, $currentValueToDisplay, $Value)
|
||||
return $false
|
||||
}
|
||||
@@ -560,7 +560,7 @@ function Test-TargetResource
|
||||
}
|
||||
# Ensure = 'Absent'
|
||||
else
|
||||
{
|
||||
{
|
||||
if ($checkMachineTarget)
|
||||
{
|
||||
if (Test-PathsInValue -ExistingPaths $currentValueFromMachine -QueryPaths $Value -FindCriteria 'Any')
|
||||
@@ -580,7 +580,7 @@ function Test-TargetResource
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# If the control reached here, none of the specified paths were found in the existing path-variable, return success
|
||||
Write-Verbose ($script:localizedData.EnvVarFoundWithMisMatchingValue -f $Name, $currentValueToDisplay, $Value)
|
||||
return $true
|
||||
@@ -590,7 +590,7 @@ function Test-TargetResource
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Retrieves the value of the environment variable from the given Target.
|
||||
|
||||
|
||||
.PARAMETER Name
|
||||
The name of the environment variable to retrieve the value from.
|
||||
|
||||
@@ -602,23 +602,23 @@ function Test-TargetResource
|
||||
function Get-EnvironmentVariable
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('Process', 'Machine')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Target
|
||||
)
|
||||
|
||||
$valueToReturn = $null
|
||||
|
||||
if ($Target -eq 'Process')
|
||||
if ($Target -eq 'Process')
|
||||
{
|
||||
$valueToReturn = Get-ProcessEnvironmentVariable -Name $Name
|
||||
}
|
||||
@@ -640,27 +640,26 @@ function Get-EnvironmentVariable
|
||||
$valueToReturn = $retrievedProperty.$Name
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $valueToReturn
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Wrapper function to retrieve an environment variable from the current process.
|
||||
|
||||
|
||||
.PARAMETER Name
|
||||
The name of the variable to retrieve
|
||||
|
||||
#>
|
||||
function Get-ProcessEnvironmentVariable
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name
|
||||
)
|
||||
|
||||
@@ -672,28 +671,28 @@ function Get-ProcessEnvironmentVariable
|
||||
If there are any paths in NewPaths that aren't in CurrentValue they will be added
|
||||
to the current paths value and a String will be returned containing all old paths
|
||||
and new paths. Otherwise the original value will be returned unchanged.
|
||||
|
||||
|
||||
.PARAMETER CurrentValue
|
||||
A semicolon-separated String containing the current path values.
|
||||
|
||||
.PARAMETER NewPaths
|
||||
A semicolon-separated String containing any paths that should be added to
|
||||
the current value. If CurrentValue already contains a path, it will not be added.
|
||||
the current value. If CurrentValue already contains a path, it will not be added.
|
||||
#>
|
||||
function Add-PathsToValue
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
param
|
||||
(
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$CurrentValue,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$NewValue
|
||||
)
|
||||
|
||||
@@ -725,7 +724,7 @@ function Add-PathsToValue
|
||||
paths that remain, or an empty string will be returned if all paths were removed.
|
||||
If none of the paths in PathsToRemove are in CurrentValue then this function will
|
||||
return CurrentValue since nothing needs to be changed.
|
||||
|
||||
|
||||
.PARAMETER CurrentValue
|
||||
A semicolon-separated String containing the current path values.
|
||||
|
||||
@@ -735,18 +734,18 @@ function Add-PathsToValue
|
||||
#>
|
||||
function Remove-PathsFromValue
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$CurrentValue,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$PathsToRemove
|
||||
)
|
||||
|
||||
@@ -769,12 +768,12 @@ function Remove-PathsFromValue
|
||||
{
|
||||
# the current $subpath was not part of the $specifiedPaths (to be removed) so keep this $subpath in the finalPath
|
||||
$finalPath += $subpath + ';'
|
||||
}
|
||||
}
|
||||
|
||||
# Remove any extraneous ';' at the end (and potentially start - as a side-effect) of the $finalPath
|
||||
$finalPath = $finalPath.Trim(';')
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
# Remove any extraneous ';' at the end (and potentially start - as a side-effect) of the $finalPath
|
||||
$finalPath = $finalPath.Trim(';')
|
||||
|
||||
if ($varAltered)
|
||||
{
|
||||
return $finalPath
|
||||
@@ -789,14 +788,14 @@ function Remove-PathsFromValue
|
||||
.SYNOPSIS
|
||||
Sets the value of the environment variable with the given name if a value is specified.
|
||||
If no value is specified, then the environment variable will be removed.
|
||||
|
||||
|
||||
.PARAMETER Name
|
||||
The name of the environment variable to set or remove.
|
||||
|
||||
.PARAMETER Value
|
||||
The value to set the environment variable to. If not provided, then the variable will
|
||||
be removed.
|
||||
|
||||
|
||||
.PARAMETER Target
|
||||
Indicates where to set or remove the environment variable: The machine, the process, or both.
|
||||
The logic for User is also included here for future expansion of this resource.
|
||||
@@ -805,19 +804,19 @@ function Set-EnvironmentVariable
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Value,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('Process', 'Machine')]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$Target
|
||||
)
|
||||
|
||||
@@ -825,8 +824,8 @@ function Set-EnvironmentVariable
|
||||
|
||||
try
|
||||
{
|
||||
# If the Value is set to [String]::Empty then nothing should be updated for the process
|
||||
if (($Target -contains 'Process') -and (-not $valueSpecified -or ($Value -ne [String]::Empty)))
|
||||
# If the Value is set to [System.String]::Empty then nothing should be updated for the process
|
||||
if (($Target -contains 'Process') -and (-not $valueSpecified -or ($Value -ne [System.String]::Empty)))
|
||||
{
|
||||
if (-not $valueSpecified)
|
||||
{
|
||||
@@ -847,7 +846,7 @@ function Set-EnvironmentVariable
|
||||
|
||||
$path = $script:envVarRegPathMachine
|
||||
|
||||
if (-not $valueSpecified)
|
||||
if (-not $valueSpecified)
|
||||
{
|
||||
$environmentKey = Get-ItemProperty -Path $path -Name $Name -ErrorAction 'SilentlyContinue'
|
||||
|
||||
@@ -866,7 +865,7 @@ function Set-EnvironmentVariable
|
||||
Set-ItemProperty -Path $path -Name $Name -Value $Value
|
||||
$environmentKey = Get-ItemProperty -Path $path -Name $Name -ErrorAction 'SilentlyContinue'
|
||||
|
||||
if ($null -eq $environmentKey)
|
||||
if ($null -eq $environmentKey)
|
||||
{
|
||||
$message = ($script:localizedData.GetItemPropertyFailure -f $Name, $path)
|
||||
New-InvalidArgumentException -Message $message -ArgumentName $Name
|
||||
@@ -884,7 +883,7 @@ function Set-EnvironmentVariable
|
||||
|
||||
$path = $script:envVarRegPathUser
|
||||
|
||||
if (-not $valueSpecified)
|
||||
if (-not $valueSpecified)
|
||||
{
|
||||
$environmentKey = Get-ItemProperty -Path $path -Name $Name -ErrorAction 'SilentlyContinue'
|
||||
|
||||
@@ -903,7 +902,7 @@ function Set-EnvironmentVariable
|
||||
Set-ItemProperty -Path $path -Name $Name -Value $Value
|
||||
$environmentKey = Get-ItemProperty -Path $path -Name $Name -ErrorAction 'SilentlyContinue'
|
||||
|
||||
if ($null -eq $environmentKey)
|
||||
if ($null -eq $environmentKey)
|
||||
{
|
||||
$message = ($script:localizedData.GetItemPropertyFailure -f $Name, $path)
|
||||
New-InvalidArgumentException -Message $message -ArgumentName $Name
|
||||
@@ -911,7 +910,7 @@ function Set-EnvironmentVariable
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
catch
|
||||
{
|
||||
New-InvalidOperationException -Message ($script:localizedData.EnvVarSetError -f $Name, $Value) `
|
||||
-ErrorRecord $_
|
||||
@@ -922,13 +921,12 @@ function Set-EnvironmentVariable
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Wrapper function to set an environment variable for the current process.
|
||||
|
||||
|
||||
.PARAMETER Name
|
||||
The name of the environment variable to set.
|
||||
|
||||
.PARAMETER Value
|
||||
The value to set the environment variable to.
|
||||
|
||||
#>
|
||||
function Set-ProcessEnvironmentVariable
|
||||
{
|
||||
@@ -937,12 +935,12 @@ function Set-ProcessEnvironmentVariable
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
$Value = [String]::Empty
|
||||
[System.String]
|
||||
$Value = [System.String]::Empty
|
||||
)
|
||||
|
||||
[System.Environment]::SetEnvironmentVariable($Name, $Value)
|
||||
@@ -952,7 +950,7 @@ function Set-ProcessEnvironmentVariable
|
||||
.SYNOPSIS
|
||||
Removes an environment variable from the given target(s) by calling Set-EnvironmentVariable
|
||||
with no Value specified.
|
||||
|
||||
|
||||
.PARAMETER Name
|
||||
The name of the environment variable to remove.
|
||||
|
||||
@@ -963,23 +961,23 @@ function Remove-EnvironmentVariable
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('Process', 'Machine')]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$Target
|
||||
)
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
Set-EnvironmentVariable -Name $Name -Target $Target
|
||||
}
|
||||
catch
|
||||
catch
|
||||
{
|
||||
New-InvalidOperationException -Message ($script:localizedData.EnvVarRemoveError -f $Name) `
|
||||
-ErrorRecord $_
|
||||
@@ -993,7 +991,7 @@ function Remove-EnvironmentVariable
|
||||
paths in QueryPaths are in ExistingPaths, otherwise it will return False.
|
||||
If FindCriteria is set to 'Any' then it will return True if any of the paths
|
||||
in QueryPaths are in ExistingPaths, otherwise it will return False.
|
||||
|
||||
|
||||
.PARAMETER ExistingPaths
|
||||
A semicolon-separated String containing the path values to test against.
|
||||
|
||||
@@ -1007,21 +1005,21 @@ function Remove-EnvironmentVariable
|
||||
#>
|
||||
function Test-PathsInValue
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
$ExistingPaths,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$ExistingPaths,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[System.String]
|
||||
$QueryPaths,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('Any', 'All')]
|
||||
[String]
|
||||
[System.String]
|
||||
$FindCriteria
|
||||
)
|
||||
|
||||
@@ -1038,30 +1036,30 @@ function Test-PathsInValue
|
||||
{
|
||||
# Found this $queryPath in the existing paths, return $true
|
||||
return $true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# If the control reached here, none of the QueryPaths were found in ExistingPaths
|
||||
return $false
|
||||
return $false
|
||||
}
|
||||
|
||||
'All'
|
||||
{
|
||||
foreach ($queryPath in $queryPathList)
|
||||
{
|
||||
if ($queryPath)
|
||||
if ($queryPath)
|
||||
{
|
||||
if ($existingPathList -notcontains $queryPath)
|
||||
{
|
||||
# The current $queryPath wasn't found in any of the $existingPathList, return false
|
||||
# The current $queryPath wasn't found in any of the $existingPathList, return false
|
||||
return $false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# If the control reached here, all of the QueryPaths were found in ExistingPaths
|
||||
return $true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1072,7 +1070,7 @@ function Test-PathsInValue
|
||||
name and its current value on the machine. This is to most closely represent what the
|
||||
actual API call returns. If an environment variable with the given name is not found, then
|
||||
$null will be returned.
|
||||
|
||||
|
||||
.PARAMETER Name
|
||||
The name of the environment variable to retrieve the value of.
|
||||
#>
|
||||
@@ -1084,14 +1082,14 @@ function Get-EnvironmentVariableWithoutExpanding
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name
|
||||
)
|
||||
|
||||
$path = $script:envVarRegPathMachine
|
||||
$pathTokens = $path.Split('\',[System.StringSplitOptions]::RemoveEmptyEntries)
|
||||
$entry = $pathTokens[1..($pathTokens.Count - 1)] -join '\'
|
||||
|
||||
|
||||
# Since the target registry path coming to this function is hardcoded for local machine
|
||||
$hive = [Microsoft.Win32.Registry]::LocalMachine
|
||||
|
||||
@@ -1100,14 +1098,14 @@ function Get-EnvironmentVariableWithoutExpanding
|
||||
try
|
||||
{
|
||||
$key = $hive.OpenSubKey($entry)
|
||||
|
||||
|
||||
$valueNames = $key.GetValueNames()
|
||||
if ($valueNames -inotcontains $Name)
|
||||
{
|
||||
return $null
|
||||
}
|
||||
|
||||
[String] $value = Get-KeyValue -Name $Name -Key $key
|
||||
|
||||
[System.String] $value = Get-KeyValue -Name $Name -Key $key
|
||||
$noteProperties.Add($Name, $value)
|
||||
}
|
||||
finally
|
||||
@@ -1127,7 +1125,7 @@ function Get-EnvironmentVariableWithoutExpanding
|
||||
.SYNOPSIS
|
||||
Wrapper function to get the value of the environment variable with the given name
|
||||
from the specified registry key.
|
||||
|
||||
|
||||
.PARAMETER Name
|
||||
The name of the environment variable to retrieve the value of.
|
||||
|
||||
@@ -1136,13 +1134,13 @@ function Get-EnvironmentVariableWithoutExpanding
|
||||
#>
|
||||
function Get-KeyValue
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Localized resources for MSFT_EnvironmentResource
|
||||
# Localized resources for MSFT_EnvironmentResource
|
||||
|
||||
ConvertFrom-StringData @'
|
||||
ArgumentTooLong = Argument is too long.
|
||||
|
||||
@@ -87,13 +87,13 @@ if (-not (Test-IsNanoServer))
|
||||
#>
|
||||
function Get-TargetResource
|
||||
{
|
||||
[OutputType([Hashtable])]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$GroupName,
|
||||
|
||||
[Parameter()]
|
||||
@@ -186,28 +186,28 @@ function Set-TargetResource
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$GroupName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Description,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$Members,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$MembersToInclude,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$MembersToExclude,
|
||||
|
||||
[Parameter()]
|
||||
@@ -284,34 +284,34 @@ function Set-TargetResource
|
||||
#>
|
||||
function Test-TargetResource
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$GroupName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Description,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$Members,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$MembersToInclude,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$MembersToExclude,
|
||||
|
||||
[Parameter()]
|
||||
@@ -347,13 +347,13 @@ function Test-TargetResource
|
||||
#>
|
||||
function Get-TargetResourceOnFullSKU
|
||||
{
|
||||
[OutputType([Hashtable])]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$GroupName,
|
||||
|
||||
[Parameter()]
|
||||
@@ -416,13 +416,13 @@ function Get-TargetResourceOnFullSKU
|
||||
#>
|
||||
function Get-TargetResourceOnNanoServer
|
||||
{
|
||||
[OutputType([Hashtable])]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$GroupName,
|
||||
|
||||
[Parameter()]
|
||||
@@ -520,28 +520,28 @@ function Set-TargetResourceOnFullSKU
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$GroupName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Description,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$Members,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$MembersToInclude,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$MembersToExclude,
|
||||
|
||||
[Parameter()]
|
||||
@@ -642,7 +642,7 @@ function Set-TargetResourceOnFullSKU
|
||||
|
||||
if ($Members.Count -eq 0 -and $null -ne $actualMembersAsPrincipals -and $actualMembersAsPrincipals.Count -ne 0)
|
||||
{
|
||||
Clear-GroupMembers -Group $group
|
||||
Clear-GroupMember -Group $group
|
||||
$saveChanges = $true
|
||||
}
|
||||
elseif ($Members.Count -ne 0)
|
||||
@@ -877,28 +877,28 @@ function Set-TargetResourceOnNanoServer
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$GroupName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Description,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$Members,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$MembersToInclude,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$MembersToExclude,
|
||||
|
||||
[Parameter()]
|
||||
@@ -992,7 +992,7 @@ function Set-TargetResourceOnNanoServer
|
||||
}
|
||||
elseif ($PSBoundParameters.ContainsKey('MembersToInclude') -or $PSBoundParameters.ContainsKey('MembersToExclude'))
|
||||
{
|
||||
[array]$groupMembers = Get-MembersOnNanoServer -Group $group
|
||||
[System.Array] $groupMembers = Get-MembersOnNanoServer -Group $group
|
||||
|
||||
$uniqueMembersToInclude = $MembersToInclude | Select-Object -Unique
|
||||
$uniqueMembersToExclude = $MembersToExclude | Select-Object -Unique
|
||||
@@ -1110,34 +1110,34 @@ function Set-TargetResourceOnNanoServer
|
||||
#>
|
||||
function Test-TargetResourceOnFullSKU
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$GroupName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Description,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$Members,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$MembersToInclude,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$MembersToExclude,
|
||||
|
||||
[Parameter()]
|
||||
@@ -1377,34 +1377,34 @@ function Test-TargetResourceOnFullSKU
|
||||
#>
|
||||
function Test-TargetResourceOnNanoServer
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$GroupName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Description,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$Members,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$MembersToInclude,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$MembersToExclude,
|
||||
|
||||
[Parameter()]
|
||||
@@ -1458,7 +1458,7 @@ function Test-TargetResourceOnNanoServer
|
||||
}
|
||||
}
|
||||
|
||||
[array]$groupMembers = Get-MembersOnNanoServer -Group $group
|
||||
[System.Array] $groupMembers = Get-MembersOnNanoServer -Group $group
|
||||
|
||||
# Remove duplicate names as strings.
|
||||
$uniqueMembers = $Members | Select-Object -Unique
|
||||
@@ -1600,7 +1600,7 @@ function Get-MembersOnFullSKU
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[Hashtable]
|
||||
[System.Collections.Hashtable]
|
||||
[AllowEmptyCollection()]
|
||||
$PrincipalContextCache,
|
||||
|
||||
@@ -1686,7 +1686,7 @@ function Get-MembersAsPrincipalsList
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[Hashtable]
|
||||
[System.Collections.Hashtable]
|
||||
[AllowEmptyCollection()]
|
||||
$PrincipalContextCache,
|
||||
|
||||
@@ -1804,7 +1804,7 @@ function Assert-GroupNameValid
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$GroupName
|
||||
)
|
||||
|
||||
@@ -1813,7 +1813,7 @@ function Assert-GroupNameValid
|
||||
if ($GroupName.IndexOfAny($invalidCharacters) -ne -1)
|
||||
{
|
||||
New-InvalidArgumentException -ArgumentName 'GroupName' `
|
||||
-Message ($script:localizedData.InvalidGroupName -f $GroupName, [String]::Join(' ', $invalidCharacters))
|
||||
-Message ($script:localizedData.InvalidGroupName -f $GroupName, [System.String]::Join(' ', $invalidCharacters))
|
||||
}
|
||||
|
||||
$nameContainsOnlyWhitspaceOrDots = $true
|
||||
@@ -1821,7 +1821,7 @@ function Assert-GroupNameValid
|
||||
# Check if the name consists of only periods and/or white spaces.
|
||||
for ($groupNameIndex = 0; $groupNameIndex -lt $GroupName.Length; $groupNameIndex++)
|
||||
{
|
||||
if (-not [Char]::IsWhiteSpace($GroupName, $groupNameIndex) -and $GroupName[$groupNameIndex] -ne '.')
|
||||
if (-not [System.Char]::IsWhiteSpace($GroupName, $groupNameIndex) -and $GroupName[$groupNameIndex] -ne '.')
|
||||
{
|
||||
$nameContainsOnlyWhitspaceOrDots = $false
|
||||
break
|
||||
@@ -1831,7 +1831,7 @@ function Assert-GroupNameValid
|
||||
if ($nameContainsOnlyWhitspaceOrDots)
|
||||
{
|
||||
New-InvalidArgumentException -ArgumentName 'GroupName' `
|
||||
-Message ($script:localizedData.InvalidGroupName -f $GroupName, [String]::Join(' ', $invalidCharacters))
|
||||
-Message ($script:localizedData.InvalidGroupName -f $GroupName, [System.String]::Join(' ', $invalidCharacters))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1859,12 +1859,12 @@ function ConvertTo-UniquePrincipalsList
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$MemberNames,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[Hashtable]
|
||||
[System.Collections.Hashtable]
|
||||
[AllowEmptyCollection()]
|
||||
$PrincipalContextCache,
|
||||
|
||||
@@ -1949,12 +1949,12 @@ function ConvertTo-Principal
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[String]
|
||||
[System.String]
|
||||
$MemberName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[Hashtable]
|
||||
[System.Collections.Hashtable]
|
||||
[AllowEmptyCollection()]
|
||||
$PrincipalContextCache,
|
||||
|
||||
@@ -2051,7 +2051,7 @@ function Resolve-SidToPrincipal
|
||||
$PrincipalContext,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$Scope
|
||||
)
|
||||
|
||||
@@ -2101,7 +2101,7 @@ function Get-PrincipalContext
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Scope,
|
||||
|
||||
[Parameter()]
|
||||
@@ -2111,7 +2111,7 @@ function Get-PrincipalContext
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[Hashtable]
|
||||
[System.Collections.Hashtable]
|
||||
[AllowEmptyCollection()]
|
||||
$PrincipalContextCache,
|
||||
|
||||
@@ -2151,7 +2151,7 @@ function Get-PrincipalContext
|
||||
# Create a PrincipalContext targeting $Scope using the network credentials that were passed in.
|
||||
$credentialDomain = $Credential.GetNetworkCredential().Domain
|
||||
$credentialUserName = $Credential.GetNetworkCredential().UserName
|
||||
if ($credentialDomain -ne [String]::Empty)
|
||||
if ($credentialDomain -ne [System.String]::Empty)
|
||||
{
|
||||
$principalContextName = "$credentialDomain\$credentialUserName"
|
||||
}
|
||||
@@ -2191,13 +2191,13 @@ function Get-PrincipalContext
|
||||
#>
|
||||
function Test-IsLocalMachine
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Scope
|
||||
)
|
||||
|
||||
@@ -2284,7 +2284,7 @@ function Split-MemberName
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$MemberName
|
||||
)
|
||||
|
||||
@@ -2370,7 +2370,7 @@ function Find-Principal
|
||||
$PrincipalContext,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$IdentityValue,
|
||||
|
||||
[Parameter()]
|
||||
@@ -2415,7 +2415,7 @@ function Get-Group
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$GroupName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
@@ -2470,7 +2470,7 @@ function Get-GroupMembersFromDirectoryEntry
|
||||
.PARAMETER Group
|
||||
The group to clear the members of.
|
||||
#>
|
||||
function Clear-GroupMembers
|
||||
function Clear-GroupMember
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Suppress Global Vars PSSA Error because $global:DSCMachineStatus must be allowed
|
||||
# Suppress Global Vars PSSA Error because $global:DSCMachineStatus must be allowed
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
|
||||
param()
|
||||
@@ -30,18 +30,18 @@ $script:msiTools = $null
|
||||
#>
|
||||
function Get-TargetResource
|
||||
{
|
||||
[OutputType([Hashtable])]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ProductId,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path
|
||||
)
|
||||
|
||||
@@ -90,7 +90,7 @@ function Get-TargetResource
|
||||
.PARAMETER Arguments
|
||||
The arguments to pass to the MSI package during installation or uninstallation
|
||||
if needed.
|
||||
|
||||
|
||||
.PARAMETER Credential
|
||||
The credential of a user account to be used to mount a UNC path if needed.
|
||||
|
||||
@@ -122,51 +122,51 @@ function Set-TargetResource
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ProductId,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Arguments,
|
||||
|
||||
[Parameter()]
|
||||
[PSCredential]
|
||||
[System.Management.Automation.PSCredential]
|
||||
[System.Management.Automation.Credential()]
|
||||
$Credential,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$FileHash,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5', 'RIPEMD160')]
|
||||
[String]
|
||||
[System.String]
|
||||
$HashAlgorithm = 'SHA256',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$SignerSubject,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$SignerThumbprint,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ServerCertificateValidationCallback,
|
||||
|
||||
[Parameter()]
|
||||
@@ -223,7 +223,7 @@ function Set-TargetResource
|
||||
if ($uri.IsUnc)
|
||||
{
|
||||
$psDriveArgs = @{
|
||||
Name = [Guid]::NewGuid()
|
||||
Name = [System.Guid]::NewGuid()
|
||||
PSProvider = 'FileSystem'
|
||||
Root = Split-Path -Path $localPath
|
||||
}
|
||||
@@ -269,7 +269,7 @@ function Set-TargetResource
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ($null -ne $responseStream)
|
||||
if ((Test-Path -Path variable:responseStream) -and ($null -ne $responseStream))
|
||||
{
|
||||
Close-Stream -Stream $responseStream
|
||||
}
|
||||
@@ -298,8 +298,8 @@ function Set-TargetResource
|
||||
|
||||
# Check if the MSI package specifies the ProductCode, and if so make sure they match
|
||||
$productCode = Get-MsiProductCode -Path $Path
|
||||
|
||||
if ((-not [String]::IsNullOrEmpty($identifyingNumber)) -and ($identifyingNumber -ne $productCode))
|
||||
|
||||
if ((-not [System.String]::IsNullOrEmpty($identifyingNumber)) -and ($identifyingNumber -ne $productCode))
|
||||
{
|
||||
New-InvalidArgumentException -ArgumentName 'ProductId' -Message ($script:localizedData.InvalidId -f $identifyingNumber, $productCode)
|
||||
}
|
||||
@@ -369,7 +369,7 @@ function Set-TargetResource
|
||||
|
||||
.PARAMETER ProductId
|
||||
The identifying number used to find the package, usually a GUID.
|
||||
|
||||
|
||||
.PARAMETER Path
|
||||
Not Used in Test-TargetResource
|
||||
|
||||
@@ -407,57 +407,57 @@ function Set-TargetResource
|
||||
#>
|
||||
function Test-TargetResource
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ProductId,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Arguments,
|
||||
|
||||
[Parameter()]
|
||||
[PSCredential]
|
||||
[System.Management.Automation.PSCredential]
|
||||
[System.Management.Automation.Credential()]
|
||||
$Credential,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$FileHash,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5', 'RIPEMD160')]
|
||||
[String]
|
||||
[System.String]
|
||||
$HashAlgorithm = 'SHA256',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$SignerSubject,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$SignerThumbprint,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ServerCertificateValidationCallback,
|
||||
|
||||
[Parameter()]
|
||||
@@ -497,7 +497,7 @@ function Assert-PathExtensionValid
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path
|
||||
)
|
||||
|
||||
@@ -520,19 +520,19 @@ function Assert-PathExtensionValid
|
||||
#>
|
||||
function Convert-PathToUri
|
||||
{
|
||||
[OutputType([Uri])]
|
||||
[OutputType([System.Uri])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path
|
||||
)
|
||||
|
||||
try
|
||||
{
|
||||
$uri = [Uri]$Path
|
||||
$uri = [System.Uri] $Path
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -559,20 +559,20 @@ function Convert-PathToUri
|
||||
#>
|
||||
function Convert-ProductIdToIdentifyingNumber
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ProductId
|
||||
)
|
||||
|
||||
try
|
||||
{
|
||||
Write-Verbose -Message ($script:localizedData.ParsingProductIdAsAnIdentifyingNumber -f $ProductId)
|
||||
$identifyingNumber = '{{{0}}}' -f [Guid]::Parse($ProductId).ToString().ToUpper()
|
||||
$identifyingNumber = '{{{0}}}' -f [System.Guid]::Parse($ProductId).ToString().ToUpper()
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.ParsedProductIdAsIdentifyingNumber -f $ProductId, $identifyingNumber)
|
||||
return $identifyingNumber
|
||||
@@ -598,7 +598,7 @@ function Get-ProductEntry
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$IdentifyingNumber
|
||||
)
|
||||
|
||||
@@ -607,7 +607,7 @@ function Get-ProductEntry
|
||||
|
||||
$productEntry = $null
|
||||
|
||||
if (-not [String]::IsNullOrEmpty($IdentifyingNumber))
|
||||
if (-not [System.String]::IsNullOrEmpty($IdentifyingNumber))
|
||||
{
|
||||
$productEntryKeyLocation = Join-Path -Path $uninstallRegistryKey -ChildPath $IdentifyingNumber
|
||||
$productEntry = Get-Item -Path $productEntryKeyLocation -ErrorAction 'SilentlyContinue'
|
||||
@@ -631,7 +631,7 @@ function Get-ProductEntry
|
||||
#>
|
||||
function Get-ProductEntryInfo
|
||||
{
|
||||
[OutputType([Hashtable])]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
@@ -646,7 +646,7 @@ function Get-ProductEntryInfo
|
||||
{
|
||||
try
|
||||
{
|
||||
$installDate = '{0:d}' -f [DateTime]::ParseExact($installDate, 'yyyyMMdd',[System.Globalization.CultureInfo]::InvariantCulture).Date
|
||||
$installDate = '{0:d}' -f [System.DateTime]::ParseExact($installDate, 'yyyyMMdd',[System.Globalization.CultureInfo]::CurrentCulture).Date
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -695,7 +695,7 @@ function Get-ProductEntryInfo
|
||||
#>
|
||||
function Get-ProductEntryValue
|
||||
{
|
||||
[OutputType([Object])]
|
||||
[OutputType([System.Object])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
@@ -704,7 +704,7 @@ function Get-ProductEntryValue
|
||||
$ProductEntry,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$Property
|
||||
)
|
||||
|
||||
@@ -725,7 +725,7 @@ function New-LogFile
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath
|
||||
)
|
||||
|
||||
@@ -765,11 +765,11 @@ function Get-WebRequestResponse
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[Uri]
|
||||
[System.Uri]
|
||||
$Uri,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ServerCertificateValidationCallback
|
||||
)
|
||||
|
||||
@@ -779,23 +779,23 @@ function Get-WebRequestResponse
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.CreatingTheSchemeStream -f $uriScheme)
|
||||
$webRequest = Get-WebRequest -Uri $Uri
|
||||
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.SettingDefaultCredential)
|
||||
$webRequest.Credentials = [System.Net.CredentialCache]::DefaultCredentials
|
||||
$webRequest.AuthenticationLevel = [System.Net.Security.AuthenticationLevel]::None
|
||||
|
||||
|
||||
if ($uriScheme -eq 'http')
|
||||
{
|
||||
# Default value is MutualAuthRequested, which applies to the https scheme
|
||||
Write-Verbose -Message ($script:localizedData.SettingAuthenticationLevel)
|
||||
$webRequest.AuthenticationLevel = [System.Net.Security.AuthenticationLevel]::None
|
||||
}
|
||||
elseif ($uriScheme -eq 'https' -and -not [String]::IsNullOrEmpty($ServerCertificateValidationCallback))
|
||||
elseif ($uriScheme -eq 'https' -and -not [System.String]::IsNullOrEmpty($ServerCertificateValidationCallback))
|
||||
{
|
||||
Write-Verbose -Message $script:localizedData.SettingCertificateValidationCallback
|
||||
$webRequest.ServerCertificateValidationCallBack = (Get-ScriptBlock -FunctionName $ServerCertificateValidationCallback)
|
||||
}
|
||||
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.GettingTheSchemeResponseStream -f $uriScheme)
|
||||
$responseStream = Get-WebRequestResponseStream -WebRequest $webRequest
|
||||
|
||||
@@ -822,7 +822,7 @@ function Get-WebRequest
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[Uri]
|
||||
[System.Uri]
|
||||
$Uri
|
||||
)
|
||||
|
||||
@@ -848,7 +848,7 @@ function Get-WebRequestResponseStream
|
||||
$WebRequest
|
||||
)
|
||||
|
||||
return (([System.Net.HttpWebRequest]$WebRequest).GetResponse()).GetResponseStream()
|
||||
return (([System.Net.HttpWebRequest] $WebRequest).GetResponse()).GetResponseStream()
|
||||
}
|
||||
|
||||
<#
|
||||
@@ -861,16 +861,16 @@ function Get-WebRequestResponseStream
|
||||
#>
|
||||
function Get-ScriptBlock
|
||||
{
|
||||
[OutputType([ScriptBlock])]
|
||||
[OutputType([System.Management.Automation.ScriptBlock])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$FunctionName
|
||||
)
|
||||
|
||||
return [ScriptBlock]::Create($FunctionName)
|
||||
return [System.Management.Automation.ScriptBlock]::Create($FunctionName)
|
||||
}
|
||||
|
||||
<#
|
||||
@@ -959,32 +959,32 @@ function Assert-FileValid
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$FileHash,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$HashAlgorithm = 'SHA256',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$SignerThumbprint,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$SignerSubject
|
||||
)
|
||||
|
||||
if (-not [String]::IsNullOrEmpty($FileHash))
|
||||
if (-not [System.String]::IsNullOrEmpty($FileHash))
|
||||
{
|
||||
Assert-FileHashValid -Path $Path -Hash $FileHash -Algorithm $HashAlgorithm
|
||||
}
|
||||
|
||||
if (-not [String]::IsNullOrEmpty($SignerThumbprint) -or -not [String]::IsNullOrEmpty($SignerSubject))
|
||||
if (-not [System.String]::IsNullOrEmpty($SignerThumbprint) -or -not [System.String]::IsNullOrEmpty($SignerSubject))
|
||||
{
|
||||
Assert-FileSignatureValid -Path $Path -Thumbprint $SignerThumbprint -Subject $SignerSubject
|
||||
}
|
||||
@@ -1010,15 +1010,15 @@ function Assert-FileHashValid
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$Hash,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Algorithm = 'SHA256'
|
||||
)
|
||||
|
||||
@@ -1051,15 +1051,15 @@ function Assert-FileSignatureValid
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Thumbprint,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Subject
|
||||
)
|
||||
|
||||
@@ -1076,12 +1076,12 @@ function Assert-FileSignatureValid
|
||||
Write-Verbose -Message ($script:localizedData.FileHasValidSignature -f $Path, $signature.SignerCertificate.Thumbprint, $signature.SignerCertificate.Subject)
|
||||
}
|
||||
|
||||
if (-not [String]::IsNullOrEmpty($Subject) -and ($signature.SignerCertificate.Subject -notlike $Subject))
|
||||
if (-not [System.String]::IsNullOrEmpty($Subject) -and ($signature.SignerCertificate.Subject -notlike $Subject))
|
||||
{
|
||||
New-InvalidArgumentException -ArgumentName 'SignerSubject' -Message ($script:localizedData.WrongSignerSubject -f $Path, $Subject)
|
||||
}
|
||||
|
||||
if (-not [String]::IsNullOrEmpty($Thumbprint) -and ($signature.SignerCertificate.Thumbprint -ne $Thumbprint))
|
||||
if (-not [System.String]::IsNullOrEmpty($Thumbprint) -and ($signature.SignerCertificate.Thumbprint -ne $Thumbprint))
|
||||
{
|
||||
New-InvalidArgumentException -ArgumentName 'SignerThumbprint' -Message ($script:localizedData.WrongSignerThumbprint -f $Path, $Thumbprint)
|
||||
}
|
||||
@@ -1112,31 +1112,31 @@ function Assert-FileSignatureValid
|
||||
#>
|
||||
function Start-MsiProcess
|
||||
{
|
||||
[OutputType([Int32])]
|
||||
[OutputType([System.Int32])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$IdentifyingNumber,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Arguments,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath,
|
||||
|
||||
[Parameter()]
|
||||
@@ -1149,9 +1149,9 @@ function Start-MsiProcess
|
||||
|
||||
# Necessary for I/O redirection
|
||||
$startInfo.UseShellExecute = $false
|
||||
|
||||
|
||||
$startInfo.FileName = "$env:winDir\system32\msiexec.exe"
|
||||
|
||||
|
||||
if ($Ensure -eq 'Present')
|
||||
{
|
||||
$startInfo.Arguments = '/i "{0}"' -f $Path
|
||||
@@ -1160,31 +1160,31 @@ function Start-MsiProcess
|
||||
else
|
||||
{
|
||||
$productEntry = Get-ProductEntry -IdentifyingNumber $identifyingNumber
|
||||
|
||||
|
||||
$id = Split-Path -Path $productEntry.Name -Leaf
|
||||
$startInfo.Arguments = ('/x{0}' -f $id)
|
||||
}
|
||||
|
||||
if (-not [String]::IsNullOrEmpty($LogPath))
|
||||
|
||||
if (-not [System.String]::IsNullOrEmpty($LogPath))
|
||||
{
|
||||
$startInfo.Arguments += (' /log "{0}"' -f $LogPath)
|
||||
}
|
||||
|
||||
|
||||
$startInfo.Arguments += ' /quiet /norestart'
|
||||
|
||||
if (-not [String]::IsNullOrEmpty($Arguments))
|
||||
|
||||
if (-not [System.String]::IsNullOrEmpty($Arguments))
|
||||
{
|
||||
# Append any specified arguments with a space
|
||||
$startInfo.Arguments += (' {0}' -f $Arguments)
|
||||
}
|
||||
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.StartingWithStartInfoFileNameStartInfoArguments -f $startInfo.FileName, $startInfo.Arguments)
|
||||
|
||||
|
||||
$exitCode = 0
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if (-not [String]::IsNullOrEmpty($RunAsCredential))
|
||||
if (-not [System.String]::IsNullOrEmpty($RunAsCredential))
|
||||
{
|
||||
$commandLine = ('"{0}" {1}' -f $startInfo.FileName, $startInfo.Arguments)
|
||||
$exitCode = Invoke-PInvoke -CommandLine $commandLine -RunAsCredential $RunAsCredential
|
||||
@@ -1222,7 +1222,7 @@ function Invoke-PInvoke
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$CommandLine,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
@@ -1277,13 +1277,13 @@ function Invoke-Process
|
||||
#>
|
||||
function Get-MsiProductCode
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path
|
||||
)
|
||||
|
||||
@@ -1349,7 +1349,7 @@ function Get-MsiTool
|
||||
return GetPackageProperty(msi, "ProductName");
|
||||
}
|
||||
'@
|
||||
|
||||
|
||||
# Check if the the type is already defined
|
||||
if (([System.Management.Automation.PSTypeName]'Microsoft.Windows.DesiredStateConfiguration.MsiPackageResource.MsiTools').Type)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Localized resources for MSFT_MsiPackage
|
||||
# Localized resources for MSFT_MsiPackage
|
||||
|
||||
ConvertFrom-StringData @'
|
||||
CheckingFileHash = Checking file '{0}' for expected {2} hash value of {1}
|
||||
|
||||
@@ -39,27 +39,27 @@ $script:registryDriveRoots = @{
|
||||
function Get-TargetResource
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([Hashtable])]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Key,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[String]
|
||||
[System.String]
|
||||
[AllowEmptyString()]
|
||||
$ValueName,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$ValueData,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('String', 'Binary', 'DWord', 'QWord', 'MultiString', 'ExpandString')]
|
||||
[String]
|
||||
[System.String]
|
||||
$ValueType
|
||||
)
|
||||
|
||||
@@ -86,7 +86,7 @@ function Get-TargetResource
|
||||
Write-Verbose -Message ($script:localizedData.RegistryKeyExists -f $Key)
|
||||
|
||||
# Check if the user specified a value name to retrieve
|
||||
$valueNameSpecified = (-not [String]::IsNullOrEmpty($ValueName)) -or $PSBoundParameters.ContainsKey('ValueType') -or $PSBoundParameters.ContainsKey('ValueData')
|
||||
$valueNameSpecified = (-not [System.String]::IsNullOrEmpty($ValueName)) -or $PSBoundParameters.ContainsKey('ValueType') -or $PSBoundParameters.ContainsKey('ValueData')
|
||||
|
||||
if ($valueNameSpecified)
|
||||
{
|
||||
@@ -144,10 +144,10 @@ function Get-TargetResource
|
||||
|
||||
.PARAMETER Ensure
|
||||
Specifies whether or not the registry key with the given path and the registry key value with the given name should exist.
|
||||
|
||||
|
||||
To ensure that the registry key and value exists, set this property to Present.
|
||||
To ensure that the registry key and value do not exist, set this property to Absent.
|
||||
|
||||
|
||||
The default value is Present.
|
||||
|
||||
.PARAMETER ValueData
|
||||
@@ -155,7 +155,7 @@ function Get-TargetResource
|
||||
|
||||
.PARAMETER ValueType
|
||||
The type of the value to set.
|
||||
|
||||
|
||||
The supported types are:
|
||||
String (REG_SZ)
|
||||
Binary (REG-BINARY)
|
||||
@@ -169,12 +169,12 @@ function Get-TargetResource
|
||||
|
||||
If specified, DWORD/QWORD value data is presented in hexadecimal format.
|
||||
Not valid for other value types.
|
||||
|
||||
|
||||
The default value is $false.
|
||||
|
||||
.PARAMETER Force
|
||||
Specifies whether or not to overwrite the registry key with the given path with the new
|
||||
value if it is already present.
|
||||
value if it is already present.
|
||||
#>
|
||||
function Set-TargetResource
|
||||
{
|
||||
@@ -183,36 +183,36 @@ function Set-TargetResource
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Key,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[String]
|
||||
[System.String]
|
||||
[AllowEmptyString()]
|
||||
$ValueName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNull()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$ValueData = @(),
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('String', 'Binary', 'DWord', 'QWord', 'MultiString', 'ExpandString')]
|
||||
[String]
|
||||
[System.String]
|
||||
$ValueType = 'String',
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Hex = $false,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Force = $false
|
||||
)
|
||||
|
||||
@@ -239,7 +239,7 @@ function Set-TargetResource
|
||||
{
|
||||
Write-Verbose -Message ($script:localizedData.RegistryKeyExists -f $Key)
|
||||
|
||||
$valueNameSpecified = (-not [String]::IsNullOrEmpty($ValueName)) -or $PSBoundParameters.ContainsKey('ValueType') -or $PSBoundParameters.ContainsKey('ValueData')
|
||||
$valueNameSpecified = (-not [System.String]::IsNullOrEmpty($ValueName)) -or $PSBoundParameters.ContainsKey('ValueType') -or $PSBoundParameters.ContainsKey('ValueData')
|
||||
|
||||
# Check if the user wants to set a registry key value
|
||||
if ($valueNameSpecified)
|
||||
@@ -295,7 +295,7 @@ function Set-TargetResource
|
||||
Write-Verbose -Message ($script:localizedData.OverwritingRegistryKeyValue -f $valueDisplayName, $Key)
|
||||
$null = Set-RegistryKeyValue -RegistryKeyName $registryKeyName -RegistryKeyValueName $ValueName -RegistryKeyValue $expectedRegistryKeyValue -ValueType $ValueType
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -304,9 +304,9 @@ function Set-TargetResource
|
||||
if ($null -ne $actualRegistryKeyValue)
|
||||
{
|
||||
Write-Verbose -Message ($script:localizedData.RemovingRegistryKeyValue -f $valueDisplayName, $Key)
|
||||
|
||||
|
||||
# If the specified registry key value exists, check if the user specified a registry key value with a name to remove
|
||||
if (-not [String]::IsNullOrEmpty($ValueName))
|
||||
if (-not [System.String]::IsNullOrEmpty($ValueName))
|
||||
{
|
||||
# If the user specified a registry key value with a name to remove, remove the registry key value with the specified name
|
||||
$null = Remove-ItemProperty -Path $Key -Name $ValueName -Force
|
||||
@@ -359,7 +359,7 @@ function Set-TargetResource
|
||||
|
||||
.PARAMETER Ensure
|
||||
Specifies whether or not the registry key and value should exist.
|
||||
|
||||
|
||||
To test that they exist, set this property to "Present".
|
||||
To test that they do not exist, set the property to "Absent".
|
||||
The default value is "Present".
|
||||
@@ -369,7 +369,7 @@ function Set-TargetResource
|
||||
|
||||
.PARAMETER ValueType
|
||||
The type of the value.
|
||||
|
||||
|
||||
The supported types are:
|
||||
String (REG_SZ)
|
||||
Binary (REG-BINARY)
|
||||
@@ -387,41 +387,41 @@ function Set-TargetResource
|
||||
function Test-TargetResource
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Key,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[AllowEmptyString()]
|
||||
[ValidateNotNull()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ValueName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNull()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$ValueData = @(),
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('String', 'Binary', 'DWord', 'QWord', 'MultiString', 'ExpandString')]
|
||||
[String]
|
||||
[System.String]
|
||||
$ValueType = 'String',
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Hex = $false,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Force = $false
|
||||
)
|
||||
|
||||
@@ -447,7 +447,7 @@ function Test-TargetResource
|
||||
$registryResource = Get-TargetResource @getTargetResourceParameters
|
||||
|
||||
# Check if the user specified a value name to retrieve
|
||||
$valueNameSpecified = (-not [String]::IsNullOrEmpty($ValueName)) -or $PSBoundParameters.ContainsKey('ValueType') -or $PSBoundParameters.ContainsKey('ValueData')
|
||||
$valueNameSpecified = (-not [System.String]::IsNullOrEmpty($ValueName)) -or $PSBoundParameters.ContainsKey('ValueType') -or $PSBoundParameters.ContainsKey('ValueData')
|
||||
|
||||
if ($valueNameSpecified)
|
||||
{
|
||||
@@ -542,13 +542,13 @@ function Test-TargetResource
|
||||
#>
|
||||
function Get-PathRoot
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path
|
||||
)
|
||||
|
||||
@@ -572,13 +572,13 @@ function Get-PathRoot
|
||||
#>
|
||||
function ConvertTo-RegistryDriveName
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$RegistryDriveRoot
|
||||
)
|
||||
|
||||
@@ -608,13 +608,13 @@ function ConvertTo-RegistryDriveName
|
||||
#>
|
||||
function Get-RegistryDriveName
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$RegistryKeyPath
|
||||
)
|
||||
|
||||
@@ -634,7 +634,7 @@ function Get-RegistryDriveName
|
||||
{
|
||||
$registryDriveName = ConvertTo-RegistryDriveName -RegistryDriveRoot $registryKeyPathRoot
|
||||
|
||||
if ([String]::IsNullOrEmpty($registryDriveName))
|
||||
if ([System.String]::IsNullOrEmpty($registryDriveName))
|
||||
{
|
||||
New-InvalidArgumentException -ArgumentName 'Key' -Message ($script:localizedData.InvalidRegistryDrive -f $registryKeyPathRoot)
|
||||
}
|
||||
@@ -657,7 +657,7 @@ function Mount-RegistryDrive
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$RegistryDriveName
|
||||
)
|
||||
|
||||
@@ -707,12 +707,12 @@ function Open-RegistrySubKey
|
||||
$ParentKey,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
[AllowEmptyString()]
|
||||
$SubKey,
|
||||
|
||||
[Parameter()]
|
||||
[Switch]
|
||||
[System.Management.Automation.SwitchParameter]
|
||||
$WriteAccessAllowed
|
||||
)
|
||||
|
||||
@@ -744,11 +744,11 @@ function Get-RegistryKey
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$RegistryKeyPath,
|
||||
|
||||
[Parameter()]
|
||||
[Switch]
|
||||
[System.Management.Automation.SwitchParameter]
|
||||
$WriteAccessAllowed
|
||||
)
|
||||
|
||||
@@ -788,20 +788,20 @@ function Get-RegistryKey
|
||||
#>
|
||||
function Get-RegistryKeyValueDisplayName
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[AllowNull()]
|
||||
[AllowEmptyString()]
|
||||
[System.String]
|
||||
$RegistryKeyValueName
|
||||
)
|
||||
|
||||
$registryKeyValueDisplayName = $RegistryKeyValueName
|
||||
|
||||
if ([String]::IsNullOrEmpty($RegistryKeyValueName))
|
||||
if ([System.String]::IsNullOrEmpty($RegistryKeyValueName))
|
||||
{
|
||||
$registryKeyValueDisplayName = $script:localizedData.DefaultValueDisplayName
|
||||
}
|
||||
@@ -822,7 +822,7 @@ function Get-RegistryKeyValueDisplayName
|
||||
#>
|
||||
function Get-RegistryKeyValue
|
||||
{
|
||||
[OutputType([Object[]])]
|
||||
[OutputType([System.Object[]])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
@@ -832,8 +832,8 @@ function Get-RegistryKeyValue
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[String]
|
||||
[AllowEmptyString()]
|
||||
[System.String]
|
||||
$RegistryKeyValueName
|
||||
)
|
||||
|
||||
@@ -856,7 +856,7 @@ function Get-RegistryKeyValue
|
||||
#>
|
||||
function Get-RegistryKeyValueType
|
||||
{
|
||||
[OutputType([Type])]
|
||||
[OutputType([System.Type])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
@@ -866,8 +866,8 @@ function Get-RegistryKeyValueType
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[String]
|
||||
[AllowEmptyString()]
|
||||
[System.String]
|
||||
$RegistryKeyValueName
|
||||
)
|
||||
|
||||
@@ -883,14 +883,14 @@ function Get-RegistryKeyValueType
|
||||
#>
|
||||
function Convert-ByteArrayToHexString
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[Object[]]
|
||||
[AllowEmptyCollection()]
|
||||
[System.Object[]]
|
||||
$ByteArray
|
||||
)
|
||||
|
||||
@@ -916,23 +916,23 @@ function Convert-ByteArrayToHexString
|
||||
#>
|
||||
function ConvertTo-ReadableString
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[Object[]]
|
||||
[AllowNull()]
|
||||
[AllowEmptyCollection()]
|
||||
[System.Object[]]
|
||||
$RegistryKeyValue,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('String', 'Binary', 'DWord', 'QWord', 'MultiString', 'ExpandString')]
|
||||
[String]
|
||||
[System.String]
|
||||
$RegistryKeyValueType
|
||||
)
|
||||
|
||||
$registryKeyValueAsString = [String]::Empty
|
||||
$registryKeyValueAsString = [System.String]::Empty
|
||||
|
||||
if ($null -ne $RegistryKeyValue)
|
||||
{
|
||||
@@ -941,13 +941,13 @@ function ConvertTo-ReadableString
|
||||
{
|
||||
$RegistryKeyValue = Convert-ByteArrayToHexString -ByteArray $RegistryKeyValue
|
||||
}
|
||||
|
||||
|
||||
if ($RegistryKeyValueType -ne 'MultiString')
|
||||
{
|
||||
$RegistryKeyValue = [String[]]@() + $RegistryKeyValue
|
||||
$RegistryKeyValue = [System.String[]] @() + $RegistryKeyValue
|
||||
}
|
||||
|
||||
if ($RegistryKeyValue.Count -eq 1 -and -not [String]::IsNullOrEmpty($RegistryKeyValue[0]))
|
||||
if ($RegistryKeyValue.Count -eq 1 -and -not [System.String]::IsNullOrEmpty($RegistryKeyValue[0]))
|
||||
{
|
||||
$registryKeyValueAsString = $RegistryKeyValue[0].ToString()
|
||||
}
|
||||
@@ -983,7 +983,7 @@ function New-RegistrySubKey
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$SubKeyName
|
||||
)
|
||||
|
||||
@@ -1006,7 +1006,7 @@ function New-RegistryKey
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$RegistryKeyPath
|
||||
)
|
||||
|
||||
@@ -1038,7 +1038,7 @@ function New-RegistryKey
|
||||
#>
|
||||
function Get-RegistryKeyName
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
@@ -1059,14 +1059,14 @@ function Get-RegistryKeyName
|
||||
#>
|
||||
function ConvertTo-Binary
|
||||
{
|
||||
[OutputType([Byte[]])]
|
||||
[OutputType([System.Byte[]])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter()]
|
||||
[AllowNull()]
|
||||
[String[]]
|
||||
[AllowEmptyCollection()]
|
||||
[System.String[]]
|
||||
$RegistryKeyValue
|
||||
)
|
||||
|
||||
@@ -1075,9 +1075,9 @@ function ConvertTo-Binary
|
||||
New-InvalidArgumentException -ArgumentName 'ValueData' -Message ($script:localizedData.ArrayNotAllowedForExpectedType -f 'Binary')
|
||||
}
|
||||
|
||||
$binaryRegistryKeyValue = [Byte[]] @()
|
||||
$binaryRegistryKeyValue = [System.Byte[]] @()
|
||||
|
||||
if (($null -ne $RegistryKeyValue) -and ($RegistryKeyValue.Count -eq 1) -and (-not [String]::IsNullOrEmpty($RegistryKeyValue[0])))
|
||||
if (($null -ne $RegistryKeyValue) -and ($RegistryKeyValue.Count -eq 1) -and (-not [System.String]::IsNullOrEmpty($RegistryKeyValue[0])))
|
||||
{
|
||||
$singleRegistryKeyValue = $RegistryKeyValue[0]
|
||||
|
||||
@@ -1095,7 +1095,7 @@ function ConvertTo-Binary
|
||||
{
|
||||
for ($singleRegistryKeyValueIndex = 0 ; $singleRegistryKeyValueIndex -lt ($singleRegistryKeyValue.Length - 1) ; $singleRegistryKeyValueIndex = $singleRegistryKeyValueIndex + 2)
|
||||
{
|
||||
$binaryRegistryKeyValue += [Byte]::Parse($singleRegistryKeyValue.Substring($singleRegistryKeyValueIndex, 2), 'HexNumber')
|
||||
$binaryRegistryKeyValue += [System.Byte]::Parse($singleRegistryKeyValue.Substring($singleRegistryKeyValueIndex, 2), 'HexNumber')
|
||||
}
|
||||
}
|
||||
catch
|
||||
@@ -1122,12 +1122,12 @@ function ConvertTo-DWord
|
||||
(
|
||||
[Parameter()]
|
||||
[AllowNull()]
|
||||
[String[]]
|
||||
[AllowEmptyCollection()]
|
||||
[System.String[]]
|
||||
$RegistryKeyValue,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Hex = $false
|
||||
)
|
||||
|
||||
@@ -1138,7 +1138,7 @@ function ConvertTo-DWord
|
||||
|
||||
$dwordRegistryKeyValue = [System.Int32] 0
|
||||
|
||||
if (($null -ne $RegistryKeyValue) -and ($RegistryKeyValue.Count -eq 1) -and (-not [String]::IsNullOrEmpty($RegistryKeyValue[0])))
|
||||
if (($null -ne $RegistryKeyValue) -and ($RegistryKeyValue.Count -eq 1) -and (-not [System.String]::IsNullOrEmpty($RegistryKeyValue[0])))
|
||||
{
|
||||
$singleRegistryKeyValue = $RegistryKeyValue[0]
|
||||
|
||||
@@ -1152,7 +1152,7 @@ function ConvertTo-DWord
|
||||
$currentCultureInfo = [System.Globalization.CultureInfo]::CurrentCulture
|
||||
$referenceValue = $null
|
||||
|
||||
if ([System.Int32]::TryParse($singleRegistryKeyValue, 'HexNumber', $currentCultureInfo, [Ref] $referenceValue))
|
||||
if ([System.Int32]::TryParse($singleRegistryKeyValue, 'HexNumber', $currentCultureInfo, [ref] $referenceValue))
|
||||
{
|
||||
$dwordRegistryKeyValue = $referenceValue
|
||||
}
|
||||
@@ -1179,22 +1179,22 @@ function ConvertTo-DWord
|
||||
#>
|
||||
function ConvertTo-MultiString
|
||||
{
|
||||
[OutputType([String[]])]
|
||||
[OutputType([System.String[]])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter()]
|
||||
[AllowNull()]
|
||||
[String[]]
|
||||
[AllowEmptyCollection()]
|
||||
[System.String[]]
|
||||
$RegistryKeyValue
|
||||
)
|
||||
|
||||
$multiStringRegistryKeyValue = [String[]] @()
|
||||
$multiStringRegistryKeyValue = [System.String[]] @()
|
||||
|
||||
if (($null -ne $RegistryKeyValue) -and ($RegistryKeyValue.Length -gt 0))
|
||||
{
|
||||
$multiStringRegistryKeyValue = [String[]]$RegistryKeyValue
|
||||
$multiStringRegistryKeyValue = [System.String[]] $RegistryKeyValue
|
||||
}
|
||||
|
||||
return $multiStringRegistryKeyValue
|
||||
@@ -1215,12 +1215,12 @@ function ConvertTo-QWord
|
||||
(
|
||||
[Parameter()]
|
||||
[AllowNull()]
|
||||
[String[]]
|
||||
[AllowEmptyCollection()]
|
||||
[System.String[]]
|
||||
$RegistryKeyValue,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Hex = $false
|
||||
)
|
||||
|
||||
@@ -1231,7 +1231,7 @@ function ConvertTo-QWord
|
||||
|
||||
$qwordRegistryKeyValue = [System.Int64] 0
|
||||
|
||||
if (($null -ne $RegistryKeyValue) -and ($RegistryKeyValue.Count -eq 1) -and (-not [String]::IsNullOrEmpty($RegistryKeyValue[0])))
|
||||
if (($null -ne $RegistryKeyValue) -and ($RegistryKeyValue.Count -eq 1) -and (-not [System.String]::IsNullOrEmpty($RegistryKeyValue[0])))
|
||||
{
|
||||
$singleRegistryKeyValue = $RegistryKeyValue[0]
|
||||
|
||||
@@ -1245,7 +1245,7 @@ function ConvertTo-QWord
|
||||
$currentCultureInfo = [System.Globalization.CultureInfo]::CurrentCulture
|
||||
$referenceValue = $null
|
||||
|
||||
if ([System.Int64]::TryParse($singleRegistryKeyValue, 'HexNumber', $currentCultureInfo, [Ref] $referenceValue))
|
||||
if ([System.Int64]::TryParse($singleRegistryKeyValue, 'HexNumber', $currentCultureInfo, [ref] $referenceValue))
|
||||
{
|
||||
$qwordRegistryKeyValue = $referenceValue
|
||||
}
|
||||
@@ -1272,14 +1272,14 @@ function ConvertTo-QWord
|
||||
#>
|
||||
function ConvertTo-String
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter()]
|
||||
[AllowNull()]
|
||||
[String[]]
|
||||
[AllowEmptyCollection()]
|
||||
[System.String[]]
|
||||
$RegistryKeyValue
|
||||
)
|
||||
|
||||
@@ -1288,11 +1288,11 @@ function ConvertTo-String
|
||||
New-InvalidArgumentException -ArgumentName 'ValueData' -Message ($script:localizedData.ArrayNotAllowedForExpectedType -f 'String or ExpandString')
|
||||
}
|
||||
|
||||
$registryKeyValueAsString = [String]::Empty
|
||||
$registryKeyValueAsString = [System.String]::Empty
|
||||
|
||||
if (($null -ne $RegistryKeyValue) -and ($RegistryKeyValue.Count -eq 1))
|
||||
{
|
||||
$registryKeyValueAsString = [String]$RegistryKeyValue[0]
|
||||
$registryKeyValueAsString = [System.String] $RegistryKeyValue[0]
|
||||
}
|
||||
|
||||
return $registryKeyValueAsString
|
||||
@@ -1322,33 +1322,33 @@ function Set-RegistryKeyValue
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$RegistryKeyName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[String]
|
||||
[AllowEmptyString()]
|
||||
[System.String]
|
||||
$RegistryKeyValueName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[Object]
|
||||
[AllowNull()]
|
||||
[System.Object]
|
||||
$RegistryKeyValue,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('String', 'Binary', 'DWord', 'QWord', 'MultiString', 'ExpandString')]
|
||||
[String]
|
||||
[System.String]
|
||||
$ValueType
|
||||
)
|
||||
|
||||
if ($ValueType -eq 'Binary')
|
||||
{
|
||||
$RegistryKeyValue = [Byte[]]$RegistryKeyValue
|
||||
$RegistryKeyValue = [System.Byte[]] $RegistryKeyValue
|
||||
}
|
||||
elseif ($ValueType -eq 'MultiString')
|
||||
{
|
||||
$RegistryKeyValue = [String[]]$RegistryKeyValue
|
||||
$RegistryKeyValue = [System.String[]] $RegistryKeyValue
|
||||
}
|
||||
|
||||
$null = [Microsoft.Win32.Registry]::SetValue($RegistryKeyName, $RegistryKeyValueName, $RegistryKeyValue, $ValueType)
|
||||
@@ -1369,23 +1369,23 @@ function Set-RegistryKeyValue
|
||||
#>
|
||||
function Test-RegistryKeyValuesMatch
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[Object]
|
||||
[AllowNull()]
|
||||
[System.Object]
|
||||
$ExpectedRegistryKeyValue,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[Object]
|
||||
[AllowNull()]
|
||||
[System.Object]
|
||||
$ActualRegistryKeyValue,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('String', 'Binary', 'DWord', 'QWord', 'MultiString', 'ExpandString')]
|
||||
[String]
|
||||
[System.String]
|
||||
$RegistryKeyValueType
|
||||
)
|
||||
|
||||
@@ -1427,9 +1427,9 @@ function Test-RegistryKeyValuesMatch
|
||||
.SYNOPSIS
|
||||
Removes the default value of the specified registry key.
|
||||
This is a wrapper function for unit testing.
|
||||
|
||||
|
||||
.PARAMETER RegistryKey
|
||||
The registry key to remove the default value of.
|
||||
The registry key to remove the default value of.
|
||||
#>
|
||||
function Remove-DefaultRegistryKeyValue
|
||||
{
|
||||
@@ -1454,7 +1454,7 @@ function Remove-DefaultRegistryKeyValue
|
||||
#>
|
||||
function Get-RegistryKeySubKeyCount
|
||||
{
|
||||
[OutputType([Int])]
|
||||
[OutputType([System.Int32])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
|
||||
@@ -26,25 +26,25 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_ScriptResource'
|
||||
.PARAMETER Credential
|
||||
The Credential to run the get script under if needed.
|
||||
#>
|
||||
function Get-TargetResource
|
||||
function Get-TargetResource
|
||||
{
|
||||
[OutputType([Hashtable])]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$GetScript,
|
||||
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$SetScript,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$TestScript,
|
||||
|
||||
[Parameter()]
|
||||
@@ -55,9 +55,9 @@ function Get-TargetResource
|
||||
)
|
||||
|
||||
Write-Verbose -Message $script:localizedData.GetTargetResourceStartVerboseMessage
|
||||
|
||||
|
||||
$invokeScriptParameters = @{
|
||||
ScriptBlock = [ScriptBlock]::Create($GetScript)
|
||||
ScriptBlock = [System.Management.Automation.ScriptBlock]::Create($GetScript)
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('Credential'))
|
||||
@@ -72,7 +72,7 @@ function Get-TargetResource
|
||||
New-InvalidOperationException -Message $script:localizedData.GetScriptThrewError -ErrorRecord $invokeScriptResult
|
||||
}
|
||||
|
||||
$invokeScriptResultAsHashTable = $invokeScriptResult -as [Hashtable]
|
||||
$invokeScriptResultAsHashTable = $invokeScriptResult -as [System.Collections.Hashtable]
|
||||
|
||||
if ($null -eq $invokeScriptResultAsHashTable)
|
||||
{
|
||||
@@ -101,24 +101,24 @@ function Get-TargetResource
|
||||
.PARAMETER Credential
|
||||
The Credential to run the set script under if needed.
|
||||
#>
|
||||
function Set-TargetResource
|
||||
function Set-TargetResource
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$GetScript,
|
||||
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$SetScript,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$TestScript,
|
||||
|
||||
[Parameter()]
|
||||
@@ -131,7 +131,7 @@ function Set-TargetResource
|
||||
Write-Verbose -Message $script:localizedData.SetTargetResourceStartVerboseMessage
|
||||
|
||||
$invokeScriptParameters = @{
|
||||
ScriptBlock = [ScriptBlock]::Create($SetScript)
|
||||
ScriptBlock = [System.Management.Automation.ScriptBlock]::Create($SetScript)
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('Credential'))
|
||||
@@ -166,25 +166,25 @@ function Set-TargetResource
|
||||
.PARAMETER Credential
|
||||
The Credential to run the test script under if needed.
|
||||
#>
|
||||
function Test-TargetResource
|
||||
function Test-TargetResource
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$GetScript,
|
||||
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$SetScript,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$TestScript,
|
||||
|
||||
[Parameter()]
|
||||
@@ -197,7 +197,7 @@ function Test-TargetResource
|
||||
Write-Verbose -Message $script:localizedData.TestTargetResourceStartVerboseMessage
|
||||
|
||||
$invokeScriptParameters = @{
|
||||
ScriptBlock = [ScriptBlock]::Create($TestScript)
|
||||
ScriptBlock = [System.Management.Automation.ScriptBlock]::Create($TestScript)
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('Credential'))
|
||||
@@ -208,7 +208,7 @@ function Test-TargetResource
|
||||
$invokeScriptResult = Invoke-Script @invokeScriptParameters
|
||||
|
||||
# If the script is returing multiple objects, then we consider the last object to be the result of the script execution.
|
||||
if ($invokeScriptResult -is [Object[]] -and $invokeScriptResult.Count -gt 0)
|
||||
if ($invokeScriptResult -is [System.Object[]] -and $invokeScriptResult.Count -gt 0)
|
||||
{
|
||||
$invokeScriptResult = $invokeScriptResult[$invokeScriptResult.Count - 1]
|
||||
}
|
||||
@@ -218,7 +218,7 @@ function Test-TargetResource
|
||||
New-InvalidOperationException -Message $script:localizedData.TestScriptThrewError -ErrorRecord $invokeScriptResult
|
||||
}
|
||||
|
||||
if ($null -eq $invokeScriptResult -or -not ($invokeScriptResult -is [Boolean]))
|
||||
if ($null -eq $invokeScriptResult -or -not ($invokeScriptResult -is [System.Boolean]))
|
||||
{
|
||||
New-InvalidArgumentException -ArgumentName 'TestScript' -Message $script:localizedData.TestScriptDidNotReturnBoolean
|
||||
}
|
||||
@@ -243,14 +243,14 @@ function Test-TargetResource
|
||||
#>
|
||||
function Invoke-Script
|
||||
{
|
||||
[OutputType([Object])]
|
||||
[OutputType([System.Object])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ScriptBlock]
|
||||
[System.Management.Automation.ScriptBlock]
|
||||
$ScriptBlock,
|
||||
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNull()]
|
||||
[System.Management.Automation.PSCredential]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Localized MSFT_ScriptResource.strings.psd1
|
||||
# Localized MSFT_ScriptResource.strings.psd1
|
||||
|
||||
ConvertFrom-StringData @'
|
||||
GetTargetResourceStartVerboseMessage = Begin executing get script.
|
||||
|
||||
@@ -27,13 +27,13 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_ServiceResource'
|
||||
#>
|
||||
function Get-TargetResource
|
||||
{
|
||||
[OutputType([Hashtable])]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name
|
||||
)
|
||||
|
||||
@@ -60,7 +60,7 @@ function Get-TargetResource
|
||||
'NT Authority\LocalService' { 'LocalService'; break }
|
||||
default { $serviceCimInstance.StartName }
|
||||
}
|
||||
|
||||
|
||||
$serviceResource = @{
|
||||
Name = $Name
|
||||
Ensure = 'Present'
|
||||
@@ -71,7 +71,7 @@ function Get-TargetResource
|
||||
DisplayName = $service.DisplayName
|
||||
Description = $serviceCimInstance.Description
|
||||
DesktopInteract = $serviceCimInstance.DesktopInteract
|
||||
Dependencies = $dependencies
|
||||
Dependencies = $dependencies
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -99,7 +99,7 @@ function Get-TargetResource
|
||||
|
||||
.PARAMETER Ensure
|
||||
Specifies whether the service should exist or not.
|
||||
|
||||
|
||||
Set this property to Present to create or modify a service.
|
||||
Set this property to Absent to delete a service.
|
||||
|
||||
@@ -168,7 +168,7 @@ function Get-TargetResource
|
||||
Here are the paths through which Set-TargetResource calls Invoke-CimMethod:
|
||||
|
||||
Set-TargetResource --> Set-ServicePath --> Invoke-CimMethod
|
||||
--> Set-ServiceProperty --> Set-ServiceDependencies --> Invoke-CimMethod
|
||||
--> Set-ServiceProperty --> Set-ServiceDependency --> Invoke-CimMethod
|
||||
--> Set-ServiceAccountProperty --> Invoke-CimMethod
|
||||
--> Set-ServiceStartupType --> Invoke-CimMethod
|
||||
#>
|
||||
@@ -179,59 +179,59 @@ function Set-TargetResource
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Automatic', 'Manual', 'Disabled')]
|
||||
[String]
|
||||
[System.String]
|
||||
$StartupType,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('LocalSystem', 'LocalService', 'NetworkService')]
|
||||
[String]
|
||||
[System.String]
|
||||
$BuiltInAccount,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Running', 'Stopped', 'Ignore')]
|
||||
[String]
|
||||
[System.String]
|
||||
$State = 'Running',
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$DesktopInteract = $false,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$DisplayName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Description,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
[AllowEmptyCollection()]
|
||||
$Dependencies,
|
||||
|
||||
[Parameter()]
|
||||
[UInt32]
|
||||
[System.UInt32]
|
||||
$StartupTimeout = 30000,
|
||||
|
||||
[Parameter()]
|
||||
[UInt32]
|
||||
[System.UInt32]
|
||||
$TerminateTimeout = 30000,
|
||||
|
||||
[Parameter()]
|
||||
@@ -306,7 +306,7 @@ function Set-TargetResource
|
||||
$setServicePropertyParameters[$servicePropertyParameterName] = $PSBoundParameters[$servicePropertyParameterName]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($setServicePropertyParameters.Count -gt 0)
|
||||
{
|
||||
Write-Verbose -Message ($script:localizedData.EditingServiceProperties -f $Name)
|
||||
@@ -337,14 +337,14 @@ function Set-TargetResource
|
||||
|
||||
.PARAMETER Name
|
||||
The name of the service to test.
|
||||
|
||||
|
||||
This may be different from the service's display name.
|
||||
To retrieve a list of all services with their names and current states, use the Get-Service
|
||||
cmdlet.
|
||||
|
||||
.PARAMETER Ensure
|
||||
Specifies whether the service should exist or not.
|
||||
|
||||
|
||||
Set this property to Present to test if a service exists.
|
||||
Set this property to Absent to test if a service does not exist.
|
||||
|
||||
@@ -396,65 +396,65 @@ function Set-TargetResource
|
||||
#>
|
||||
function Test-TargetResource
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Automatic', 'Manual', 'Disabled')]
|
||||
[String]
|
||||
[System.String]
|
||||
$StartupType,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('LocalSystem', 'LocalService', 'NetworkService')]
|
||||
[String]
|
||||
[System.String]
|
||||
$BuiltInAccount,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$DesktopInteract = $false,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Running', 'Stopped', 'Ignore')]
|
||||
[String]
|
||||
[System.String]
|
||||
$State = 'Running',
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNull()]
|
||||
[String]
|
||||
[System.String]
|
||||
$DisplayName,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
[AllowEmptyString()]
|
||||
$Description,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
[AllowEmptyCollection()]
|
||||
$Dependencies,
|
||||
|
||||
[Parameter()]
|
||||
[UInt32]
|
||||
[System.UInt32]
|
||||
$StartupTimeout = 30000,
|
||||
|
||||
[Parameter()]
|
||||
[UInt32]
|
||||
[System.UInt32]
|
||||
$TerminateTimeout = 30000,
|
||||
|
||||
[Parameter()]
|
||||
@@ -541,7 +541,7 @@ function Test-TargetResource
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Check the service desktop interation setting
|
||||
if ($PSBoundParameters.ContainsKey('DesktopInteract') -and $serviceResource.DesktopInteract -ine $DesktopInteract)
|
||||
{
|
||||
@@ -593,7 +593,7 @@ function Test-TargetResource
|
||||
#>
|
||||
function Get-ServiceCimInstance
|
||||
{
|
||||
[OutputType([CimInstance])]
|
||||
[OutputType([Microsoft.Management.Infrastructure.CimInstance])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
@@ -615,13 +615,13 @@ function Get-ServiceCimInstance
|
||||
#>
|
||||
function ConvertTo-StartupTypeString
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('Auto', 'Manual', 'Disabled')]
|
||||
[String]
|
||||
[System.String]
|
||||
$StartMode
|
||||
)
|
||||
|
||||
@@ -647,24 +647,24 @@ function ConvertTo-StartupTypeString
|
||||
.PARAMETER State
|
||||
The service state to check.
|
||||
#>
|
||||
function Assert-NoStartupTypeStateConflict
|
||||
function Assert-NoStartupTypeStateConflict
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ServiceName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('Automatic', 'Manual', 'Disabled')]
|
||||
[String]
|
||||
[System.String]
|
||||
$StartupType,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('Running', 'Stopped', 'Ignore')]
|
||||
[String]
|
||||
[System.String]
|
||||
$State
|
||||
)
|
||||
|
||||
@@ -700,22 +700,22 @@ function Assert-NoStartupTypeStateConflict
|
||||
#>
|
||||
function Test-PathsMatch
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ExpectedPath,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ActualPath
|
||||
)
|
||||
|
||||
return (0 -eq [String]::Compare($ExpectedPath, $ActualPath, [System.Globalization.CultureInfo]::CurrentUICulture))
|
||||
return (0 -eq [System.String]::Compare($ExpectedPath, $ActualPath, [System.Globalization.CultureInfo]::CurrentUICulture))
|
||||
}
|
||||
|
||||
<#
|
||||
@@ -728,13 +728,13 @@ function Test-PathsMatch
|
||||
#>
|
||||
function ConvertTo-StartName
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Username
|
||||
)
|
||||
|
||||
@@ -773,18 +773,18 @@ function ConvertTo-StartName
|
||||
#>
|
||||
function Set-ServicePath
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding(SupportsShouldProcess = $true)]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ServiceName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path
|
||||
)
|
||||
|
||||
@@ -814,7 +814,7 @@ function Set-ServicePath
|
||||
{
|
||||
$serviceChangePropertyString = $changeServiceArguments.Keys -join ', '
|
||||
$errorMessage = $script:localizedData.InvokeCimMethodFailed -f 'Change', $ServiceName, $serviceChangePropertyString, $changeServiceResult.ReturnValue
|
||||
New-InvalidArgumentException -ArgumentName 'Path' -Message $errorMessage
|
||||
New-InvalidArgumentException -ArgumentName 'Path' -Message $errorMessage
|
||||
}
|
||||
|
||||
return $true
|
||||
@@ -835,18 +835,18 @@ function Set-ServicePath
|
||||
SupportsShouldProcess is enabled because Invoke-CimMethod calls ShouldProcess.
|
||||
This function calls Invoke-CimMethod directly.
|
||||
#>
|
||||
function Set-ServiceDependencies
|
||||
function Set-ServiceDependency
|
||||
{
|
||||
[CmdletBinding(SupportsShouldProcess = $true)]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ServiceName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
[AllowEmptyCollection()]
|
||||
$Dependencies
|
||||
)
|
||||
@@ -910,7 +910,7 @@ function Grant-LogOnAsServiceRight
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Username
|
||||
)
|
||||
|
||||
@@ -940,7 +940,7 @@ function Grant-LogOnAsServiceRight
|
||||
private const int UNLEN = 256;
|
||||
private const int DNLEN = 15;
|
||||
|
||||
// Extra characteres for "\","@" etc.
|
||||
// Extra characteres for '\', '@' etc.
|
||||
private const int EXTRA_LENGTH = 3;
|
||||
#endregion constants
|
||||
|
||||
@@ -1335,11 +1335,11 @@ function Set-ServiceAccountProperty
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ServiceName,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
[ValidateSet('LocalSystem', 'LocalService', 'NetworkService')]
|
||||
$BuiltInAccount,
|
||||
|
||||
@@ -1349,7 +1349,7 @@ function Set-ServiceAccountProperty
|
||||
$Credential,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$DesktopInteract
|
||||
)
|
||||
|
||||
@@ -1422,12 +1422,12 @@ function Set-ServiceStartupType
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ServiceName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('Automatic', 'Manual', 'Disabled')]
|
||||
[String]
|
||||
[System.String]
|
||||
$StartupType
|
||||
)
|
||||
|
||||
@@ -1498,7 +1498,7 @@ function Set-ServiceStartupType
|
||||
SupportsShouldProcess is enabled because Invoke-CimMethod calls ShouldProcess.
|
||||
Here are the paths through which Set-ServiceProperty calls Invoke-CimMethod:
|
||||
|
||||
Set-ServiceProperty --> Set-ServiceDependencies --> Invoke-CimMethod
|
||||
Set-ServiceProperty --> Set-ServiceDependency --> Invoke-CimMethod
|
||||
--> Set-ServieceAccountProperty --> Invoke-CimMethod
|
||||
--> Set-ServiceStartupType --> Invoke-CimMethod
|
||||
#>
|
||||
@@ -1509,35 +1509,35 @@ function Set-ServiceProperty
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ServiceName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Automatic', 'Manual', 'Disabled')]
|
||||
[String]
|
||||
[System.String]
|
||||
$StartupType,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('LocalSystem', 'LocalService', 'NetworkService')]
|
||||
[String]
|
||||
[System.String]
|
||||
$BuiltInAccount,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$DesktopInteract,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$DisplayName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Description,
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
[AllowEmptyCollection()]
|
||||
$Dependencies,
|
||||
|
||||
@@ -1550,7 +1550,7 @@ function Set-ServiceProperty
|
||||
|
||||
# Update display name and/or description if needed
|
||||
$serviceCimInstance = Get-ServiceCimInstance -ServiceName $ServiceName
|
||||
|
||||
|
||||
$setServiceParameters = @{}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('DisplayName') -and $serviceCimInstance.DisplayName -ine $DisplayName)
|
||||
@@ -1571,7 +1571,7 @@ function Set-ServiceProperty
|
||||
# Update service dependencies if needed
|
||||
if ($PSBoundParameters.ContainsKey('Dependencies'))
|
||||
{
|
||||
Set-ServiceDependencies -ServiceName $ServiceName -Dependencies $Dependencies
|
||||
Set-ServiceDependency -ServiceName $ServiceName -Dependencies $Dependencies
|
||||
}
|
||||
|
||||
# Update service account properties if needed
|
||||
@@ -1619,7 +1619,7 @@ function Remove-Service
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name
|
||||
)
|
||||
|
||||
@@ -1643,20 +1643,20 @@ function Remove-ServiceWithTimeout
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[UInt32]
|
||||
[System.UInt32]
|
||||
$TerminateTimeout
|
||||
)
|
||||
|
||||
Remove-Service -Name $Name
|
||||
|
||||
$serviceDeleted = $false
|
||||
$start = [DateTime]::Now
|
||||
$start = [System.DateTime]::Now
|
||||
|
||||
while (-not $serviceDeleted -and ([DateTime]::Now - $start).TotalMilliseconds -lt $TerminateTimeout)
|
||||
while (-not $serviceDeleted -and ([System.DateTime]::Now - $start).TotalMilliseconds -lt $TerminateTimeout)
|
||||
{
|
||||
$service = Get-Service -Name $Name -ErrorAction 'SilentlyContinue'
|
||||
|
||||
@@ -1685,7 +1685,7 @@ function Remove-ServiceWithTimeout
|
||||
.SYNOPSIS
|
||||
Waits for the service with the given name to reach the given state within the given time
|
||||
span.
|
||||
|
||||
|
||||
This is a wrapper function for unit testing.
|
||||
|
||||
.PARAMETER ServiceName
|
||||
@@ -1704,7 +1704,7 @@ function Wait-ServiceStateWithTimeout
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ServiceName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
@@ -1712,7 +1712,7 @@ function Wait-ServiceStateWithTimeout
|
||||
$State,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[TimeSpan]
|
||||
[System.TimeSpan]
|
||||
$WaitTimeSpan
|
||||
)
|
||||
|
||||
@@ -1738,11 +1738,11 @@ function Start-ServiceWithTimeout
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ServiceName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[UInt32]
|
||||
[System.UInt32]
|
||||
$StartupTimeout
|
||||
)
|
||||
|
||||
@@ -1769,11 +1769,11 @@ function Stop-ServiceWithTimeout
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ServiceName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[UInt32]
|
||||
[System.UInt32]
|
||||
$TerminateTimeout
|
||||
)
|
||||
|
||||
|
||||
@@ -34,13 +34,13 @@ else
|
||||
#>
|
||||
function Get-TargetResource
|
||||
{
|
||||
[OutputType([Hashtable])]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$UserName
|
||||
)
|
||||
|
||||
@@ -57,7 +57,7 @@ function Get-TargetResource
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates, modifies, or deletes a user.
|
||||
|
||||
|
||||
.PARAMETER UserName
|
||||
The name of the user to create, modify, or delete.
|
||||
|
||||
@@ -91,30 +91,32 @@ function Get-TargetResource
|
||||
Specifies whether the user is allowed to change their password or not.
|
||||
By default this is set to $false
|
||||
|
||||
.NOTES
|
||||
.NOTES
|
||||
If Ensure is set to 'Present' then the password parameter is required.
|
||||
#>
|
||||
function Set-TargetResource
|
||||
{
|
||||
[CmdletBinding()]
|
||||
# Should process is called in a helper functions but not directly in Set-TargetResource
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '')]
|
||||
[CmdletBinding(SupportsShouldProcess = $true)]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$UserName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$FullName,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Description,
|
||||
|
||||
[Parameter()]
|
||||
@@ -124,19 +126,19 @@ function Set-TargetResource
|
||||
$Password,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Disabled,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordNeverExpires,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordChangeRequired,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordChangeNotAllowed
|
||||
)
|
||||
|
||||
@@ -186,26 +188,26 @@ function Set-TargetResource
|
||||
#>
|
||||
function Test-TargetResource
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$UserName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$FullName,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Description,
|
||||
|
||||
[Parameter()]
|
||||
@@ -215,19 +217,19 @@ function Test-TargetResource
|
||||
$Password,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Disabled,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordNeverExpires,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordChangeRequired,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordChangeNotAllowed
|
||||
)
|
||||
|
||||
@@ -251,13 +253,13 @@ function Test-TargetResource
|
||||
#>
|
||||
function Get-TargetResourceOnFullSKU
|
||||
{
|
||||
[OutputType([Hashtable])]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$UserName
|
||||
)
|
||||
|
||||
@@ -312,7 +314,7 @@ function Get-TargetResourceOnFullSKU
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates, modifies, or deletes a user when on a full server.
|
||||
|
||||
|
||||
.PARAMETER UserName
|
||||
The name of the user to create, modify, or delete.
|
||||
|
||||
@@ -346,30 +348,30 @@ function Get-TargetResourceOnFullSKU
|
||||
Specifies whether the user is allowed to change their password or not.
|
||||
By default this is set to $false
|
||||
|
||||
.NOTES
|
||||
.NOTES
|
||||
If Ensure is set to 'Present' then the Password parameter is required.
|
||||
#>
|
||||
function Set-TargetResourceOnFullSKU
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[CmdletBinding(SupportsShouldProcess = $true)]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$UserName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$FullName,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Description,
|
||||
|
||||
[Parameter()]
|
||||
@@ -379,19 +381,19 @@ function Set-TargetResourceOnFullSKU
|
||||
$Password,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Disabled,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordNeverExpires,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordChangeRequired,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordChangeNotAllowed
|
||||
)
|
||||
|
||||
@@ -410,7 +412,7 @@ function Set-TargetResourceOnFullSKU
|
||||
try
|
||||
{
|
||||
$user = Find-UserByNameOnFullSku -UserName $UserName
|
||||
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -456,7 +458,7 @@ function Set-TargetResourceOnFullSKU
|
||||
}
|
||||
elseif (-not $userExists)
|
||||
{
|
||||
<#
|
||||
<#
|
||||
For a newly created user, set the DisplayName property to an empty string
|
||||
since by default DisplayName is set to user's name.
|
||||
#>
|
||||
@@ -574,26 +576,26 @@ function Set-TargetResourceOnFullSKU
|
||||
#>
|
||||
function Test-TargetResourceOnFullSKU
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$UserName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$FullName,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Description,
|
||||
|
||||
[Parameter()]
|
||||
@@ -603,19 +605,19 @@ function Test-TargetResourceOnFullSKU
|
||||
$Password,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Disabled,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordNeverExpires,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordChangeRequired,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordChangeNotAllowed
|
||||
)
|
||||
|
||||
@@ -731,13 +733,13 @@ function Test-TargetResourceOnFullSKU
|
||||
#>
|
||||
function Get-TargetResourceOnNanoServer
|
||||
{
|
||||
[OutputType([Hashtable])]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$UserName
|
||||
)
|
||||
|
||||
@@ -793,7 +795,7 @@ function Get-TargetResourceOnNanoServer
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates, modifies, or deletes a user when on Nano Server.
|
||||
|
||||
|
||||
.PARAMETER UserName
|
||||
The name of the user to create, modify, or delete.
|
||||
|
||||
@@ -827,7 +829,7 @@ function Get-TargetResourceOnNanoServer
|
||||
Specifies whether the user is allowed to change their password or not.
|
||||
By default this is set to $false
|
||||
|
||||
.NOTES
|
||||
.NOTES
|
||||
If Ensure is set to 'Present' then the Password parameter is required.
|
||||
#>
|
||||
function Set-TargetResourceOnNanoServer
|
||||
@@ -836,20 +838,20 @@ function Set-TargetResourceOnNanoServer
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$UserName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$FullName,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Description,
|
||||
|
||||
[Parameter()]
|
||||
@@ -859,19 +861,19 @@ function Set-TargetResourceOnNanoServer
|
||||
$Password,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Disabled,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordNeverExpires,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordChangeRequired,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordChangeNotAllowed
|
||||
)
|
||||
|
||||
@@ -883,7 +885,7 @@ function Set-TargetResourceOnNanoServer
|
||||
|
||||
# Try to find a user by a name.
|
||||
$userExists = $false
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
$user = Find-UserByNameOnNanoServer -UserName $UserName
|
||||
@@ -965,12 +967,12 @@ function Set-TargetResourceOnNanoServer
|
||||
# NOTE: The parameter name and the property name have opposite meaning.
|
||||
$expected = (-not $PasswordChangeNotAllowed)
|
||||
$actual = $expected
|
||||
|
||||
|
||||
if ($userExists)
|
||||
{
|
||||
$actual = $user.UserMayChangePassword
|
||||
}
|
||||
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('PasswordChangeNotAllowed') -and ((-not $userExists) -or ($expected -ne $actual)))
|
||||
{
|
||||
Set-LocalUser -Name $UserName -UserMayChangePassword $expected
|
||||
@@ -1031,26 +1033,26 @@ function Set-TargetResourceOnNanoServer
|
||||
#>
|
||||
function Test-TargetResourceOnNanoServer
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$UserName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$FullName,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Description,
|
||||
|
||||
[Parameter()]
|
||||
@@ -1060,19 +1062,19 @@ function Test-TargetResourceOnNanoServer
|
||||
$Password,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Disabled,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordNeverExpires,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordChangeRequired,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$PasswordChangeNotAllowed
|
||||
)
|
||||
|
||||
@@ -1172,35 +1174,35 @@ function Assert-UserNameValid
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$UserName
|
||||
)
|
||||
|
||||
# Check if the name consists of only periods and/or white spaces
|
||||
$wrongName = $true
|
||||
|
||||
|
||||
for ($i = 0; $i -lt $UserName.Length; $i++)
|
||||
{
|
||||
if (-not [Char]::IsWhiteSpace($UserName, $i) -and $UserName[$i] -ne '.')
|
||||
if (-not [System.Char]::IsWhiteSpace($UserName, $i) -and $UserName[$i] -ne '.')
|
||||
{
|
||||
$wrongName = $false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
$invalidChars = @('\','/','"','[',']',':','|','<','>','+','=',';',',','?','*','@')
|
||||
$invalidChars = @('\', '/', '"', '[', ']', ':', '|', '<', '>', '+', '=', ';', ',', '?', '*', '@')
|
||||
|
||||
if ($wrongName)
|
||||
{
|
||||
New-InvalidArgumentException `
|
||||
-Message ($script:localizedData.InvalidUserName -f $UserName, [String]::Join(' ', $invalidChars)) `
|
||||
-Message ($script:localizedData.InvalidUserName -f $UserName, [System.String]::Join(' ', $invalidChars)) `
|
||||
-ArgumentName 'UserName'
|
||||
}
|
||||
|
||||
if ($UserName.IndexOfAny($invalidChars) -ne -1)
|
||||
{
|
||||
New-InvalidArgumentException `
|
||||
-Message ($script:localizedData.InvalidUserName -f $UserName, [String]::Join(' ', $invalidChars)) `
|
||||
-Message ($script:localizedData.InvalidUserName -f $UserName, [System.String]::Join(' ', $invalidChars)) `
|
||||
-ArgumentName 'UserName'
|
||||
}
|
||||
}
|
||||
@@ -1208,7 +1210,7 @@ function Assert-UserNameValid
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Tests the local user's credentials on the local machine.
|
||||
|
||||
|
||||
.PARAMETER UserName
|
||||
The username to validate the credentials of.
|
||||
|
||||
@@ -1217,18 +1219,18 @@ function Assert-UserNameValid
|
||||
#>
|
||||
function Test-CredentialsValidOnNanoServer
|
||||
{
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$UserName,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[SecureString]
|
||||
[System.Security.SecureString]
|
||||
$Password
|
||||
)
|
||||
|
||||
@@ -1314,7 +1316,7 @@ function Test-CredentialsValidOnNanoServer
|
||||
.SYNOPSIS
|
||||
Queries a user by the given username. If found the function returns a UserPrincipal object.
|
||||
Otherwise, the function returns $null.
|
||||
|
||||
|
||||
.PARAMETER UserName
|
||||
The username to search for.
|
||||
#>
|
||||
@@ -1342,7 +1344,7 @@ function Find-UserByNameOnFullSku
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Adds a user with the given username and returns the new user object
|
||||
|
||||
|
||||
.PARAMETER UserName
|
||||
The username for the new user
|
||||
#>
|
||||
@@ -1383,7 +1385,7 @@ function Add-UserOnFullSku
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sets the password for the given user
|
||||
|
||||
|
||||
.PARAMETER User
|
||||
The user to set the password for
|
||||
|
||||
@@ -1415,7 +1417,7 @@ function Set-UserPasswordOnFullSku
|
||||
.SYNOPSIS
|
||||
Validates the password is correct for the given user. Returns $true if the
|
||||
Password is correct for the given username, false otherwise.
|
||||
|
||||
|
||||
.PARAMETER UserName
|
||||
The UserName to check
|
||||
|
||||
@@ -1459,7 +1461,7 @@ function Test-UserPasswordOnFullSku
|
||||
.SYNOPSIS
|
||||
Queries a user by the given username. If found the function returns a UserPrincipal object.
|
||||
Otherwise, the function returns $null.
|
||||
|
||||
|
||||
.PARAMETER UserName
|
||||
The username to search for.
|
||||
#>
|
||||
@@ -1498,7 +1500,7 @@ function Remove-UserOnFullSku
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Saves changes for the given user on a machine.
|
||||
|
||||
|
||||
.PARAMETER User
|
||||
The user to save the changes of
|
||||
#>
|
||||
@@ -1519,7 +1521,7 @@ function Save-UserOnFullSku
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Expires the password of the given user.
|
||||
|
||||
|
||||
.PARAMETER User
|
||||
The user to expire the password of.
|
||||
#>
|
||||
@@ -1541,7 +1543,7 @@ function Revoke-UserPassword
|
||||
.SYNOPSIS
|
||||
Queries a user by the given username. If found the function returns a LocalUser object.
|
||||
Otherwise, the function throws an error that the user was not found.
|
||||
|
||||
|
||||
.PARAMETER UserName
|
||||
The username to search for.
|
||||
#>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Localized resources for User
|
||||
# Localized resources for User
|
||||
|
||||
ConvertFrom-StringData @'
|
||||
UserWithName = User: {0}
|
||||
|
||||
@@ -26,32 +26,32 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_WindowsFeature'
|
||||
If the specified role or feature does not contain any subfeatures then
|
||||
IncludeAllSubFeature will be set to $false. If the specified feature contains one
|
||||
or more subfeatures then IncludeAllSubFeature will be set to $true only if all the
|
||||
subfeatures are installed. Otherwise, IncludeAllSubFeature will be set to $false.
|
||||
subfeatures are installed. Otherwise, IncludeAllSubFeature will be set to $false.
|
||||
#>
|
||||
function Get-TargetResource
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([Hashtable])]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.Management.Automation.PSCredential]
|
||||
[System.Management.Automation.Credential()]
|
||||
$Credential
|
||||
)
|
||||
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.GetTargetResourceStartMessage -f $Name)
|
||||
|
||||
Import-ServerManager
|
||||
|
||||
|
||||
Import-ServerManager
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.QueryFeature -f $Name)
|
||||
|
||||
|
||||
$isWinServer2008R2SP1 = Test-IsWinServer2008R2SP1
|
||||
if ($isWinServer2008R2SP1 -and $PSBoundParameters.ContainsKey('Credential'))
|
||||
{
|
||||
@@ -63,11 +63,11 @@ function Get-TargetResource
|
||||
{
|
||||
$feature = Get-WindowsFeature @PSBoundParameters
|
||||
}
|
||||
|
||||
Assert-SingleFeatureExists -Feature $feature -Name $Name
|
||||
|
||||
|
||||
Assert-SingleInstanceOfFeature -Feature $feature -Name $Name
|
||||
|
||||
$includeAllSubFeature = $true
|
||||
|
||||
|
||||
if ($feature.SubFeatures.Count -eq 0)
|
||||
{
|
||||
$includeAllSubFeature = $false
|
||||
@@ -82,7 +82,7 @@ function Get-TargetResource
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('Credential'))
|
||||
{
|
||||
$getWindowsFeatureParameters['Credential'] = $Credential
|
||||
$getWindowsFeatureParameters['Credential'] = $Credential
|
||||
}
|
||||
|
||||
if ($isWinServer2008R2SP1 -and $PSBoundParameters.ContainsKey('Credential'))
|
||||
@@ -100,9 +100,9 @@ function Get-TargetResource
|
||||
{
|
||||
$subFeature = Get-WindowsFeature @getWindowsFeatureParameters
|
||||
}
|
||||
|
||||
Assert-SingleFeatureExists -Feature $subFeature -Name $currentSubFeatureName
|
||||
|
||||
|
||||
Assert-SingleInstanceOfFeature -Feature $subFeature -Name $currentSubFeatureName
|
||||
|
||||
if (-not $subFeature.Installed)
|
||||
{
|
||||
$includeAllSubFeature = $false
|
||||
@@ -121,7 +121,7 @@ function Get-TargetResource
|
||||
}
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.GetTargetResourceEndMessage -f $Name)
|
||||
|
||||
|
||||
# Add all feature properties to the hash table
|
||||
return @{
|
||||
Name = $Name
|
||||
@@ -134,7 +134,7 @@ function Get-TargetResource
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Installs or uninstalls the role or feature with the given name on the target machine
|
||||
with the option of installing or uninstalling all subfeatures as well.
|
||||
with the option of installing or uninstalling all subfeatures as well.
|
||||
|
||||
.PARAMETER Name
|
||||
The name of the role or feature to install or uninstall.
|
||||
@@ -166,16 +166,16 @@ function Set-TargetResource
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$IncludeAllSubFeature = $false,
|
||||
|
||||
[Parameter()]
|
||||
@@ -186,7 +186,7 @@ function Set-TargetResource
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath
|
||||
)
|
||||
|
||||
@@ -205,7 +205,7 @@ function Set-TargetResource
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('LogPath'))
|
||||
{
|
||||
$addWindowsFeatureParameters['LogPath'] = $LogPath
|
||||
$addWindowsFeatureParameters['LogPath'] = $LogPath
|
||||
}
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.InstallFeature -f $Name)
|
||||
@@ -225,7 +225,7 @@ function Set-TargetResource
|
||||
{
|
||||
if ($PSBoundParameters.ContainsKey('Credential'))
|
||||
{
|
||||
$addWindowsFeatureParameters['Credential'] = $Credential
|
||||
$addWindowsFeatureParameters['Credential'] = $Credential
|
||||
}
|
||||
|
||||
$feature = Add-WindowsFeature @addWindowsFeatureParameters
|
||||
@@ -256,7 +256,7 @@ function Set-TargetResource
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('LogPath'))
|
||||
{
|
||||
$removeWindowsFeatureParameters['LogPath'] = $LogPath
|
||||
$removeWindowsFeatureParameters['LogPath'] = $LogPath
|
||||
}
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.UninstallFeature -f $Name)
|
||||
@@ -276,7 +276,7 @@ function Set-TargetResource
|
||||
{
|
||||
if ($PSBoundParameters.ContainsKey('Credential'))
|
||||
{
|
||||
$addWindowsFeatureParameters['Credential'] = $Credential
|
||||
$addWindowsFeatureParameters['Credential'] = $Credential
|
||||
}
|
||||
|
||||
$feature = Remove-WindowsFeature @removeWindowsFeatureParameters
|
||||
@@ -304,7 +304,7 @@ function Set-TargetResource
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Tests if the role or feature with the given name is in the desired state.
|
||||
Tests if the role or feature with the given name is in the desired state.
|
||||
|
||||
.PARAMETER Name
|
||||
The name of the role or feature to test the state of.
|
||||
@@ -315,11 +315,11 @@ function Set-TargetResource
|
||||
By default this is set to Present.
|
||||
|
||||
.PARAMETER IncludeAllSubFeature
|
||||
Specifies whether or not the installation state of all subfeatures should be tested with
|
||||
Specifies whether or not the installation state of all subfeatures should be tested with
|
||||
the specified role or feature. Default is false.
|
||||
-If this property is set to true and Ensure is set to Present,
|
||||
-If this property is set to true and Ensure is set to Present,
|
||||
each subfeature will be tested to ensure it is installed.
|
||||
-If this property is set to true and Ensure is set to Absent,
|
||||
-If this property is set to true and Ensure is set to Absent,
|
||||
each subfeature will be tested to ensure it is uninstalled.
|
||||
-If this property is false, subfeatures will not be tested.
|
||||
|
||||
@@ -340,16 +340,16 @@ function Test-TargetResource
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$IncludeAllSubFeature = $false,
|
||||
|
||||
[Parameter()]
|
||||
@@ -360,15 +360,15 @@ function Test-TargetResource
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath
|
||||
|
||||
)
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.TestTargetResourceStartMessage -f $Name)
|
||||
|
||||
|
||||
Import-ServerManager
|
||||
|
||||
|
||||
$testTargetResourceResult = $false
|
||||
|
||||
$getWindowsFeatureParameters = @{
|
||||
@@ -377,11 +377,11 @@ function Test-TargetResource
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('Credential'))
|
||||
{
|
||||
$getWindowsFeatureParameters['Credential'] = $Credential
|
||||
$getWindowsFeatureParameters['Credential'] = $Credential
|
||||
}
|
||||
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.QueryFeature -f $Name)
|
||||
|
||||
|
||||
$isWinServer2008R2SP1 = Test-IsWinServer2008R2SP1
|
||||
if ($isWinServer2008R2SP1 -and $PSBoundParameters.ContainsKey('Credential'))
|
||||
{
|
||||
@@ -398,22 +398,22 @@ function Test-TargetResource
|
||||
{
|
||||
$feature = Get-WindowsFeature @getWindowsFeatureParameters
|
||||
}
|
||||
|
||||
Assert-SingleFeatureExists -Feature $feature -Name $Name
|
||||
|
||||
|
||||
Assert-SingleInstanceOfFeature -Feature $feature -Name $Name
|
||||
|
||||
# Check if the feature is in the requested Ensure state.
|
||||
if (($Ensure -eq 'Present' -and $feature.Installed -eq $true) -or `
|
||||
($Ensure -eq 'Absent' -and $feature.Installed -eq $false))
|
||||
{
|
||||
$testTargetResourceResult = $true
|
||||
|
||||
|
||||
if ($IncludeAllSubFeature)
|
||||
{
|
||||
# Check if each subfeature is in the requested state.
|
||||
foreach ($currentSubFeatureName in $feature.SubFeatures)
|
||||
{
|
||||
$getWindowsFeatureParameters['Name'] = $currentSubFeatureName
|
||||
|
||||
|
||||
if ($isWinServer2008R2SP1 -and $PSBoundParameters.ContainsKey('Credential'))
|
||||
{
|
||||
<#
|
||||
@@ -429,15 +429,15 @@ function Test-TargetResource
|
||||
{
|
||||
$subFeature = Get-WindowsFeature @getWindowsFeatureParameters
|
||||
}
|
||||
|
||||
Assert-SingleFeatureExists -Feature $subFeature -Name $currentSubFeatureName
|
||||
|
||||
|
||||
Assert-SingleInstanceOfFeature -Feature $subFeature -Name $currentSubFeatureName
|
||||
|
||||
if (-not $subFeature.Installed -and $Ensure -eq 'Present')
|
||||
{
|
||||
$testTargetResourceResult = $false
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
if ($subFeature.Installed -and $Ensure -eq 'Absent')
|
||||
{
|
||||
$testTargetResourceResult = $false
|
||||
@@ -451,9 +451,9 @@ function Test-TargetResource
|
||||
# Ensure is not in the correct state
|
||||
$testTargetResourceResult = $false
|
||||
}
|
||||
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.TestTargetResourceEndMessage -f $Name)
|
||||
|
||||
|
||||
return $testTargetResourceResult
|
||||
}
|
||||
|
||||
@@ -467,19 +467,19 @@ function Test-TargetResource
|
||||
|
||||
.PARAMETER Name
|
||||
The name of the role or feature to include in any error messages that are thrown.
|
||||
(Not used to assert validity of the feature).
|
||||
(Not used to assert validity of the feature).
|
||||
#>
|
||||
function Assert-SingleFeatureExists
|
||||
function Assert-SingleInstanceOfFeature
|
||||
{
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter()]
|
||||
[PSObject]
|
||||
[System.Management.Automation.PSObject]
|
||||
$Feature,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name
|
||||
)
|
||||
|
||||
@@ -501,7 +501,7 @@ function Assert-SingleFeatureExists
|
||||
#>
|
||||
function Import-ServerManager
|
||||
{
|
||||
param
|
||||
param
|
||||
()
|
||||
|
||||
<#
|
||||
@@ -552,7 +552,7 @@ function Import-ServerManager
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Tests if the machine is a Windows Server 2008 R2 SP1 machine.
|
||||
|
||||
|
||||
.NOTES
|
||||
Since Assert-PrequisitesValid ensures that ServerManager is available on the machine,
|
||||
this function only checks the OS version.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Localized strings for MSFT_WindowsFeature.psd1
|
||||
# Localized strings for MSFT_WindowsFeature.psd1
|
||||
|
||||
ConvertFrom-StringData @'
|
||||
FeatureNotFoundError = The requested feature {0} could not be found on the target machine.
|
||||
|
||||
@@ -19,11 +19,11 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_WindowsOptionalFea
|
||||
function Get-TargetResource
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([Hashtable])]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name
|
||||
)
|
||||
|
||||
@@ -32,11 +32,11 @@ function Get-TargetResource
|
||||
Assert-ResourcePrerequisitesValid
|
||||
|
||||
$windowsOptionalFeature = Dism\Get-WindowsOptionalFeature -FeatureName $Name -Online
|
||||
|
||||
|
||||
<#
|
||||
$windowsOptionalFeatureProperties and this section of code are needed because an error will be thrown if a property
|
||||
is not found in WMF 4 instead of returning null.
|
||||
#>
|
||||
#>
|
||||
$windowsOptionalFeatureProperties = @{}
|
||||
$propertiesNeeded = @( 'LogPath', 'State', 'CustomProperties', 'FeatureName', 'LogLevel', 'Description', 'DisplayName' )
|
||||
|
||||
@@ -55,8 +55,8 @@ function Get-TargetResource
|
||||
$windowsOptionalFeatureResource = @{
|
||||
LogPath = $windowsOptionalFeatureProperties.LogPath
|
||||
Ensure = Convert-FeatureStateToEnsure -State $windowsOptionalFeatureProperties.State
|
||||
CustomProperties =
|
||||
Convert-CustomPropertyArrayToStringArray -CustomProperties $windowsOptionalFeatureProperties.CustomProperties
|
||||
CustomProperties = Convert-CustomPropertyArrayToStringArray `
|
||||
-CustomProperties $windowsOptionalFeatureProperties.CustomProperties
|
||||
Name = $windowsOptionalFeatureProperties.FeatureName
|
||||
LogLevel = $windowsOptionalFeatureProperties.LogLevel
|
||||
Description = $windowsOptionalFeatureProperties.Description
|
||||
@@ -85,7 +85,7 @@ function Get-TargetResource
|
||||
being disabled.
|
||||
|
||||
.PARAMETER NoWindowsUpdateCheck
|
||||
Specifies whether or not DISM contacts Windows Update (WU) when searching for the source
|
||||
Specifies whether or not DISM contacts Windows Update (WU) when searching for the source
|
||||
files to enable the feature.
|
||||
If $true, DISM will not contact WU.
|
||||
|
||||
@@ -106,29 +106,29 @@ function Set-TargetResource
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$RemoveFilesOnDisable,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$NoWindowsUpdateCheck,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('ErrorsOnly', 'ErrorsAndWarning', 'ErrorsAndWarningAndInformation')]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogLevel = 'ErrorsAndWarningAndInformation'
|
||||
)
|
||||
|
||||
@@ -138,9 +138,23 @@ function Set-TargetResource
|
||||
|
||||
$dismLogLevel = switch ($LogLevel)
|
||||
{
|
||||
'ErrorsOnly' { 'Errors'; break }
|
||||
'ErrorsAndWarning' { 'Warnings'; break }
|
||||
'ErrorsAndWarningAndInformation' { 'WarningsInfo'; break }
|
||||
'ErrorsOnly'
|
||||
{
|
||||
'Errors'
|
||||
break
|
||||
}
|
||||
|
||||
'ErrorsAndWarning'
|
||||
{
|
||||
'Warnings'
|
||||
break
|
||||
}
|
||||
|
||||
'ErrorsAndWarningAndInformation'
|
||||
{
|
||||
'WarningsInfo'
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
# Construct splatting hashtable for DISM cmdlets
|
||||
@@ -188,7 +202,7 @@ function Set-TargetResource
|
||||
<#
|
||||
$restartNeeded and this section of code are needed because an error will be thrown if the
|
||||
RestartNeeded property is not found in WMF 4.
|
||||
#>
|
||||
#>
|
||||
try
|
||||
{
|
||||
$restartNeeded = $windowsOptionalFeature.RestartNeeded
|
||||
@@ -235,33 +249,33 @@ function Set-TargetResource
|
||||
function Test-TargetResource
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$RemoveFilesOnDisable,
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$NoWindowsUpdateCheck,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('ErrorsOnly', 'ErrorsAndWarning', 'ErrorsAndWarningAndInformation')]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogLevel = 'ErrorsAndWarningAndInformation'
|
||||
)
|
||||
|
||||
@@ -270,7 +284,7 @@ function Test-TargetResource
|
||||
Assert-ResourcePrerequisitesValid
|
||||
|
||||
$windowsOptionalFeature = Dism\Get-WindowsOptionalFeature -FeatureName $Name -Online
|
||||
|
||||
|
||||
$featureIsInDesiredState = $false
|
||||
|
||||
if ($null -eq $windowsOptionalFeature -or $windowsOptionalFeature.State -eq 'Disabled')
|
||||
@@ -281,9 +295,9 @@ function Test-TargetResource
|
||||
{
|
||||
$featureIsInDesiredState = $Ensure -eq 'Present'
|
||||
}
|
||||
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.TestTargetResourceEndMessage -f $Name)
|
||||
|
||||
|
||||
return $featureIsInDesiredState
|
||||
}
|
||||
|
||||
@@ -298,15 +312,15 @@ function Test-TargetResource
|
||||
function Convert-CustomPropertyArrayToStringArray
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([String[]])]
|
||||
[OutputType([System.String[]])]
|
||||
param
|
||||
(
|
||||
[Parameter()]
|
||||
[PSCustomObject[]]
|
||||
[System.Management.Automation.PSObject[]]
|
||||
$CustomProperties
|
||||
)
|
||||
|
||||
$propertiesAsStrings = [String[]] @()
|
||||
$propertiesAsStrings = [System.String[]] @()
|
||||
|
||||
foreach ($customProperty in $CustomProperties)
|
||||
{
|
||||
@@ -330,11 +344,11 @@ function Convert-CustomPropertyArrayToStringArray
|
||||
function Convert-FeatureStateToEnsure
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$State
|
||||
)
|
||||
|
||||
@@ -381,15 +395,16 @@ function Assert-ResourcePrerequisitesValid
|
||||
# Check that we are running as an administrator
|
||||
$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$windowsPrincipal = New-Object -TypeName 'System.Security.Principal.WindowsPrincipal' -ArgumentList @( $windowsIdentity )
|
||||
|
||||
|
||||
$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator
|
||||
|
||||
if (-not $windowsPrincipal.IsInRole($adminRole))
|
||||
{
|
||||
New-InvalidOperationException -Message $script:localizedData.ElevationRequired
|
||||
}
|
||||
|
||||
# Check that Dism PowerShell module is available
|
||||
Import-Module -Name 'Dism' -ErrorVariable 'errorsFromDismImport' -ErrorAction 'SilentlyContinue' -Force
|
||||
Import-Module -Name 'Dism' -ErrorVariable 'errorsFromDismImport' -ErrorAction 'SilentlyContinue' -Force -Verbose:$false
|
||||
|
||||
if ($errorsFromDismImport.Count -gt 0)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
$errorActionPreference = 'Stop'
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) `
|
||||
@@ -30,27 +30,27 @@ Import-Module -Name 'Dism'
|
||||
function Get-TargetResource
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([Hashtable])]
|
||||
[OutputType([System.Collections.Hashtable])]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$SourcePath,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath
|
||||
)
|
||||
|
||||
@@ -72,7 +72,7 @@ function Get-TargetResource
|
||||
}
|
||||
|
||||
Write-Verbose -Message ($script:localizedData.RetrievingPackage -f $Name)
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
$windowsPackageInfo = Dism\Get-WindowsPackage @getWindowsPackageParams
|
||||
@@ -118,22 +118,22 @@ function Set-TargetResource
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$SourcePath,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath
|
||||
)
|
||||
|
||||
@@ -143,10 +143,10 @@ function Set-TargetResource
|
||||
{
|
||||
New-InvalidArgumentException -ArgumentName 'SourcePath' -Message ($script:localizedData.SourcePathDoesNotExist -f $SourcePath)
|
||||
}
|
||||
|
||||
|
||||
if ($Ensure -ieq 'Present')
|
||||
{
|
||||
Write-Verbose -Message ($script:localizedData.AddingPackage -f $SourcePath)
|
||||
Write-Verbose -Message ($script:localizedData.AddingPackage -f $SourcePath)
|
||||
Dism\Add-WindowsPackage -PackagePath $SourcePath -LogPath $LogPath -Online
|
||||
}
|
||||
else
|
||||
@@ -180,27 +180,27 @@ function Set-TargetResource
|
||||
function Test-TargetResource
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([Boolean])]
|
||||
[OutputType([System.Boolean])]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$SourcePath,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath
|
||||
)
|
||||
|
||||
@@ -226,7 +226,7 @@ function Test-TargetResource
|
||||
{
|
||||
Write-Verbose -Message ($script:localizedData.EnsureStatesDoNotMatch -f $Name)
|
||||
return $false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function '*-TargetResource'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[Description("This resource is used to install or uninstall a package from a windows cabinet (cab) file.") : Amended,AMENDMENT, LOCALE("MS_409")]
|
||||
[Description("This resource is used to install or uninstall a package from a windows cabinet (cab) file.") : Amended,AMENDMENT, LOCALE("MS_409")]
|
||||
class MSFT_WindowsPackageCab : OMI_BaseResource
|
||||
{
|
||||
[Key, Description("The name of the package to install or uninstall.") : Amended] String Name;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Localized resources for WindowsPackageCab
|
||||
# Localized resources for WindowsPackageCab
|
||||
|
||||
ConvertFrom-StringData @'
|
||||
RetrievingPackage = Retrieving information for the package {0}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
@{
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'ProcessSet.schema.psm1'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
$errorActionPreference = 'Stop'
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
# Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock
|
||||
@@ -51,43 +51,43 @@ Configuration ProcessSet
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true, HelpMessage="The file paths to the executables of the processes to start or stop. Only the names of the files may be specified if they are all accessible through the environment path. Relative paths are not supported.")]
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$Path,
|
||||
|
||||
[Parameter(HelpMessage="Specifies whether or not the processes should exist. To start processes, set this property to Present. To stop processes, set this property to Absent.")]
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure,
|
||||
|
||||
[Parameter(HelpMessage="The credential of the user account to start the processes under.")]
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.Management.Automation.PSCredential]
|
||||
[System.Management.Automation.Credential()]
|
||||
$Credential,
|
||||
|
||||
[Parameter(HelpMessage="The file path to write the standard output to. Any existing file at this path will be overwritten.This property cannot be specified at the same time as Credential when running the processes as a local user.")]
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$StandardOutputPath,
|
||||
|
||||
[Parameter(HelpMessage="The file path to write the standard error output to. Any existing file at this path will be overwritten.")]
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$StandardErrorPath,
|
||||
|
||||
[Parameter(HelpMessage="The file path to get standard input from. This property cannot be specified at the same time as Credential when running the processes as a local user.")]
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$StandardInputPath,
|
||||
|
||||
[Parameter(HelpMessage="The file path to use as the working directory for the processes. Any existing file at this path will be overwritten. This property cannot be specified at the same time as Credential when running the processes as a local user.")]
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$WorkingDirectory
|
||||
)
|
||||
|
||||
|
||||
$newResourceSetConfigurationParams = @{
|
||||
ResourceName = 'WindowsProcess'
|
||||
ModuleName = 'PSDscResources'
|
||||
@@ -97,7 +97,7 @@ Configuration ProcessSet
|
||||
|
||||
# Arguments is a key parameter in WindowsProcess resource. Adding it as a common parameter with an empty value string
|
||||
$newResourceSetConfigurationParams['Parameters']['Arguments'] = ''
|
||||
|
||||
|
||||
$configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams
|
||||
|
||||
# This script block must be run directly in this configuration in order to resolve variables
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# This module should not write any verbose or error messages unless a localization file for it is added
|
||||
# This module should not write any verbose or error messages unless a localization file for it is added
|
||||
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
@@ -27,24 +27,24 @@ Set-StrictMode -Version 'Latest'
|
||||
#>
|
||||
function New-ResourceSetCommonParameterString
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$KeyParameterName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[Hashtable]
|
||||
[System.Collections.Hashtable]
|
||||
$Parameters
|
||||
)
|
||||
|
||||
$stringBuilder = New-Object -TypeName 'System.Text.StringBuilder'
|
||||
|
||||
foreach ($parameterName in $Parameters.Keys)
|
||||
foreach ($parameterName in $Parameters.Keys)
|
||||
{
|
||||
# All composite resources have an extra parameter 'InstanceName'
|
||||
if ($parameterName -ine $KeyParameterName -and $parameterName -ine 'InstanceName')
|
||||
@@ -53,7 +53,7 @@ function New-ResourceSetCommonParameterString
|
||||
|
||||
if ($null -ne $parameterValue)
|
||||
{
|
||||
if ($parameterValue -is [String])
|
||||
if ($parameterValue -is [System.String])
|
||||
{
|
||||
$null = $stringBuilder.AppendFormat('{0} = "{1}"', $parameterName, $parameterValue)
|
||||
}
|
||||
@@ -106,7 +106,7 @@ function New-ResourceSetCommonParameterString
|
||||
Name = "Telnet-Client"
|
||||
Ensure = "Present"
|
||||
IncludeAllSubFeature = $true
|
||||
}
|
||||
}
|
||||
|
||||
WindowsFeature Resource1
|
||||
{
|
||||
@@ -117,33 +117,33 @@ function New-ResourceSetCommonParameterString
|
||||
#>
|
||||
function New-ResourceSetConfigurationString
|
||||
{
|
||||
[OutputType([String])]
|
||||
[OutputType([System.String])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ResourceName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ModuleName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$KeyParameterName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
$KeyParameterValues,
|
||||
|
||||
[System.String[]]
|
||||
$KeyParameterValues,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$CommonParameterString
|
||||
)
|
||||
|
||||
@@ -162,7 +162,7 @@ function New-ResourceSetConfigurationString
|
||||
$null = $stringBuilder.AppendLine()
|
||||
$null = $stringBuilder.Append($CommonParameterString)
|
||||
$null = $stringBuilder.AppendLine('}')
|
||||
|
||||
|
||||
$resourceCount++
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ function New-ResourceSetConfigurationString
|
||||
CommonParameterNames = @( 'Ensure', 'MembersToInclude', 'MembersToExclude', 'Credential' )
|
||||
Parameters = $PSBoundParameters
|
||||
}
|
||||
|
||||
|
||||
$configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams
|
||||
|
||||
.NOTES
|
||||
@@ -205,28 +205,28 @@ function New-ResourceSetConfigurationString
|
||||
#>
|
||||
function New-ResourceSetConfigurationScriptBlock
|
||||
{
|
||||
[OutputType([ScriptBlock])]
|
||||
[OutputType([System.Management.Automation.ScriptBlock])]
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ResourceName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ModuleName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$KeyParameterName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[Hashtable]
|
||||
[System.Collections.Hashtable]
|
||||
$Parameters
|
||||
)
|
||||
|
||||
@@ -242,7 +242,7 @@ function New-ResourceSetConfigurationScriptBlock
|
||||
|
||||
$resourceString = New-ResourceSetConfigurationString @newResourceSetConfigurationStringParams
|
||||
|
||||
return [ScriptBlock]::Create($resourceString)
|
||||
return [System.Management.Automation.ScriptBlock]::Create($resourceString)
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function @( 'New-ResourceSetConfigurationScriptBlock' )
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@{
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'ServiceSet.schema.psm1'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
$errorActionPreference = 'Stop'
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
# Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock
|
||||
@@ -18,7 +18,7 @@ Import-Module -Name $script:resourceSetHelperFilePath
|
||||
|
||||
.PARAMETER Ensure
|
||||
Specifies whether or not the set of services should exist.
|
||||
|
||||
|
||||
Set this property to Present to modify a set of services.
|
||||
Set this property to Absent to remove a set of services.
|
||||
|
||||
@@ -51,32 +51,32 @@ Configuration ServiceSet
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true, HelpMessage="An array of the names of the services to configure.")]
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$Name,
|
||||
|
||||
[Parameter(HelpMessage="Specifies whether or not the set of services should exist. Set this property to Present to modify a set of services. Set this property to Absent to remove a set of services.")]
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure,
|
||||
|
||||
[Parameter(HelpMessage="The startup type each service in the set should have.")]
|
||||
[Parameter()]
|
||||
[ValidateSet('Automatic', 'Manual', 'Disabled')]
|
||||
[String]
|
||||
[System.String]
|
||||
$StartupType,
|
||||
|
||||
[Parameter(HelpMessage="The built-in account each service in the set should start under. Cannot be specified at the same time as Credential. The user account specified by this property must have access to the service executable paths in order to start the services.")]
|
||||
[Parameter()]
|
||||
[ValidateSet('LocalSystem', 'LocalService', 'NetworkService')]
|
||||
[String]
|
||||
[System.String]
|
||||
$BuiltInAccount,
|
||||
|
||||
[Parameter(HelpMessage="The state each service in the set should be in. From the default value defined in Service, the default will be Running.")]
|
||||
[Parameter()]
|
||||
[ValidateSet('Running', 'Stopped', 'Ignore')]
|
||||
[String]
|
||||
[System.String]
|
||||
$State,
|
||||
|
||||
[Parameter(HelpMessage="he credential of the user account each service in the set should start under. Cannot be specified at the same time as BuiltInAccount. The user specified by this credential will automatically be granted the Log on as a Service right. The user account specified by this property must have access to the service executable paths in order to start the services.")]
|
||||
[Parameter()]
|
||||
[ValidateNotNull()]
|
||||
[System.Management.Automation.PSCredential]
|
||||
[System.Management.Automation.Credential()]
|
||||
@@ -89,7 +89,7 @@ Configuration ServiceSet
|
||||
KeyParameterName = 'Name'
|
||||
Parameters = $PSBoundParameters
|
||||
}
|
||||
|
||||
|
||||
$configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams
|
||||
|
||||
# This script block must be run directly in this configuration in order to resolve variables
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@{
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'WindowsFeatureSet.schema.psm1'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
$errorActionPreference = 'Stop'
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
# Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock
|
||||
@@ -41,42 +41,34 @@ Configuration WindowsFeatureSet
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true, HelpMessage="The name of the roles or features to install or uninstall.")]
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$Name,
|
||||
|
||||
[Parameter(HelpMessage="Specifies whether the roles or features should be installed or uninstalled.
|
||||
|
||||
To install the features, set this property to Present.
|
||||
To uninstall the features, set this property to Absent.")]
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure,
|
||||
|
||||
[Parameter(HelpMessage="Specify the source")]
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Source,
|
||||
|
||||
[Parameter(HelpMessage="Specifies whether or not all subfeatures should be installed or uninstalled alongside the specified roles or features.
|
||||
|
||||
If this property is true and Ensure is set to Present, all subfeatures will be installed.
|
||||
If this property is false and Ensure is set to Present, subfeatures will not be installed or uninstalled.
|
||||
If Ensure is set to Absent, all subfeatures will be uninstalled.")]
|
||||
[Boolean]
|
||||
[Parameter()]
|
||||
[System.Boolean]
|
||||
$IncludeAllSubFeature,
|
||||
|
||||
[Parameter(HelpMessage="The credential of the user account under which to install or uninstall the roles or features.")]
|
||||
[Parameter()]
|
||||
[ValidateNotNull()]
|
||||
[System.Management.Automation.PSCredential]
|
||||
[System.Management.Automation.Credential()]
|
||||
$Credential,
|
||||
|
||||
[Parameter(HelpMessage="The custom file path to which to log this operation.
|
||||
If not passed in, the default log path will be used (%windir%\logs\ServerManager.log).")]
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath
|
||||
)
|
||||
|
||||
@@ -86,7 +78,7 @@ Configuration WindowsFeatureSet
|
||||
KeyParameterName = 'Name'
|
||||
Parameters = $PSBoundParameters
|
||||
}
|
||||
|
||||
|
||||
$configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams
|
||||
|
||||
# This script block must be run directly in this configuration in order to resolve variables
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@{
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'WindowsOptionalFeatureSet.schema.psm1'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
$errorActionPreference = 'Stop'
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
# Import ResourceSetHelper for New-ResourceSetConfigurationScriptBlock
|
||||
@@ -41,35 +41,32 @@ Configuration WindowsOptionalFeatureSet
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true, HelpMessage="The names of the Windows optional features to enable or disable.")]
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
$Name,
|
||||
|
||||
[Parameter(Mandatory = $true, HelpMessage="Specifies whether the features should be enabled or disabled.
|
||||
|
||||
To enable a set of features, set this property to Present.
|
||||
To disable a set of features, set this property to Absent.")]
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure,
|
||||
|
||||
[Parameter(HelpMessage="Specifies whether or not to remove all files associated with the features when they are disabled.")]
|
||||
[Boolean]
|
||||
[Parameter()]
|
||||
[System.Boolean]
|
||||
$RemoveFilesOnDisable,
|
||||
|
||||
[Parameter(HelpMessage="Specifies whether or not DISM should contact Windows Update (WU) when searching for the source files to restore Windows optional features on an online image.")]
|
||||
[Boolean]
|
||||
[Parameter()]
|
||||
[System.Boolean]
|
||||
$NoWindowsUpdateCheck,
|
||||
|
||||
[Parameter(HelpMessage="The file path to which to log the opertation.")]
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath,
|
||||
|
||||
[Parameter(HelpMessage="The level of detail to include in the log.")]
|
||||
[Parameter()]
|
||||
[ValidateSet('ErrorsOnly', 'ErrorsAndWarning', 'ErrorsAndWarningAndInformation')]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogLevel
|
||||
)
|
||||
|
||||
@@ -79,7 +76,7 @@ Configuration WindowsOptionalFeatureSet
|
||||
KeyParameterName = 'Name'
|
||||
Parameters = $PSBoundParameters
|
||||
}
|
||||
|
||||
|
||||
$configurationScriptBlock = New-ResourceSetConfigurationScriptBlock @newResourceSetConfigurationParams
|
||||
|
||||
# This script block must be run directly in this configuration in order to resolve variables
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Expands the archive located at 'C:\ExampleArchivePath\Archive.zip' to the destination path
|
||||
'C:\ExampleDestinationPath\Destination'.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Remove the expansion of the archive located at 'C:\ExampleArchivePath\Archive.zip' from the
|
||||
destination path 'C:\ExampleDestinationPath\Destination'.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Removes the expansion of the archive located at 'C:\ExampleArchivePath\Archive.zip' from the
|
||||
destination path 'C:\ExampleDestinationPath\Destination'.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates the environment variable 'TestEnvironmentVariable' and sets the value to 'TestValue'
|
||||
both on the machine and within the process.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates the environment variable 'TestPathEnvironmentVariable' and sets the value to 'TestValue'
|
||||
if it doesn't already exist or appends the value 'TestValue' to the existing path if it does
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Removes the environment variable 'TestEnvironmentVariable' from
|
||||
both the machine and the process.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
If the groups named GroupName1 and Administrators do not exist, creates the groups named
|
||||
GroupName1 and Administrators and adds the users with the usernames Username1 and Username2
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
If the group named GroupName1 does not exist, creates a group named GroupName1.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
If the group named GroupName1 does not exist, creates a group named GroupName1 and adds the
|
||||
users with the usernames Username1 and Username2 to the group.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Starts the processes with the executables at the file paths C:\Windows\cmd.exe and
|
||||
C:\TestPath\TestProcess.exe with no arguments.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Stops the processes with the executables at the file paths C:\Windows\cmd.exe and
|
||||
C:\TestPath\TestProcess.exe with no arguments and logs any output to the path
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Create a new registry key called MyNewKey as a subkey under the key
|
||||
'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
If the registry key value MyValue under the key
|
||||
'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' does not exist,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Removes the registry key called MyNewKey under the parent key
|
||||
'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Removes the registry key value MyValue from the key
|
||||
'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates a file at the given file path with the specified content through the Script resource.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sets the Secure Socket Tunneling Protocol and DHCP Client services to run under the
|
||||
built-in account LocalService.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Ensures that the DHCP Client and Windows Firewall services are running.
|
||||
#>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Configuration UserExample
|
||||
Configuration UserExample
|
||||
{
|
||||
param (
|
||||
[System.Management.Automation.PSCredential]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory)]
|
||||
[System.String]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates a custom configuration for installing or uninstalling a Windows role or feature.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Installs the TelnetClient and RSAT-File-Services Windows features, including all their
|
||||
subfeatures. Logs the operation to the file at 'C:\LogPath\Log.log'.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Uninstalls the TelnetClient and RSAT-File-Services Windows features, including all their
|
||||
subfeatures. Logs the operation to the file at 'C:\LogPath\Log.log'.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Enables the Windows optional feature with the specified name and outputs a log to the specified path.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Disables the Windows optional features TelnetClient and LegacyComponents and removes all
|
||||
files associated with these features.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Enables the Windows optional features MicrosoftWindowsPowerShellV2 and
|
||||
Internet-Explorer-Optional-amd64 and outputs a log of the operations to a file at the path
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Installs a package from the cab file with the specified name from the specified source path
|
||||
and outputs a log to the specified log path.
|
||||
|
||||
+29
-2
@@ -4,7 +4,7 @@
|
||||
# RootModule = ''
|
||||
|
||||
# Version number of this module.
|
||||
moduleVersion = '2.11.0.0'
|
||||
moduleVersion = '2.12.0.0'
|
||||
|
||||
# Supported PSEditions
|
||||
# CompatiblePSEditions = @()
|
||||
@@ -101,7 +101,33 @@ PrivateData = @{
|
||||
# IconUri = ''
|
||||
|
||||
# ReleaseNotes of this module
|
||||
ReleaseNotes = '* Fix Custom DSC Resource Kit PSSA Rule Failures
|
||||
ReleaseNotes = '* Ports style fixes that were recently made in xPSDesiredStateConfiguration
|
||||
on test related files.
|
||||
* Ports most of the style upgrades from xPSDesiredStateConfiguration that have
|
||||
been made in files in the DscResources folder.
|
||||
* Ports fixes for the following issues:
|
||||
[Issue 505](https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/505)
|
||||
[Issue 590](https://github.com/PowerShell/xPSDesiredStateConfiguration/issues/590)
|
||||
Changes to test helper Enter-DscResourceTestEnvironment so that it only
|
||||
updates DSCResource.Tests when it is longer than 120 minutes since
|
||||
it was last pulled. This is to improve performance of test execution
|
||||
and reduce the likelihood of connectivity issues caused by inability to
|
||||
pull DSCResource.Tests.
|
||||
* Fixes issue where MsiPackage Integration tests fail if the test HttpListener
|
||||
fails to start. Moves the test HttpListener objects to dynamically assigned,
|
||||
higher numbered ports to avoid conflicts with other services, and also checks
|
||||
to ensure that the ports are available before using them. Adds checks to
|
||||
ensure that no outstanding HTTP server jobs are running before attempting to
|
||||
setup a new one. Also adds additional instrumentation to make it easier to
|
||||
troubleshoot issues with the test HttpListener objects in the future.
|
||||
Specifically fixes
|
||||
[Issue 142](https://github.com/PowerShell/PSDscResources/issues/142)
|
||||
* Improved speed of Test-IsNanoServer function
|
||||
* Remove the Byte Order Mark (BOM) from all affected files
|
||||
* Opt-in to "Validate Module Files" and "Validate Script Files" common meta-tests
|
||||
* Opt-in to "Common Tests - Relative Path Length" common meta-test
|
||||
* Fix README markdownlint validation failures
|
||||
* Move change log from README.md to CHANGELOG.md
|
||||
|
||||
'
|
||||
|
||||
@@ -127,3 +153,4 @@ PrivateData = @{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
master: [](https://ci.appveyor.com/project/PowerShell/psdscresources/branch/master)
|
||||
[](https://codecov.io/gh/PowerShell/PSDscResources)
|
||||
|
||||
dev: [](https://ci.appveyor.com/project/PowerShell/psdscresources/branch/dev)
|
||||
[](https://codecov.io/gh/PowerShell/PSDscResources)
|
||||
|
||||
# PSDscResources
|
||||
|
||||
PSDscResources is the new home of the in-box resources from PSDesiredStateConfiguration.
|
||||
@@ -17,11 +11,13 @@ Because PSDscResources overwrites in-box resources, it is only available for WMF
|
||||
Many of the resource updates provided here are also included in the [xPSDesiredStateConfiguration](https://github.com/PowerShell/xPSDesiredStateConfiguration) module which is still compatible with WMF 4 and WMF 5 (though this module is not supported and may be removed in the future).
|
||||
|
||||
To update your in-box resources to the newest versions provided by PSDscResources, first install PSDscResources from the PowerShell Gallery:
|
||||
|
||||
```powershell
|
||||
Install-Module PSDscResources
|
||||
```
|
||||
|
||||
Then, simply add this line to your DSC configuration:
|
||||
|
||||
```powershell
|
||||
Import-DscResource -ModuleName PSDscResources
|
||||
```
|
||||
@@ -29,12 +25,36 @@ Import-DscResource -ModuleName PSDscResources
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
||||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
||||
|
||||
## Branches
|
||||
|
||||
### master
|
||||
|
||||
[](https://ci.appveyor.com/project/PowerShell/psdscresources/branch/master)
|
||||
[](https://codecov.io/gh/PowerShell/PSDscResources)
|
||||
|
||||
This is the branch containing the latest release -
|
||||
no contributions should be made directly to this branch.
|
||||
|
||||
### dev
|
||||
|
||||
[](https://ci.appveyor.com/project/PowerShell/AuditPolicyDsc/branch/dev)
|
||||
[](https://codecov.io/gh/PowerShell/AuditPolicyDsc/branch/dev)
|
||||
|
||||
This is the development branch
|
||||
to which contributions should be proposed by contributors as pull requests.
|
||||
This development branch will periodically be merged to the master branch,
|
||||
and be released to [PowerShell Gallery](https://www.powershellgallery.com/).
|
||||
|
||||
## Contributing
|
||||
|
||||
This module does not accept breaking changes.
|
||||
|
||||
Please check out the common DSC Resources [contributing guidelines](https://github.com/PowerShell/DscResource.Kit/blob/master/CONTRIBUTING.md).
|
||||
|
||||
## Change log
|
||||
|
||||
A full list of changes in each version can be found in the [change log](CHANGELOG.md).
|
||||
|
||||
## Resources
|
||||
|
||||
* [Archive](#archive): Provides a mechanism to expand an archive (.zip) file to a specific path or remove an expanded archive (.zip) file from a specific path on a target node.
|
||||
@@ -572,137 +592,3 @@ The following parameters will be the same for each process in the set:
|
||||
|
||||
* [Start multiple processes](https://github.com/PowerShell/PSDesResources/blob/master/Examples/Sample_ProcessSet_Start.ps1)
|
||||
* [Stop multiple processes](https://github.com/PowerShell/PSDesResources/blob/master/Examples/Sample_ProcessSet_Stop.ps1)
|
||||
|
||||
## Versions
|
||||
|
||||
### Unreleased
|
||||
|
||||
### 2.11.0.0
|
||||
|
||||
* Fix Custom DSC Resource Kit PSSA Rule Failures
|
||||
|
||||
### 2.10.0.0
|
||||
|
||||
* Fixed CompanyName typo - Fixes [Issue #100](https://github.com/PowerShell/PSDscResources/issues/100)
|
||||
* Update LICENSE file to match the Microsoft Open Source Team
|
||||
standard - Fixes [Issue #120](https://github.com/PowerShell/PSDscResources/issues/120).
|
||||
* Update `CommonResourceHelper` unit tests to meet Pester 4.0.0
|
||||
standards ([issue #129](https://github.com/PowerShell/PSDscResources/issues/129)).
|
||||
* Update `ResourceHelper` unit tests to meet Pester 4.0.0
|
||||
standards ([issue #129](https://github.com/PowerShell/PSDscResources/issues/129)).
|
||||
* Ported fixes from [xPSDesiredStateConfiguration](https://github.com/PowerShell/xPSDesiredStateConfiguration):
|
||||
* xArchive
|
||||
* Fix end-to-end tests.
|
||||
* Update integration tests to meet Pester 4.0.0 standards.
|
||||
* Update end-to-end tests to meet Pester 4.0.0 standards.
|
||||
* Update unit and integration tests to meet Pester 4.0.0 standards.
|
||||
* Wrapped all path and identifier strings in verbose messages with
|
||||
quotes to make it easier to identify the limit of the string when
|
||||
debugging.
|
||||
* Refactored date/time checksum code to improve testability and ensure
|
||||
tests can run on machines with localized datetime formats that are not
|
||||
US.
|
||||
* Fix 'Get-ArchiveEntryLastWriteTime' to return `[datetime]`.
|
||||
* Improved verbose logging to make debugging path issues easier.
|
||||
* Added .gitattributes file to ensure CRLF settings are configured correctly
|
||||
for the repository.
|
||||
* Updated '.vscode\settings.json' to refer to AnalyzerSettings.psd1 so that
|
||||
custom syntax problems are highlighted in Visual Studio Code.
|
||||
* Fixed style guideline violations in `CommonResourceHelper.psm1`.
|
||||
* Updated 'appveyor.yml' to meet more recent standards.
|
||||
* Removed OS image version from 'appveyor.yml' to use default image
|
||||
([Issue #127](https://github.com/PowerShell/PSDscResources/issues/127)).
|
||||
* Removed code to install WMF5.1 from 'appveyor.yml' because it is already
|
||||
installed in AppVeyor images ([Issue #128](https://github.com/PowerShell/PSDscResources/issues/128)).
|
||||
* Removed .vscode from .gitignore so that Visual Studio code environment
|
||||
settings can be committed.
|
||||
* Environment
|
||||
* Update tests to meet Pester 4.0.0 standards ([issue #129](https://github.com/PowerShell/PSDscResources/issues/129)).
|
||||
* Group
|
||||
* Update tests to meet Pester 4.0.0 standards ([issue #129](https://github.com/PowerShell/PSDscResources/issues/129)).
|
||||
* Fix unit tests to run on Nano Server.
|
||||
* Refactored unit tests to enclude Context fixtures and change functions
|
||||
to Describe fixtures.
|
||||
* GroupSet
|
||||
* Update tests to meet Pester 4.0.0 standards ([issue #129](https://github.com/PowerShell/PSDscResources/issues/129)).
|
||||
|
||||
### 2.9.0.0
|
||||
|
||||
* Added Description and Parameter description for composite resources
|
||||
|
||||
### 2.8.0.0
|
||||
|
||||
* Archive
|
||||
* Added handling of directory archive entries that end with a foward slash
|
||||
* Removed formatting of LastWriteTime timestamp and updated comparison of timestamps to handle dates in different formats
|
||||
* WindowsProcess
|
||||
* Fix unreliable tests
|
||||
* Updated Test-IsNanoServer to return false if Get-ComputerInfo fails
|
||||
* Registry
|
||||
* Fixed bug when using the full registry drive name (e.g. HKEY\_LOCAL\_MACHINE) and using a key name that includes a drive with forward slashes (e.g. C:/)
|
||||
|
||||
### 2.7.0.0
|
||||
|
||||
* MsiPackage
|
||||
* Parse installation date from registry using invariant culture.
|
||||
* Fix a bug in unit test failing, when regional setting differs from English-US.
|
||||
|
||||
### 2.6.0.0
|
||||
|
||||
* Archive
|
||||
* Fixed a minor bug in the unit tests where sometimes the incorrect DateTime format was used.
|
||||
* Added MsiPackage
|
||||
|
||||
### 2.5.0.0
|
||||
|
||||
* Enable codecov.io code coverage reporting
|
||||
* Group
|
||||
* Added support for domain based group members on Nano server.
|
||||
* Added the Archive resource
|
||||
* Update Test-IsNanoServer cmdlet to properly test for a Nano server rather than the core version of PowerShell
|
||||
* Registry
|
||||
* Fixed bug where an error was thrown when running Get-DscConfiguration if the registry already existed
|
||||
|
||||
### 2.4.0.0
|
||||
|
||||
* Cleaned User
|
||||
* Updated User to have non-dependent unit tests.
|
||||
* Ported fixes from [xPSDesiredStateConfiguration](https://github.com/PowerShell/xPSDesiredStateConfiguration):
|
||||
* WindowsProcess: Minor updates to integration tests
|
||||
* Registry: Fixed support for forward slashes in registry key names
|
||||
* Group:
|
||||
* Group members in the "NT Authority", "BuiltIn" and "NT Service" scopes should now be resolved without an error. If you were seeing the errors "Exception calling ".ctor" with "4" argument(s): "Server names cannot contain a space character."" or "Exception calling ".ctor" with "2" argument(s): "Server names cannot contain a space character."", this fix should resolve those errors. If you are still seeing one of the errors, there is probably another local scope we need to add. Please let us know.
|
||||
* The resource will no longer attempt to resolve group members if Members, MembersToInclude, and MembersToExclude are not specified.
|
||||
* Added Environment
|
||||
|
||||
### 2.3.0.0
|
||||
|
||||
* Updated manifest to include both WindowsOptionalFeature and WindowsOptionalFeatureSet instead of just WindowsOptionalFeature twice
|
||||
|
||||
### 2.2.0.0
|
||||
|
||||
* WindowsFeature:
|
||||
* Added Catch to ignore RuntimeException when importing ServerManager module. This solves the issue described [here](https://social.technet.microsoft.com/Forums/en-US/9fc314e1-27bf-4f03-ab78-5e0f7a662b8f/importmodule-servermanager-some-or-all-identity-references-could-not-be-translated?forum=winserverpowershell).
|
||||
* Updated unit tests.
|
||||
* Added WindowsProcess
|
||||
* CommonTestHelper:
|
||||
* Added Get-AppVeyorAdministratorCredential.
|
||||
* Added Set-StrictMode -'Latest' and $errorActionPreference -'Stop'.
|
||||
* Service:
|
||||
* Updated resource module, unit tests, integration tests, and examples to reflect the changes made in xPSDesiredStateConfiguration.
|
||||
* Group:
|
||||
* Updated resource module, examples, and integration tests to reflect the changes made in xPSDesiredStateConfiguration.
|
||||
* Added Script.
|
||||
* Added GroupSet, ServiceSet, WindowsFeatureSet, WindowsOptionalFeatureSet, and ProcessSet.
|
||||
* Added Set-StrictMode -'Latest' and $errorActionPreference -'Stop' to Group, Service, User, WindowsFeature, WindowsOptionalFeature, WindowsPackageCab.
|
||||
* Fixed bug in WindowsFeature in which is was checking the 'Count' property of an object that was not always an array.
|
||||
* Cleaned Group and Service resources and tests.
|
||||
* Added Registry.
|
||||
|
||||
### 2.1.0.0
|
||||
|
||||
* Added WindowsFeature.
|
||||
|
||||
### 2.0.0.0
|
||||
|
||||
* Initial release of PSDscResources.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
|
||||
param ()
|
||||
|
||||
if ($PSVersionTable.PSVersion -lt [Version] '5.1')
|
||||
@@ -65,8 +65,8 @@ try
|
||||
Ensure = 'Present'
|
||||
}
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName1 | Should -Be $false
|
||||
Test-GroupExists -GroupName $testGroupName2 | Should -Be $false
|
||||
Test-GroupExists -GroupName $testGroupName1 | Should -BeFalse
|
||||
Test-GroupExists -GroupName $testGroupName2 | Should -BeFalse
|
||||
|
||||
try
|
||||
{
|
||||
@@ -76,8 +76,8 @@ try
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should -Not -Throw
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName1 -Members @() | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName2 -Members @() | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName1 -Members @() | Should -BeTrue
|
||||
Test-GroupExists -GroupName $testGroupName2 -Members @() | Should -BeTrue
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -105,7 +105,7 @@ try
|
||||
MembersToInclude = $groupMembers
|
||||
}
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName1 | Should -Be $false
|
||||
Test-GroupExists -GroupName $testGroupName1 | Should -BeFalse
|
||||
|
||||
try
|
||||
{
|
||||
@@ -115,7 +115,7 @@ try
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should -Not -Throw
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName1 -MembersToInclude $groupMembers | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName1 -MembersToInclude $groupMembers | Should -BeTrue
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -140,8 +140,8 @@ try
|
||||
MembersToInclude = $groupMembers
|
||||
}
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $false
|
||||
Test-GroupExists -GroupName $administratorsGroupName | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeFalse
|
||||
Test-GroupExists -GroupName $administratorsGroupName | Should -BeTrue
|
||||
|
||||
try
|
||||
{
|
||||
@@ -151,8 +151,8 @@ try
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should -Not -Throw
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName -MembersToInclude $groupMembers | Should -Be $true
|
||||
Test-GroupExists -GroupName $administratorsGroupName -MembersToInclude $groupMembers | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName -MembersToInclude $groupMembers | Should -BeTrue
|
||||
Test-GroupExists -GroupName $administratorsGroupName -MembersToInclude $groupMembers | Should -BeTrue
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -178,11 +178,11 @@ try
|
||||
|
||||
foreach ($testGroupName in $testGroupNames)
|
||||
{
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $false
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeFalse
|
||||
|
||||
New-Group -GroupName $testGroupName -Members $testUsernames
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeTrue
|
||||
}
|
||||
|
||||
try
|
||||
@@ -195,7 +195,7 @@ try
|
||||
|
||||
foreach ($testGroupName in $testGroupNames)
|
||||
{
|
||||
Test-GroupExists -GroupName $testGroupName -MembersToExclude $groupMembersToExclude | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName -MembersToExclude $groupMembersToExclude | Should -BeTrue
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -222,11 +222,11 @@ try
|
||||
|
||||
foreach ($testGroupName in $testGroupNames)
|
||||
{
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $false
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeFalse
|
||||
|
||||
New-Group -GroupName $testGroupName
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeTrue
|
||||
}
|
||||
|
||||
try
|
||||
@@ -239,7 +239,7 @@ try
|
||||
|
||||
foreach ($testGroupName in $testGroupNames)
|
||||
{
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $false
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeFalse
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[System.String]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
$errorActionPreference = 'Stop'
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
if ($PSVersionTable.PSVersion -lt [Version] '5.1')
|
||||
@@ -140,7 +140,7 @@ Describe 'Archive End to End Tests' {
|
||||
$destination = Join-Path -Path $TestDrive -ChildPath 'NonExistentDestinationForExpand'
|
||||
|
||||
It 'Destination should not exist before configuration' {
|
||||
Test-Path -Path $destination | Should -Be $false
|
||||
Test-Path -Path $destination | Should -BeFalse
|
||||
}
|
||||
|
||||
$archiveParameters = @{
|
||||
@@ -151,7 +151,7 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return false from Test-TargetResource with the same parameters before configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing an exception' {
|
||||
@@ -163,15 +163,15 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Destination should exist after configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should match the file structure of the archive after configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,25 +199,25 @@ Describe 'Archive End to End Tests' {
|
||||
$otherItems[$otherFilePath] = $otherFileContent
|
||||
|
||||
It 'Destination should exist before configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
foreach ($otherItemPath in $otherItems.Keys)
|
||||
{
|
||||
$otherItemName = Split-Path -Path $otherItemPath -Leaf
|
||||
$otherItemExpectedContent = $otherItems[$otherItemPath]
|
||||
$otherItemIsDirectory = [String]::IsNullOrEmpty($otherItemExpectedContent)
|
||||
$otherItemIsDirectory = [System.String]::IsNullOrEmpty($otherItemExpectedContent)
|
||||
|
||||
if ($otherItemIsDirectory)
|
||||
{
|
||||
It "Other item under destination $otherItemName should exist as a directory before configuration" {
|
||||
Test-Path -Path $otherItemPath -PathType 'Container' | Should -Be $true
|
||||
Test-Path -Path $otherItemPath -PathType 'Container' | Should -BeTrue
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
It "Other item under destination $otherItemName should exist as a file before configuration" {
|
||||
Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -Be $true
|
||||
Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -BeTrue
|
||||
}
|
||||
|
||||
It "Other file under destination $otherItemName should have the expected content before configuration" {
|
||||
@@ -234,7 +234,7 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return false from Test-TargetResource with the same parameters before configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing an exception' {
|
||||
@@ -246,29 +246,29 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Destination should exist after configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should match the file structure of the archive after configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
foreach ($otherItemPath in $otherItems.Keys)
|
||||
{
|
||||
$otherItemName = Split-Path -Path $otherItemPath -Leaf
|
||||
$otherItemExpectedContent = $otherItems[$otherItemPath]
|
||||
$otherItemIsDirectory = [String]::IsNullOrEmpty($otherItemExpectedContent)
|
||||
$otherItemIsDirectory = [System.String]::IsNullOrEmpty($otherItemExpectedContent)
|
||||
|
||||
if ($otherItemIsDirectory)
|
||||
{
|
||||
It "Other item under destination $otherItemName should exist as a directory after configuration" {
|
||||
Test-Path -Path $otherItemPath -PathType 'Container' | Should -Be $true
|
||||
Test-Path -Path $otherItemPath -PathType 'Container' | Should -BeTrue
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
It "Other item under destination $otherItemName should exist as a file after configuration" {
|
||||
Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -Be $true
|
||||
Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -BeTrue
|
||||
}
|
||||
|
||||
It "Other file under destination $otherItemName should have the expected after before configuration" {
|
||||
@@ -278,7 +278,7 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,11 +291,11 @@ Describe 'Archive End to End Tests' {
|
||||
$null = Expand-Archive -Path $script:testArchiveFilePath -DestinationPath $destination -Force
|
||||
|
||||
It 'Destination should exist before configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should match the file structure of the archive before configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
$archiveParameters = @{
|
||||
@@ -306,7 +306,7 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters before configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing an exception' {
|
||||
@@ -318,15 +318,15 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Destination should exist after configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should match the file structure of the archive after configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,15 +339,15 @@ Describe 'Archive End to End Tests' {
|
||||
$null = Expand-Archive -Path $script:testArchiveFileWithDifferentFileContentPath -DestinationPath $destination -Force
|
||||
|
||||
It 'Destination should exist before configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should match the file structure of the archive before configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File contents of destination should not match the file contents of the archive' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -BeFalse
|
||||
}
|
||||
|
||||
$archiveParameters = @{
|
||||
@@ -361,7 +361,7 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return false from Test-TargetResource with the same parameters before configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should compile and run configuration and throw an error for attempting to overwrite files without Force specified' {
|
||||
@@ -374,19 +374,19 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Destination should exist after configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should match the file structure of the archive after configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File contents of destination should not match the file contents of the archive after configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should return false from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeFalse
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,15 +399,15 @@ Describe 'Archive End to End Tests' {
|
||||
$null = Expand-Archive -Path $script:testArchiveFileWithDifferentFileContentPath -DestinationPath $destination -Force
|
||||
|
||||
It 'Destination should exist before configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should match the file structure of the archive before configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File contents of destination should not match the file contents of the archive before configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -BeFalse
|
||||
}
|
||||
|
||||
$archiveParameters = @{
|
||||
@@ -421,7 +421,7 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return false from Test-TargetResource with the same parameters before configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing an exception' {
|
||||
@@ -433,19 +433,19 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Destination should exist after configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should match the file structure of the archive after configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File contents of destination should match the file contents of the archive after configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -458,15 +458,15 @@ Describe 'Archive End to End Tests' {
|
||||
$null = Expand-Archive -Path $script:testArchiveFilePath -DestinationPath $destination -Force
|
||||
|
||||
It 'Destination should exist before configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should match the file structure of the archive before configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File contents of destination should match the file contents of the archive before configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -BeTrue
|
||||
}
|
||||
|
||||
$archiveParameters = @{
|
||||
@@ -480,7 +480,7 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters before configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing an exception' {
|
||||
@@ -492,19 +492,19 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Destination should exist after configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should match the file structure of the archive after configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File contents of destination should match the file contents of the archive after configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -517,11 +517,11 @@ Describe 'Archive End to End Tests' {
|
||||
$null = Expand-Archive -Path $script:testArchiveFilePath -DestinationPath $destination -Force
|
||||
|
||||
It 'Destination should exist before configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should match the file structure of the archive before configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
$archiveParameters = @{
|
||||
@@ -532,7 +532,7 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return false from Test-TargetResource with the same parameters before configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing an exception' {
|
||||
@@ -544,15 +544,15 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Destination should exist after configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should not match the file structure of the archive after configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -582,25 +582,25 @@ Describe 'Archive End to End Tests' {
|
||||
$otherItems[$otherFilePath] = $otherFileContent
|
||||
|
||||
It 'Destination should exist before configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
foreach ($otherItemPath in $otherItems.Keys)
|
||||
{
|
||||
$otherItemName = Split-Path -Path $otherItemPath -Leaf
|
||||
$otherItemExpectedContent = $otherItems[$otherItemPath]
|
||||
$otherItemIsDirectory = [String]::IsNullOrEmpty($otherItemExpectedContent)
|
||||
$otherItemIsDirectory = [System.String]::IsNullOrEmpty($otherItemExpectedContent)
|
||||
|
||||
if ($otherItemIsDirectory)
|
||||
{
|
||||
It "Other item under destination $otherItemName should exist as a directory before configuration" {
|
||||
Test-Path -Path $otherItemPath -PathType 'Container' | Should -Be $true
|
||||
Test-Path -Path $otherItemPath -PathType 'Container' | Should -BeTrue
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
It "Other item under destination $otherItemName should exist as a file before configuration" {
|
||||
Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -Be $true
|
||||
Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -BeTrue
|
||||
}
|
||||
|
||||
It "Other file under destination $otherItemName should have the expected content before configuration" {
|
||||
@@ -610,7 +610,7 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'File structure of destination should match the file structure of the archive before configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
$archiveParameters = @{
|
||||
@@ -621,7 +621,7 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return false from Test-TargetResource with the same parameters before configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing an exception' {
|
||||
@@ -633,25 +633,25 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Destination should exist after configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
foreach ($otherItemPath in $otherItems.Keys)
|
||||
{
|
||||
$otherItemName = Split-Path -Path $otherItemPath -Leaf
|
||||
$otherItemExpectedContent = $otherItems[$otherItemPath]
|
||||
$otherItemIsDirectory = [String]::IsNullOrEmpty($otherItemExpectedContent)
|
||||
$otherItemIsDirectory = [System.String]::IsNullOrEmpty($otherItemExpectedContent)
|
||||
|
||||
if ($otherItemIsDirectory)
|
||||
{
|
||||
It "Other item under destination $otherItemName should exist as a directory before configuration" {
|
||||
Test-Path -Path $otherItemPath -PathType 'Container' | Should -Be $true
|
||||
Test-Path -Path $otherItemPath -PathType 'Container' | Should -BeTrue
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
It "Other item under destination $otherItemName should exist as a file before configuration" {
|
||||
Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -Be $true
|
||||
Test-Path -Path $otherItemPath -PathType 'Leaf' | Should -BeTrue
|
||||
}
|
||||
|
||||
It "Other file under destination $otherItemName should have the expected content before configuration" {
|
||||
@@ -661,11 +661,11 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'File structure of destination should not match the file structure of the archive after configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -676,11 +676,11 @@ Describe 'Archive End to End Tests' {
|
||||
$null = New-Item -Path $destination -ItemType 'Directory'
|
||||
|
||||
It 'Destination should exist before configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should not match the file structure of the archive before configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeFalse
|
||||
}
|
||||
|
||||
$archiveParameters = @{
|
||||
@@ -691,7 +691,7 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters before configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing an exception' {
|
||||
@@ -703,15 +703,15 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Destination should exist after configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should not match the file structure of the archive after configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -721,7 +721,7 @@ Describe 'Archive End to End Tests' {
|
||||
$destination = Join-Path -Path $TestDrive -ChildPath 'NonexistentDestinationForRemove'
|
||||
|
||||
It 'Destination should not exist before configuration' {
|
||||
Test-Path -Path $destination | Should -Be $false
|
||||
Test-Path -Path $destination | Should -BeFalse
|
||||
}
|
||||
|
||||
$archiveParameters = @{
|
||||
@@ -732,7 +732,7 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters before configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing an exception' {
|
||||
@@ -744,11 +744,11 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Destination should not exist after configuration' {
|
||||
Test-Path -Path $destination | Should -Be $false
|
||||
Test-Path -Path $destination | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -761,15 +761,15 @@ Describe 'Archive End to End Tests' {
|
||||
$null = Expand-Archive -Path $script:testArchiveFileWithDifferentFileContentPath -DestinationPath $destination -Force
|
||||
|
||||
It 'Destination should exist before configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should match the file structure of the archive before configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File contents of destination should not match the file contents of the archive before configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -BeFalse
|
||||
}
|
||||
|
||||
$archiveParameters = @{
|
||||
@@ -783,7 +783,7 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters before configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing an exception' {
|
||||
@@ -795,19 +795,19 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Destination should exist after configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should match the file structure of the archive after configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File contents of destination should not match the file contents of the archive after configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -820,11 +820,11 @@ Describe 'Archive End to End Tests' {
|
||||
$null = Expand-Archive -Path $script:testArchiveFilePath -DestinationPath $destination -Force
|
||||
|
||||
It 'Destination should exist before configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure and contents of destination should match the file contents of the archive before configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination -CheckContents | Should -BeTrue
|
||||
}
|
||||
|
||||
$archiveParameters = @{
|
||||
@@ -838,7 +838,7 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return false from Test-TargetResource with the same parameters before configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $false
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing an exception' {
|
||||
@@ -850,15 +850,15 @@ Describe 'Archive End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Destination should exist after configuration' {
|
||||
Test-Path -Path $destination | Should -Be $true
|
||||
Test-Path -Path $destination | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure of destination should not match the file structure of the archive after configuration' {
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $script:testArchiveFilePathWithoutExtension -DestinationPath $destination | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should return false from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -Be $true
|
||||
MSFT_Archive\Test-TargetResource @archiveParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,15 +46,15 @@ Describe 'Archive Integration Tests' {
|
||||
$destinationDirectoryPath = Join-Path -Path $TestDrive -ChildPath $destinationDirectoryName
|
||||
|
||||
It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return false before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return true before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Set-TargetResource should not throw' {
|
||||
@@ -62,15 +62,15 @@ Describe 'Archive Integration Tests' {
|
||||
}
|
||||
|
||||
It 'File structure and contents of the destination should match the file structure and contents of the archive after Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return true after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return false after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeFalse
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,15 +93,15 @@ Describe 'Archive Integration Tests' {
|
||||
$null = Expand-Archive -Path $zipFilePath -DestinationPath $destinationDirectoryPath -Force
|
||||
|
||||
It 'File structure and contents of the destination should match the file structure and contents of the archive before Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return true before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return false before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Set-TargetResource should not throw' {
|
||||
@@ -109,15 +109,15 @@ Describe 'Archive Integration Tests' {
|
||||
}
|
||||
|
||||
It 'File structure and contents of the destination should not match the file structure and contents of the archive after Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return false after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return true after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,15 +164,15 @@ Describe 'Archive Integration Tests' {
|
||||
$destinationDirectoryPath = Join-Path -Path $TestDrive -ChildPath $destinationDirectoryName
|
||||
|
||||
It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return false before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return true before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Set-TargetResource should not throw' {
|
||||
@@ -180,15 +180,15 @@ Describe 'Archive Integration Tests' {
|
||||
}
|
||||
|
||||
It 'File structure and contents of the destination should match the file structure and contents of the archive after Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return true after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return false after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeFalse
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,15 +237,15 @@ Describe 'Archive Integration Tests' {
|
||||
$null = Expand-Archive -Path $zipFilePath -DestinationPath $destinationDirectoryPath -Force
|
||||
|
||||
It 'File structure and contents of the destination should match the file structure and contents of the archive before Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return true before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return false before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Set-TargetResource should not throw' {
|
||||
@@ -253,15 +253,15 @@ Describe 'Archive Integration Tests' {
|
||||
}
|
||||
|
||||
It 'File structure and contents of the destination should not match the file structure and contents of the archive after Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return false after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return true after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,23 +295,23 @@ Describe 'Archive Integration Tests' {
|
||||
$destinationDirectoryPath = Join-Path -Path $TestDrive -ChildPath $destinationDirectoryName
|
||||
|
||||
It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath1 -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath1 -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return false for specified archive before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return true for specified archive before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return false for other archive with same timestamp with before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return true for other archive with same timestamp before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Set-TargetResource should not throw' {
|
||||
@@ -319,23 +319,23 @@ Describe 'Archive Integration Tests' {
|
||||
}
|
||||
|
||||
It 'File structure and contents of the destination should match the file structure and contents of the archive after Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath1 -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath1 -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return true for specified archive after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return false for specified archive after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath1 -Destination $destinationDirectoryPath | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return false for other archive with same timestamp with before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return true for other archive with same timestamp before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath2 -Destination $destinationDirectoryPath | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,19 +371,19 @@ Describe 'Archive Integration Tests' {
|
||||
$null = Set-Content -Path $newFilePath -Value 'Fake text'
|
||||
|
||||
It 'File structure and contents of the destination should match the file structure and contents of the archive before Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return true before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return false before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Extra file should be present before Set-TargetResource' {
|
||||
Test-Path -Path $newFilePath | Should -Be $true
|
||||
Test-Path -Path $newFilePath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Set-TargetResource should not throw' {
|
||||
@@ -391,19 +391,19 @@ Describe 'Archive Integration Tests' {
|
||||
}
|
||||
|
||||
It 'File structure and contents of the destination should not match the file structure and contents of the archive after Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return false after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return true after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Extra file should be present after Set-TargetResource' {
|
||||
Test-Path -Path $newFilePath | Should -Be $true
|
||||
Test-Path -Path $newFilePath | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,26 +454,25 @@ Describe 'Archive Integration Tests' {
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return true before file edit' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return false before file edit' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeFalse
|
||||
}
|
||||
|
||||
$fileToEditPath = Join-Path -Path $destinationDirectoryPath -ChildPath $fileToEditName
|
||||
|
||||
It 'File to edit should exist at the destination before Set-TargetResource' {
|
||||
Test-Path -Path $fileToEditPath | Should -Be $true
|
||||
Test-Path -Path $fileToEditPath | Should -BeTrue
|
||||
}
|
||||
|
||||
$fileBeforeEdit = Get-Item -Path $fileToEditPath
|
||||
$lastWriteTimeBeforeEdit = $fileBeforeEdit.LastWriteTime
|
||||
$creationTimeBeforeEdit = $fileBeforeEdit.CreationTime
|
||||
|
||||
$null = Set-Content -Path $fileToEditPath -Value 'Different false text' -Force
|
||||
Set-ItemProperty -Path $fileToEditPath -Name 'LastWriteTime' -Value ([DateTime]::MaxValue)
|
||||
Set-ItemProperty -Path $fileToEditPath -Name 'CreationTime' -Value ([DateTime]::MaxValue)
|
||||
Set-ItemProperty -Path $fileToEditPath -Name 'LastWriteTime' -Value ([System.DateTime]::MaxValue)
|
||||
Set-ItemProperty -Path $fileToEditPath -Name 'CreationTime' -Value ([System.DateTime]::MaxValue)
|
||||
|
||||
$fileAfterEdit = Get-Item -Path $fileToEditPath
|
||||
|
||||
@@ -490,15 +489,15 @@ Describe 'Archive Integration Tests' {
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return false before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return true before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Set-TargetResource should not throw' {
|
||||
@@ -508,7 +507,7 @@ Describe 'Archive Integration Tests' {
|
||||
$fileAfterSetTargetResource = Get-Item -Path $fileToEditPath
|
||||
|
||||
It 'Edited file should exist at the destination after Set-TargetResource' {
|
||||
Test-Path -Path $fileToEditPath | Should -Be $true
|
||||
Test-Path -Path $fileToEditPath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Edited file at the destination should have the same content as the same file in the archive after Set-TargetResource' {
|
||||
@@ -524,15 +523,15 @@ Describe 'Archive Integration Tests' {
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return true after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return false after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'File structure and contents of the destination should match the file structure and contents of the archive after Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $true
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,26 +566,25 @@ Describe 'Archive Integration Tests' {
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return true before file edit' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return false before file edit' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeFalse
|
||||
}
|
||||
|
||||
$fileToEditPath = Join-Path -Path $destinationDirectoryPath -ChildPath $fileToEditName
|
||||
|
||||
It 'File to edit should exist at the destination before Set-TargetResource' {
|
||||
Test-Path -Path $fileToEditPath | Should -Be $true
|
||||
Test-Path -Path $fileToEditPath | Should -BeTrue
|
||||
}
|
||||
|
||||
$fileBeforeEdit = Get-Item -Path $fileToEditPath
|
||||
$lastWriteTimeBeforeEdit = $fileBeforeEdit.LastWriteTime
|
||||
$creationTimeBeforeEdit = $fileBeforeEdit.CreationTime
|
||||
|
||||
$null = Set-Content -Path $fileToEditPath -Value 'Different false text' -Force
|
||||
Set-ItemProperty -Path $fileToEditPath -Name 'LastWriteTime' -Value ([DateTime]::MaxValue)
|
||||
Set-ItemProperty -Path $fileToEditPath -Name 'CreationTime' -Value ([DateTime]::MaxValue)
|
||||
Set-ItemProperty -Path $fileToEditPath -Name 'LastWriteTime' -Value ([System.DateTime]::MaxValue)
|
||||
Set-ItemProperty -Path $fileToEditPath -Name 'CreationTime' -Value ([System.DateTime]::MaxValue)
|
||||
|
||||
$fileAfterEdit = Get-Item -Path $fileToEditPath
|
||||
|
||||
@@ -603,15 +601,15 @@ Describe 'Archive Integration Tests' {
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return false before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return true before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeFalse
|
||||
}
|
||||
|
||||
{ Set-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue } | Should -Throw
|
||||
@@ -648,26 +646,25 @@ Describe 'Archive Integration Tests' {
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return true before file edit' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return false before file edit' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeFalse
|
||||
}
|
||||
|
||||
$fileToEditPath = Join-Path -Path $destinationDirectoryPath -ChildPath $fileToEditName
|
||||
|
||||
It 'File to edit should exist at the destination before Set-TargetResource' {
|
||||
Test-Path -Path $fileToEditPath | Should -Be $true
|
||||
Test-Path -Path $fileToEditPath | Should -BeTrue
|
||||
}
|
||||
|
||||
$fileBeforeEdit = Get-Item -Path $fileToEditPath
|
||||
$lastWriteTimeBeforeEdit = $fileBeforeEdit.LastWriteTime
|
||||
$creationTimeBeforeEdit = $fileBeforeEdit.CreationTime
|
||||
|
||||
$null = Set-Content -Path $fileToEditPath -Value 'Different false text' -Force
|
||||
Set-ItemProperty -Path $fileToEditPath -Name 'LastWriteTime' -Value ([DateTime]::MaxValue)
|
||||
Set-ItemProperty -Path $fileToEditPath -Name 'CreationTime' -Value ([DateTime]::MaxValue)
|
||||
Set-ItemProperty -Path $fileToEditPath -Name 'LastWriteTime' -Value ([System.DateTime]::MaxValue)
|
||||
Set-ItemProperty -Path $fileToEditPath -Name 'CreationTime' -Value ([System.DateTime]::MaxValue)
|
||||
|
||||
$fileAfterEdit = Get-Item -Path $fileToEditPath
|
||||
|
||||
@@ -684,25 +681,23 @@ Describe 'Archive Integration Tests' {
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return false before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return true before Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure and contents of the destination should not match the file structure and contents of the archive before Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Set-TargetResource should not throw' {
|
||||
{ Set-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue } | Should -Not -Throw
|
||||
}
|
||||
|
||||
$fileAfterSetTargetResource = Get-Item -Path $fileToEditPath
|
||||
|
||||
It 'Edited file should exist at the destination after Set-TargetResource' {
|
||||
Test-Path -Path $fileToEditPath | Should -Be $true
|
||||
Test-Path -Path $fileToEditPath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Edited file at the destination should have the edited content' {
|
||||
@@ -718,15 +713,15 @@ Describe 'Archive Integration Tests' {
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Present should return false after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $false
|
||||
Test-TargetResource -Ensure 'Present' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Test-TargetResource with Ensure as Absent should return true after Set-TargetResource' {
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -Be $true
|
||||
Test-TargetResource -Ensure 'Absent' -Path $zipFilePath -Destination $destinationDirectoryPath -Validate $true -Checksum $possibleChecksumValue | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'File structure and contents of the destination should not match the file structure and contents of the archive after Set-TargetResource' {
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -Be $false
|
||||
Test-FileStructuresMatch -SourcePath $zipFileSourcePath -DestinationPath $destinationDirectoryPath -CheckContents | Should -BeFalse
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$ConfigurationName
|
||||
)
|
||||
|
||||
@@ -11,17 +11,17 @@ Configuration $ConfigurationName
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Destination,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$ConfigurationName
|
||||
)
|
||||
|
||||
@@ -11,29 +11,29 @@ Configuration $ConfigurationName
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Destination,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Validate = $false,
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Checksum = 'SHA-256',
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Force = $false
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$ConfigurationName
|
||||
)
|
||||
|
||||
@@ -11,21 +11,21 @@ Configuration $ConfigurationName
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Destination,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$Validate = $false
|
||||
)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
Please note that some of these tests depend on each other.
|
||||
They must be run in the order given - if one test fails, subsequent tests may
|
||||
also fail.
|
||||
@@ -27,53 +27,53 @@ try
|
||||
{
|
||||
Describe 'EnvironmentResouce Integration Tests - with both Targets specified (default)' {
|
||||
BeforeAll {
|
||||
$testEnvironmentVarName = 'TestEnvironmentVariableName'
|
||||
$testPathEnvironmentVarName = 'TestPathEnvironmentVariableName'
|
||||
$machineEnvironmentRegistryPath = 'HKLM:\System\CurrentControlSet\Control\Session Manager\Environment'
|
||||
$script:testEnvironmentVarName = 'TestEnvironmentVariableName'
|
||||
$script:testPathEnvironmentVarName = 'TestPathEnvironmentVariableName'
|
||||
$script:machineEnvironmentRegistryPath = 'HKLM:\System\CurrentControlSet\Control\Session Manager\Environment'
|
||||
|
||||
$testValue = 'InitialTestValue'
|
||||
$newTestValue = 'NewTestValue'
|
||||
$script:testValue = 'InitialTestValue'
|
||||
$script:newTestValue = 'NewTestValue'
|
||||
|
||||
$configFile = Join-Path -Path $PSScriptRoot -ChildPath 'MSFT_EnvironmentResource.config.ps1'
|
||||
$script:configFile = Join-Path -Path $PSScriptRoot -ChildPath 'MSFT_EnvironmentResource.config.ps1'
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
# Remove variables from the process:
|
||||
[System.Environment]::SetEnvironmentVariable($testEnvironmentVarName, $null)
|
||||
[System.Environment]::SetEnvironmentVariable($testPathEnvironmentVarName, $null)
|
||||
[System.Environment]::SetEnvironmentVariable($script:testEnvironmentVarName, $null)
|
||||
[System.Environment]::SetEnvironmentVariable($script:testPathEnvironmentVarName, $null)
|
||||
|
||||
# Remove variables from machine:
|
||||
if (Get-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
if (Get-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
{
|
||||
Remove-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testEnvironmentVarName
|
||||
Remove-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testEnvironmentVarName
|
||||
}
|
||||
|
||||
if (Get-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testPathEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
if (Get-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testPathEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
{
|
||||
Remove-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testPathEnvironmentVarName
|
||||
Remove-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testPathEnvironmentVarName
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should create the environment variable $testEnvironmentVarName" {
|
||||
Context "Should create the environment variable $script:testEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Create'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
# Ensure the environment variable doesn't exist
|
||||
|
||||
# Remove variable from the process:
|
||||
[System.Environment]::SetEnvironmentVariable($testEnvironmentVarName, $null)
|
||||
[System.Environment]::SetEnvironmentVariable($script:testEnvironmentVarName, $null)
|
||||
|
||||
# Remove variable from machine:
|
||||
if (Get-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
if (Get-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
{
|
||||
Remove-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testEnvironmentVarName
|
||||
Remove-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testEnvironmentVarName
|
||||
}
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testEnvironmentVarName `
|
||||
-Value $testValue `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testEnvironmentVarName `
|
||||
-Value $script:testValue `
|
||||
-Ensure 'Present' `
|
||||
-OutputPath $configurationPath `
|
||||
-ErrorAction 'Stop'
|
||||
@@ -87,21 +87,21 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $testValue
|
||||
$currentConfig.Name | Should -Be $script:testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $script:testValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should update environment variable $testEnvironmentVarName" {
|
||||
Context "Should update environment variable $script:testEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Update'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testEnvironmentVarName `
|
||||
-Value $newTestValue `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testEnvironmentVarName `
|
||||
-Value $script:newTestValue `
|
||||
-Ensure 'Present' `
|
||||
-OutputPath $configurationPath `
|
||||
-ErrorAction 'Stop'
|
||||
@@ -115,8 +115,8 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $newTestValue
|
||||
$currentConfig.Name | Should -Be $script:testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $script:newTestValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
@@ -127,8 +127,8 @@ try
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testEnvironmentVarName `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testEnvironmentVarName `
|
||||
-Value 'otherValue' `
|
||||
-Ensure 'Absent' `
|
||||
-OutputPath $configurationPath `
|
||||
@@ -143,20 +143,20 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $newTestValue
|
||||
$currentConfig.Name | Should -Be $script:testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $script:newTestValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should remove environment variable $testEnvironmentVarName" {
|
||||
Context "Should remove environment variable $script:testEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Remove'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testEnvironmentVarName `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testEnvironmentVarName `
|
||||
-Value $null `
|
||||
-Ensure 'Absent' `
|
||||
-OutputPath $configurationPath `
|
||||
@@ -171,32 +171,32 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testEnvironmentVarName
|
||||
$currentConfig.Name | Should -Be $script:testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $null
|
||||
$currentConfig.Ensure | Should -Be 'Absent'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should create the path environment variable $testPathEnvironmentVarName" {
|
||||
Context "Should create the path environment variable $script:testPathEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Create_Path'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
# Ensure the environment variable doesn't exist
|
||||
|
||||
# Remove variable from the process:
|
||||
[System.Environment]::SetEnvironmentVariable($testPathEnvironmentVarName, $null)
|
||||
[System.Environment]::SetEnvironmentVariable($script:testPathEnvironmentVarName, $null)
|
||||
|
||||
# Remove variable from machine:
|
||||
if (Get-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testPathEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
if (Get-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testPathEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
{
|
||||
Remove-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testPathEnvironmentVarName
|
||||
Remove-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testPathEnvironmentVarName
|
||||
}
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testPathEnvironmentVarName `
|
||||
-Value $testValue `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testPathEnvironmentVarName `
|
||||
-Value $script:testValue `
|
||||
-Ensure 'Present' `
|
||||
-Path $true `
|
||||
-OutputPath $configurationPath `
|
||||
@@ -211,23 +211,23 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $testValue
|
||||
$currentConfig.Name | Should -Be $script:testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $script:testValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should update environment variable $testPathEnvironmentVarName" {
|
||||
Context "Should update environment variable $script:testPathEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Update_Path'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
$expectedValue = $testValue + ';' + $newTestValue
|
||||
$expectedValue = $script:testValue + ';' + $script:newTestValue
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testPathEnvironmentVarName `
|
||||
-Value $newTestValue `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testPathEnvironmentVarName `
|
||||
-Value $script:newTestValue `
|
||||
-Ensure 'Present' `
|
||||
-Path $true `
|
||||
-OutputPath $configurationPath `
|
||||
@@ -242,7 +242,7 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testPathEnvironmentVarName
|
||||
$currentConfig.Name | Should -Be $script:testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $expectedValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
@@ -252,12 +252,12 @@ try
|
||||
$configurationName = 'MSFT_EnvironmentResource_NonRemove_Path'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
$expectedValue = $testValue + ';' + $newTestValue
|
||||
$expectedValue = $script:testValue + ';' + $script:newTestValue
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testPathEnvironmentVarName `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testPathEnvironmentVarName `
|
||||
-Value 'otherValue' `
|
||||
-Ensure 'Absent' `
|
||||
-Path $true `
|
||||
@@ -273,21 +273,21 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testPathEnvironmentVarName
|
||||
$currentConfig.Name | Should -Be $script:testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $expectedValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should remove only one value from environment variable $testPathEnvironmentVarName" {
|
||||
Context "Should remove only one value from environment variable $script:testPathEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_PartialRemove_Path'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testPathEnvironmentVarName `
|
||||
-Value $testValue `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testPathEnvironmentVarName `
|
||||
-Value $script:testValue `
|
||||
-Ensure 'Absent' `
|
||||
-Path $true `
|
||||
-OutputPath $configurationPath `
|
||||
@@ -302,20 +302,20 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $newTestValue
|
||||
$currentConfig.Name | Should -Be $script:testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $script:newTestValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should remove the environment variable $testPathEnvironmentVarName" {
|
||||
Context "Should remove the environment variable $script:testPathEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Remove_Path'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testPathEnvironmentVarName `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testPathEnvironmentVarName `
|
||||
-Value $null `
|
||||
-Ensure 'Absent' `
|
||||
-Path $true `
|
||||
@@ -331,7 +331,7 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testPathEnvironmentVarName
|
||||
$currentConfig.Name | Should -Be $script:testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $null
|
||||
$currentConfig.Ensure | Should -Be 'Absent'
|
||||
}
|
||||
@@ -340,45 +340,45 @@ try
|
||||
|
||||
Describe 'EnvironmentResouce Integration Tests - only Process Target specified' {
|
||||
BeforeAll {
|
||||
$testEnvironmentVarName = 'TestProcessEnvironmentVariableName'
|
||||
$testPathEnvironmentVarName = 'TestProcessPathEnvironmentVariableName'
|
||||
$script:testEnvironmentVarName = 'TestProcessEnvironmentVariableName'
|
||||
$script:testPathEnvironmentVarName = 'TestProcessPathEnvironmentVariableName'
|
||||
|
||||
$testValue = 'InitialProcessTestValue'
|
||||
$newTestValue = 'NewProcessTestValue'
|
||||
$script:testValue = 'InitialProcessTestValue'
|
||||
$script:newTestValue = 'NewProcessTestValue'
|
||||
|
||||
$configFile = Join-Path -Path $PSScriptRoot -ChildPath 'MSFT_EnvironmentResource.config.ps1'
|
||||
$script:configFile = Join-Path -Path $PSScriptRoot -ChildPath 'MSFT_EnvironmentResource.config.ps1'
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
# Remove variables from the process:
|
||||
[System.Environment]::SetEnvironmentVariable($testEnvironmentVarName, $null)
|
||||
[System.Environment]::SetEnvironmentVariable($testPathEnvironmentVarName, $null)
|
||||
[System.Environment]::SetEnvironmentVariable($script:testEnvironmentVarName, $null)
|
||||
[System.Environment]::SetEnvironmentVariable($script:testPathEnvironmentVarName, $null)
|
||||
|
||||
# Remove variables from machine (these shouldn't have been set):
|
||||
if (Get-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
if (Get-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
{
|
||||
Remove-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testEnvironmentVarName
|
||||
Remove-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testEnvironmentVarName
|
||||
}
|
||||
if (Get-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testPathEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
if (Get-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testPathEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
{
|
||||
Remove-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testPathEnvironmentVarName
|
||||
Remove-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testPathEnvironmentVarName
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should create the environment variable $testEnvironmentVarName" {
|
||||
Context "Should create the environment variable $script:testEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Create'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
# Ensure the environment variable doesn't exist
|
||||
|
||||
# Remove variable from the process:
|
||||
[System.Environment]::SetEnvironmentVariable($testEnvironmentVarName, $null)
|
||||
[System.Environment]::SetEnvironmentVariable($script:testEnvironmentVarName, $null)
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testEnvironmentVarName `
|
||||
-Value $testValue `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testEnvironmentVarName `
|
||||
-Value $script:testValue `
|
||||
-Ensure 'Present' `
|
||||
-Target @('Process') `
|
||||
-OutputPath $configurationPath `
|
||||
@@ -393,21 +393,21 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $testValue
|
||||
$currentConfig.Name | Should -Be $script:testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $script:testValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should update environment variable $testEnvironmentVarName" {
|
||||
Context "Should update environment variable $script:testEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Update'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testEnvironmentVarName `
|
||||
-Value $newTestValue `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testEnvironmentVarName `
|
||||
-Value $script:newTestValue `
|
||||
-Ensure 'Present' `
|
||||
-Target @('Process') `
|
||||
-OutputPath $configurationPath `
|
||||
@@ -422,8 +422,8 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $newTestValue
|
||||
$currentConfig.Name | Should -Be $script:testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $script:newTestValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
@@ -434,8 +434,8 @@ try
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testEnvironmentVarName `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testEnvironmentVarName `
|
||||
-Value 'otherValue' `
|
||||
-Ensure 'Absent' `
|
||||
-Target @('Process') `
|
||||
@@ -451,20 +451,20 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $newTestValue
|
||||
$currentConfig.Name | Should -Be $script:testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $script:newTestValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should remove environment variable $testEnvironmentVarName" {
|
||||
Context "Should remove environment variable $script:testEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Remove'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testEnvironmentVarName `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testEnvironmentVarName `
|
||||
-Value $null `
|
||||
-Ensure 'Absent' `
|
||||
-Target @('Process') `
|
||||
@@ -480,26 +480,26 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testEnvironmentVarName
|
||||
$currentConfig.Name | Should -Be $script:testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $null
|
||||
$currentConfig.Ensure | Should -Be 'Absent'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should create the path environment variable $testPathEnvironmentVarName" {
|
||||
Context "Should create the path environment variable $script:testPathEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Create_Path'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
# Ensure the environment variable doesn't exist
|
||||
|
||||
# Remove variable from the process:
|
||||
[System.Environment]::SetEnvironmentVariable($testPathEnvironmentVarName, $null)
|
||||
[System.Environment]::SetEnvironmentVariable($script:testPathEnvironmentVarName, $null)
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testPathEnvironmentVarName `
|
||||
-Value $testValue `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testPathEnvironmentVarName `
|
||||
-Value $script:testValue `
|
||||
-Ensure 'Present' `
|
||||
-Path $true `
|
||||
-Target @('Process') `
|
||||
@@ -515,23 +515,23 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $testValue
|
||||
$currentConfig.Name | Should -Be $script:testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $script:testValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should update environment variable $testPathEnvironmentVarName" {
|
||||
Context "Should update environment variable $script:testPathEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Update_Path'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
$expectedValue = $testValue + ';' + $newTestValue
|
||||
$expectedValue = $script:testValue + ';' + $script:newTestValue
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testPathEnvironmentVarName `
|
||||
-Value $newTestValue `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testPathEnvironmentVarName `
|
||||
-Value $script:newTestValue `
|
||||
-Ensure 'Present' `
|
||||
-Path $true `
|
||||
-Target @('Process') `
|
||||
@@ -547,7 +547,7 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testPathEnvironmentVarName
|
||||
$currentConfig.Name | Should -Be $script:testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $expectedValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
@@ -557,12 +557,12 @@ try
|
||||
$configurationName = 'MSFT_EnvironmentResource_NonRemove_Path'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
$expectedValue = $testValue + ';' + $newTestValue
|
||||
$expectedValue = $script:testValue + ';' + $script:newTestValue
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testPathEnvironmentVarName `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testPathEnvironmentVarName `
|
||||
-Value 'otherValue' `
|
||||
-Ensure 'Absent' `
|
||||
-Path $true `
|
||||
@@ -579,21 +579,21 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testPathEnvironmentVarName
|
||||
$currentConfig.Name | Should -Be $script:testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $expectedValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should remove only one value from environment variable $testPathEnvironmentVarName" {
|
||||
Context "Should remove only one value from environment variable $script:testPathEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_PartialRemove_Path'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testPathEnvironmentVarName `
|
||||
-Value $testValue `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testPathEnvironmentVarName `
|
||||
-Value $script:testValue `
|
||||
-Ensure 'Absent' `
|
||||
-Path $true `
|
||||
-Target @('Process') `
|
||||
@@ -609,20 +609,20 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $newTestValue
|
||||
$currentConfig.Name | Should -Be $script:testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $script:newTestValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should remove the environment variable $testPathEnvironmentVarName" {
|
||||
Context "Should remove the environment variable $script:testPathEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Remove_Path'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testPathEnvironmentVarName `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testPathEnvironmentVarName `
|
||||
-Value $null `
|
||||
-Ensure 'Absent' `
|
||||
-Path $true `
|
||||
@@ -639,7 +639,7 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testPathEnvironmentVarName
|
||||
$currentConfig.Name | Should -Be $script:testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $null
|
||||
$currentConfig.Ensure | Should -Be 'Absent'
|
||||
}
|
||||
@@ -648,48 +648,48 @@ try
|
||||
|
||||
Describe 'EnvironmentResouce Integration Tests - only Machine Target specified' {
|
||||
BeforeAll {
|
||||
$testEnvironmentVarName = 'TestMachineEnvironmentVariableName'
|
||||
$testPathEnvironmentVarName = 'TestMachinePathEnvironmentVariableName'
|
||||
$script:testEnvironmentVarName = 'TestMachineEnvironmentVariableName'
|
||||
$script:testPathEnvironmentVarName = 'TestMachinePathEnvironmentVariableName'
|
||||
|
||||
$testValue = 'InitialMachineTestValue'
|
||||
$newTestValue = 'NewMachineTestValue'
|
||||
$script:testValue = 'InitialMachineTestValue'
|
||||
$script:newTestValue = 'NewMachineTestValue'
|
||||
|
||||
$configFile = Join-Path -Path $PSScriptRoot -ChildPath 'MSFT_EnvironmentResource.config.ps1'
|
||||
$script:configFile = Join-Path -Path $PSScriptRoot -ChildPath 'MSFT_EnvironmentResource.config.ps1'
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
# Remove variables from the process (these shouldn't have been set):
|
||||
[System.Environment]::SetEnvironmentVariable($testEnvironmentVarName, $null)
|
||||
[System.Environment]::SetEnvironmentVariable($testPathEnvironmentVarName, $null)
|
||||
[System.Environment]::SetEnvironmentVariable($script:testEnvironmentVarName, $null)
|
||||
[System.Environment]::SetEnvironmentVariable($script:testPathEnvironmentVarName, $null)
|
||||
|
||||
# Remove variables from machine:
|
||||
if (Get-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
if (Get-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
{
|
||||
Remove-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testEnvironmentVarName
|
||||
Remove-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testEnvironmentVarName
|
||||
}
|
||||
if (Get-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testPathEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
if (Get-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testPathEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
{
|
||||
Remove-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testPathEnvironmentVarName
|
||||
Remove-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testPathEnvironmentVarName
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should create the environment variable $testEnvironmentVarName" {
|
||||
Context "Should create the environment variable $script:testEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Create'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
# Ensure the environment variable doesn't exist:
|
||||
|
||||
# Remove variable from machine:
|
||||
if (Get-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
if (Get-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
{
|
||||
Remove-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testEnvironmentVarName
|
||||
Remove-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testEnvironmentVarName
|
||||
}
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testEnvironmentVarName `
|
||||
-Value $testValue `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testEnvironmentVarName `
|
||||
-Value $script:testValue `
|
||||
-Ensure 'Present' `
|
||||
-Target @('Machine') `
|
||||
-OutputPath $configurationPath `
|
||||
@@ -704,21 +704,21 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $testValue
|
||||
$currentConfig.Name | Should -Be $script:testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $script:testValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should update environment variable $testEnvironmentVarName" {
|
||||
Context "Should update environment variable $script:testEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Update'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testEnvironmentVarName `
|
||||
-Value $newTestValue `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testEnvironmentVarName `
|
||||
-Value $script:newTestValue `
|
||||
-Ensure 'Present' `
|
||||
-Target @('Machine') `
|
||||
-OutputPath $configurationPath `
|
||||
@@ -733,8 +733,8 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $newTestValue
|
||||
$currentConfig.Name | Should -Be $script:testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $script:newTestValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
@@ -745,8 +745,8 @@ try
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testEnvironmentVarName `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testEnvironmentVarName `
|
||||
-Value 'otherValue' `
|
||||
-Ensure 'Absent' `
|
||||
-Target @('Machine') `
|
||||
@@ -762,20 +762,20 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $newTestValue
|
||||
$currentConfig.Name | Should -Be $script:testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $script:newTestValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should remove environment variable $testEnvironmentVarName" {
|
||||
Context "Should remove environment variable $script:testEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Remove'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testEnvironmentVarName `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testEnvironmentVarName `
|
||||
-Value $null `
|
||||
-Ensure 'Absent' `
|
||||
-Target @('Machine') `
|
||||
@@ -791,29 +791,29 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testEnvironmentVarName
|
||||
$currentConfig.Name | Should -Be $script:testEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $null
|
||||
$currentConfig.Ensure | Should -Be 'Absent'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should create the path environment variable $testPathEnvironmentVarName" {
|
||||
Context "Should create the path environment variable $script:testPathEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Create_Path'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
# Ensure the environment variable doesn't exist:
|
||||
|
||||
# Remove variable from machine:
|
||||
if (Get-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testPathEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
if (Get-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testPathEnvironmentVarName -ErrorAction 'SilentlyContinue')
|
||||
{
|
||||
Remove-ItemProperty -Path $machineEnvironmentRegistryPath -Name $testPathEnvironmentVarName
|
||||
Remove-ItemProperty -Path $script:machineEnvironmentRegistryPath -Name $script:testPathEnvironmentVarName
|
||||
}
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testPathEnvironmentVarName `
|
||||
-Value $testValue `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testPathEnvironmentVarName `
|
||||
-Value $script:testValue `
|
||||
-Ensure 'Present' `
|
||||
-Path $true `
|
||||
-Target @('Machine') `
|
||||
@@ -829,23 +829,23 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $testValue
|
||||
$currentConfig.Name | Should -Be $script:testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $script:testValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should update environment variable $testPathEnvironmentVarName" {
|
||||
Context "Should update environment variable $script:testPathEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Update_Path'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
$expectedValue = $testValue + ';' + $newTestValue
|
||||
$expectedValue = $script:testValue + ';' + $script:newTestValue
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testPathEnvironmentVarName `
|
||||
-Value $newTestValue `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testPathEnvironmentVarName `
|
||||
-Value $script:newTestValue `
|
||||
-Ensure 'Present' `
|
||||
-Path $true `
|
||||
-Target @('Machine') `
|
||||
@@ -861,7 +861,7 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testPathEnvironmentVarName
|
||||
$currentConfig.Name | Should -Be $script:testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $expectedValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
@@ -871,12 +871,12 @@ try
|
||||
$configurationName = 'MSFT_EnvironmentResource_NonRemove_Path'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
$expectedValue = $testValue + ';' + $newTestValue
|
||||
$expectedValue = $script:testValue + ';' + $script:newTestValue
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testPathEnvironmentVarName `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testPathEnvironmentVarName `
|
||||
-Value 'otherValue' `
|
||||
-Ensure 'Absent' `
|
||||
-Path $true `
|
||||
@@ -893,21 +893,21 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testPathEnvironmentVarName
|
||||
$currentConfig.Name | Should -Be $script:testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $expectedValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should remove only one value from environment variable $testPathEnvironmentVarName" {
|
||||
Context "Should remove only one value from environment variable $script:testPathEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_PartialRemove_Path'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testPathEnvironmentVarName `
|
||||
-Value $testValue `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testPathEnvironmentVarName `
|
||||
-Value $script:testValue `
|
||||
-Ensure 'Absent' `
|
||||
-Path $true `
|
||||
-Target @('Machine') `
|
||||
@@ -923,20 +923,20 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $newTestValue
|
||||
$currentConfig.Name | Should -Be $script:testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $script:newTestValue
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
Context "Should remove the environment variable $testPathEnvironmentVarName" {
|
||||
Context "Should remove the environment variable $script:testPathEnvironmentVarName" {
|
||||
$configurationName = 'MSFT_EnvironmentResource_Remove_Path'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
|
||||
It 'Should compile without throwing' {
|
||||
{
|
||||
. $configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $testPathEnvironmentVarName `
|
||||
. $script:configFile -ConfigurationName $configurationName
|
||||
& $configurationName -Name $script:testPathEnvironmentVarName `
|
||||
-Value $null `
|
||||
-Ensure 'Absent' `
|
||||
-Path $true `
|
||||
@@ -953,7 +953,7 @@ try
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should -Be $testPathEnvironmentVarName
|
||||
$currentConfig.Name | Should -Be $script:testPathEnvironmentVarName
|
||||
$currentConfig.Value | Should -Be $null
|
||||
$currentConfig.Ensure | Should -Be 'Absent'
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# These tests must be run with elevated access
|
||||
# These tests must be run with elevated access
|
||||
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
@@ -64,7 +64,7 @@ try
|
||||
# Verify the environmnet variable $envVar is successfully created
|
||||
$retrievedVar.Ensure | Should -Be 'Absent'
|
||||
|
||||
# Verify the create environmnet variable's value is set to default value [String]::Empty
|
||||
# Verify the create environmnet variable's value is set to default value [System.String]::Empty
|
||||
$retrievedVar.Value | Should -Be $null
|
||||
|
||||
# Remove the created test variable
|
||||
@@ -189,10 +189,11 @@ try
|
||||
It 'Should return true when an environment variable is present and should be' {
|
||||
$envVar = 'BlahVar'
|
||||
$val = 'A;B;C'
|
||||
|
||||
Set-TargetResource -Name $envVar -Value $val
|
||||
|
||||
# Test the created environmnet variable
|
||||
Test-TargetResource -Name $envVar | Should -Be $true
|
||||
Test-TargetResource -Name $envVar | Should -BeTrue
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
@@ -204,7 +205,7 @@ try
|
||||
Set-TargetResource -Name $envVar -Value $val
|
||||
|
||||
# Verify the environmnet variable exists
|
||||
Test-TargetResource -Name $envVar -Value $val | Should -Be $true
|
||||
Test-TargetResource -Name $envVar -Value $val | Should -BeTrue
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
@@ -215,7 +216,7 @@ try
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
|
||||
# Verify the environmnet variable exists
|
||||
Test-TargetResource -Name $envVar -Ensure Absent | Should -Be $true
|
||||
Test-TargetResource -Name $envVar -Ensure Absent | Should -BeTrue
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
@@ -229,7 +230,7 @@ try
|
||||
$subpath = 'B'
|
||||
|
||||
# Test a sub-path exists in environment variable
|
||||
Test-TargetResource -Name $envVar -Value $subpath -Path $true | Should -Be $true
|
||||
Test-TargetResource -Name $envVar -Value $subpath -Path $true | Should -BeTrue
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
@@ -242,7 +243,7 @@ try
|
||||
|
||||
$subpath = 'B;a;c'
|
||||
|
||||
Test-TargetResource -Name $envVar -Value $subpath -Path $true | Should -Be $true
|
||||
Test-TargetResource -Name $envVar -Value $subpath -Path $true | Should -BeTrue
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
@@ -255,7 +256,7 @@ try
|
||||
|
||||
$subpath = 'D;E'
|
||||
|
||||
Test-TargetResource -Name $envVar -Value $subpath -Path $true -Ensure Absent | Should -Be $true
|
||||
Test-TargetResource -Name $envVar -Value $subpath -Path $true -Ensure Absent | Should -BeTrue
|
||||
|
||||
# Remove the created test variable
|
||||
Set-TargetResource -Name $envVar -Ensure Absent
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[System.String]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
|
||||
param ()
|
||||
|
||||
$errorActionPreference = 'Stop'
|
||||
@@ -76,7 +76,7 @@ try
|
||||
GroupName = $testGroupName
|
||||
}
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $false
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeFalse
|
||||
|
||||
try
|
||||
{
|
||||
@@ -86,7 +86,7 @@ try
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should -Not -Throw
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName -Members @() | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName -Members @() | Should -BeTrue
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -106,7 +106,7 @@ try
|
||||
GroupName = $testGroupName
|
||||
}
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeTrue
|
||||
|
||||
{
|
||||
. $script:confgurationNoMembersFilePath -ConfigurationName $configurationName
|
||||
@@ -114,7 +114,7 @@ try
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should -Not -Throw
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should add a member to the built-in Users group with MembersToInclude' {
|
||||
@@ -127,7 +127,7 @@ try
|
||||
MembersToInclude = $testUsername1
|
||||
}
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeTrue
|
||||
|
||||
{
|
||||
. $script:confgurationWithMembersToIncludeExcludeFilePath -ConfigurationName $configurationName
|
||||
@@ -135,7 +135,7 @@ try
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should -Not -Throw
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName -MembersToInclude $testUsername1 | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName -MembersToInclude $testUsername1 | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should create a group with two test users using Members' {
|
||||
@@ -150,7 +150,7 @@ try
|
||||
Members = $groupMembers
|
||||
}
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $false
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeFalse
|
||||
|
||||
try
|
||||
{
|
||||
@@ -160,7 +160,7 @@ try
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should -Not -Throw
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName -Members $groupMembers | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName -Members $groupMembers | Should -BeTrue
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -183,11 +183,11 @@ try
|
||||
MembersToInclude = $groupMembers
|
||||
}
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $false
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeFalse
|
||||
|
||||
New-Group -GroupName $testGroupName
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeTrue
|
||||
|
||||
try
|
||||
{
|
||||
@@ -197,7 +197,7 @@ try
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should -Not -Throw
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName -MembersToInclude $groupMembers | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName -MembersToInclude $groupMembers | Should -BeTrue
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -220,11 +220,11 @@ try
|
||||
MembersToExclude = $groupMembersToExclude
|
||||
}
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $false
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeFalse
|
||||
|
||||
New-Group -GroupName $testGroupName -Members $groupMembersToExclude
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeTrue
|
||||
|
||||
try
|
||||
{
|
||||
@@ -234,7 +234,7 @@ try
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should -Not -Throw
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName -MembersToExclude $groupMembersToExclude | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName -MembersToExclude $groupMembersToExclude | Should -BeTrue
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -254,11 +254,11 @@ try
|
||||
GroupName = $testGroupName
|
||||
}
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $false
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeFalse
|
||||
|
||||
New-Group -GroupName $testGroupName
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $true
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeTrue
|
||||
|
||||
try
|
||||
{
|
||||
@@ -268,7 +268,7 @@ try
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should -Not -Throw
|
||||
|
||||
Test-GroupExists -GroupName $testGroupName | Should -Be $false
|
||||
Test-GroupExists -GroupName $testGroupName | Should -BeFalse
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[System.String]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[System.String]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[System.String]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
Please note that some of these tests depend on each other.
|
||||
They must be run in the order given - if one test fails, subsequent tests may
|
||||
also fail.
|
||||
@@ -43,7 +43,7 @@ Describe 'MsiPackage End to End Tests' {
|
||||
|
||||
<#
|
||||
This log file is used to log messages from the mock server which is important for debugging since
|
||||
most of the work of the mock server is done within a separate process.
|
||||
most of the work of the mock server is done within a separate process.
|
||||
#>
|
||||
$script:logFile = Join-Path -Path $PSScriptRoot -ChildPath 'PackageTestLogFile.txt'
|
||||
$script:environmentInIncorrectStateErrorMessage = 'The current environment is not in the expected state for this test - either something was setup incorrectly on your machine or a previous test failed - results after this may be invalid.'
|
||||
@@ -55,6 +55,9 @@ Describe 'MsiPackage End to End Tests' {
|
||||
|
||||
$null = New-TestMsi -DestinationPath $script:msiLocation
|
||||
|
||||
$script:testHttpPort = Get-UnusedTcpPort
|
||||
$script:testHttpsPort = Get-UnusedTcpPort -ExcludePorts @($script:testHttpPort)
|
||||
|
||||
# Clear the log file
|
||||
'Beginning integration tests' > $script:logFile
|
||||
}
|
||||
@@ -85,8 +88,8 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return True from Test-TargetResource with the same parameters before configuration' {
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should Be $true
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should -BeTrue
|
||||
|
||||
if ($testTargetResourceInitialResult -ne $true)
|
||||
{
|
||||
@@ -100,23 +103,23 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Package should not exist on the machine before configuration is run' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $false
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @msiPackageParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should return True from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Package should not exist on the machine' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $false
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeFalse
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,8 +133,8 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return False from Test-TargetResource with the same parameters before configuration' {
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should Be $false
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should -BeFalse
|
||||
|
||||
if ($testTargetResourceInitialResult -ne $false)
|
||||
{
|
||||
@@ -145,23 +148,23 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Package should not exist on the machine before configuration is run' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $false
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @msiPackageParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should return True from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Package should exist on the machine' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $true
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,8 +178,8 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return True from Test-TargetResource with the same parameters before configuration' {
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should Be $true
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should -BeTrue
|
||||
|
||||
if ($testTargetResourceInitialResult -ne $true)
|
||||
{
|
||||
@@ -190,23 +193,23 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Package should exist on the machine before configuration is run' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $true
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @msiPackageParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should return True from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Package should exist on the machine' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $true
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,8 +223,8 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return False from Test-TargetResource with the same parameters before configuration' {
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should Be $false
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should -BeFalse
|
||||
|
||||
if ($testTargetResourceInitialResult -ne $false)
|
||||
{
|
||||
@@ -235,23 +238,23 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Package should exist on the machine before configuration is run' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $true
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @msiPackageParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should return True from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Package should not exist on the machine' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $false
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeFalse
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,8 +276,8 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return False from Test-TargetResource with the same parameters before configuration' {
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should Be $false
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should -BeFalse
|
||||
|
||||
if ($testTargetResourceInitialResult -ne $false)
|
||||
{
|
||||
@@ -288,27 +291,27 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Package should not exist on the machine before configuration is run' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $false
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:configurationFilePathLogPath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @msiPackageParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should return True from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should have created the log file' {
|
||||
Test-Path -Path $logPath | Should Be $true
|
||||
Test-Path -Path $logPath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Package should exist on the machine' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $true
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,8 +333,8 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return False from Test-TargetResource with the same parameters before configuration' {
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should Be $false
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should -BeFalse
|
||||
|
||||
if ($testTargetResourceInitialResult -ne $false)
|
||||
{
|
||||
@@ -345,35 +348,36 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Package should exist on the machine before configuration is run' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $true
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:configurationFilePathLogPath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @msiPackageParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should return True from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should have created the log file' {
|
||||
Test-Path -Path $logPath | Should Be $true
|
||||
Test-Path -Path $logPath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Package should not exist on the machine' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $false
|
||||
}
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeFalse
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Install package from HTTP Url' {
|
||||
$configurationName = 'UninstallExistingMsiPackageFromHttp'
|
||||
|
||||
$baseUrl = 'http://localhost:1242/'
|
||||
$msiUrl = "$baseUrl" + 'package.msi'
|
||||
$uriBuilder = [System.UriBuilder]::new('http', 'localhost', $script:testHttpPort)
|
||||
$uriBuilder.Path = 'package.msi'
|
||||
$msiUrl = $uriBuilder.Uri.AbsoluteUri
|
||||
|
||||
$fileServerStarted = $null
|
||||
$job = $null
|
||||
@@ -385,8 +389,8 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return False from Test-TargetResource with the same parameters before configuration' {
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should Be $false
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should -BeFalse
|
||||
|
||||
if ($testTargetResourceInitialResult -ne $false)
|
||||
{
|
||||
@@ -400,23 +404,26 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Package should not exist on the machine before configuration is run' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $false
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeFalse
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $false
|
||||
# Make sure no existing HTTP(S) test servers are running
|
||||
Stop-EveryTestServerInstance
|
||||
|
||||
$serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $false -HttpPort $script:testHttpPort -HttpsPort $script:testHttpsPort
|
||||
$fileServerStarted = $serverResult.FileServerStarted
|
||||
$job = $serverResult.Job
|
||||
$job = $serverResult.Job
|
||||
|
||||
$fileServerStarted.WaitOne(30000)
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @msiPackageParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -429,19 +436,20 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return True from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Package should exist on the machine' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $true
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Uninstall Msi package from HTTP Url' {
|
||||
$configurationName = 'InstallMsiPackageFromHttp'
|
||||
|
||||
$baseUrl = 'http://localhost:1242/'
|
||||
$msiUrl = "$baseUrl" + 'package.msi'
|
||||
$uriBuilder = [System.UriBuilder]::new('http', 'localhost', $script:testHttpPort)
|
||||
$uriBuilder.Path = 'package.msi'
|
||||
$msiUrl = $uriBuilder.Uri.AbsoluteUri
|
||||
|
||||
$fileServerStarted = $null
|
||||
$job = $null
|
||||
@@ -453,8 +461,8 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return False from Test-TargetResource with the same parameters before configuration' {
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should Be $false
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should -BeFalse
|
||||
|
||||
if ($testTargetResourceInitialResult -ne $false)
|
||||
{
|
||||
@@ -468,23 +476,26 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Package should exist on the machine before configuration is run' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $true
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeTrue
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
$serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $false
|
||||
# Make sure no existing HTTP(S) test servers are running
|
||||
Stop-EveryTestServerInstance
|
||||
|
||||
$serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $false -HttpPort $script:testHttpPort -HttpsPort $script:testHttpsPort
|
||||
$fileServerStarted = $serverResult.FileServerStarted
|
||||
$job = $serverResult.Job
|
||||
|
||||
$fileServerStarted.WaitOne(30000)
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @msiPackageParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -497,19 +508,20 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Package should not exist on the machine' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $false
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeFalse
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Install Msi package from HTTPS Url' {
|
||||
$configurationName = 'InstallMsiPackageFromHttpS'
|
||||
|
||||
$baseUrl = 'https://localhost:1243/'
|
||||
$msiUrl = "$baseUrl" + 'package.msi'
|
||||
$uriBuilder = [System.UriBuilder]::new('https', 'localhost', $script:testHttpsPort)
|
||||
$uriBuilder.Path = 'package.msi'
|
||||
$msiUrl = $uriBuilder.Uri.AbsoluteUri
|
||||
|
||||
$fileServerStarted = $null
|
||||
$job = $null
|
||||
@@ -521,8 +533,8 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return False from Test-TargetResource with the same parameters before configuration' {
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should Be $false
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should -BeFalse
|
||||
|
||||
if ($testTargetResourceInitialResult -ne $false)
|
||||
{
|
||||
@@ -536,23 +548,26 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Package should not exist on the machine before configuration is run' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $false
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeFalse
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
$serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $true
|
||||
# Make sure no existing HTTP(S) test servers are running
|
||||
Stop-EveryTestServerInstance
|
||||
|
||||
$serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $true -HttpPort $script:testHttpPort -HttpsPort $script:testHttpsPort
|
||||
$fileServerStarted = $serverResult.FileServerStarted
|
||||
$job = $serverResult.Job
|
||||
|
||||
$fileServerStarted.WaitOne(30000)
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @msiPackageParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -565,19 +580,20 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Package should exist on the machine' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $true
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Context 'Uninstall Msi package from HTTPS Url' {
|
||||
$configurationName = 'UninstallMsiPackageFromHttps'
|
||||
|
||||
$baseUrl = 'https://localhost:1243/'
|
||||
$msiUrl = "$baseUrl" + 'package.msi'
|
||||
$uriBuilder = [System.UriBuilder]::new('https', 'localhost', $script:testHttpsPort)
|
||||
$uriBuilder.Path = 'package.msi'
|
||||
$msiUrl = $uriBuilder.Uri.AbsoluteUri
|
||||
|
||||
$fileServerStarted = $null
|
||||
$job = $null
|
||||
@@ -589,8 +605,8 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return False from Test-TargetResource with the same parameters before configuration' {
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should Be $false
|
||||
$testTargetResourceInitialResult = MSFT_MsiPackage\Test-TargetResource @msiPackageParameters
|
||||
$testTargetResourceInitialResult | Should -BeFalse
|
||||
|
||||
if ($testTargetResourceInitialResult -ne $false)
|
||||
{
|
||||
@@ -604,23 +620,26 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Package should exist on the machine before configuration is run' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $true
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeTrue
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $true
|
||||
# Make sure no existing HTTP(S) test servers are running
|
||||
Stop-EveryTestServerInstance
|
||||
|
||||
$serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $true -HttpPort $script:testHttpPort -HttpsPort $script:testHttpsPort
|
||||
$fileServerStarted = $serverResult.FileServerStarted
|
||||
$job = $serverResult.Job
|
||||
|
||||
$fileServerStarted.WaitOne(30000)
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:configurationFilePathNoOptionalParameters -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @msiPackageParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -633,11 +652,11 @@ Describe 'MsiPackage End to End Tests' {
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters after configuration' {
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should Be $true
|
||||
MSFT_MsiPackage\Test-TargetResource @msiPackageParameters | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Package should not exist on the machine' {
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $false
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeFalse
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
$errorActionPreference = 'Stop'
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
if ($PSVersionTable.PSVersion -lt [Version] '5.1')
|
||||
@@ -37,7 +37,7 @@ try
|
||||
|
||||
<#
|
||||
This log file is used to log messages from the mock server which is important for debugging since
|
||||
most of the work of the mock server is done within a separate process.
|
||||
most of the work of the mock server is done within a separate process.
|
||||
#>
|
||||
$script:logFile = Join-Path -Path $PSScriptRoot -ChildPath 'PackageTestLogFile.txt'
|
||||
|
||||
@@ -49,6 +49,9 @@ try
|
||||
|
||||
$null = New-TestMsi -DestinationPath $script:msiLocation
|
||||
|
||||
$script:testHttpPort = Get-UnusedTcpPort
|
||||
$script:testHttpsPort = Get-UnusedTcpPort -ExcludePorts @($script:testHttpPort)
|
||||
|
||||
# Clear the log file
|
||||
'Beginning integration tests' > $script:logFile
|
||||
}
|
||||
@@ -114,34 +117,34 @@ try
|
||||
-Path $script:msiLocation `
|
||||
-ProductId $script:packageId
|
||||
|
||||
$testTargetResourceResult | Should Be $false
|
||||
$testTargetResourceResult | Should -BeFalse
|
||||
|
||||
$testTargetResourceResult = Test-TargetResource `
|
||||
-Ensure 'Absent' `
|
||||
-Path $script:msiLocation `
|
||||
-ProductId $script:packageId
|
||||
|
||||
$testTargetResourceResult | Should Be $true
|
||||
$testTargetResourceResult | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should return correct value when package is present' {
|
||||
Set-TargetResource -Ensure 'Present' -Path $script:msiLocation -ProductId $script:packageId
|
||||
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $true
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeTrue
|
||||
|
||||
$testTargetResourceResult = Test-TargetResource `
|
||||
-Ensure 'Present' `
|
||||
-Path $script:msiLocation `
|
||||
-ProductId $script:packageId `
|
||||
|
||||
$testTargetResourceResult | Should Be $true
|
||||
$testTargetResourceResult | Should -BeTrue
|
||||
|
||||
$testTargetResourceResult = Test-TargetResource `
|
||||
-Ensure 'Absent' `
|
||||
-Path $script:msiLocation `
|
||||
-ProductId $script:packageId `
|
||||
|
||||
$testTargetResourceResult | Should Be $false
|
||||
$testTargetResourceResult | Should -BeFalse
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,30 +152,33 @@ try
|
||||
It 'Should correctly install and remove a .msi package' {
|
||||
Set-TargetResource -Ensure 'Present' -Path $script:msiLocation -ProductId $script:packageId
|
||||
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $true
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeTrue
|
||||
|
||||
$getTargetResourceResult = Get-TargetResource -Path $script:msiLocation -ProductId $script:packageId
|
||||
|
||||
$getTargetResourceResult.Version | Should Be '1.2.3.4'
|
||||
$getTargetResourceResult.InstalledOn | Should Be ('{0:d}' -f [DateTime]::Now.Date)
|
||||
$getTargetResourceResult.ProductId | Should Be $script:packageId
|
||||
$getTargetResourceResult.Version | Should -Be '1.2.3.4'
|
||||
$getTargetResourceResult.InstalledOn | Should -Be ('{0:d}' -f [System.DateTime]::Now.Date)
|
||||
$getTargetResourceResult.ProductId | Should -Be $script:packageId
|
||||
|
||||
[Math]::Round($getTargetResourceResult.Size, 2) | Should Be 0.03
|
||||
[Math]::Round($getTargetResourceResult.Size, 2) | Should -Be 0.03
|
||||
|
||||
Set-TargetResource -Ensure 'Absent' -Path $script:msiLocation -ProductId $script:packageId
|
||||
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $false
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should throw with incorrect product id' {
|
||||
$wrongPackageId = '{deadbeef-80c6-41e6-a1b9-8bdb8a050272}'
|
||||
|
||||
{ Set-TargetResource -Ensure 'Present' -Path $script:msiLocation -ProductId $wrongPackageId } | Should Throw
|
||||
{ Set-TargetResource -Ensure 'Present' -Path $script:msiLocation -ProductId $wrongPackageId } | Should -Throw
|
||||
}
|
||||
|
||||
It 'Should correctly install and remove a package from a HTTP URL' {
|
||||
$baseUrl = 'http://localhost:1242/'
|
||||
$msiUrl = "$baseUrl" + 'package.msi'
|
||||
$uriBuilder = [System.UriBuilder]::new('http', 'localhost', $script:testHttpPort)
|
||||
$baseUrl = $uriBuilder.Uri.AbsoluteUri
|
||||
|
||||
$uriBuilder.Path = 'package.msi'
|
||||
$msiUrl = $uriBuilder.Uri.AbsoluteUri
|
||||
|
||||
$fileServerStarted = $null
|
||||
$job = $null
|
||||
@@ -181,20 +187,29 @@ try
|
||||
{
|
||||
'Http tests:' >> $script:logFile
|
||||
|
||||
$serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $false
|
||||
# Make sure no existing HTTP(S) test servers are running
|
||||
Stop-EveryTestServerInstance
|
||||
|
||||
$serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $false -HttpPort $script:testHttpPort -HttpsPort $script:testHttpsPort
|
||||
$fileServerStarted = $serverResult.FileServerStarted
|
||||
$job = $serverResult.Job
|
||||
|
||||
# Wait for the file server to be ready to receive requests
|
||||
$fileServerStarted.WaitOne(30000)
|
||||
|
||||
{ Set-TargetResource -Ensure 'Present' -Path $baseUrl -ProductId $script:packageId } | Should Throw
|
||||
{ Set-TargetResource -Ensure 'Present' -Path $baseUrl -ProductId $script:packageId } | Should -Throw
|
||||
|
||||
Set-TargetResource -Ensure 'Present' -Path $msiUrl -ProductId $script:packageId
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $true
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeTrue
|
||||
|
||||
Set-TargetResource -Ensure 'Absent' -Path $msiUrl -ProductId $script:packageId
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $false
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeFalse
|
||||
}
|
||||
catch
|
||||
{
|
||||
Write-Warning -Message 'Caught exception performing HTTP server tests. Outputting HTTP server log.' -Verbose
|
||||
Get-Content -Path $script:logFile | Write-Verbose -Verbose
|
||||
throw $_
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -207,9 +222,11 @@ try
|
||||
}
|
||||
|
||||
It 'Should correctly install and remove a package from a HTTPS URL' -Skip:$script:skipHttpsTest {
|
||||
$uriBuilder = [System.UriBuilder]::new('https', 'localhost', $script:testHttpsPort)
|
||||
$baseUrl = $uriBuilder.Uri.AbsoluteUri
|
||||
|
||||
$baseUrl = 'https://localhost:1243/'
|
||||
$msiUrl = "$baseUrl" + 'package.msi'
|
||||
$uriBuilder.Path = 'package.msi'
|
||||
$msiUrl = $uriBuilder.Uri.AbsoluteUri
|
||||
|
||||
$fileServerStarted = $null
|
||||
$job = $null
|
||||
@@ -218,20 +235,29 @@ try
|
||||
{
|
||||
'Https tests:' >> $script:logFile
|
||||
|
||||
$serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $true
|
||||
# Make sure no existing HTTP(S) test servers are running
|
||||
Stop-EveryTestServerInstance
|
||||
|
||||
$serverResult = Start-Server -FilePath $script:msiLocation -LogPath $script:logFile -Https $true -HttpPort $script:testHttpPort -HttpsPort $script:testHttpsPort
|
||||
$fileServerStarted = $serverResult.FileServerStarted
|
||||
$job = $serverResult.Job
|
||||
$job = $serverResult.Job
|
||||
|
||||
# Wait for the file server to be ready to receive requests
|
||||
$fileServerStarted.WaitOne(30000)
|
||||
|
||||
{ Set-TargetResource -Ensure 'Present' -Path $baseUrl -ProductId $script:packageId } | Should Throw
|
||||
{ Set-TargetResource -Ensure 'Present' -Path $baseUrl -ProductId $script:packageId } | Should -Throw
|
||||
|
||||
Set-TargetResource -Ensure 'Present' -Path $msiUrl -ProductId $script:packageId
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $true
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeTrue
|
||||
|
||||
Set-TargetResource -Ensure 'Absent' -Path $msiUrl -ProductId $script:packageId
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should Be $false
|
||||
Test-PackageInstalledById -ProductId $script:packageId | Should -BeFalse
|
||||
}
|
||||
catch
|
||||
{
|
||||
Write-Warning -Message 'Caught exception performing HTTPS server tests. Outputting HTTPS server log.' -Verbose
|
||||
Get-Content -Path $script:logFile | Write-Verbose -Verbose
|
||||
throw $_
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -253,8 +279,8 @@ try
|
||||
|
||||
Set-TargetResource -Ensure 'Present' -Path $script:msiLocation -LogPath $logPath -ProductId $script:packageId
|
||||
|
||||
Test-Path -Path $logPath | Should Be $true
|
||||
Get-Content -Path $logPath | Should Not Be $null
|
||||
Test-Path -Path $logPath | Should -BeTrue
|
||||
Get-Content -Path $logPath | Should -Not -Be $null
|
||||
}
|
||||
|
||||
It 'Should add space after .MSI installation arguments' {
|
||||
@@ -281,7 +307,7 @@ try
|
||||
ProductId = $script:packageId
|
||||
}
|
||||
|
||||
{ Set-TargetResource -Ensure 'Present' @packageParameters } | Should Not Throw
|
||||
{ Set-TargetResource -Ensure 'Present' @packageParameters } | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should install package using user credentials when specified' {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$ConfigurationName
|
||||
)
|
||||
|
||||
@@ -11,20 +11,20 @@ Configuration $ConfigurationName
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ProductId,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$ConfigurationName
|
||||
)
|
||||
|
||||
@@ -11,16 +11,16 @@ Configuration $ConfigurationName
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$ProductId,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present'
|
||||
)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
WARNING: DO NOT RUN THESE TESTS ON A VALUABLE MACHINE!
|
||||
Running on a disposable VM or AppVeyor is strongly recommended.
|
||||
If these tests go awry, your machine's registry could be corrupted which will brick your machine!
|
||||
@@ -54,25 +54,25 @@ try
|
||||
}
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:confgurationFilePathKeyAndNameOnly -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @registryParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should -Not -Throw
|
||||
}
|
||||
|
||||
$registryKey = Get-Item -Path $registryParameters.Key -ErrorAction 'SilentlyContinue'
|
||||
|
||||
It 'Should have created the registry key' {
|
||||
$registryKey | Should Not Be $null
|
||||
$registryKey | Should -Not -Be $null
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters' {
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should Be $true
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,29 +86,29 @@ try
|
||||
}
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:confgurationFilePathKeyAndNameOnly -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @registryParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should -Not -Throw
|
||||
}
|
||||
|
||||
$registryKeyValue = Get-ItemProperty -Path $registryParameters.Key -Name $registryParameters.ValueName -ErrorAction 'SilentlyContinue'
|
||||
|
||||
It 'Should have created the registry key value' {
|
||||
$registryKeyValue | Should Not Be $null
|
||||
$registryKeyValue | Should -Not -Be $null
|
||||
}
|
||||
|
||||
It 'Should not have set the registry key value' {
|
||||
$registryKeyValue.($registryParameters.ValueName) | Should Be ''
|
||||
$registryKeyValue.($registryParameters.ValueName) | Should -Be ''
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters' {
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should Be $true
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,29 +124,29 @@ try
|
||||
}
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:confgurationFilePathWithDataAndType -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @registryParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should -Not -Throw
|
||||
}
|
||||
|
||||
$registryKeyValue = Get-ItemProperty -Path $registryParameters.Key -Name $registryParameters.ValueName -ErrorAction 'SilentlyContinue'
|
||||
|
||||
It 'Should have created the registry key value' {
|
||||
$registryKeyValue | Should Not Be $null
|
||||
$registryKeyValue | Should -Not -Be $null
|
||||
}
|
||||
|
||||
It 'Should have set the registry key value to the specified String value' {
|
||||
$registryKeyValue.($registryParameters.ValueName) | Should Be $registryParameters.ValueData
|
||||
$registryKeyValue.($registryParameters.ValueName) | Should -Be $registryParameters.ValueData
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters' {
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should Be $true
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,8 +156,8 @@ try
|
||||
{
|
||||
'String' { 'TestString2'; break }
|
||||
'Binary' { '0xCAC1111'; break }
|
||||
'DWord' { [Int32]::MaxValue.ToString(); break }
|
||||
'QWord' { [Int64]::MaxValue.ToString(); break }
|
||||
'DWord' { [System.Int32]::MaxValue.ToString(); break }
|
||||
'QWord' { [System.Int64]::MaxValue.ToString(); break }
|
||||
'MultiString' { @('MultiString1', 'MultiString2'); break }
|
||||
'ExpandString' { '%WINDIR%'; break }
|
||||
}
|
||||
@@ -165,10 +165,10 @@ try
|
||||
$expectedRegistryKeyValue = switch ($registryKeyValueType)
|
||||
{
|
||||
'String' { 'TestString2'; break }
|
||||
'Binary' { [Byte[]]@( 12, 172, 17, 17 ); break }
|
||||
'DWord' { [Int32]::MaxValue; break }
|
||||
'QWord' { [Int64]::MaxValue; break }
|
||||
'MultiString' { [String[]]@('MultiString1', 'MultiString2'); break }
|
||||
'Binary' { [System.Byte[]] @( 12, 172, 17, 17 ); break }
|
||||
'DWord' { [System.Int32]::MaxValue; break }
|
||||
'QWord' { [System.Int64]::MaxValue; break }
|
||||
'MultiString' { [System.String[]] @('MultiString1', 'MultiString2'); break }
|
||||
'ExpandString' { 'C:\windows'; break }
|
||||
}
|
||||
|
||||
@@ -184,29 +184,29 @@ try
|
||||
}
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:confgurationFilePathWithDataAndType -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @registryParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should -Not -Throw
|
||||
}
|
||||
|
||||
$registryKeyValue = Get-ItemProperty -Path $registryParameters.Key -Name $registryParameters.ValueName -ErrorAction 'SilentlyContinue'
|
||||
|
||||
It 'Should be able to retrieve the registry key value' {
|
||||
$registryKeyValue | Should Not Be $null
|
||||
$registryKeyValue | Should -Not -Be $null
|
||||
}
|
||||
|
||||
It 'Should have set the registry key value to the specified value' {
|
||||
Compare-Object -ReferenceObject $expectedRegistryKeyValue -DifferenceObject $registryKeyValue.($registryParameters.ValueName) | Should Be $null
|
||||
Compare-Object -ReferenceObject $expectedRegistryKeyValue -DifferenceObject $registryKeyValue.($registryParameters.ValueName) | Should -Be $null
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters' {
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should Be $true
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,32 +222,32 @@ try
|
||||
ValueData = '0x00'
|
||||
}
|
||||
|
||||
$expectedRegistryKeyValue = [Byte[]]@(0)
|
||||
$expectedRegistryKeyValue = [System.Byte[]] @(0)
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:confgurationFilePathWithDataAndType -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @registryParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should -Not -Throw
|
||||
}
|
||||
|
||||
$registryKeyValue = Get-ItemProperty -Path $registryParameters.Key -Name $registryParameters.ValueName -ErrorAction 'SilentlyContinue'
|
||||
|
||||
It 'Should be able to retrieve the registry key value' {
|
||||
$registryKeyValue | Should Not Be $null
|
||||
$registryKeyValue | Should -Not -Be $null
|
||||
}
|
||||
|
||||
It 'Should have set the registry key value to the specified Binary value' {
|
||||
Compare-Object -ReferenceObject $expectedRegistryKeyValue -DifferenceObject $registryKeyValue.'(default)' | Should Be $null
|
||||
Compare-Object -ReferenceObject $expectedRegistryKeyValue -DifferenceObject $registryKeyValue.'(default)' | Should -Be $null
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters' {
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should Be $true
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,15 +263,15 @@ try
|
||||
}
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:confgurationFilePathWithDataAndType -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @registryParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should -Not -Throw
|
||||
}
|
||||
|
||||
$parentRegistryKey = Get-Item -Path 'HKLM:'
|
||||
@@ -286,7 +286,7 @@ try
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters' {
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should Be $true
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,25 +300,25 @@ try
|
||||
}
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:confgurationFilePathKeyAndNameOnly -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @registryParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should -Not -Throw
|
||||
}
|
||||
|
||||
$registryKeyValue = Get-ItemProperty -Path $registryParameters.Key -Name $registryParameters.ValueName -ErrorAction 'SilentlyContinue'
|
||||
|
||||
It 'Should have removed the registry key value' {
|
||||
$registryKeyValue | Should Be $null
|
||||
$registryKeyValue | Should -Be $null
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters' {
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should Be $true
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,25 +334,25 @@ try
|
||||
}
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:confgurationFilePathWithDataAndType -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @registryParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should -Not -Throw
|
||||
}
|
||||
|
||||
$registryKeyValue = Get-ItemProperty -Path $registryParameters.Key -Name $registryParameters.ValueName -ErrorAction 'SilentlyContinue'
|
||||
|
||||
It 'Should have removed the registry key value' {
|
||||
$registryKeyValue | Should Be $null
|
||||
$registryKeyValue | Should -Be $null
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters' {
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should Be $true
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,25 +366,25 @@ try
|
||||
}
|
||||
|
||||
It 'Should compile and run configuration' {
|
||||
{
|
||||
{
|
||||
. $script:confgurationFilePathKeyAndNameOnly -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @registryParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should -Not -Throw
|
||||
}
|
||||
|
||||
$registryKey = Get-Item -Path $registryParameters.Key -ErrorAction 'SilentlyContinue'
|
||||
|
||||
It 'Should have removed the registry key value' {
|
||||
$registryKey | Should Be $null
|
||||
$registryKey | Should -Be $null
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters' {
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should Be $true
|
||||
MSFT_RegistryResource\Test-TargetResource @registryParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -393,4 +393,4 @@ finally
|
||||
{
|
||||
Exit-DscResourceTestEnvironment -TestEnvironment $script:testEnvironment
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
WARNING: DO NOT RUN THESE TESTS ON A VALUABLE MACHINE!
|
||||
Running on a disposable VM or AppVeyor is strongly recommended.
|
||||
If these tests go awry, your machine's registry could be corrupted which will brick your machine!
|
||||
@@ -78,27 +78,27 @@ try
|
||||
It 'Should return Present when retrieving a blank value from an existing registry key' {
|
||||
$registryKeyPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
|
||||
$getTargetResourceResult = Get-TargetResource -Key $registryKeyPath -ValueName ''
|
||||
$getTargetResourceResult.Ensure | Should Be 'Present'
|
||||
$getTargetResourceResult.Ensure | Should -Be 'Present'
|
||||
}
|
||||
|
||||
It 'Should return Absent when retrieving a blank value from a registry key that does not exist' {
|
||||
$registryKeyPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environmental'
|
||||
$getTargetResourceResult = Get-TargetResource -Key $registryKeyPath -ValueName ''
|
||||
$getTargetResourceResult.Ensure | Should Be 'Absent'
|
||||
$getTargetResourceResult.Ensure | Should -Be 'Absent'
|
||||
}
|
||||
|
||||
It 'Should return Present when retrieving an existing value from an existing registry key' {
|
||||
$registryKeyPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
|
||||
$registryKeyPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
|
||||
$registryValueName = 'Path'
|
||||
$getTargetResourceResult = Get-TargetResource -Key $registryKeyPath -ValueName $registryValueName
|
||||
$getTargetResourceResult.Ensure | Should Be 'Present'
|
||||
$getTargetResourceResult.Ensure | Should -Be 'Present'
|
||||
}
|
||||
|
||||
It 'Should return Absent when retrieving a nonexistant value from an existing registry key' {
|
||||
$registryKeyPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
|
||||
$registryKeyPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
|
||||
$registryValueName = 'PsychoPath'
|
||||
$getTargetResourceResult = Get-TargetResource -Key $registryKeyPath -ValueName $registryValueName
|
||||
$getTargetResourceResult.Ensure | Should Be 'Absent'
|
||||
$getTargetResourceResult.Ensure | Should -Be 'Absent'
|
||||
}
|
||||
|
||||
$commonRegistryKeys = @( 'HKEY_CURRENT_USER', 'HKEY_CLASSES_ROOT', 'HKEY_USERS', 'HKEY_CURRENT_CONFIG' )
|
||||
@@ -106,7 +106,7 @@ try
|
||||
{
|
||||
It "Should return Present when retrieving a blank value from $commonRegistryKey" {
|
||||
$getTargetResourceResult = Get-TargetResource -Key $commonRegistryKey -ValueName ''
|
||||
$getTargetResourceResult.Ensure | Should Be 'Present'
|
||||
$getTargetResourceResult.Ensure | Should -Be 'Present'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ try
|
||||
|
||||
# Verify that the registry key has been created
|
||||
$registryKeyExists = Test-RegistryKeyExists -KeyPath $script:registryKeyPath
|
||||
$registryKeyExists | Should Be $true
|
||||
$registryKeyExists | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should create a new registry key tree' {
|
||||
@@ -126,7 +126,7 @@ try
|
||||
|
||||
# Verify that the registry key has been created
|
||||
$registryKeyExists = Test-RegistryKeyExists -KeyPath $registryKeyTreePath
|
||||
$registryKeyExists | Should Be $true
|
||||
$registryKeyExists | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should remove a registry key' {
|
||||
@@ -135,14 +135,14 @@ try
|
||||
|
||||
# Verify that the registry key exists before removal
|
||||
$registryKeyExists = Test-RegistryKeyExists -KeyPath $script:registryKeyPath
|
||||
$registryKeyExists | Should Be $true
|
||||
$registryKeyExists | Should -BeTrue
|
||||
|
||||
# Now remove the TestKey
|
||||
# Now remove the TestKey
|
||||
Set-TargetResource -Key $script:registryKeyPath -ValueName '' -Ensure 'Absent'
|
||||
|
||||
# Verify that the registry key has been removed
|
||||
$registryKeyExists = Test-RegistryKeyExists -KeyPath $script:registryKeyPath
|
||||
$registryKeyExists | Should Be $false
|
||||
$registryKeyExists | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should remove a registry key tree' {
|
||||
@@ -153,27 +153,27 @@ try
|
||||
|
||||
# Verify that the registry key tree exists before removal
|
||||
$registryKeyExists = Test-RegistryKeyExists -KeyPath $registryKeyTreePath
|
||||
$registryKeyExists | Should Be $true
|
||||
$registryKeyExists | Should -BeTrue
|
||||
|
||||
# Remove the test registry key tree
|
||||
# Remove the test registry key tree
|
||||
Set-TargetResource -Key $registryKeyTreePath -ValueName '' -Ensure 'Absent'
|
||||
|
||||
# Verify that the registry key tree has been removed
|
||||
$registryKeyExists = Test-RegistryKeyExists -KeyPath $registryKeyTreePath
|
||||
$registryKeyExists | Should Be $false
|
||||
$registryKeyExists | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should create a new string registry key value' {
|
||||
$valueName = 'TestValue'
|
||||
$valueData = 'TestData'
|
||||
$valueType = 'String'
|
||||
|
||||
# Create the new registry key value
|
||||
|
||||
# Create the new registry key value
|
||||
Set-TargetResource -Key $script:registryKeyPath -ValueName $valueName -ValueData $valueData -ValueType $valueType
|
||||
|
||||
# Verify that the registry key value has been created with the correct data and type
|
||||
$registryValueExists = Test-RegistryValueExists -KeyPath $script:registryKeyPath -ValueName $valueName -ValueData $valueData -ValueType $valueType
|
||||
$registryValueExists | Should Be $true
|
||||
$registryValueExists | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should create a new binary registry key value' {
|
||||
@@ -181,24 +181,24 @@ try
|
||||
$valueData = 'aabbcc'
|
||||
$valueType = 'Binary'
|
||||
|
||||
# Create the new registry key value
|
||||
# Create the new registry key value
|
||||
Set-TargetResource -Key $script:registryKeyPath -ValueName $valueName -ValueData $valueData -ValueType $valueType -Hex $true
|
||||
|
||||
# Verify that the registry key value has been created with the correct data and type
|
||||
$registryValueExists = Test-RegistryValueExists -KeyPath $script:registryKeyPath -ValueName $valueName -ValueData $valueData -ValueType $valueType
|
||||
$registryValueExists | Should Be $true
|
||||
$registryValueExists | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should set the default value of a registry key' {
|
||||
$valueName = ''
|
||||
$valueData = 'DefaultValue'
|
||||
|
||||
# Create the new registry key value
|
||||
# Create the new registry key value
|
||||
Set-TargetResource -Key $script:registryKeyPath -ValueName $valueName -ValueData $valueData
|
||||
|
||||
# Verify that the registry key value has been created with the correct data and type
|
||||
$registryValueExists = Test-RegistryValueExists -KeyPath $script:registryKeyPath -ValueName '(default)' -ValueData $valueData -ValueType 'String'
|
||||
$registryValueExists | Should Be $true
|
||||
$registryValueExists | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should remove a registry key value' {
|
||||
@@ -208,17 +208,17 @@ try
|
||||
|
||||
# Create the test registry value
|
||||
New-RegistryValue -KeyPath $script:registryKeyPath -ValueName $valueName -ValueData $valueData -ValueType $valueType
|
||||
|
||||
|
||||
# Verify that the registry key value exists before removal
|
||||
$registryValueExists = Test-RegistryValueExists -KeyPath $script:registryKeyPath -ValueName $valueName
|
||||
$registryValueExists | Should Be $true
|
||||
$registryValueExists | Should -BeTrue
|
||||
|
||||
# Remove the registry value
|
||||
Set-TargetResource -Key $script:registryKeyPath -ValueName $valueName -Ensure 'Absent'
|
||||
|
||||
# Verify that the registry key value has been removed
|
||||
$registryValueExists = Test-RegistryValueExists -KeyPath $script:registryKeyPath -ValueName $valueName
|
||||
$registryValueExists | Should Be $false
|
||||
$registryValueExists | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should remove the default value for a registry key' {
|
||||
@@ -228,17 +228,17 @@ try
|
||||
|
||||
# Create the test registry value
|
||||
New-RegistryValue -KeyPath $script:registryKeyPath -ValueName '(default)' -ValueData $valueData -ValueType $valueType
|
||||
|
||||
|
||||
# Verify that the registry key value exists before removal
|
||||
$registryValueExists = Test-RegistryValueExists -KeyPath $script:registryKeyPath -ValueName '(default)'
|
||||
$registryValueExists | Should Be $true
|
||||
$registryValueExists | Should -BeTrue
|
||||
|
||||
# Remove the registry value
|
||||
Set-TargetResource -Key $script:registryKeyPath -ValueName $valueName -Ensure 'Absent'
|
||||
|
||||
# Verify that the registry key value has been removed
|
||||
$registryValueExists = Test-RegistryValueExists -KeyPath $script:registryKeyPath -ValueName '(default)'
|
||||
$registryValueExists | Should Be $false
|
||||
$registryValueExists | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should create a new key and value with path containing forward slashes' {
|
||||
@@ -246,51 +246,51 @@ try
|
||||
$valueName = 'Testing'
|
||||
$valueData = 'TestValue'
|
||||
|
||||
# Create the new registry key value
|
||||
# Create the new registry key value
|
||||
Set-TargetResource -Key $registryKeyPathWithForwardSlashes -ValueName $valueName -ValueData $valueData
|
||||
|
||||
# Verify that the registry key value has been created with the correct data and type
|
||||
$registryValueExists = Test-RegistryValueExists -KeyPath $registryKeyPathWithForwardSlashes -ValueName $valueName -ValueData $valueData
|
||||
$registryValueExists | Should Be $true
|
||||
$registryValueExists | Should -BeTrue
|
||||
}
|
||||
|
||||
# Test-TargetResource
|
||||
It 'Should return true for an existing registry key' {
|
||||
$registryKeyPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
|
||||
$testTargetResourceResult = Test-TargetResource -Key $registryKeyPath -ValueName ''
|
||||
$testTargetResourceResult | Should Be $true
|
||||
$testTargetResourceResult | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should return false for a registry key that does not exist' {
|
||||
$registryKeyPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environmentally'
|
||||
$testTargetResourceResult = Test-TargetResource -Key $registryKeyPath -ValueName ''
|
||||
$testTargetResourceResult | Should Be $false
|
||||
$testTargetResourceResult | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should return true for an existing registry value' {
|
||||
$registryKeyPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
|
||||
$valueName = 'path'
|
||||
$testTargetResourceResult = Test-TargetResource -Key $registryKeyPath -ValueName $valueName
|
||||
$testTargetResourceResult | Should Be $true
|
||||
$testTargetResourceResult | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should return false for a registry value that does not exist' {
|
||||
$registryKeyPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
|
||||
$registryKeyPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
|
||||
$valueName = 'NonExisting'
|
||||
$testTargetResourceResult = Test-TargetResource -Key $registryKeyPath -ValueName $valueName
|
||||
$testTargetResourceResult | Should Be $false
|
||||
$testTargetResourceResult | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should return true when Ensure is Absent and registry key does not exist' {
|
||||
$registryKeyPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environmentally'
|
||||
$testTargetResourceResult = Test-TargetResource -Key $registryKeyPath -ValueName '' -Ensure 'Absent'
|
||||
$testTargetResourceResult | Should Be $true
|
||||
$testTargetResourceResult | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should return false when Ensure is Absent and registry key exists' {
|
||||
$registryKeyPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
|
||||
$testTargetResourceResult = Test-TargetResource -Key $registryKeyPath -ValueName '' -Ensure 'Absent'
|
||||
$testTargetResourceResult | Should Be $false
|
||||
$testTargetResourceResult | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should return false when Ensure is Absent and registry value exists with invalid data' {
|
||||
@@ -299,7 +299,7 @@ try
|
||||
$valueData = 'FakePath'
|
||||
|
||||
$testTargetResourceResult = Test-TargetResource -Key $registryKeyPath -ValueName $valueName -ValueData $valueData -Ensure 'Absent'
|
||||
$testTargetResourceResult | Should Be $false
|
||||
$testTargetResourceResult | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should return true for a multi-string registry value' {
|
||||
@@ -311,7 +311,7 @@ try
|
||||
New-RegistryValue -KeyPath $script:registryKeyPath -ValueName $valueName -ValueData $valueData -ValueType $valueType
|
||||
|
||||
$testTargetResourceResult = Test-TargetResource -Key $registryKeyPath -ValueName $valueName -ValueData $valueData
|
||||
$testTargetResourceResult | Should Be $true
|
||||
$testTargetResourceResult | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should return true for a binary registry value' {
|
||||
@@ -323,7 +323,7 @@ try
|
||||
New-RegistryValue -KeyPath $script:registryKeyPath -ValueName $valueName -ValueData $valueData -ValueType $valueType
|
||||
|
||||
$testTargetResourceResult = Test-TargetResource -Key $script:registryKeyPath -ValueName $valueName -ValueData $valueData
|
||||
$testTargetResourceResult | Should Be $true
|
||||
$testTargetResourceResult | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should return true for an empty binary registry value' {
|
||||
@@ -336,10 +336,10 @@ try
|
||||
|
||||
# Verify that the registry key value has been created with the correct data and type
|
||||
$registryValueExists = Test-RegistryValueExists -KeyPath $script:registryKeyPath -ValueName $valueName -ValueData $valueData -ValueType $valueType
|
||||
$registryValueExists | Should Be $true
|
||||
$registryValueExists | Should -BeTrue
|
||||
|
||||
$testTargetResourceResult = Test-TargetResource -Key $script:registryKeyPath -ValueName $valueName -ValueData $valueData
|
||||
$testTargetResourceResult | Should Be $true
|
||||
$testTargetResourceResult | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should return true for binary registry value with zeroes' {
|
||||
@@ -351,7 +351,7 @@ try
|
||||
New-RegistryValue -KeyPath $script:registryKeyPath -ValueName $valueName -ValueData $valueData -ValueType $valueType
|
||||
|
||||
$testTargetResourceResult = Test-TargetResource -Key $script:registryKeyPath -ValueName $valueName -ValueData $valueData
|
||||
$testTargetResourceResult | Should Be $true
|
||||
$testTargetResourceResult | Should -BeTrue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$ConfigurationName
|
||||
)
|
||||
|
||||
@@ -11,15 +11,15 @@ Configuration $ConfigurationName
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Key,
|
||||
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
[AllowEmptyString()]
|
||||
$ValueName
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$ConfigurationName
|
||||
)
|
||||
|
||||
@@ -11,25 +11,25 @@ Configuration $ConfigurationName
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Key,
|
||||
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
[AllowEmptyString()]
|
||||
$ValueName,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('String', 'Binary', 'DWord', 'QWord', 'MultiString', 'ExpandString')]
|
||||
[String]
|
||||
[System.String]
|
||||
$ValueType,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
[AllowEmptyCollection()]
|
||||
$ValueData
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
$errorActionPreference = 'Stop'
|
||||
$errorActionPreference = 'Stop'
|
||||
Set-StrictMode -Version 'Latest'
|
||||
|
||||
if ($PSVersionTable.PSVersion -lt [Version] '5.1')
|
||||
@@ -58,15 +58,15 @@ Describe 'Script Integration Tests' {
|
||||
# Cannot use $TestDrive here because script is run outside of Pester
|
||||
$resourceParameters = @{
|
||||
FilePath = $script:testFilePath
|
||||
FileContent = 'Test file content'
|
||||
FileContent = 'Test file content'
|
||||
}
|
||||
|
||||
It 'Should have removed test file before the configuration' {
|
||||
Test-Path -Path $resourceParameters.FilePath | Should Be $false
|
||||
Test-Path -Path $resourceParameters.FilePath | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing' {
|
||||
{
|
||||
{
|
||||
. $script:configurationNoCredentialFilePath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @resourceParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
@@ -74,7 +74,7 @@ Describe 'Script Integration Tests' {
|
||||
}
|
||||
|
||||
It 'Should have created the test file' {
|
||||
Test-Path -Path $resourceParameters.FilePath | Should Be $true
|
||||
Test-Path -Path $resourceParameters.FilePath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should have set file content correctly' {
|
||||
@@ -91,7 +91,7 @@ Describe 'Script Integration Tests' {
|
||||
}
|
||||
|
||||
$configurationName = 'TestScriptWithCredential'
|
||||
|
||||
|
||||
# Cannot use $TestDrive here because script is run outside of Pester
|
||||
$resourceParameters = @{
|
||||
FilePath = $script:testFilePath
|
||||
@@ -100,7 +100,7 @@ Describe 'Script Integration Tests' {
|
||||
}
|
||||
|
||||
It 'Should have removed test file before config runs' {
|
||||
Test-Path -Path $resourceParameters.FilePath | Should Be $false
|
||||
Test-Path -Path $resourceParameters.FilePath | Should -BeFalse
|
||||
}
|
||||
|
||||
$configData = @{
|
||||
@@ -114,19 +114,19 @@ Describe 'Script Integration Tests' {
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing' {
|
||||
{
|
||||
{
|
||||
. $script:configurationWithCredentialFilePath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive -ConfigurationData $configData @resourceParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should have created the test file' {
|
||||
Test-Path -Path $resourceParameters.FilePath | Should Be $true
|
||||
Test-Path -Path $resourceParameters.FilePath | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should have set file content correctly' {
|
||||
Get-Content -Path $resourceParameters.FilePath -Raw | Should Be "$($resourceParameters.FileContent)`r`n"
|
||||
Get-Content -Path $resourceParameters.FilePath -Raw | Should -Be "$($resourceParameters.FileContent)`r`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$ConfigurationName
|
||||
)
|
||||
|
||||
@@ -12,12 +12,12 @@ Configuration $ConfigurationName
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$FilePath,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$FileContent
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$ConfigurationName
|
||||
)
|
||||
|
||||
@@ -12,12 +12,12 @@ Configuration $ConfigurationName
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$FilePath,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$FileContent,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
|
||||
@@ -122,59 +122,59 @@ try
|
||||
$resourceParameters = $script:existingServiceProperties
|
||||
|
||||
It 'Should compile and apply the MOF without throwing' {
|
||||
{
|
||||
{
|
||||
. $script:configurationAllExceptCredentialFilePath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @resourceParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
$service = Get-Service -Name $resourceParameters.Name -ErrorAction 'SilentlyContinue'
|
||||
$serviceCimInstance = Get-CimInstance -ClassName 'Win32_Service' -Filter "Name='$($resourceParameters.Name)'" -ErrorAction 'SilentlyContinue'
|
||||
|
||||
It 'Should have created a new service with the specified name' {
|
||||
$service | Should Not Be $null
|
||||
$serviceCimInstance | Should Not Be $null
|
||||
$service | Should -Not -Be $null
|
||||
$serviceCimInstance | Should -Not -Be $null
|
||||
|
||||
$service.Name | Should Be $resourceParameters.Name
|
||||
$serviceCimInstance.Name | Should Be $resourceParameters.Name
|
||||
$service.Name | Should -Be $resourceParameters.Name
|
||||
$serviceCimInstance.Name | Should -Be $resourceParameters.Name
|
||||
}
|
||||
|
||||
It 'Should have created a new service with the specified path' {
|
||||
$serviceCimInstance.PathName | Should Be $resourceParameters.Path
|
||||
$serviceCimInstance.PathName | Should -Be $resourceParameters.Path
|
||||
}
|
||||
|
||||
It 'Should have created a new service with the specified display name' {
|
||||
$service.DisplayName | Should Be $resourceParameters.DisplayName
|
||||
$service.DisplayName | Should -Be $resourceParameters.DisplayName
|
||||
}
|
||||
|
||||
It 'Should have created a new service with the specified description' {
|
||||
$serviceCimInstance.Description | Should Be $resourceParameters.Description
|
||||
$serviceCimInstance.Description | Should -Be $resourceParameters.Description
|
||||
}
|
||||
|
||||
It 'Should have created a new service with the specified dependencies' {
|
||||
$differentDependencies = Compare-Object -ReferenceObject $resourceParameters.Dependencies -DifferenceObject $service.ServicesDependedOn.Name
|
||||
$differentDependencies | Should Be $null
|
||||
$differentDependencies | Should -Be $null
|
||||
}
|
||||
|
||||
It 'Should have created a new service with the default state as Running' {
|
||||
$service.Status | Should Be 'Running'
|
||||
$service.Status | Should -Be 'Running'
|
||||
}
|
||||
|
||||
It 'Should have created a new service with the default startup type as Auto' {
|
||||
$serviceCimInstance.StartMode | Should Be 'Auto'
|
||||
$serviceCimInstance.StartMode | Should -Be 'Auto'
|
||||
}
|
||||
|
||||
It 'Should have created a new service with the default startup account name as LocalSystem' {
|
||||
$serviceCimInstance.StartName | Should Be 'LocalSystem'
|
||||
$serviceCimInstance.StartName | Should -Be 'LocalSystem'
|
||||
}
|
||||
|
||||
It 'Should have created a new service with the default desktop interaction setting as False' {
|
||||
$serviceCimInstance.DesktopInteract | Should Be $false
|
||||
$serviceCimInstance.DesktopInteract | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters' {
|
||||
MSFT_ServiceResource\Test-TargetResource @resourceParameters | Should Be $true
|
||||
MSFT_ServiceResource\Test-TargetResource @resourceParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,59 +185,59 @@ try
|
||||
$resourceParameters = $script:newServiceProperties
|
||||
|
||||
It 'Should compile and apply the MOF without throwing' {
|
||||
{
|
||||
{
|
||||
. $script:configurationAllExceptCredentialFilePath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @resourceParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
$service = Get-Service -Name $resourceParameters.Name -ErrorAction 'SilentlyContinue'
|
||||
$serviceCimInstance = Get-CimInstance -ClassName 'Win32_Service' -Filter "Name='$($resourceParameters.Name)'" -ErrorAction 'SilentlyContinue'
|
||||
|
||||
It 'Should not have removed service with specified name' {
|
||||
$service | Should Not Be $null
|
||||
$serviceCimInstance | Should Not Be $null
|
||||
$service | Should -Not -Be $null
|
||||
$serviceCimInstance | Should -Not -Be $null
|
||||
|
||||
$service.Name | Should Be $resourceParameters.Name
|
||||
$serviceCimInstance.Name | Should Be $resourceParameters.Name
|
||||
$service.Name | Should -Be $resourceParameters.Name
|
||||
$serviceCimInstance.Name | Should -Be $resourceParameters.Name
|
||||
}
|
||||
|
||||
It 'Should have edited service to have the specified path' {
|
||||
$serviceCimInstance.PathName | Should Be $resourceParameters.Path
|
||||
$serviceCimInstance.PathName | Should -Be $resourceParameters.Path
|
||||
}
|
||||
|
||||
It 'Should have edited service to have the specified display name' {
|
||||
$service.DisplayName | Should Be $resourceParameters.DisplayName
|
||||
$service.DisplayName | Should -Be $resourceParameters.DisplayName
|
||||
}
|
||||
|
||||
It 'Should have edited service to have the specified description' {
|
||||
$serviceCimInstance.Description | Should Be $resourceParameters.Description
|
||||
$serviceCimInstance.Description | Should -Be $resourceParameters.Description
|
||||
}
|
||||
|
||||
It 'Should have edited service to have the specified dependencies' {
|
||||
$differentDependencies = Compare-Object -ReferenceObject $resourceParameters.Dependencies -DifferenceObject $service.ServicesDependedOn.Name
|
||||
$differentDependencies | Should Be $null
|
||||
$differentDependencies | Should -Be $null
|
||||
}
|
||||
|
||||
It 'Should not have changed the service state from Running' {
|
||||
$service.Status | Should Be 'Running'
|
||||
$service.Status | Should -Be 'Running'
|
||||
}
|
||||
|
||||
It 'Should not have changed the service startup type from Auto' {
|
||||
$serviceCimInstance.StartMode | Should Be 'Auto'
|
||||
$serviceCimInstance.StartMode | Should -Be 'Auto'
|
||||
}
|
||||
|
||||
It 'Should not have changed the service startup account name from LocalSystem' {
|
||||
$serviceCimInstance.StartName | Should Be 'LocalSystem'
|
||||
$serviceCimInstance.StartName | Should -Be 'LocalSystem'
|
||||
}
|
||||
|
||||
It 'Should not have changed the service desktop interaction setting from False' {
|
||||
$serviceCimInstance.DesktopInteract | Should Be $false
|
||||
$serviceCimInstance.DesktopInteract | Should -BeFalse
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters' {
|
||||
MSFT_ServiceResource\Test-TargetResource @resourceParameters | Should Be $true
|
||||
MSFT_ServiceResource\Test-TargetResource @resourceParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,34 +253,34 @@ try
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing' {
|
||||
{
|
||||
{
|
||||
. $script:configurationAllExceptCredentialFilePath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @resourceParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
$service = Get-Service -Name $resourceParameters.Name -ErrorAction 'SilentlyContinue'
|
||||
$serviceCimInstance = Get-CimInstance -ClassName 'Win32_Service' -Filter "Name='$($resourceParameters.Name)'" -ErrorAction 'SilentlyContinue'
|
||||
|
||||
It 'Should not have removed service with specified name' {
|
||||
$service | Should Not Be $null
|
||||
$serviceCimInstance | Should Not Be $null
|
||||
$service | Should -Not -Be $null
|
||||
$serviceCimInstance | Should -Not -Be $null
|
||||
|
||||
$service.Name | Should Be $resourceParameters.Name
|
||||
$serviceCimInstance.Name | Should Be $resourceParameters.Name
|
||||
$service.Name | Should -Be $resourceParameters.Name
|
||||
$serviceCimInstance.Name | Should -Be $resourceParameters.Name
|
||||
}
|
||||
|
||||
It 'Should have edited the service to have the specified state' {
|
||||
$service.Status | Should Be $resourceParameters.State
|
||||
$service.Status | Should -Be $resourceParameters.State
|
||||
}
|
||||
|
||||
It 'Should have edited the service to have the specified startup type' {
|
||||
$serviceCimInstance.StartMode | Should Be $resourceParameters.StartupType
|
||||
$serviceCimInstance.StartMode | Should -Be $resourceParameters.StartupType
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters' {
|
||||
MSFT_ServiceResource\Test-TargetResource @resourceParameters | Should Be $true
|
||||
MSFT_ServiceResource\Test-TargetResource @resourceParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,22 +303,22 @@ try
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing' {
|
||||
{
|
||||
{
|
||||
. $script:configurationCredentialOnlyFilePath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive -ConfigurationData $configData @resourceParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
$service = Get-Service -Name $resourceParameters.Name -ErrorAction 'SilentlyContinue'
|
||||
$serviceCimInstance = Get-CimInstance -ClassName 'Win32_Service' -Filter "Name='$($resourceParameters.Name)'" -ErrorAction 'SilentlyContinue'
|
||||
|
||||
It 'Should not have removed service with specified name' {
|
||||
$service | Should Not Be $null
|
||||
$serviceCimInstance | Should Not Be $null
|
||||
$service | Should -Not -Be $null
|
||||
$serviceCimInstance | Should -Not -Be $null
|
||||
|
||||
$service.Name | Should Be $resourceParameters.Name
|
||||
$serviceCimInstance.Name | Should Be $resourceParameters.Name
|
||||
$service.Name | Should -Be $resourceParameters.Name
|
||||
$serviceCimInstance.Name | Should -Be $resourceParameters.Name
|
||||
}
|
||||
|
||||
It 'Should have edited the service to have the specified startup account name' {
|
||||
@@ -329,11 +329,11 @@ try
|
||||
$expectedStartName = $expectedStartName.TrimStart("$env:COMPUTERNAME\")
|
||||
}
|
||||
|
||||
$serviceCimInstance.StartName | Should Be ".\$expectedStartName"
|
||||
$serviceCimInstance.StartName | Should -Be ".\$expectedStartName"
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters' {
|
||||
MSFT_ServiceResource\Test-TargetResource @resourceParameters | Should Be $true
|
||||
MSFT_ServiceResource\Test-TargetResource @resourceParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,30 +348,30 @@ try
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing' {
|
||||
{
|
||||
{
|
||||
. $script:configurationAllExceptCredentialFilePath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @resourceParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
$service = Get-Service -Name $resourceParameters.Name -ErrorAction 'SilentlyContinue'
|
||||
$serviceCimInstance = Get-CimInstance -ClassName 'Win32_Service' -Filter "Name='$($resourceParameters.Name)'" -ErrorAction 'SilentlyContinue'
|
||||
|
||||
It 'Should not have removed service with specified name' {
|
||||
$service | Should Not Be $null
|
||||
$serviceCimInstance | Should Not Be $null
|
||||
$service | Should -Not -Be $null
|
||||
$serviceCimInstance | Should -Not -Be $null
|
||||
|
||||
$service.Name | Should Be $resourceParameters.Name
|
||||
$serviceCimInstance.Name | Should Be $resourceParameters.Name
|
||||
$service.Name | Should -Be $resourceParameters.Name
|
||||
$serviceCimInstance.Name | Should -Be $resourceParameters.Name
|
||||
}
|
||||
|
||||
It 'Should have edited the service to have the specified startup account name' {
|
||||
$serviceCimInstance.StartName | Should Be 'NT Authority\LocalService'
|
||||
$serviceCimInstance.StartName | Should -Be 'NT Authority\LocalService'
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters' {
|
||||
MSFT_ServiceResource\Test-TargetResource @resourceParameters | Should Be $true
|
||||
MSFT_ServiceResource\Test-TargetResource @resourceParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,23 +386,23 @@ try
|
||||
}
|
||||
|
||||
It 'Should compile and apply the MOF without throwing' {
|
||||
{
|
||||
{
|
||||
. $script:configurationAllExceptCredentialFilePath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @resourceParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
$service = Get-Service -Name $resourceParameters.Name -ErrorAction 'SilentlyContinue'
|
||||
$serviceCimInstance = Get-CimInstance -ClassName 'Win32_Service' -Filter "Name='$($resourceParameters.Name)'" -ErrorAction 'SilentlyContinue'
|
||||
|
||||
It 'Should have removed the service with specified name' {
|
||||
$service | Should Be $null
|
||||
$serviceCimInstance | Should Be $null
|
||||
$service | Should -Be $null
|
||||
$serviceCimInstance | Should -Be $null
|
||||
}
|
||||
|
||||
It 'Should return true from Test-TargetResource with the same parameters' {
|
||||
MSFT_ServiceResource\Test-TargetResource @resourceParameters | Should Be $true
|
||||
MSFT_ServiceResource\Test-TargetResource @resourceParameters | Should -BeTrue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$ConfigurationName
|
||||
)
|
||||
|
||||
@@ -11,58 +11,58 @@ Configuration $ConfigurationName
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Path,
|
||||
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$DisplayName = "$Name DisplayName",
|
||||
|
||||
[Parameter()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Description = 'TestDescription',
|
||||
|
||||
[Parameter()]
|
||||
[String[]]
|
||||
[System.String[]]
|
||||
[AllowEmptyCollection()]
|
||||
$Dependencies = @(),
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('LocalSystem', 'LocalService', 'NetworkService')]
|
||||
[String]
|
||||
[System.String]
|
||||
$BuiltInAccount = 'LocalSystem',
|
||||
|
||||
[Parameter()]
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$DesktopInteract = $false,
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Automatic', 'Manual', 'Disabled')]
|
||||
[String]
|
||||
[System.String]
|
||||
$StartupType = 'Automatic',
|
||||
|
||||
[Parameter()]
|
||||
[ValidateSet('Running', 'Stopped', 'Ignore')]
|
||||
[String]
|
||||
[System.String]
|
||||
$State = 'Running',
|
||||
|
||||
[Parameter()]
|
||||
[UInt32]
|
||||
[System.UInt32]
|
||||
$StartupTimeout = 30000,
|
||||
|
||||
[Parameter()]
|
||||
[UInt32]
|
||||
[System.UInt32]
|
||||
$TerminateTimeout = 30000
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$ConfigurationName
|
||||
)
|
||||
|
||||
@@ -11,12 +11,12 @@ Configuration $ConfigurationName
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<#
|
||||
To run these tests, the currently logged on user must have rights to create a user.
|
||||
These integration tests cover creating a brand new user, updating values
|
||||
These integration tests cover creating a brand new user, updating values
|
||||
of a user that already exists, and deleting a user that exists.
|
||||
#>
|
||||
#>
|
||||
|
||||
# Suppressing this rule since we need to create a plaintext password to test this resource
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
|
||||
@@ -45,13 +45,13 @@ try
|
||||
}
|
||||
|
||||
$script:logPath = Join-Path -Path $TestDrive -ChildPath 'NewUser.log'
|
||||
|
||||
|
||||
$script:testUserName = 'TestUserName12345'
|
||||
$script:testPassword = 'StrongOne7.'
|
||||
$script:testDescription = 'Test Description'
|
||||
$script:newTestDescription = 'New Test Description'
|
||||
$script:secureTestPassword = ConvertTo-SecureString $script:testPassword -AsPlainText -Force
|
||||
$script:testCredential = New-Object PSCredential ($script:testUserName, $script:secureTestPassword)
|
||||
$script:testCredential = New-Object PSCredential ($script:testUserName, $script:secureTestPassword)
|
||||
|
||||
Context 'Should create a new user' {
|
||||
$configurationName = 'MSFT_User_NewUser'
|
||||
@@ -67,23 +67,23 @@ try
|
||||
-Description $script:testDescription `
|
||||
-OutputPath $configurationPath `
|
||||
-ConfigurationData $script:configData `
|
||||
-ErrorAction 'Stop'
|
||||
-ErrorAction Stop
|
||||
Start-DscConfiguration -Path $configurationPath -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
{ Get-DscConfiguration -ErrorAction Stop } | Should -Not -Throw
|
||||
}
|
||||
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction Stop
|
||||
$currentConfig.UserName | Should Be $script:testUserName
|
||||
$currentConfig.Ensure | Should Be 'Present'
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
$currentConfig.Description | Should Be $script:testDescription
|
||||
$currentConfig.PasswordNeverExpires | Should Be $false
|
||||
$currentConfig.Disabled | Should Be $false
|
||||
$currentConfig.PasswordChangeRequired | Should Be $null
|
||||
$currentConfig.PasswordNeverExpires | Should -BeFalse
|
||||
$currentConfig.Disabled | Should -BeFalse
|
||||
$currentConfig.PasswordChangeRequired | Should -Be $null
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -98,7 +98,7 @@ try
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Context 'Should update Description of an existing user' {
|
||||
$configurationName = 'MSFT_User_UpdateUserDescription'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
@@ -122,14 +122,14 @@ try
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
}
|
||||
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.UserName | Should Be $script:testUserName
|
||||
$currentConfig.Ensure | Should Be 'Present'
|
||||
$currentConfig.Description | Should Be $newTestDescription
|
||||
$currentConfig.PasswordNeverExpires | Should Be $false
|
||||
$currentConfig.Disabled | Should Be $false
|
||||
$currentConfig.PasswordNeverExpires | Should -BeFalse
|
||||
$currentConfig.Disabled | Should -BeFalse
|
||||
$currentConfig.PasswordChangeRequired | Should Be $null
|
||||
}
|
||||
}
|
||||
@@ -163,24 +163,24 @@ try
|
||||
-PasswordNeverExpires $true `
|
||||
-OutputPath $configurationPath `
|
||||
-ConfigurationData $script:configData `
|
||||
-ErrorAction 'Stop'
|
||||
-ErrorAction Stop
|
||||
Start-DscConfiguration -Path $configurationPath -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
{ Get-DscConfiguration -ErrorAction Stop } | Should -Not -Throw
|
||||
}
|
||||
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction Stop
|
||||
$currentConfig.UserName | Should Be $script:testUserName
|
||||
$currentConfig.Ensure | Should Be 'Present'
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
$currentConfig.Description | Should Be $script:testDescription
|
||||
$currentConfig.FullName | Should Be $newFullName
|
||||
$currentConfig.PasswordNeverExpires | Should Be $true
|
||||
$currentConfig.Disabled | Should Be $false
|
||||
$currentConfig.PasswordChangeRequired | Should Be $null
|
||||
$currentConfig.PasswordNeverExpires | Should -BeTrue
|
||||
$currentConfig.Disabled | Should -BeFalse
|
||||
$currentConfig.PasswordChangeRequired | Should -Be $null
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -195,7 +195,7 @@ try
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Context 'Should delete an existing user' {
|
||||
$configurationName = 'MSFT_User_DeleteUser'
|
||||
$configurationPath = Join-Path -Path $TestDrive -ChildPath $configurationName
|
||||
@@ -210,19 +210,19 @@ try
|
||||
-OutputPath $configurationPath `
|
||||
-ConfigurationData $script:configData `
|
||||
-Ensure 'Absent' `
|
||||
-ErrorAction 'Stop'
|
||||
-ErrorAction Stop
|
||||
Start-DscConfiguration -Path $configurationPath -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
{ Get-DscConfiguration -ErrorAction Stop } | Should -Not -Throw
|
||||
}
|
||||
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction Stop
|
||||
$currentConfig.UserName | Should Be $script:testUserName
|
||||
$currentConfig.Ensure | Should Be 'Absent'
|
||||
$currentConfig.Ensure | Should -Be 'Absent'
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
|
||||
|
||||
# Integration Test Config Template Version 1.0.0
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[System.String]
|
||||
$ConfigurationName
|
||||
)
|
||||
|
||||
|
||||
|
||||
Configuration $ConfigurationName
|
||||
{
|
||||
param
|
||||
(
|
||||
param
|
||||
(
|
||||
[System.String]
|
||||
$UserName = 'Test UserName',
|
||||
|
||||
|
||||
[System.String]
|
||||
$Description = 'Test Description',
|
||||
|
||||
|
||||
[System.String]
|
||||
$FullName = 'Test Full Name',
|
||||
|
||||
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[System.Management.Automation.PSCredential]
|
||||
[System.Management.Automation.Credential()]
|
||||
@@ -33,9 +33,9 @@ Configuration $ConfigurationName
|
||||
[Boolean]
|
||||
$PasswordNeverExpires = $false
|
||||
)
|
||||
|
||||
|
||||
Import-DscResource -ModuleName 'PSDscResources'
|
||||
|
||||
|
||||
Node localhost {
|
||||
|
||||
User UserResource1
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<#
|
||||
<#
|
||||
Integration tests for installing/uninstalling a Windows Feature. Currently Telnet-Client is
|
||||
set as the feature to test since it's fairly small and doesn't require a restart. ADRMS
|
||||
is set as the feature to test installing/uninstalling a feature with subfeatures,
|
||||
but this takes a good chunk of time, so by default these tests are set to be skipped.
|
||||
If there's any major changes to the resource, then set the skipLongTests variable to $false
|
||||
and run those tests at least once to test the new functionality more completely.
|
||||
and run those tests at least once to test the new functionality more completely.
|
||||
#>
|
||||
|
||||
# Suppressing this rule since we need to create a plaintext password to test this resource
|
||||
@@ -45,7 +45,7 @@ try
|
||||
$script:testFeatureName = 'Telnet-Client'
|
||||
$script:testFeatureWithSubFeaturesName = 'RSAT-File-Services'
|
||||
|
||||
#Saving the state so we can clean up afterwards
|
||||
# Saving the state so we can clean up afterwards
|
||||
$testFeature = Get-WindowsFeature -Name $script:testFeatureName
|
||||
$script:installStateOfTestFeature = $testFeature.Installed
|
||||
|
||||
@@ -103,23 +103,23 @@ try
|
||||
-OutputPath $configurationPath `
|
||||
-ErrorAction 'Stop'
|
||||
Start-DscConfiguration -Path $configurationPath -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should -Not -Throw
|
||||
}
|
||||
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should Be $script:testFeatureName
|
||||
$currentConfig.IncludeAllSubFeature | Should Be $false
|
||||
$currentConfig.Ensure | Should Be 'Present'
|
||||
$currentConfig.Name | Should -Be $script:testFeatureName
|
||||
$currentConfig.IncludeAllSubFeature | Should -BeFalse
|
||||
$currentConfig.Ensure | Should -Be 'Present'
|
||||
}
|
||||
|
||||
It 'Should be Installed' {
|
||||
$feature = Get-WindowsFeature -Name $script:testFeatureName
|
||||
$feature.Installed | Should Be $true
|
||||
$feature.Installed | Should -BeTrue
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -152,23 +152,23 @@ try
|
||||
-OutputPath $configurationPath `
|
||||
-ErrorAction 'Stop'
|
||||
Start-DscConfiguration -Path $configurationPath -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should -Not -Throw
|
||||
}
|
||||
|
||||
|
||||
It 'Should return the correct configuration' {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should Be $script:testFeatureName
|
||||
$currentConfig.IncludeAllSubFeature | Should Be $false
|
||||
$currentConfig.Ensure | Should Be 'Absent'
|
||||
$currentConfig.Name | Should -Be $script:testFeatureName
|
||||
$currentConfig.IncludeAllSubFeature | Should -BeFalse
|
||||
$currentConfig.Ensure | Should -Be 'Absent'
|
||||
}
|
||||
|
||||
It 'Should not be installed' {
|
||||
$feature = Get-WindowsFeature -Name $script:testFeatureName
|
||||
$feature.Installed | Should Be $false
|
||||
$feature.Installed | Should -BeFalse
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -187,7 +187,7 @@ try
|
||||
<#
|
||||
This test triggers a pending reboot on the machine which crashes the WindowsFeatureSet
|
||||
and WindowsOptionalFeatureSet tests on AppVeyor.
|
||||
|
||||
|
||||
If anyone knows of a Windows Feature that exists on Server 2012 R2, does not require a
|
||||
reboot, and has subfeatures, please update $script:testFeatureWithSubFeaturesName with
|
||||
the name of that feature and turn these tests back on in AppVeyor
|
||||
@@ -221,22 +221,22 @@ try
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' -Skip:$script:skipLongTests {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
}
|
||||
|
||||
|
||||
It 'Should return the correct configuration' -Skip:$script:skipLongTests {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should Be $script:testFeatureWithSubFeaturesName
|
||||
$currentConfig.IncludeAllSubFeature | Should Be $true
|
||||
$currentConfig.IncludeAllSubFeature | Should -BeTrue
|
||||
$currentConfig.Ensure | Should Be 'Present'
|
||||
}
|
||||
|
||||
It 'Should be Installed (includes check for subFeatures)' -Skip:$script:skipLongTests {
|
||||
$feature = Get-WindowsFeature -Name $script:testFeatureWithSubFeaturesName
|
||||
$feature.Installed | Should Be $true
|
||||
$feature.Installed | Should -BeTrue
|
||||
|
||||
foreach ($subFeatureName in $feature.SubFeatures)
|
||||
{
|
||||
$subFeature = Get-WindowsFeature -Name $subFeatureName
|
||||
$subFeature.Installed | Should Be $true
|
||||
$subFeature.Installed | Should -BeTrue
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -262,22 +262,22 @@ try
|
||||
It 'Should be able to call Get-DscConfiguration without throwing' -Skip:$script:skipLongTests {
|
||||
{ Get-DscConfiguration -ErrorAction 'Stop' } | Should Not Throw
|
||||
}
|
||||
|
||||
|
||||
It 'Should return the correct configuration' -Skip:$script:skipLongTests {
|
||||
$currentConfig = Get-DscConfiguration -ErrorAction 'Stop'
|
||||
$currentConfig.Name | Should Be $script:testFeatureWithSubFeaturesName
|
||||
$currentConfig.IncludeAllSubFeature | Should Be $false
|
||||
$currentConfig.IncludeAllSubFeature | Should -BeFalse
|
||||
$currentConfig.Ensure | Should Be 'Absent'
|
||||
}
|
||||
|
||||
It 'Should not be installed (includes check for subFeatures)' -Skip:$script:skipLongTests {
|
||||
$feature = Get-WindowsFeature -Name $script:testFeatureWithSubFeaturesName
|
||||
$feature.Installed | Should Be $false
|
||||
$feature.Installed | Should -BeFalse
|
||||
|
||||
foreach ($subFeatureName in $feature.SubFeatures)
|
||||
{
|
||||
$subFeature = Get-WindowsFeature -Name $subFeatureName
|
||||
$subFeature.Installed | Should Be $false
|
||||
$subFeature.Installed | Should -BeFalse
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory)]
|
||||
[System.String]
|
||||
@@ -8,8 +8,8 @@
|
||||
Configuration $ConfigurationName
|
||||
{
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
@@ -20,9 +20,9 @@ Configuration $ConfigurationName
|
||||
[System.Boolean]
|
||||
$IncludeAllSubFeature = $false
|
||||
)
|
||||
|
||||
|
||||
Import-DscResource -ModuleName 'PSDscResources'
|
||||
|
||||
|
||||
Node Localhost
|
||||
{
|
||||
WindowsFeature WindowsFeatureTest
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if ($PSVersionTable.PSVersion -lt [Version] '5.1')
|
||||
if ($PSVersionTable.PSVersion -lt [Version] '5.1')
|
||||
{
|
||||
Write-Warning -Message 'Cannot run PSDscResources integration tests on PowerShell versions lower than 5.1'
|
||||
return
|
||||
@@ -25,7 +25,7 @@ try
|
||||
|
||||
$script:confgurationFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'MSFT_WindowsOptionalFeature.config.ps1'
|
||||
}
|
||||
|
||||
|
||||
It 'Should enable a valid Windows optional feature' {
|
||||
$configurationName = 'EnableWindowsOptionalFeature'
|
||||
|
||||
@@ -45,16 +45,16 @@ try
|
||||
Dism\Disable-WindowsOptionalFeature -FeatureName $resourceParameters.Name -Online -NoRestart
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
. $script:confgurationFilePath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @resourceParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
|
||||
$windowsOptionalFeature = Dism\Get-WindowsOptionalFeature -FeatureName $resourceParameters.Name -Online
|
||||
|
||||
$windowsOptionalFeature | Should Not Be $null
|
||||
$windowsOptionalFeature.State -in $script:enabledStates | Should Be $true
|
||||
$windowsOptionalFeature | Should -Not -Be $null
|
||||
$windowsOptionalFeature.State -in $script:enabledStates | Should -BeTrue
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -94,16 +94,16 @@ try
|
||||
Dism\Enable-WindowsOptionalFeature -FeatureName $resourceParameters.Name -Online -NoRestart
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
. $script:confgurationFilePath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @resourceParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
|
||||
$windowsOptionalFeature = Dism\Get-WindowsOptionalFeature -FeatureName $resourceParameters.Name -Online
|
||||
|
||||
$windowsOptionalFeature | Should Not Be $null
|
||||
$windowsOptionalFeature.State -in $script:disabledStates | Should Be $true
|
||||
$windowsOptionalFeature | Should -Not -Be $null
|
||||
$windowsOptionalFeature.State -in $script:disabledStates | Should -BeTrue
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -133,19 +133,19 @@ try
|
||||
NoWindowsUpdateCheck = $true
|
||||
}
|
||||
|
||||
Dism\Get-WindowsOptionalFeature -FeatureName $resourceParameters.Name -Online | Should Be $null
|
||||
Dism\Get-WindowsOptionalFeature -FeatureName $resourceParameters.Name -Online | Should -Be $null
|
||||
|
||||
try
|
||||
{
|
||||
{
|
||||
{
|
||||
. $script:confgurationFilePath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @resourceParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Throw "Feature name $($resourceParameters.Name) is unknown."
|
||||
} | Should -Throw "Feature name $($resourceParameters.Name) is unknown."
|
||||
|
||||
Test-Path -Path $resourceParameters.LogPath | Should Be $true
|
||||
Test-Path -Path $resourceParameters.LogPath | Should -BeTrue
|
||||
|
||||
Dism\Get-WindowsOptionalFeature -FeatureName $resourceParameters.Name -Online | Should Be $null
|
||||
Dism\Get-WindowsOptionalFeature -FeatureName $resourceParameters.Name -Online | Should -Be $null
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$ConfigurationName
|
||||
)
|
||||
|
||||
@@ -11,22 +11,22 @@ Configuration $ConfigurationName
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure = 'Present',
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath = (Join-Path -Path (Get-Location) -ChildPath 'WOFTestLog.txt'),
|
||||
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$RemoveFilesOnDisable = $false,
|
||||
|
||||
[Boolean]
|
||||
[System.Boolean]
|
||||
$NoWindowsUpdateCheck = $true
|
||||
)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
if ($PSVersionTable.PSVersion -lt [Version] '5.1')
|
||||
if ($PSVersionTable.PSVersion -lt [Version] '5.1')
|
||||
{
|
||||
Write-Warning -Message 'Cannot run PSDscResources integration tests on PowerShell versions lower than 5.1'
|
||||
return
|
||||
@@ -21,14 +21,14 @@ try
|
||||
Describe 'WindowsPackageCab Integration Tests' {
|
||||
BeforeAll {
|
||||
Import-Module -Name 'Dism'
|
||||
|
||||
|
||||
$script:installedStates = @( 'Installed', 'InstallPending' )
|
||||
$script:confgurationFilePath = Join-Path -Path $PSScriptRoot -ChildPath 'MSFT_WindowsPackageCab.config.ps1'
|
||||
|
||||
$script:testPackageName = ''
|
||||
$script:testPackageName = ''
|
||||
$script:testSourcePath = Join-Path -Path $PSScriptRoot -ChildPath ''
|
||||
|
||||
$script:cabPackageNotProvided = $script:testPackageName -eq [String]::Empty
|
||||
$script:cabPackageNotProvided = $script:testPackageName -eq [System.String]::Empty
|
||||
|
||||
try
|
||||
{
|
||||
@@ -58,7 +58,7 @@ try
|
||||
{
|
||||
try
|
||||
{
|
||||
$windowsPackage = Dism\Get-WindowsPackage -PackageName $script:testPackageName -Online
|
||||
$windowsPackage = Dism\Get-WindowsPackage -PackageName $script:testPackageName -Online
|
||||
if ($null -ne $windowsPackage -and $windowsPackage.PackageState -in $script:installedStates)
|
||||
{
|
||||
Dism\Remove-WindowsPackage -PackageName $script:testPackageName.Name -Online -NoRestart
|
||||
@@ -70,7 +70,7 @@ try
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
It 'Should install a Windows package through a cab file' -Skip:$script:cabPackageNotProvided {
|
||||
$configurationName = 'InstallWindowsPackageCab'
|
||||
|
||||
@@ -80,17 +80,17 @@ try
|
||||
Ensure = 'Present'
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
. $script:confgurationFilePath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @resourceParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
|
||||
{ $windowsPackage = Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online } | Should Not Throw
|
||||
{ $null = Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online } | Should -Not -Throw
|
||||
|
||||
$windowsPackage = Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online
|
||||
$windowsPackage | Should Not Be $null
|
||||
$windowsPackage.PackageState -in $script:installedStates | Should Be $true
|
||||
$windowsPackage | Should -Not -Be $null
|
||||
$windowsPackage.PackageState -in $script:installedStates | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Should uninstall a Windows package through a cab file' -Skip:$script:cabPackageNotProvided {
|
||||
@@ -104,15 +104,15 @@ try
|
||||
|
||||
Dism\Add-WindowsPackage -PackagePath $resourceParameters.SourcePath -Online -NoRestart
|
||||
|
||||
{ $windowsPackage = Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online } | Should Not Throw
|
||||
{ $null = Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online } | Should -Not -Throw
|
||||
|
||||
{
|
||||
{
|
||||
. $script:confgurationFilePath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @resourceParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Not Throw
|
||||
} | Should -Not -Throw
|
||||
|
||||
{ $windowsPackage = Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online } | Should Throw
|
||||
{ $null = Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online } | Should -Throw
|
||||
}
|
||||
|
||||
It 'Should not install an invalid Windows package through a cab file' {
|
||||
@@ -125,17 +125,17 @@ try
|
||||
LogPath = (Join-Path -Path $TestDrive -ChildPath 'InvalidWindowsPackageCab.log')
|
||||
}
|
||||
|
||||
{ Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online } | Should Throw
|
||||
{ Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online } | Should -Throw
|
||||
|
||||
{
|
||||
{
|
||||
. $script:confgurationFilePath -ConfigurationName $configurationName
|
||||
& $configurationName -OutputPath $TestDrive @resourceParameters
|
||||
Start-DscConfiguration -Path $TestDrive -ErrorAction 'Stop' -Wait -Force
|
||||
} | Should Throw
|
||||
} | Should -Throw
|
||||
|
||||
Test-Path -Path $resourceParameters.LogPath | Should Be $true
|
||||
Test-Path -Path $resourceParameters.LogPath | Should -BeTrue
|
||||
|
||||
{ Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online } | Should Throw
|
||||
{ Dism\Get-WindowsPackage -PackageName $resourceParameters.Name -Online } | Should -Throw
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
param
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
[System.String]
|
||||
$ConfigurationName
|
||||
)
|
||||
|
||||
@@ -11,21 +11,21 @@ Configuration $ConfigurationName
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$Name,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('Present', 'Absent')]
|
||||
[String]
|
||||
[System.String]
|
||||
$Ensure,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$SourcePath,
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
[System.String]
|
||||
$LogPath = (Join-Path -Path (Get-Location) -ChildPath 'WindowsPackageCabTestLog.txt')
|
||||
)
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user