Understanding this snippet of code

Hello All,

 

I can see someone on the internet has written some code which following this

$Username = $Account.Username

Now I understand $username is a variable and it is a product of the variable $account however what does the .username mean ? what is the coder trying to achieve by adding a .extension (.username)

 

For example he includes it in his loop but this .username is new to me.

 

$Username = $Account.Username
If (Get-ADUser -Filter {Name -eq $Username})

{
$account | Select Username,SamAccountName | Out-File C:\temp\exist.txt -append
Write-Host “$Username already exists in Active Directory” -ForegroundColor RED
}
Else
{
Write-Host “I am sorry, $Username does not exist.”
}

}

 

 

Thanks

 

@fishandchips82, Request you start with PowerShell basics before you really jump in into any PowerShell scripting…

Please go through this tutorial for better understanding, it is a best place to start with and still valid…

https://channel9.msdn.com/Series/GetStartedPowerShell3

And coming to your question, it is called dot notation, and used to represent the object properties. $Account is a AD object it seems and .Username is a property of it to fetch the username and store it to $Username.

Thank you.