1

I have a issue with my powershell script to get all files in directory because it's contains an utf8 caracter

when i execute this command directly in powershell window : Test-Path -LiteralPath "G:\Drive partagés", it's ok

but when i do the same command in script.ps1, resultat is false

i don't know how manage utf8 inside my script

thx a lot in advance

i cannot change the name of directory... and i cannot update regestry... i tried to force encoding but doesn't work for test-path and get-childitem i tried to add defautencoding but doesn't work too

Max
  • 21
  • 3
  • result : G:\Drive partagés instead of G:\Drive partagés – Max Nov 02 '22 at 13:22
  • 2
    powershell 5.1 only understands a script encoded in utf8withbom or unicode (utf16le) – js2010 Nov 02 '22 at 13:30
  • Which application/editor are you using to write and save your scripts? Notepad? VS Code? Notepad++? PowerShell ISE? – Mathias R. Jessen Nov 02 '22 at 13:44
  • I use VS Code and tried to NotePad++ but same result – Max Nov 02 '22 at 13:47
  • In VSCode: F1 -> change file encoding -> save with encoding -> UTF8 with BOM. If all else fails, you may use `"G:\Drive partag$([char]233)s"`, but this really shouldn't be necessary. – zett42 Nov 02 '22 at 13:51
  • simply.... it's work ! thx u're solved my issue – Max Nov 02 '22 at 13:58
  • Since the problem occurs with a _string literal_ in your _source code_, the likeliest explanation is that your script file is misinterpreted by the Windows PowerShell engine, which happens if the script is saved as UTF-8 _without a BOM_. Try saving your script as UTF-8 _with BOM_; see the linked duplicate for details. – mklement0 Nov 02 '22 at 14:08

0 Answers0