Quantcast
Channel: PowerShell Daily » test path
Viewing all articles
Browse latest Browse all 2

Getting OS Language

$
0
0

When you use some language oriented objects of workstation like local admin user or local admins group it’s names and other properties depends on the language of OS.
That’s why it’s helpful to know the language of OS you are using or writing scripts for.
For this purposes here it is a script which generates a csv file with workstation names and OS languages.

$path = "c:\oslang.csv"
#deleting old file if exist one
if (Test-Path "$path")
    {
    Remove-Item "$path"
    }
Get-QADComputer | ForEach-Object `
    {
    if (Test-Connection $_.name -count 1 -quiet)
        {
        $pcname=$_.name
#making for current workstation a variable with oscode
        $oscode = Get-WmiObject Win32_OperatingSystem -ComputerName $pcname -ErrorAction continue | foreach {$_.oslanguage}
#making a variable to switch to needed text depending on oscode (decimal language code)
#it can be wided by adding your language code for example from here: http://www.science.co.il/language/Locale-Codes.asp
        $switch = switch ($oscode) `
            {
            1033 {"English"};
            1049 {"Russian"};
            default {"Unknown"}
            }
#core operation for getting oslanguage using above variables
        Get-WmiObject Win32_OperatingSystem -ComputerName $pcname -ErrorAction stop | foreach {$_.csname + ", " + $switch >> $path}
#trapping error code for last operation. on operation before this last one pointed an option  -erroraction continue which means that it's not capturing with trap cmdlet and exclude double writing workstation names with errors to csv file
        trap {$pcname + ", " + "{0}" -f $_.Exception.Message >> $path; continue}
        }
    }

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images