Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,14 @@ function ConvertTo-LocalFriendlyName
else
{
# if id is an friendly name convert it to a sid and then to an NTAccount
$friendlyNames += ( ConvertTo-Sid -Identity $id -Verbose:$VerbosePreference | ConvertTo-NTAccount -Policy $Policy -Scope $Scope )
$sidResult = ConvertTo-Sid -Identity $id -Scope $Scope -Verbose:$VerbosePreference

if ($sidResult -isnot [System.Security.Principal.SecurityIdentifier])
{
continue
}

$friendlyNames += ConvertTo-NTAccount -SID $sidResult.Value -Policy $Policy -Scope $Scope
}
}

Expand Down Expand Up @@ -388,21 +395,33 @@ function ConvertTo-Sid
param
(
[Parameter()]
[String]
$Identity
[System.String]
$Identity,

[Parameter()]
[System.String]
$Scope = 'Get'
)

$id = [System.Security.Principal.NTAccount]$Identity
try
{
$sid = $id.Translate([System.Security.Principal.SecurityIdentifier])
$result = $id.Translate([System.Security.Principal.SecurityIdentifier])
}
catch
{
throw "$($script:localizedData.ErrorIdToSid -f $Identity)"
if ($Scope -eq 'Get')
{
Write-Verbose -Message ($script:localizedData.ErrorIdToSid -f $Identity)
$result = $id
}
else
{
throw "$($script:localizedData.ErrorIdToSid -f $Identity)"
}
}

return $sid.Value
return $result
}


Expand Down
Binary file modified Misc/TestHelpers/sample.inf
Binary file not shown.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ to ensure the resource configuration instance is unique.
## Versions

### Unreleased
* Added additional error handling to ConvertTo-Sid helper function.

### 2.3.0.0
* Updated documentation.
Expand Down
7 changes: 7 additions & 0 deletions Tests/Unit/SecurityPolicyResourceHelper.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ try
{ConvertTo-LocalFriendlyName -Identity 'S-1-5-32-600' -Scope 'Get'} | Should Not throw
}

It "Should not Throw when Scope is Get and Identity is a unresolvable name" {
{ConvertTo-LocalFriendlyName -Identity 'badName' -Scope 'Get'} | Should Not throw
}

It "Should Throw when Scope is Set and Identity is an unresolvable name" {
{ConvertTo-LocalFriendlyName -Identity 'badName' -Scope 'Set'} | Should throw
}
It "Should Throw when Scope is 'SET'" {
{ConvertTo-LocalFriendlyName -Identity 'S-1-5-32-600' -Scope 'Set'} | Should throw
}
Expand Down