$secpasswd = ConvertTo-SecureString "password" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("nazwa_konta@domena", $secpasswd)
Get-ADGroupMember -Identity "nazwa_grupy" | ForEach-Object {
Get-ADUser -Identity $_.SamAccountName -Credential $mycreds -Properties EmailAddress, LastLogonDate, Created, Office |
Where-Object { $_.Office -like 'nazwa_firmy' -and $_.Enabled -eq 'true' } |
Select-Object -Property Name, GivenName, Surname, UserPrincipalName, EmailAddress, Enabled, LastLogonDate, Created, Office
}