# Newbie - Echo - Value or Label?

**URL:** <https://forums.powershell.org/t/newbie-echo-value-or-label/16979>\
**Category:** PowerShell Help\
**Created:** [July 5, 2021, 7:41am UTC](https://forums.powershell.org/t/newbie-echo-value-or-label/16979 "2021-07-05T07:41:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShelfStacker](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@ShelfStacker](https://forums.powershell.org/u/ShelfStacker)\
**Post date:** [July 5, 2021, 7:41am UTC](https://forums.powershell.org/t/newbie-echo-value-or-label/16979/1 "2021-07-05T07:41:00Z")

</div>

I have been playing with PowerShell to interrogate an AD.

I have looked, but am failing to understand some of the behaviour when using ‘echo’ to dump stuff to screen (when debugging). My lack of understanding means I cant be sure it will behave as expected.

Example user “djones” with the email address “[djones@smith.com](mailto:djones@smith.com)”

If I use the code;

> Echo $user.emailAddress

It will return “djones.emailAddress”

If I use the code;

```auto
> $emailMyStr = $user.emailAddress
> Echo $emailMyStr

```

It will return “[djones@smith.com](mailto:djones@smith.com)”

It is the second output I want - how do I ensure returning the value (@smith.com) and not the label (emailAddress)? Is there a simple rule to force the value to be used instead of the label? What am I missing?

Many thanks

I don’t expect the rest of my script to be relevant, but as it is my first\* and I’m not sure, its attached here. You’ll note that this is not really my work - just an adaptation of others work (borrowed this approach from u$) 🙂

```auto
foreach ($user in $group.members)
	{
		# only process users valid for my domain (should just check it ends "@smith.com")  
		IF (($user.emailAddress).length -gt 5)
		{
			#Is user prohibited from changing password? 			
			if ($user.UserCannotChangePassword -eq $false)
			{
				#is user enabled?
				if ($user.Enabled -eq $true)
				{
					#calculate number of days before expiry
					$daysRemaining = ($user.LastPasswordSet.AddDays($MaxPwdAge) - $todaysDate).Days
					#Has Password got ($maxWarningDays or less) before expiry?
					if (($daysRemaining -lt 8) -And ($daysRemaining -gt 0))
					{
						$emailAddStr = $user.emailAddress
						#password is old enough for warning - and has not expired					
						echo "FOUND ONE!! $emailAddStr password expires in $daysRemaining days"
						#send nag email 
					}	
				}	
                             # Echo EVERY user to screen for debugging
				$debStr = $user.emailAddress	
				echo "DEBUG INFO $debStr password expires in $daysRemaining days"										
			}
		}	
	}

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [July 5, 2021, 11:07am UTC](https://forums.powershell.org/t/newbie-echo-value-or-label/16979/2 "2021-07-05T11:07:01Z")

</div>

ShelfStacker,  
Welcome to the forum.

First of all: You should not use aliasses in scripts and please do not use aliasses in forums.

Then: If you want to learn more about a particular cmdlet you should start with its help. The cmdlet for the alias “`echo`” is

> **[Write-Host (Microsoft.PowerShell.Utility) - PowerShell](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-host?view=powershell-7.2&viewFallbackFrom=powershell-7.1)**
>
> The Write-Host cmdlet's primary purpose is to produce for-(host)-display-only output, such as printing colored text like when prompting the user for input in conjunction with Read-Host. Write-Host uses the ToString() method to write the output. By...

The behaviour you experience comes from the variable expansion PowerShell does implicitly for you when you provide a variable like this for Write-Host.

The proper way for an output like this would be to use a subexpression like this:

```auto
Write-Host "DEBUG INFO $($user.emailAddress) password expires in $daysRemaining days"

```

… and the real proper way to output debug information would be to use

> **[Write-Debug (Microsoft.PowerShell.Utility) - PowerShell](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-debug?view=powershell-7.2&viewFallbackFrom=powershell-7.1)**
>
> The Write-Debug cmdlet writes debug messages to the host from a script or command. By default, debug messages are not displayed in the console, but you can display them by using the Debug parameter or the $DebugPreference variable.

This way you could run the function or script by default without outputting the debug information and in case you need them you can add the parameter `-Debug` and get the info you need.

To learn more about variables you may read

> **[about Variables - PowerShell](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_variables?view=powershell-7)**
>
> Describes how variables store values that can be used in PowerShell.

and some additional info here:

> **[PowerShell One-Liners: Variables, Parameters, Properties, and Objects -...](https://www.red-gate.com/simple-talk/sysadmin/powershell/powershell-one-liners-variables-parameters-properties-and-objects/)**
>
> PowerShell isn't a conventional language, though it draws inspiration widely. Many people learn it, and use it, best by collecting snippets, or one-liners, and adapting them for use. Michael Sorens provides the second in a series of collections of...

---

<div class="post-metadata">

**Author:** ![ShelfStacker](https://avatars.discourse-cdn.com/v4/letter/s/ecccb3/32.png) [@ShelfStacker](https://forums.powershell.org/u/ShelfStacker)\
**Post date:** [July 5, 2021, 1:25pm UTC](https://forums.powershell.org/t/newbie-echo-value-or-label/16979/3 "2021-07-05T13:25:21Z")

</div>

Many thanks Olaf.

It looks like I will need a lot of extra brackets to be sure I get what I expect.

In your link about variables, it explains braces and back ticks can actually be used as part of a variable name - almost as confusing as aliases (which I will omit from any future posts).

I will keep trying with PS - I’m currently playing with ISE. Hope to be able to use the debugger, else it will be a return to c#.

Thanks again

ss

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [July 5, 2021, 2:38pm UTC](https://forums.powershell.org/t/newbie-echo-value-or-label/16979/4 "2021-07-05T14:38:29Z")

</div>

> [@ShelfStacker](#):
>
> it explains braces and back ticks can actually be used as part of a variable name

Hmmm … not everything what’s possible make sense and should be used. Especially backticks should be avoided if possible at any costs in my opinion … not just in variable names. 😉

> [@ShelfStacker](#):
>
> I will keep trying with PS

👍🏽

> [@ShelfStacker](#):
>
> I’m currently playing with ISE.

You may keep in mind … that’s just the IDE. The target runtime environment for PowerShell scripts - especially non interactive scripts - is the normal PowerShell console.

And if you want to keep using PowerShell and writing script you may take a look at

> **[Visual Studio Code - Code Editing. Redefined](https://code.visualstudio.com)**
>
> Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications.  Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.

It’s a far superior IDE than the PowerShell\_ISE.

---

<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:23pm UTC](https://forums.powershell.org/t/newbie-echo-value-or-label/16979/5 "2024-05-16T20:23:57Z")

</div>


