I have been shown the following example in a training course which I believe to be wrong.
The code is supposed to copy an Active Directory User in PowerShell:
$userInstance = Get-ADUser -Identity "kmill"
$userInstance = New-Object Microsoft.ActiveDirectory.Management.ADUser
$userInstance.DisplayName = "Peter Piper"
New-ADUser -SAMAccountName "ppiper" -Instance $userInstance
It is my understnading that we get "Kmill"'s user account as an object and store it in a variable in Line 1.
It is also my understanding that in Line 2 - we completely Overwrite that variable and essentialy wipe all data obtained in line 1 (and therefore wouldn't copy an existing user)
Am I wrong here?