Link to home
Start Free TrialLog in
Avatar of David Sankovsky
David SankovskyFlag for Israel

asked on

Powershell won't write hebrew characters in specific cases

Hi Experts,

I'm trying to write a PS Script that will allow me to create a folder on a users Desktop that will hold a set of shortcuts that will always open via Google Chrome regardless of which browser the user has set as a default one.

Also, since some of out users have chrome installed to a non-standard path due to specific restrictions I can't just use a set of shotcuts and copy them from a shared drive via GPO.


I resorted to writing a custom PS Script for that task,

The script will check if the folder exists on the desktop and will create it if not,

It will then iterate through a hash table of links and dames to create the shortcuts.

Here's the problem: the names of the shortcut have to be in Hebrew, as my users can't speak English to save their own lives if they had to!


While the part that created the desktop folder (Whose name is also in Hebrew mind you) works perfectly, the shortcut creaton logic refuses to read or write hebrew characters and doesn't create the shortcuts:


$chexec = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe" -Name "(default)"
$chpath = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe" -Name "Path" $DesktopPath = [Environment]::GetFolderPath("Desktop") $shortdirpath = $DesktopPath + "\קיצורי דרך מטמון" if (!(Test-Path $shortdirpath)) {     New-Item -ItemType Directory -Force -Path $shortdirpath } $shortcuts = @(     [pscustomobject]@{url="https://ynet.co.il";name="חדשות"},     [pscustomobject]@{url="https://google.com";name="חיפוש"} ) foreach ($shortcut in $shortcuts) {     #Write-Host $shortcut.name     $shortcutpath = ($shortdirpath)+ '\' +($shortcut.name)+".lnk"     $targetFile = '"'+$chexec+'"'     $url = $shortcut.url     $WshShell = New-Object -ComObject WScript.Shell     $shtcut = $WshShell.CreateShortcut($shortcutpath)     $shtcut.TargetPath = $targetFile     $shtcut.Arguments = $url     $shtcut.WorkingDirectory = $chpath     $shtcut }

Open in new window

The result is this: 

FullName         : C:\Users\davidsa\Desktop\?????? ??? ?????\?????.lnk
Arguments        : https://ynet.co.il
Description      :
Hotkey           :
IconLocation     : ,0
RelativePath     :
TargetPath       : C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
WindowStyle      : 1
WorkingDirectory : C:\Program Files (x86)\Google\Chrome\Application

FullName         : C:\Users\davidsa\Desktop\?????? ??? ?????\?????.lnk
Arguments        : https://google.com
Description      :
Hotkey           :
IconLocation     : ,0
RelativePath     :
TargetPath       : C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
WindowStyle      : 1
WorkingDirectory : C:\Program Files (x86)\Google\Chrome\Application


But if I only ask the system to write the names without the entire shortcut creation logic, it works fine:

$chexec = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe" -Name "(default)"
$chpath = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe" -Name "Path" $DesktopPath = [Environment]::GetFolderPath("Desktop") $shortdirpath = $DesktopPath + "\קיצורי דרך מטמון" if (!(Test-Path $shortdirpath)) {     New-Item -ItemType Directory -Force -Path $shortdirpath } $shortcuts = @(     [pscustomobject]@{url="https://ynet.co.il";name="חדשות"},     [pscustomobject]@{url="https://google.com";name="חיפוש"} ) foreach ($shortcut in $shortcuts) {     $shortcut.name }

Open in new window


חדשות
חיפוש

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David Sankovsky

ASKER

Revised Solution based on Ryan's Idea:

$chexec = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe" -Name "(default)"
$chpath = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe" -Name "Path"

$DesktopPath = [Environment]::GetFolderPath("Desktop")
$shortdirpath = $DesktopPath + "\shortcuts"
if (!(Test-Path $shortdirpath))
{
    New-Item -ItemType Directory -Force -Path $shortdirpath
}

$shortcuts = @(
    [pscustomobject]@{url="https://ynet.co.il";ename="News";name="חדשות"},
    [pscustomobject]@{url="https://google.com";ename="Search";name="חיפוש"}
)
foreach ($shortcut in $shortcuts)
{
    #Write-Host $shortcut.name
    $shortcutpath = ($shortdirpath)+ '\' +($shortcut.ename)+".lnk"
    $targetFile = '"'+$chexec+'"'
    $url = $shortcut.url
    $WshShell = New-Object -ComObject WScript.Shell
    $shtcut = $WshShell.CreateShortcut($shortcutpath)
    $shtcut.TargetPath = $targetFile
    $shtcut.Arguments = $url
    $shtcut.WorkingDirectory = $chpath
    #$shtcut
    $shtcut.save()
    $hname = $shortcut.name+".lnk"
    Rename-Item -Path $shortcutpath -NewName $hname
}
Rename-Item -Path $shortdirpath -NewName "קיצורי דרך מטמון"

Open in new window