...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.
Code:
powershell "Get-wmiObject Win32_Volume | Where-Object {$_.FileSystem -eq 'NTFS'} | Sort Name | ForEach-Object {'{0} [{1}]' -f $_.Name , $_.Label }"
Code:
C:\>powershell "Get-wmiObject Win32_Volume | Where-Object {$_.FileSystem -eq 'NTFS'} | Sort Name | ForEach-Object {'{0} [{1}]' -f $_.Name , $_.Label }"
\\?\Volume{1d2da924-dbfa-41bb-a5b4-95dc9aeadf23}\ [Windows RE tools]
C:\ [Windows]
D:\ [RECOVERY]
C:\>
Two separate commands work. The output should be OS Manufacturer:MicrosoftCorporation . . .
Code:
PowerShellWrite-Host"' OS Manufacturer : '"
OS Manufacturer:
C:\Windows\system32>PowerShell"Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property Manufacturer | Format-Table -HideTableHeaders"
MicrosoftCorporation
Code:
C:\>PowerShell "' OS Manufacturer : {0}' -f (Get-CimInstance -ClassName Win32_OperatingSystem).Manufacturer
OS Manufacturer : Microsoft Corporation
C:\>
Code:
PowerShell"(Get-CimInstance -ClassName Win32_OperatingSystem).Name"
MicrosoftWindows10Pro|C:\Windows|\Device\Harddisk0\Partition2
------------------------------------------
---You could of course, also usethis---
------------------------------------------
PowerShell"Get-CimInstance -ClassName Win32_OperatingSystem | Select Name"
MicrosoftWindows10Pro|C:\Windows|\Device\Harddisk0\Partition2
I would like the output to just be \Device\Harddisk0\Partition2
Code:
PowerShell "(Get-CimInstance -ClassName Win32_OperatingSystem).Name.Split('|')[-1]"
Code:
C:\>PowerShell "(Get-CimInstance -ClassName Win32_OperatingSystem).Name.Split('|')[-1]"
\Device\Harddisk0\Partition3
C:\>
Code:
PowerShellWrite-Host"'Disk and Partition : Disk ' -NoNewline; Get-Partition | Where-Object {$_.IsBoot -eq 'True'} | Select DiskNumber -ExpandProperty DiskNumber"
DiskandPartition:Disk0
Code:
PowerShellWrite-Host"'Disk and Partition : Partition ' -NoNewline; Get-Partition | Where-Object {$_.IsBoot -eq 'True'} | Select PartitionNumber -ExpandProperty PartitionNumber"
DiskandPartition:Partition2
Then I thought that I would try and get them BOTH on the same line, so it looks like this . . .
DiskandPartition:Disk0Partition2
Code:
PowerShell "'Disk and Partition : Disk{0}Partition{1}' -f ( ($p = Get-Partition | ? {$_.IsBoot} ).DiskNumber , $p.PartitionNumber )"
Code:
C:\>PowerShell "'Disk and Partition : Disk{0}Partition{1}' -f ( ($p = Get-Partition | ? {$_.IsBoot} ).DiskNumber , $p.PartitionNumber )"
Disk and Partition : Disk0Partition3
C:\>
How do I get the following to show . . .
Code:
SerialNumber: YL9Q402541
ReleaseDate:02/04/201919:00:00[TextHere]
Status: OK
Code:
powershell "Get-wmiObject Win32_BIOS | %{([PSCustomObject]@{'Serail Number' = $_.SerialNumber;'Release Date'= '{0} [ {1} ]' -f $_.ConvertToDateTime($_.ReleaseDate),'Some Text';'Status'=$_.Status}).PSObject.Properties | %{ ' {0,-20}: {1}' -f $_.Name , $_.Value } }"
Code:
C:\>powershell "Get-wmiObject Win32_BIOS | %{([PSCustomObject]@{'Serail Number' = $_.SerialNumber;'Release Date'= '{0} [ {1} ]' -f $_.ConvertToDateTime($_.ReleaseDate),'Some Text';'Status'=$_.Status}).PSObject.Properties | %{ ' {0,-20}: {1}' -f $_.Name , $_.Value } }"
Serail Number : 8CG7390CPZ
Release Date : 6/21/2018 07:00:00 PM [ Some Text ]
Status : OK
C:\>