Skip to content

Exception calling "Translate" with "1" argument(s): "Some or all identity references could not be translated." #38

@FoegiUpdate

Description

@FoegiUpdate

I use Win11 23H2 German Edition with PS 5.1 and get this Error:
Exception calling "Translate" with "1" argument(s): "Some or all identity references could not be translated."

PS C:#Deployment\Scripts_Deploy_and_Refresh#Files\FileAssoc> set-fta
Cmdlet Set-FTA an der Befehlspipelineposition 1
Geben Sie Werte für die folgenden Parameter an:
ProgId: FastStone.arw
Extension: arw
Ausnahme beim Aufrufen von "Translate" mit 1 Argument(en): "Manche oder alle Identitätsverweise konnten nicht übersetzt werden."
In C:#Deployment\Scripts_Deploy_and_Refresh#Files\FileAssoc#SFTA.ps1:536 Zeichen:5

  • [OutputType([string])]
    
  • ~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : IdentityNotMappedException

The Issue is. the system can't resolve the specified user or group name to a security identifier (SID), likely due to a missing or language-specific local group.
I have added the following functions with the help of AI:

function Get-SafeNTAccountSid { param ( [Parameter(Mandatory=$true)][alias('Account')] [string]$NTAccountName ) try { $nt = New-Object System.Security.Principal.NTAccount($NTAccountName) return $nt.Translate([System.Security.Principal.SecurityIdentifier]) } catch { Write-Warning "Could not resolve '$NTAccountName': $_" return $null } }

function Get-SafeSidFromSidString { param ([Parameter(Mandatory=$true)][string]$SidString) try { $sid = New-Object System.Security.Principal.SecurityIdentifier($SidString) return $sid } catch { Write-Warning "Invalid SID '$SidString': $_" return $null } }

and replaced following code:
function local:Get-UserSid { [OutputType([string])] $userSid = ((New-Object System.Security.Principal.NTAccount([Environment]::UserName)).Translate([System.Security.Principal.SecurityIdentifier]).value).ToLower() Write-Output $userSid }

with this code:
function local:Get-UserSid { [OutputType([string])] # safely translate current user $name = [Environment]::UserName $domain = $env:USERDOMAIN $account = "$domain\$name" $sidObj = Get-SafeNTAccountSid -NTAccountName $account if ($sidObj) { Write-Output $sidObj.Value.ToLower() } else { # fallback: vielleicht nur Username Write-Warning "Falling back to SID from username: $name" try { $fallback = (New-Object System.Security.Principal.NTAccount($name)).Translate([System.Security.Principal.SecurityIdentifier]) Write-Output $fallback.Value.ToLower() } catch { Write-Warning "Fallback translation also failed: $_" Write-Output "" } } }

PS-SFTA works with these additions on my computer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions