PowerCLI

Expand all | Collapse all

Output in Invoke-VMScript unreadable

IKirill

IKirillDec 13, 2019 03:07 PM

  • 1.  Output in Invoke-VMScript unreadable

    Posted Dec 13, 2019 02:29 PM

    Hi!

    In my Powercli scripts, I use the Invoke-VMScript cmdlet. On non-English operating systems, the command output becomes unreadable. For example: ���

    I know that in this example should be Cyrillic.

    How can I get a normal output ?

    I suspect I have somewhere to enable UTF-8 encoding.



  • 2.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 13, 2019 02:46 PM

    Do you launch that from a Windows or a Linux platform?
    Which Linux distro are you using?
    On the Linux box do you have the locales package installed?

    Check on the Linux box with the locale command what settings are in use.



  • 3.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 13, 2019 02:53 PM

    Have a look at (and replace en_US with the correct name) the 2nd answer in https://unix.stackexchange.com/questions/303712/how-can-i-enable-utf-8-support-in-the-linux-console



  • 4.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 13, 2019 03:07 PM

    Hi LuCD!

    I use Windows Server 2008 R2



  • 5.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 13, 2019 03:13 PM

    For the scriptblock did you save the Cyrillic codepage ? Depending on your os the code page is builtin available or not.

    $scriptBlock="Your Cyrillic text"

    $enc = [Console]::OutputEncoding
    [Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding("cp866")
    & $scriptBlock
    [Console]::OutputEncoding = $enc

    You find some additional os release related culprit information at https://stackoverflow.com/questions/49476326/displaying-unicode-in-powershell



  • 6.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 13, 2019 03:28 PM

    My script text very simple, but not working:

    -Scripttext "net use Y: \\10.2.0.254\D /user:Administrator Mypass /persistent:no

    mkdir C:\rollup

    copy Y\* C:\rollup"

    the problem is that net use does not work. I see only unreadable output, like

    ScriptOutput

    -----------------------------------------------------------------------------------------------------------------------|  ���।�������� ������: &

    .

    -----------------------------------------------------------------------------------------------------------------------

    This output is Cyrillic



  • 7.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 13, 2019 03:43 PM

    On the Windows 2008 R2 cmd what return results from wmic os get locale, oslanguage, codeset ?



  • 8.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 13, 2019 03:55 PM

    LucD

    I use Windows Server!

    DCasota

    Codeset    Locale   OSLanguage

    1251         0419      1049    



  • 9.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 13, 2019 04:06 PM

    Is the return result from the guest OS VM or from the Invoke-VMScript side ?



  • 10.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 13, 2019 10:05 PM

    Oops, I misread that.

    Is the language on the station where you run Invoke-VMScript English or also Russian?

    Did you install the Russian version of Windows 2008 R2, or did you add a language pack afterwards?



  • 11.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 14, 2019 03:18 PM

    One of our customers uses the Russian version of WIndows Server 2008 r2 as a guest system.

    The system is initially deployed Russian, without installing language packs.

    PS ISE is also launched on the Russian version of Windows Server 2012 r2. There are actually two problems.

    The first - does not work out NET USE, which has to connect a network disk.

    The second is an error that I can't read.

    Various variants of language encodings have not yet yielded a positive result.



  • 12.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 14, 2019 03:38 PM

    Do I understand that correctly, that the NET USE doesn't work?
    Only from a PS prompt?

    Only remote? Or local and remote (via Invoke-VMScript)?
    Or also from a CMD prompt?



  • 13.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 14, 2019 04:17 PM

    NET USE only works locally via CMD. That is I connect to problem WS2008R2 and through CMD without problems I connect a network disk. When I try to do the same via Invoke-VMScript, the network drive does not connect. Rather strange.

    $backVMS = get-datacenter 02 | get-vm | `

               ? {$_.Name -like "*backup*" -and $_.Guest.OSFullName -match '2008 R2'} | `

               select name -ExpandProperty name

    Write-Host "VM TO UPDATES $backVMs" -ForegroundColor Yellow

    foreach ($backVM in $backVMS) {

    Write-Host "START WORK -Work WITH $backVM" -ForegroundColor Green

    Invoke-VMScript -VM $backVM -GuestUser adm `

                                -GuestPassword Pass `

                                -ScriptType bat `

                                -Scripttext "net use Y: \\10.2.0.254\D /user:Administrator Pass /persistent:no

                                             mkdir C:\rollup

                                             copy Y\* C:\rollup

                                             " -ErrorAction SilentlyContinue

    Invoke-VMScript -VM $backVM -GuestUser adm `

                                -GuestPassword Pass `

                                -ScriptType bat `

                                -Scripttext "wusa.exe C:\rollup\Windows6.1-KB3020369-x64.msu /quiet /forcerestart" -ErrorAction SilentlyContinue

    Invoke-VMScript -VM $backVM -GuestUser adm `

                                -GuestPassword Pass `

                                -ScriptType bat `

                                -Scripttext "wusa.exe C:\rollup\windows6.1-kb3125574-v4-x64_ROLLUP-2008R2sp1-W7sp1sp1.msu /quiet /forcerestart" -ErrorAction SilentlyContinue

    sleep -Seconds 600

    Invoke-VMScript -VM $backVM -GuestUser adm -GuestPassword Pass `

                                -ScriptType bat -Scripttext "RD /S /Q C:\rollup" -ErrorAction SilentlyContinue

    }



  • 14.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 14, 2019 04:20 PM

    And when you launch a PS session on the remote station, does the NET USE work from a PS prompt?



  • 15.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 14, 2019 04:37 PM

    on a vanilla 2008 system it might be a ps version related issue.

    https://devblogs.microsoft.com/powershell/powershell-v2-backward-compatibility/



  • 16.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 14, 2019 05:05 PM

    This work fine locally on WS2008r2 with PS2.0

    $net = new-object -ComObject WScript.Network

    $net.MapNetworkDrive("y:", "\\10.2.0.254\D", $false, "administrator", "Pass")

    how can we screen these 2 lines for PowerCli?



  • 17.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 14, 2019 05:10 PM

    Does this mean that 'NET USE...' from the PS prompt does not work, when run on the target station?



  • 18.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 14, 2019 05:15 PM

    'NET USE...' from the PS prompt works fine locally!



  • 19.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 14, 2019 05:24 PM

    There have been some issues with VMware Tools (older versions) running on non-en-US language (French,Russion...) Windows platforms.

    These were primarily related to OSGuestCustomization.

    Which VMware Tools version is running on that station?
    Is it a version that corresponds with the vSphere version where the VM is hosted?



  • 20.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 14, 2019 05:41 PM

    Version of tools - 10.0.0 3000743 I realized the problem!! network path not found if run via Invoke-script! I don't make mistakes in scripts!! In other words, the same script does not work through Invoke-script (Network path not found) and works locally! Fantastic!



  • 21.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 14, 2019 05:46 PM

    So it is fixed?



  • 22.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 14, 2019 05:59 PM

    NO))) Because network path is current! Can you tell me, how can we interpret these lines for Powercli invoke-script?

    $net = new-object -ComObject WScript.Network

    $net.MapNetworkDrive("y:", "\\10.2.0.254\D", $false, "administrator", "Pass")

    This correct???

    $script = "`$net = new-object -ComObject WScript.Network

    `$net.MapNetworkDrive((""y:"", ""\\10.2.0.254\d"", `$false, ""administrator"", ""pass""))"

    Invoke-VMScript -VM $VMwork -ScriptType Powershell -ScriptText $script -GuestUser adm -GuestPassword Pass



  • 23.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 14, 2019 06:18 PM

    I would go for a here-string with single quotes, that way no substitution will occur.
    And you don't have to escape all the dollar signs.

    $script = @'

    $net = new-object -ComObject WScript.Network  

    $net.MapNetworkDrive('y:', '\\10.2.0.254\d', $false, 'administrator', 'pass')

    '@


    Invoke-VMScript -VM $VMwork -ScriptType Powershell -ScriptText $script -GuestUser adm -GuestPassword Pass



  • 24.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 14, 2019 06:25 PM

    LUCD, DCasota THX for reply ! WE are amazing)))



  • 25.  RE: Output in Invoke-VMScript unreadable

    Posted Dec 13, 2019 04:18 PM

    You may give a try to Powershell and Cyrillic in the console (updated) . To work on a Linux box (as assumed from @LucD !) might avoid culprit of Powershell ISE visualization of Cyrillic on a Windows box.

    However, it has nothing to do with the net use error you mentioned before. Check connectivity, IP, share with user privileges set.