Assigning attribute of Get-ADUser to a variable without headers [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Assigning attribute of Get-ADUser to a variable without headers [duplicate]



This question already has an answer here:



Here is my code:


$var = Get-ADUser -Identity username | Select -Property ObjectGUID

Echo $var



My output is :


ObjectGUID
-------------
XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX



I dont want the headers in the variable, so i can pass it to commands with ease.



Please send help and caffiene.



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




2 Answers
2



Try this:


$var = Get-ADUser -Identity username | Select-Object -ExpandProperty ObjectGUID



You are confusing the default output with the actual contents of your variable. $var contains an object which has a property called ObjectGUID. The default output is just showing you this.


$var


ObjectGUID



To see only the value of ObjectGUID, simply type (echo, or its underlying command Write-Output, is typically not needed):


ObjectGUID


echo


Write-Output


$var.ObjectGUID



To use it as input to another cmdlet, you can do things like:


$var.ObjectGUID | My-Command



or


My-Command -Guid $var.ObjectGUID

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered