Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell command to get object class type without international problematic [duplicate]

I have an issue with my script where I get the list of all member of the local admin group and by checking the objectclass, I am able to only focus on the user. The problem is that it will not work in french or in german, because the word used to define the object class will not be the same (user in english, utilisateur in french, usario in spanish...). enter image description here

Is there any powershell command that can help me avoid taping the word "User" in every existing languages?

like image 510
Noemie Avatar asked Apr 18 '26 23:04

Noemie


1 Answers

function Use-Culture
{    
  param(
    [Parameter(Mandatory)] [cultureinfo] $Culture,
    [Parameter(Mandatory)] [scriptblock] $ScriptBlock
  )
  # Note: In Windows 10, a culture-info object can be created from *any* string.
  #        However, an identifier that does't refer to a *predefined* culture is 
  #        reflected in .LCID containing 4096 (0x1000)
  if ($Culture.LCID -eq 4096) { Throw "Unrecognized culture: $($Culture.DisplayName)" }

  # Save the current culture / UI culture values.
  $PrevCultures = [Threading.Thread]::CurrentThread.CurrentCulture, [Threading.Thread]::CurrentThread.CurrentUICulture

  try {
    # (Temporarily) set the culture and UI culture for the current thread.
    [Threading.Thread]::CurrentThread.CurrentCulture = [Threading.Thread]::CurrentThread.CurrentUICulture = $Culture

    # Now invoke the given code.
    & $ScriptBlock

  }    
  finally {
    # Restore the previous culture / UI culture values.
    [Threading.Thread]::CurrentThread.CurrentCulture = $PrevCultures[0]
    [Threading.Thread]::CurrentThread.CurrentUICulture = $PrevCultures[1]
  }
}

Use-Culture en-US { Get-LocalGroupMember -SID S-1-5-32-544 }

Thanks to this : Temporarily change powershell language to English?

like image 126
Noemie Avatar answered Apr 20 '26 21:04

Noemie