[Solved] How can I ask for the user’s DisplayName and store it in $user


OK let’s start with the basics:

What is an cmdlet (comandlet)? You have used multiple of them. For example Get-ADUser and Read-Host. They consist of a Verb and a Noun (most of the time the words are neither verb nor noun in a gramaticle way but who cares):
Read = Verb
Host = Noun
Read-Host = cmdlet

Every cmdlet does something, like reading what you type, and most of them return the results as objects. Objects like strings, integers, hashtables or other crazy sh***…
If you don’t store the output in a variable it will be printed to screen most of the time, so better save it for later:

$MyBrandNewString = Read-Host -Prompt 'Who let the dogs out?'

Variables begin with a $ the rest of the name is up to you.
If you want to use the ouput of one cmdlet in another one you can either use the variable:

Get-ADUser -Identity $MyBrandNewString 

or put the first cmdlet in braces so that it’s executed first (The braces are replaced by the output object of the cmdlet so to say):

Get-ADUser -Identity (Read-Host -Prompt 'Who let the dogs out?')

Or (the most cool one and my favorit) you can just pipe the output of one cmdlet to another one concatenating them indefinitly:

 Read-Host -Prompt 'Who let the dogs out?' | Get-ADUser 

You can’t just put them behind eachother:

Get-ADUser Read-Host

And you can’t use them as properties of objects:

$_.Disable-ADAccount

But you can create an object and use that as propertie of another object:

$MyBrandNewString.( Read-Host -Prompt 'Write Length')

That’s enough PowerShell crash course for today. I very highly recomend you to read some tutorials, as all of this is the very very basics of PowerShell. But never give up and soon you will script like there is no tomorow!

1

solved How can I ask for the user’s DisplayName and store it in $user