Hey all,
When I run "$(Get-CimInstance -ClassName win32_diskdrive | select caption -ExpandProperty caption)" it will list all my connected drives.
When I run this in powershell it breaks the drives line by line as shown below
drive1
drive2
drive3
But when I output my command to a label it puts the drives like so: drive1drive2drive3. How can I properly display the drives? Code listed below
$drives = $(Get-CimInstance -ClassName win32_diskdrive | select caption -ExpandProperty caption)
$label1.Text = $drives
[HELP] Label output into multiple lines
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: [HELP] Label output into multiple lines
Try this:
- $captions = Get-CimInstance win32_diskdrive | select -expand caption
- $label1.Text = $captions -join "`n"
Re: [HELP] Label output into multiple lines
That is exactly what I'm looking for.
My next question would be how to get that $caption -join "`n" inside an array?
When I do the following, it gives me a an unexpected token error.
$captions = Get-CimInstance win32_diskdrive | select -expand caption
$info = @( System Info `n
"BIOS Version: $(Get-Ciminstance win32_bios | select -expand SMbiobiosversion) `n"
"Baseboard: $(Get-Ciminstance win32_baseboard | select -expand product) `n"
"Drives: $captions -join "`n""
$label1.Text = $info
My next question would be how to get that $caption -join "`n" inside an array?
When I do the following, it gives me a an unexpected token error.
$captions = Get-CimInstance win32_diskdrive | select -expand caption
$info = @( System Info `n
"BIOS Version: $(Get-Ciminstance win32_bios | select -expand SMbiobiosversion) `n"
"Baseboard: $(Get-Ciminstance win32_baseboard | select -expand product) `n"
"Drives: $captions -join "`n""
$label1.Text = $info
Re: [HELP] Label output into multiple lines
Like this:
I recommend stepping back and taking some time to learn PowerShell before you try using forms. Without good PS knowledge you will be very frustrated by how to do things,
- $label1.Text = Get-CimInstance win32_diskdrive |
- select @{ Name = 'Sysetm Info'; e = { $_.caption } } |
- Out-String