Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbreakey3 committed Jan 27, 2017
1 parent b275db0 commit e21436c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions DscResources/MSFT_UserResource/MSFT_UserResource.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -709,15 +709,15 @@ function Get-TargetResourceOnNanoServer
$UserName
)

Set-StrictMode -Version Latest

Assert-UserNameValid -UserName $UserName

$returnValue = @{}

# Try to find a user by a name
try
{
Write-Verbose -Message 'Starting Get-TargetResource on NanoServer'
$user = Find-UserByNameOnNanoServer -UserName $UserName -ErrorAction 'Stop'
$user = Find-UserByNameOnNanoServer -UserName $UserName

# The user is found. Return all user properties and Ensure = 'Present'.
$returnValue = @{
Expand All @@ -738,15 +738,13 @@ function Get-TargetResourceOnNanoServer
{
$returnValue.Add('PasswordNeverExpires', $true)
}

return $returnValue
}
catch [System.Exception]
{
if ($_.FullyQualifiedErrorId -match 'UserNotFound')
{
# The user is not found
return @{
$returnValue = @{
UserName = $UserName
Ensure = 'Absent'
}
Expand All @@ -756,6 +754,8 @@ function Get-TargetResourceOnNanoServer
New-InvalidOperationException -ErrorRecord $_
}
}

return $returnValue
}

<#
Expand Down Expand Up @@ -846,7 +846,7 @@ function Set-TargetResourceOnNanoServer

try
{
$user = Find-UserByNameOnNanoServer -UserName $UserName -ErrorAction 'Stop'
$user = Find-UserByNameOnNanoServer -UserName $UserName
$userExists = $true
}
catch [System.Exception]
Expand Down Expand Up @@ -1028,14 +1028,12 @@ function Test-TargetResourceOnNanoServer
$PasswordChangeNotAllowed
)

Set-StrictMode -Version Latest

Assert-UserNameValid -UserName $UserName

# Try to find a user by a name
try
{
$user = Find-UserByNameOnNanoServer -UserName $UserName -ErrorAction 'Stop'
$user = Find-UserByNameOnNanoServer -UserName $UserName
}
catch [System.Exception]
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/MSFT_UserResource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ try {
$testTargetResourceResult | Should Be $false
}

It 'Should throw an Invalid Operation exception' {
It 'Should throw an Invalid Operation exception when there are multiple users with the given name' {
$exception = New-Object -TypeName 'InvalidOperationException' `
-ArgumentList @($null)
$errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord `
Expand Down

0 comments on commit e21436c

Please sign in to comment.