Jump to content

Get user description not working as expected - Powershell


Recommended Posts

Posted

I'm trying to get information from the Description field from our accounts in AD.

I'm using the following powershell command to try and get the description field of an AD account.

$Description= Get-ADUser $row.samaccountname -Properties Description | Select-object Description

but this give me an output of @{Description=Actual Description} rather than just Actual Description

 

I want to use the $description as a variable as I want to add to it but I can't seem to get it to work. Can anyone point me in the right direction?

Posted

$Description= Get-ADUser -Identity $row.samaccountname -Properties Description | foreach-object { $_.Description }

 

In cases where Get-AdUser returns multiple rows, $Description will be set to the last one.

  • Thanks 1
Posted (edited)

get-members is your friend

 

$Description | gm will show that the description is a note property. To get the contents of this, reference the 'description' field of your variable.

 

So to get your text, you should reference

 

$Description.description

 

Edit - your result is showing that you're returning an array, so pcstru's advice is good.

Edited by jinnantonnixx

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...