Convert PS to CMD

Page 1 of 24 12311 ... LastLast

  1. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #1

    Convert PS to CMD


    Good afternoon,

    I almost have this, but NOT quite.

    I do NOT want alternative code etc, I want to try and crack this as a conversion from PowerShell to CMD Prompt. It's just my little Brain exercise [ little grey cells as Poirot would say ] for the day.

    This works in PowerShell . . .

    Code:
    
    Get-wmiObject Win32_Volume | Where-Object {$_.FileSystem -Match "NTFS"} | Sort {$_.Name} | ForEach-Object {echo "$(echo $_.Name) [$(echo $_.Label)]"}
    
    \\?\Volume{30cf9d4a-0000-0000-0000-100000000000}\ [System Reserved]
    C:\ [Win_10]
    D:\ [Data]
    S:\ [System_Image]

    I have tried converting it into a CMD. Here are some of the things that I have tried, and they all produce the correct results except that EACH result is spread over TWO lines, as opposed to ONE line for each as per the PowerShell output . . .

    Code:
    
    PowerShell "Get-wmiObject Win32_Volume | Where-Object {$_.FileSystem -Match 'NTFS'} | Sort {$_.Name} | ForEach-Object "{echo "$(echo $_.Name) [$(echo $_.Label)]"}""
    PowerShell "Get-wmiObject Win32_Volume | Where-Object {$_.FileSystem -Match 'NTFS'} | Sort {$_.Name} | ForEach-Object {echo "$(echo $_.Name) [$(echo $_.Label)]"}"
    PowerShell "Get-wmiObject Win32_Volume | Where-Object {$_.FileSystem -Match 'NTFS'} | Sort {$_.Name} | ForEach-Object "{echo $(echo $_.Name), [$(echo $_.Label)]}"
    PowerShell "Get-wmiObject Win32_Volume | Where-Object {$_.FileSystem -Match 'NTFS'} | Sort {$_.Name} | ForEach-Object "{echo $(echo $_.Name) [$(echo $_.Label)]}""
    PowerShell "Get-wmiObject Win32_Volume | Where-Object {$_.FileSystem -Match 'NTFS'} | Sort {$_.Name} | ForEach-Object {echo '$(echo $_.Name) [$(echo $_.Label)]'}"
    PowerShell "Get-wmiObject Win32_Volume | Where-Object {$_.FileSystem -Match 'NTFS'} | Sort {$_.Name} | ForEach-Object {echo "$^(echo $_.Name^) [$^(echo $_.Label^)]"}"
    PowerShell "Get-wmiObject Win32_Volume | Where-Object {$_.FileSystem -Match 'NTFS'} | Sort {$_.Name} | ForEach-Object {echo "$(echo $_.Name)" + "[$(echo $_.Label)]"}"
    PowerShell "Get-wmiObject Win32_Volume | Where-Object {$_.FileSystem -Match 'NTFS'} | Sort {$_.Name} | ForEach-Object {echo "$(echo $_.Name)": + "[$(echo $_.Label)]"}"
    
    
    

    Output over TWO lines from my attempts above . . .

    Code:
    
    \\?\Volume{30cf9d4a-0000-0000-0000-100000000000}\
    [System Reserved]
    C:\
    [Win_10]
    D:\
    [Data]
    S:\
    [System_Image]

    I have often converted code without any problems, but the introduction of echo has got me stumped on this one. The TWO lines for EACH result output needs to be connected together somehow. I am sure that it has something to do with the doubling up of Parenthesis or something similar.

    Thanks.
    Convert PS to CMD Attached Files
    Last edited by Paul Black; 22 Feb 2022 at 11:38.
      My Computer


  2. Posts : 5,048
    Windows 10/11 Pro x64, Various Linux Builds, Networking, Storage, Cybersecurity Specialty.
       #2

    Lol.

    I'm looking forward to the release of your new book:

    Hacking Putin

      My Computer


  3. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #3

    Cracked it . . .

    Code:
    
    PowerShell "Get-wmiObject Win32_Volume | Where-Object {$_.FileSystem -Match 'NTFS'} | Sort {$_.Name} | ForEach-Object {echo """$(echo $_.Name) [$(echo $_.Label)]"""}"
      My Computer


  4. Posts : 3,275
    Win10
       #4

    Good for you. I was trying:
    Code:
    PowerShell "Get-wmiObject Win32_Volume | Where-Object {$_.FileSystem -Match 'NTFS'} | Sort {$_.Name} | ForEach-Object "{cmd /c echo "$(echo $_.Name) [$(echo $_.Label)]"}""
      My Computers


  5. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #5

    Thanks for trying to help out @das10.

    das10 said:
    Good for you. I was trying:
    Code:
    PowerShell "Get-wmiObject Win32_Volume | Where-Object {$_.FileSystem -Match 'NTFS'} | Sort {$_.Name} | ForEach-Object "{cmd /c echo "$(echo $_.Name) [$(echo $_.Label)]"}""
    I really don't know how many Variations / Combinations / Permutations I tried. Remembering what I used and didn't work [ Edison and the Light Bulb scenario ] will hopefully help in the future if I come across a similar case.

      My Computer


  6. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #6

    Here you go guys, the one for today.

    Two separate commands work. The output should be OS Manufacturer : Microsoft Corporation . . .

    Code:
    
    PowerShell Write-Host "' OS Manufacturer      : '"
     OS Manufacturer      :
    
    C:\Windows\system32>PowerShell "Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property Manufacturer | Format-Table -HideTableHeaders"
    
    Microsoft Corporation

    Now I am trying to get it on ONE line. Here are a small collection of what I have tried so far . . .

    Code:
    
    PowerShell Write-Host "' OS Manufacturer      :'"; "Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property 'Manufacturer' | Format-Table -HideTableHeaders"
    
    PowerShell Write-Host "' OS Manufacturer      :'"; -NoNewline "Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property 'Manufacturer' | Format-Table -HideTableHeaders"
    
    PowerShell Write-Host "' OS Manufacturer      :'"; -NoNewline ("Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property 'Manufacturer' | Format-Table -HideTableHeaders")
    
    PowerShell Write-Host "' OS Manufacturer      :'" -NoNewline ("Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property 'Manufacturer' | Format-Table -HideTableHeaders")
    
    PowerShell Write-Host "' OS Manufacturer      :'" -NoNewline "Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property Manufacturer | Format-Table -HideTableHeaders"
    
    PowerShell Write-Host "' OS Manufacturer      :' -NoNewline Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property Manufacturer | Format-Table -HideTableHeaders"
    
    
    

    I have done it this way so I can put the : wherever I want it and also I do NOT want it to show the TableHeader, hence -HideTableHeaders.
      My Computer


  7. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #7

    Close . . .

    Code:
    
    PowerShell Write-Host "' OS Manufacturer      :' -NoNewline; Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property Manufacturer | Format-Table -HideTableHeaders"
    
     OS Manufacturer      :
    Microsoft Corporation
    

    Close . . .

    Code:
    
    PowerShell Write-Host ""' OS Manufacturer      :'" Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property Manufacturer | Format-Table -HideTableHeaders"
    
     OS Manufacturer : Get-CimInstance -ClassName Win32_OperatingSystem
    

    Close 'ish . . .

    Code:
    
    PowerShell Write-Host "' OS Manufacturer      :'" "(Get-CimInstance -ClassName Win32_OperatingSystem) | Select-Object -Property Manufacturer | Format-Table -HideTableHeaders"
    
     OS Manufacturer      : Win32_OperatingSystem: Microsoft Windows 10 Pro
    
    Last edited by Paul Black; 18 Feb 2022 at 13:49.
      My Computer


  8. Posts : 3,275
    Win10
       #8

    May be try :
    Code:
    PowerShell Write-Host "' OS Manufacturer      :' -NoNewline ; Get-CimInstance -ClassName Win32_OperatingSystem | Select Manufacturer -expandproperty Manufacturer| Format-Table -HideTableHeaders"
    or
    Code:
    PowerShell Write-Host "' OS Manufacturer      :' -NoNewline ; Get-CimInstance -ClassName Win32_OperatingSystem | Select Manufacturer -expandproperty Manufacturer "
    or
    Code:
    PowerShell Write-Host "' OS Manufacturer      :'(Get-CimInstance -ClassName Win32_OperatingSystem).Manufacturer"
    Last edited by das10; 22 Feb 2022 at 07:20.
      My Computers


  9. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #9

    das10 said:
    May be try :
    Code:
    PowerShell Write-Host "' OS Manufacturer      :' -NoNewline ; Get-CimInstance -ClassName Win32_OperatingSystem | Select Manufacturer -expandproperty Manufacturer| Format-Table -HideTableHeaders"
    or
    Code:
    PowerShell Write-Host "' OS Manufacturer      :' -NoNewline ; Get-CimInstance -ClassName Win32_OperatingSystem | Select Manufacturer -expandproperty Manufacturer "
    Brilliant, thank you, you beat me to it today.
      My Computer


  10. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #10

    das10 said:
    Thanks again. Have a great weekend.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 01:33.
Find Us




Windows 10 Forums