Character issue with powershell script

matteu31 467 Reputation points


I try to use this script :

$command = invoke-command -computername auditad1 -scriptblock {dcdiag.exe}  
#regex for french language  
$regex = [regex]"(?sm)\.+\sLe\stest\s(\w+).+?de\s([A-Za-z0-9_-]+)\sa\s(r.ussi|.chou.)"   
$allmatches = $regex.Matches($command)  
Foreach($line in $allmatches){  
        TestName = $line.Groups[1].Value  
        TestResult = $line.Groups[3].Value  

The result in ISE powershell is not what I would like (should be réussi and échoué on test result column) :


The result in powershell console if I execute the ps1 file is :


If I execute directly dcdiag on powershell ISE, there are also issue with "," character.

However, if I execute dcdiag in powershell console, result is ok and I have accent and not ",".


What I need to do to execute this command on remote system and not having this issue ?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,343 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,311 Reputation points Microsoft Vendor


    Please see if this helps

    & "$env:windir\system32\" 65001  

    Best Regards,


    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. matteu31 467 Reputation points


    thank for your answer.
    Unfortunately, it doesn't work and my script doesn't work anymore with this.

    However, if I do chcp 1252 it's working if I launch the script from powershell windows.
    If I launch the script from ISE, it's same result as I didn't do modification.

    If my memory is good, ISE console and powershell console don't use exactly the same shell and it's probably why it doesn't work when I'm on ISE console.

    Is there any better solution than add chcp 1252 on my dcdiag function ?

    0 comments No comments