Character issue with powershell script

matteu31 467 Reputation points
2020-12-04T15:42:26.77+00:00

Hello,

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){  
    [PSCustomObject]@{  
        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) :

45209-2020-12-04-16h37-50.png

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

45020-2020-12-04-16h39-11.png

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 ",".

45321-2020-12-04-16h41-29.png

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
    2020-12-07T09:59:18.977+00:00

    Hi,

    Please see if this helps

    & "$env:windir\system32\chcp.com" 65001  
    

    Best Regards,
    Ian

    ============================================

    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
    2020-12-07T15:54:37.78+00:00

    Hello,

    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