# How to display or process variable output

**URL:** <https://forums.powershell.org/t/how-to-display-or-process-variable-output/12688>\
**Category:** PowerShell Help\
**Created:** [June 11, 2019, 5:48am UTC](https://forums.powershell.org/t/how-to-display-or-process-variable-output/12688 "2019-06-11T05:48:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![teckra](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@teckra](https://forums.powershell.org/u/teckra)\
**Post date:** [June 11, 2019, 5:48am UTC](https://forums.powershell.org/t/how-to-display-or-process-variable-output/12688/1 "2019-06-11T05:48:31Z")

</div>

Hi - new to PS.

code:

```
$serialnum = get-ciminstance win32_bios | select serialnumber
write-host $serialnum
```

Output is: @{serialnumber=MGG18960XY7}

Questions:

1. How do I change output to just get the number portion - MGG18960XY7
2. Would you please explain why the output is happening like it is.

Thanks.

&nbsp;

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [June 11, 2019, 5:55am UTC](https://forums.powershell.org/t/how-to-display-or-process-variable-output/12688/2 "2019-06-11T05:55:47Z")

</div>

simple.

The output you get is an object, you can see the type by executing below expression.

```
Get-CimInstance -ClassName Win32_Bios | Get-Member
```

Srialnumber is property and MGG18960XY7 is the value of that property. If need only the property, you need to either save it to a variable and checrry pick or expand the property to get only the value.

```
$Bios = Get-CimInstance -ClassName Win32_Bios
Write-Host $Bios.SerialNumber

#Or

$Serialnumber = Get-CimInstance -ClassName Win32_Bios | Select-Object -ExpandProperty SerialNumber
Write-host $Serialnumber
```

the reason why you got that output is because of string expansion. Write host does a string expansion.

```
$serialnum = Get-CimInstance -ClassName Win32_Bios | Select-Object -Property serialnumber
"$Serialnum"
```

---

<div class="post-metadata">

**Author:** ![ojrivera381](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ojrivera381/32/212_2.png) [@ojrivera381](https://forums.powershell.org/u/ojrivera381)\
**Post date:** [June 13, 2019, 1:14pm UTC](https://forums.powershell.org/t/how-to-display-or-process-variable-output/12688/3 "2019-06-13T13:14:47Z")

</div>

I believe and correct me if I’m wrong is you wrapped the Ciminstance into a variable to then call it, to get your answer.

First, you could have just ran the command:

get-ciminstance win32\_bios | select serialnumber

But if you are placing it into a variable to call it later then this would have worked as well

$serialnum = get-ciminstance win32\_bios | select serialnumber

$serialnum

&nbsp;

---

<div class="post-metadata">

**Author:** ![js2010](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@js2010](https://forums.powershell.org/u/js2010)\
**Post date:** [June 13, 2019, 1:35pm UTC](https://forums.powershell.org/t/how-to-display-or-process-variable-output/12688/4 "2019-06-13T13:35:07Z")

</div>

It’s an PSCustomObject with a property. To make $serialnum just a string:

```
$serialnum = get-ciminstance win32_bios | select -expand serialnumber
write-host $serialnum

ABC1234
```

---

<div class="post-metadata">

**Author:** ![shinish](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/shinish/32/199_2.png) [@shinish](https://forums.powershell.org/u/shinish)\
**Post date:** [June 15, 2019, 8:18am UTC](https://forums.powershell.org/t/how-to-display-or-process-variable-output/12688/5 "2019-06-15T08:18:52Z")

</div>

1. How to get the serial number alone: Use the -ExpandProperty along with the Select-object

```
$serialnum = get-ciminstance win32_bios | select serialnumber -ExpandProperty serialnumber
write-host $serialnum
```
2. get-ciminstance win32\_bios | select -expand serialnumber is having several properties, hence it is showing as @{}. To see the difference use get-member
```
get-ciminstance win32_bios | select serialnumber -ExpandProperty serialnumber | gm

TypeName: System.String
```

```
get-ciminstance win32_bios | select serialnumber

serialnumber 
------------ 
2289-0334-4018-3657-1028-9433-96
```

```
get-ciminstance win32_bios | select serialnumber | gm

TypeName: Selected.Microsoft.Management.Infrastructure.CimInstance
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:32pm UTC](https://forums.powershell.org/t/how-to-display-or-process-variable-output/12688/6 "2024-05-16T20:32:08Z")

</div>


