$secpasswd = ConvertTo-SecureString "password" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("nazwa_konta@domena", $secpasswd)
$groups = "grupa1", "grupa2"
$wyniki = ForEach ($group in $groups) {
Get-ADGroupMember $group | ForEach-Object {
Get-ADUser -Identity $_.SamAccountName -Credential $mycreds -Properties EmailAddress, LastLogonDate, Created, Office, sAMAccountName, title |
Where-Object { $_.Office -like 'nazwa_firmy' -and $_.Enabled -eq 'true' -and $_.Title -ne 'stanowisko'} |
Select-Object -Property sAMAccountName
}}
$wyniki | Sort-Object -Property sAMAccountName