Convert PS to CMD

Page 2 of 24 FirstFirst 123412 ... LastLast

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

    Last one for the week.

    This is the original Command and output . . .

    Code:
    
    PowerShell "(Get-CimInstance -ClassName Win32_OperatingSystem).Name"
    
    Microsoft Windows 10 Pro|C:\Windows|\Device\Harddisk0\Partition2
    
    ------------------------------------------
    --- You could of course, also use this ---
    ------------------------------------------
    
    PowerShell "Get-CimInstance -ClassName Win32_OperatingSystem | Select Name"
    
    Microsoft Windows 10 Pro|C:\Windows|\Device\Harddisk0\Partition2

    I would like the output to just be \Device\Harddisk0\Partition2

    These are just some of which I have tried . . .

    Code:
    
    PowerShell "(((Get-CimInstance -ClassName Win32_OperatingSystem | Select Name).Trim() -Split '\'))[1]"
    PowerShell "((Get-CimInstance -ClassName Win32_OperatingSystem).Name).Substring($String.IndexOf('\'), 4)"
    PowerShell "(Get-CimInstance -ClassName Win32_OperatingSystem | Select Name).Substring($string.IndexOf('\'), 2)"
    PowerShell "Get-CimInstance -ClassName Win32_OperatingSystem | Select Name -Replace '*\\'"
    PowerShell "(Get-CimInstance -ClassName Win32_OperatingSystem).Name -replace '*\\'"
    PowerShell "(Get-CimInstance -ClassName Win32_OperatingSystem).Name -split '\',3"
    PowerShell "Get-CimInstance -ClassName Win32_OperatingSystem | Select Name -split '\',3"
    
      My Computer


  2. Posts : 3,274
    Win10
       #12

    Try :
    Code:
    PowerShell "(Get-CimInstance -ClassName Win32_OperatingSystem).Name -replace '^.*\|.*\|','' "
    or I think this could work similarly, by counting (?) the numbers of "|" pipe characters including and before which we want to remove everything (might need to do more testing with strings which have multiple pipes in them).

    Code:
    PowerShell "(Get-CimInstance -ClassName Win32_OperatingSystem).Name -replace '^.*[\|,2]','' "
      My Computers


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

    Hello @das10,

    das10 said:
    Try :
    Code:
    PowerShell "(Get-CimInstance -ClassName Win32_OperatingSystem).Name -replace '^.*\|.*\|','' "
    Works perfectly.



    I have gone off on a tangent. I always make things difficult for myself, but as my Dad used to say, it's a learning process for the future Son.

    Anyway, I came up with these . . .

    Code:
    
    PowerShell Write-Host "'Disk and Partition : Disk ' -NoNewline; Get-Partition | Where-Object {$_.IsBoot -eq 'True'} | Select DiskNumber -ExpandProperty DiskNumber"
    
    Disk and Partition : Disk 0
    Code:
    
    PowerShell Write-Host "'Disk and Partition : Partition ' -NoNewline; Get-Partition | Where-Object {$_.IsBoot -eq 'True'} | Select PartitionNumber -ExpandProperty PartitionNumber"
    
    Disk and Partition : Partition 2

    Then I thought that I would try and get them BOTH on the same line, so it looks like this . . .

    Disk and Partition : Disk 0 Partition 2

    I have ALMOST cracked it except it splits into TWO lines . . .

    Code:
    
    PowerShell Write-Host "'Disk and Partition : Disk ' -NoNewline; Get-Partition | Where-Object {$_.IsBoot -eq 'True'} | Select DiskNumber -ExpandProperty DiskNumber"; Write-Host "' Partition ' -NoNewline; Get-Partition | Where-Object {$_.IsBoot -eq 'True'} | Select PartitionNumber -ExpandProperty PartitionNumber"
    
    Disk and Partition : Disk 0
     Partition 2
    

    Once I have cracked this, I can easily apply it to another couple which are in the same format, and I am finished.



    Thanks for all your help, time, and effort on this, it is appreciated.
    Last edited by Paul Black; 19 Feb 2022 at 12:21.
      My Computer


  4. Posts : 3,274
    Win10
       #14

    The closest I get is this:
    Code:
    PowerShell $AAA="Get-Partition | Where-Object {$_.IsBoot -eq 'True'} | Select DiskNumber -ExpandProperty DiskNumber"; $BBB=" Get-Partition | Where-Object {$_.IsBoot -eq 'True'} | Select PartitionNumber -ExpandProperty PartitionNumber"; Write-Host 'Disk and Partition : Disk ' $AAA 'Partition ' $BBB
      My Computers


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

    Hello @das10,

    das10 said:
    The closest I get is this:
    Code:
    PowerShell $AAA="Get-Partition | Where-Object {$_.IsBoot -eq 'True'} | Select DiskNumber -ExpandProperty DiskNumber"; $BBB=" Get-Partition | Where-Object {$_.IsBoot -eq 'True'} | Select PartitionNumber -ExpandProperty PartitionNumber"; Write-Host 'Disk and Partition : Disk ' $AAA 'Partition ' $BBB
    Brilliant, I didn't even think of using Variables.

    It also gets rid of those pesky -NoNewline Commands. That's where being used to PS pays off.

    I have just applied that format to one previous in this thread, and it works for that, so I might change the ones I have already setup because it is cleaner and slicker.

    Thanks again.
      My Computer


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

    The following outputs . . .

    Code:
    
    PowerShell "Get-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion' | Select RegisteredOrganization"
    
    RegisteredOrganization
    ----------------------

    If the output is NULL as above, I want to put NO Information like this . . .

    Code:
    
    RegisteredOrganization
    ----------------------
    NO Information

    This is what I have tried so far . . .

    Code:
    
    PowerShell "if(Get-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion'.RegisteredOrganization -eq $NULL) {"'NO Information'"} else {($_.RegisteredOrganization)}"
    
    PowerShell "if(Get-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion'.RegisteredOrganization -eq $NULL) {"'NO Information'"} else {($_.RegisteredOrganization)}"
    
    PowerShell "@if(Get-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion'.RegisteredOrganization -eq $NULL) {'NO Info'} else ($_.RegisteredOrganization)"
    
    PowerShell @if"(Get-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion'.RegisteredOrganization -eq $NULL) {"'NO Info'"} else ($_.RegisteredOrganization)"
    
    
    

    I keep getting the message . . .

    Get-ItemProperty : Cannot bind argument to parameter 'Path' because it is null..

    I had a bit of success with this . . .

    Code:
    
    PowerShell "Get-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion' | Select RegisteredOrganization, @{Expression={if($_.RegisteredOrganization) {$_.RegisteredOrganization} else {"'NO Information'"}}}"
    
    RegisteredOrganization  if ($_.RegisteredOrganization) { $_.RegisteredOrganization } else { 'NO Information' }
    ---------------------- ----------------------------------------------------------------------------------------
                           NO Information
    
      My Computer


  7. Posts : 3,274
    Win10
       #17

    Paul, could you test the following; I keep swapping in and out of VirtualBox so I can test the Organization Name commands, but I think it works:
    Code:
    Powershell $AAA="Get-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion' | Select RegisteredOrganization -ExpandProperty RegisteredOrganization; if ($AAA -like '') { Write-Host 'Not Available' }  else { Write-Host $AAA }"
    pn: I think the code needs adjustments to reflect 'exactly' the format of the Output that you want !
      My Computers


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

    Hello @das10,

    das10 said:
    Paul, could you test the following; I keep swapping in and out of VirtualBox so I can test the Organization Name commands, but I think it works:
    Code:
    Powershell $AAA="Get-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion' | Select RegisteredOrganization -ExpandProperty RegisteredOrganization; if ($AAA -like '') { Write-Host 'Not Available' }  else { Write-Host $AAA }"
    ps: I think the code needs adjustments to reflect 'exactly' the format of the Output that you want !
    Great, I changed it to this . . .

    Code:
    
    Powershell $AAA="Get-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion' | Select RegisteredOrganization -ExpandProperty RegisteredOrganization; if ($AAA -like '') { Write-Host 'Registered Organization   : Not Available' }  else { Write-Host 'Registered Organization   : ' $AAA }"
    
    Registered Organization   : Not Available
    

    Unfortunately I can't check if it works if there IS information.
      My Computer


  9. Posts : 3,274
    Win10
       #19

    I checked in a VBox with the Registered Organization, and it seems to work; and if you want to show the Output 'exactly' like you have shown in post #17, this is is one hacky way:
    Code:
    Powershell $AAA="Get-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion' | Select RegisteredOrganization -ExpandProperty RegisteredOrganization; if ($AAA -like '') { Write-Host "`nRegisteredOrganization`n----------------------`nNo Information" }  else { Write-Host "`nRegisteredOrganization`n----------------------`n$AAA" }"
      My Computers


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

    Hello @das10,

    das10 said:
    I checked in a VBox with the Registered Organization, and it seems to work; and if you want to show the Output 'exactly' like you have shown in post #17, this is is one hacky way:
    Code:
    Powershell $AAA="Get-ItemProperty 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion' | Select RegisteredOrganization -ExpandProperty RegisteredOrganization; if ($AAA -like '') { Write-Host "`nRegisteredOrganization`n----------------------`nNo Information" }  else { Write-Host "`nRegisteredOrganization`n----------------------`n$AAA" }"
    Thanks for testing that, it is appreciated, and thanks for the extra code, I will add that to my PS folder file.

    I do actually want the output as I have got the output in post #19, so that is great.

      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 09:52.
Find Us




Windows 10 Forums