You can get the currently logged in user from a powershell script by using
$env:username. But most deployment scripts use elevated privileges. Therefore, you need to be a tad bit craftier.
Here, we’ll use the Get-WMIObject command to look at system data and then effectively grep for the username object:
Get-WMIObject -class Win32_ComputerSystem | select username