# Output just property from objects

**URL:** <https://forums.powershell.org/t/output-just-property-from-objects/1488>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/output-just-property-from-objects/1488 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/output-just-property-from-objects/1488/1 "2011-12-31T18:30:00Z")

</div>

by rambog at 2012-09-02 11:49:57

> For now, I am trying to get simply the domain name into a variable as follows:  
>   
> PS C:\Users\rambog\> $dom=get-wmiobject -class Win32\_ComputerSystem | Select D  
> omain | Out-Host  
>   
> Domain  
> ------  
> mydomain-corp.local  
>   
> As you can see, it puts it with a "Domain" colum. I simply want $dom to equal mydomain-corp.local How can I re-do the script (preferably in one line) so it gets what I am looking for. For me this comes up quite a bit as I usually want just one of the properties of an object. If you can also recommend more reading on this subject, it would be further appreciated.

by poshoholic at 2012-09-02 14:08:56

> You’re on the right track. Instead of "Select Domain", try this approach:  
>   
> `$dom = Get-WmiObject -Class Win32_ComputerSystem | Select-Object -ExpandProperty Domain`  
> Here’s another alternative:  
>   
> `$dom = (Get-WmiObject -Class Win32_ComputerSystem).Domain`

by RichardSiddaway at 2012-09-03 04:21:30

> Hi rambog  
>   
> Don’t be tempted to use the -property parameter on get-wmiobject for this as it just creates an object with a reduced property set.  
>   
> just to add to Kirk’s answer you don’t need out-host at the end of your pipeline. PowerShell will effectively do that for you.

by rambog at 2012-09-03 09:53:47

> I got it to work but Kirk’s way is much better. Here is what I was able to cobble together (not that I really understand what is going on),   
> $Dom=get-wmiobject -class Win32\_ComputerSystem -Computer $CName | Select -Property Domain| %{$_.Domain}  
> Note: the $CName changes as this statement is nested in a foreach loop.  
> Thank you Kirk and Richard. Richard, I am constantly hitting up against objects when I try to work with Powershell when I expect single values. Your point about the -property parameter still creating an object instead of a single value is something for me to keep in mind._

_by RichardSiddaway at 2012-09-03 10:20:54_

> _What you are doing is returning the WMI object for Win32\_ComputerSystem; piping that to select to pick off the Domain property and then using foreach-object to get the value of the domain property. % is an alias of foreach-object and I would strongly recommend against using it in scripts_  
>   
> _You could get the same answer like this_  
>   
> _$dom = get-wmiobject -class Win32\_ComputerSystem | %{$_.Domain}  
>   
> but the best way as Kirk stated is to do this   
>   
> $Dom=get-wmiobject -class Win32\_ComputerSystem | Select -ExpandProperty Domain  
>   
> Its the approach I would recommend - its less typing and more obvious when you come back to the script in a few months

by rambog at 2012-09-06 05:53:54

> I am now working on another script. I am having trouble understanding why the lessons you gave do not apply in the scenario below.  
> Aside for the fact that I have quite a bit of work to do in order to gather the samAccountName of the user profiles that have been touched in the last 30 days on each computer account, I was simply trying to display the computer being queried along with the profile information. It does not like my line that defines the variable $CName. I thought I was working on the object, $Obj, and that the line beginning with $CName would extract the computer name from the object like the solution in my earlier program. $Obj is some form of DirectorySearcher object and it seems these rules don’t help out. I have tried to transform it in other programs by doing something like $Computer=$Obj.Properties and then attempt to extract the name from $Computer- this time it doesn’t seem to work. Any help would again be appreciated.  
>   
> $ObjFilter = "(objectClass=Computer)"   
> $objSearch = New-Object System.DirectoryServices.DirectorySearcher   
> $objSearch.PageSize = 20000   
> $objSearch.Filter = $ObjFilter   
> $objSearch.SearchRoot = "LDAP://OU=NLH,OU=Workstations,DC=labdomain,DC=org"   
> $AllObj = $objSearch.FindAll()   
> foreach ($Obj in $AllObj)   
> {  
> $keytype=[Microsoft.Win32.RegistryHive]::LocalMachine  
> $remotekey=[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($keytype,$CName)  
> $regkey=$remotekey.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion\ProfileList")  
> #$profileList = ‘HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList’  
> $CName=get-wmiobject -class Win32\_ComputerSystem -Computer $CName | Select-Object -ExpandProperty Name  
> Write-Host "Computer Name:`t$CName"  
> #Get-WmiObject win32\_userprofile -Computer $CName |select @{LABEL="last used";EXPRESSION={$_.ConvertToDateTime($_.lastusetime)}},LocalPath, SID | ft -a |Out-Host  
> Get-childItem ‘HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList’ | % {Get-ItemProperty $\_.pspath } | Select profileImagePath, sid |Out-Host  
> }

---

<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, 9:03pm UTC](https://forums.powershell.org/t/output-just-property-from-objects/1488/2 "2024-05-16T21:03:37Z")

</div>

Closed on May 16, 2024, 9:03pm UTC


