Hi,
Does this work for you?
$server = 'W10GB54'
$user = query user /server:$server |ForEach-Object {
($_ -split ' '| Where-Object {$_}) -join ','} |
ConvertFrom-Csv | Select-Object -ExpandProperty USERNAME
$displayname = Get-ADUser -Filter {Name -eq $user} -Properties DisplayName | Select-Object -ExpandProperty DisplayName
Set-ADComputer -Identity $server -Description $displayname
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.