Tag Archives: group

Found groups that a 365 contacts is member of

If you need to found out whitch groups (mailling groups) a contact is member of in Microsoft 365, then you case use these powershell commands:

$getsessions = Get-PSSession | Select-Object -Property State, Name
$isconnected = (@($getsessions) -like '@{State=Opened; Name=ExchangeOnlineInternalSession*').Count -gt 0
If ($isconnected -ne "True") {
Connect-ExchangeOnline
}

$dn = (Get-MailContact "[email protected]").DistinguishedName
Get-Recipient -Filter "Members -eq '$dn'"

Replace [email protected] with yours mail address.

MSSQL – Always On availability group – Get sync status

If you wan to know the sync status of a always On availability group database replication, this command can be used:

SELECT 
	ar.replica_server_name, 
	adc.database_name, 
	ag.name AS ag_name, 
	drs.is_local, 
	drs.is_primary_replica, 
	drs.synchronization_state_desc, 
	drs.is_commit_participant, 
	drs.synchronization_health_desc, 
	drs.recovery_lsn, 
	drs.truncation_lsn, 
	drs.last_sent_lsn, 
	drs.last_sent_time, 
	drs.last_received_lsn, 
	drs.last_received_time, 
	drs.last_hardened_lsn, 
	drs.last_hardened_time, 
	drs.last_redone_lsn, 
	drs.last_redone_time, 
	drs.log_send_queue_size, 
	drs.log_send_rate, 
	drs.redo_queue_size, 
	drs.redo_rate, 
	drs.filestream_send_rate, 
	drs.end_of_log_lsn, 
	drs.last_commit_lsn, 
	drs.last_commit_time
FROM sys.dm_hadr_database_replica_states AS drs
INNER JOIN sys.availability_databases_cluster AS adc 
	ON drs.group_id = adc.group_id AND 
	drs.group_database_id = adc.group_database_id
INNER JOIN sys.availability_groups AS ag
	ON ag.group_id = drs.group_id
INNER JOIN sys.availability_replicas AS ar 
	ON drs.group_id = ar.group_id AND 
	drs.replica_id = ar.replica_id
ORDER BY 
	ag.name, 
	ar.replica_server_name, 
	adc.database_name;

Get a list of user and there Group Membership

This is how to get an CSV file, including user_SamAccountName;User_FullName;group1;group2;group3, etc

It posible to remove the comment before break, and then break the export after 5 user, to see that it function well.

It will first write it output at the ending of the script, so terminate it, will result in an empty file.

$user_count = 0
$output = ""
$OFS = "`r`n"
$users = Get-ADUser -Filter * -SearchBase "DC=dalbjerg,DC=local" | SELECT Name,samaccountname

foreach($user in $users) {
    #echo $user.SamAccountName
    $username = $user.SamAccountName
    $output += $username + ";" + $user.name + ";"
    $groups = Get-ADPrincipalGroupMembership $user.Samaccountname | select name
        foreach($group in $groups) {
            $output += $group.name + ";"
        }
    $output += $OFS
    $output += $OFS
    $user_count += 1
    if($user_count -eq 5) {
        #break
    }
}
Write-Output $output | out-file C:\temp\export.csv

 

Give access to calendar based on the user is member of the group.

If you need to give auser access to users calendar, based on if there are member of an group, this is the way.
Start Exchange Management Shell

$users = Get-ADGroupMember [groupname] | select -ExpandProperty name
foreach ($user in $users) {
    $Mailbox = Get-Mailbox $user
	#The Calendar, is name "Kalender" in danish
	add-MailboxFolderPermission -identity “$($Mailbox.Name):\kalender” -AccessRights Editor -User [username]
	set-MailboxFolderPermission -identity “$($Mailbox.Name):\kalender” -AccessRights Editor -User [username]

	#English calendar
	add-MailboxFolderPermission -identity “$($Mailbox.Name):\calendar” -AccessRights Editor -User [username]
	set-MailboxFolderPermission -identity “$($Mailbox.Name):\calendar” -AccessRights Editor -User [username]
} 

Edit an Group Policy object

If you receive this warning in Group Policy Management, when you are trying to edit an Group policy object:

Failed to open the Group Policy Object. You may not have appropriate rights.

Details:
The system cannot find the path specified.

This warning can happen, when one of the following folders are missing:
  • %SystemRoot%\Sysvol\Sysvol\DomainName
  • %SystemRoot%\Sysvol\Sysvol\DomainName\Policies
  • %SystemRoot%\Sysvol\Sysvol\DomainName\Policies\{GUID}
  • %SystemRoot%\Sysvol\Sysvol\DomainName\Policies\{GUID}\Machine
  • %SystemRoot%\Sysvol\Sysvol\DomainName\Policies\{GUID}\User

In my case, I was missing the Machine folder. I just created that folder, and then i could edit the object again.

Xendesktop 5 – Change logoff behavior

If you want to change a desktop group logoff behavior, this is done by PowerShell.

To turn off shutdown af use:

ASNP Citrix.*
Set-BrokerDesktopGroup -Name "Desktop Group Name" -ShutdownDesktopsAfterUse $FALSE

To turn on shutdown af use:

ASNP Citrix.*
Set-BrokerDesktopGroup -Name "Desktop Group Name" -ShutdownDesktopsAfterUse $TRUE

If you need to get a list of names of you Desktop Groups, you can run this:

ASNP Citrix.*
get-BrokerDesktopGroup | select Name

Get mailboxes and witch groups there are member of

I need to get all mailboxes, and witch group there are member of.

You need Quest ActiveRoles Management Shell for this to work:
http://www.quest.com/powershell/activeroles-server.aspx

Add-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue

$File = "C:\groupslog.txt"
$Mailboxes = Get-mailbox -resultsize unlimited | select sAMAccountName,name,alias
$Mailboxes | ForEach {
   $User = Get-QADUser -samaccountname $_.sAMAccountName | Select sAMAccountName, memberOf
   $Line = $_.sAMAccountName
   ForEach ($GroupDN In $User.memberOf)
   {
      $Group = (Get-QADGroup $GroupDN | Select sAMAccountName).sAMAccountName
      $Line = "$Line,$Group"
   }
   echo $Line
} | out-File $File

In the file c:\groupslog.txt each line is a mailbox, and the first entry is the sAMAccountName, and each entry after this is the group the Mailbox is member of.