<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PowerShell Archives - Wiredwolf Canada</title>
	<atom:link href="https://catastrophe.wiredwolf.com/category/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>https://catastrophe.wiredwolf.com/category/powershell/</link>
	<description></description>
	<lastBuildDate>Sat, 27 Apr 2024 01:20:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Office 365 &#8211; Migrating Distribution Groups</title>
		<link>https://catastrophe.wiredwolf.com/office-365-migrating-distribution-groups/</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 27 Apr 2024 00:54:48 +0000</pubDate>
				<category><![CDATA[Microsoft Exchange]]></category>
		<category><![CDATA[Microsoft Office 365]]></category>
		<category><![CDATA[PowerShell]]></category>
		<guid isPermaLink="false">https://catastrophe.wiredwolf.com/?p=22459</guid>

					<description><![CDATA[<p>Distribution Groups stuck in Active Directory can cause issues after an Exchange migration.   Users can no longer access the management of a Distribution Group in Outlook Synchronized Distribution Groups in Office 365 cannot be modified in Office 365 - as a synchronized object you must update in Active Directory Adding external contacts to a synchronized  [...]</p>
<p>The post <a href="https://catastrophe.wiredwolf.com/office-365-migrating-distribution-groups/">Office 365 &#8211; Migrating Distribution Groups</a> appeared first on <a href="https://catastrophe.wiredwolf.com">Wiredwolf Canada</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Distribution Groups stuck in Active Directory can cause issues after an Exchange migration.&nbsp;&nbsp;</p>
<ul>
<li>Users can no longer access the management of a Distribution Group in Outlook</li>
<li>Synchronized Distribution Groups in Office 365 cannot be modified in Office 365 &#8211; as a synchronized object you must update in Active Directory</li>
<li>Adding external contacts to a synchronized Distribution Group becomes difficult as you cannot synchronize contacts with Azure AD Connect</li>
</ul>
<p>The solution is relatively simple &#8211; convert all Distribution Groups to Cloud objects.</p>
<p>This script was designed to do exactly that.</p>
<blockquote>
<div>
<div>&lt;#</div>
<div>#########################################################################################</div>
<div>##</div>
<div>## Name: &nbsp; &nbsp; &nbsp; &nbsp;DG_Cloud.PS1</div>
<div>##</div>
<div>## Version: &nbsp; &nbsp; 1.0</div>
<div>##</div>
<div>## Description: $ Installs required components for Exchange Online Powershell Management</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ Creates a &#8220;Working&#8221; folder for Sea to Sky (C:\STS) for backups.</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ Creates an &#8220;Exports&#8221; folder for the temp files needed to migrate the</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Distribution Lists.</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ Backs up the Distribution List Names and Attributes to DG_Details_Backup.csv</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ Backs up the Distribution List Members to DG_Members_Backup.csv</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ Capable of running mulitple times and retaining existing backups &#8211; creates</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;new backups each time it&#8217;s run if any new groups are detected</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ Selectively Creates a copy of each Distribution Group called Cloud_$Group</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;that are specifically Distribution Groups and not Mail-Enabled Security</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;groups.</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ Deletes the selected Distribtuion Groups from Active Directory</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ Initiates an Azure AD Connect to remove the AD objects from Cloud Environment</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ Forces wait period of 5 minutes to allow Azure AD to synchronize with Exchange</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$ Completes process by renaming Cloud_$Group back to original name</div>
<div>##</div>
<div>## Usage: &nbsp; &nbsp; &nbsp; Execute script in PowerShell with elevated privileges</div>
<div>##</div>
<div>## Author: Jason Zondag</div>
<div>##</div>
<div>## Disclaimer: &nbsp;Has not been tried in every conceivable environment &#8211; always check the results</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and fall back on the backups created to recreate the Distribution Groups if</div>
<div>## &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;necessary</div>
<div>##</div>
<div>#########################################################################################</div>
<div>###### ALTERNATIVE CODE FOR MFA LOGIN TO OFFICE 365 &nbsp;####################################</div>
<div>#Connect &amp; Login to ExchangeOnline (MFA)</div>
<div>$getsessions = Get-PSSession | Select-Object -Property State, Name</div>
<div>$isconnected = (@($getsessions) -like &#8216;@{State=Opened; Name=ExchangeOnlineInternalSession*&#8217;).Count -gt 0</div>
<div>If ($isconnected -ne &#8220;True&#8221;) {</div>
<div>Connect-ExchangeOnline</div>
<div>}</div>
<div>#########################################################################################</div>
<div>#&gt;</div>
<div>clear</div>
<div>Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221; -ForegroundColor Cyan</div>
<div>Write-Host &#8220;!!!!!IMPORTANT!!!!!!&#8221; -ForeGroundColor Red</div>
<div>Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221; -ForegroundColor Cyan</div>
<div>Write-Host &#8220;!!!!!IMPORTANT!!!!!!&#8221; -ForeGroundColor Red</div>
<div>Write-Host &#8220;YOU MUST RUN THIS SCRIPT FROM THE DOMAIN CONTROLLER THAT IS RUNNING AZURE AD CONNECT&#8221; -ForeGroundColor Red</div>
<div>sleep 5</div>
<div>Write-Host &#8220;IF YOU ARE NOT PLEASE USE CTRL + C TO ESCAPE AND RUN FROM THE APPROPRIATE DOMAIN CONTROLLER&#8221; -ForeGroundColor Red</div>
<div>Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221; -ForegroundColor Cyan</div>
<div>Write-Host &#8220;It&#8217;s also important to note that this only affects Distribution Lists and not Mail-Enabled&#8221; -ForeGroundColor Green</div>
<div>Write-Host &#8220;Security Groups. &nbsp;Mail-Enabled Security Groups must be handled differently.&#8221; -ForeGroundColor Green</div>
<div>Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221; -ForegroundColor Cyan</div>
<div>sleep 15</div>
<div>Pause</div>
<div>Write-Host &#8220;Connecting to Exchange Online &#8211; installing all required PowerShell Modules and initiaing a connection&#8221; -ForegroundColor Green</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div># Load PowerShell Modules</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div>Set-ExecutionPolicy RemoteSigned -Force</div>
<div>Import-Module ActiveDirectory</div>
<div>[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12</div>
<div>Install-Module -Name ExchangeOnlineManagement -Force</div>
<div>Import-Module ExchangeOnlineManagement</div>
<div>#Connect &amp; Login to ExchangeOnline (MFA)</div>
<div>$getsession = get-pssession | select-object -Property State | select -expandproperty state</div>
<div>If ($getsession -ne &#8220;Opened&#8221;) {</div>
<div>Connect-ExchangeOnline</div>
<div>}</div>
<div>Write-Host &#8220;Completed&#8221; -ForegroundColor Green</div>
<div>Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221; -ForegroundColor Cyan</div>
<div>Write-Host</div>
<div>Write-host</div>
<div>Write-Host &#8220;______________________________________________________________________________________________&#8221; -ForegroundColor Cyan</div>
<div>Write-Host &#8220;Synchronized Distribution Groups with no ManagedBy settings will be defaulted to Organization&#8221; -ForeGroundColor Yellow</div>
<div>Write-Host &#8220;Management. This value cannot be translated.&#8221; -ForeGroundColor Yellow</div>
<div>Write-host</div>
<div>Write-Host &#8220;You must set a default account value to replace Organization Management.&#8221; -ForeGroundColor Green</div>
<div>Write-Host &#8220;The default account must be a valid licensed address for this tenant. &nbsp;IE. seatosky@domain.com &#8221; -ForeGroundColor Green</div>
<div>$ManagedByDefault = Read-host &#8220;Enter the email address of a valid licensed account for this tenant:&#8221;</div>
<div>Write-Host &#8220;______________________________________________________________________________________________&#8221; -ForegroundColor Cyan</div>
<div># Disable Azure AD Connect from initiating a sync while this process is underway</div>
<div>Set-ADSyncScheduler -SyncCycleEnabled $false</div>
<div>Write-host &#8220;Azure AD Connect Schedule Sync has been disabled temporarily.&#8221;</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div># Create Working and Export folders</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div>Write-Host &#8220;Creating a Working Directory C:\DG-Migrate and an Exports Directory within the Working Directory&#8221; -ForegroundColor Green</div>
<div># Create a working directory</div>
<div>$orginfo = Get-OrganizationConfig | select -expandproperty Name</div>
<div>$WorkingDirectory = &#8220;C:\DG-Migrate\&#8221; + $orginfo + &#8220;\&#8221;</div>
<div>$ExportDirectory = $WorkingDirectory + &#8220;ExportedAddresses\&#8221;</div>
<div>If(!(Test-Path -Path $WorkingDirectory )){</div>
<div># if WorkingDirectory doesn&#8217;t exist neither does ExportDirectory &#8211; create them both</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Write-Host &#8221; &nbsp;Creating Directory: $WorkingDirectory&#8221;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; New-Item -ItemType directory -Path $WorkingDirectory | Out-Null</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Write-Host &#8221; &nbsp;Creating Directory: $ExportDirectory&#8221;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; New-Item -ItemType directory -Path $ExportDirectory | Out-Null</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; } else {</div>
<div># WorkingDirectory may exist but that doesn&#8217;t mean ExportDirectory does &#8211; create if it doesn&#8217;t exist</div>
<div>If(!(Test-Path -Path $ExportDirectory )){</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Write-Host &#8221; &nbsp;Creating Directory: $ExportDirectory&#8221;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; New-Item -ItemType directory -Path $ExportDirectory | Out-Null</div>
<div>}</div>
<div>}</div>
<div>Write-Host &#8220;Completed&#8221; -ForegroundColor Green</div>
<div>Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221; -ForegroundColor Cyan</div>
<div>Write-Host &#8220;Creating a backup of all AD Synchronized Distribution Lists and placing into the Working Directory&#8221; -ForegroundColor Green</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div># Export all the Distribution Group Information to a separate file</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div>$check = (get-distributiongroup | Where {($_.IsDirSynced -eq $true) -AND ($_.RecipientType -eq &#8220;MailUniversalDistributionGroup&#8221;)})</div>
<div>if ((($check | Measure-Object).count) -ne 0) {</div>
<div># Not 0 so we found some Distribution Groups to migrate</div>
<div># We don&#8217;t want to overwrite an existing backup set &#8211; rename any existing files with a time stamp</div>
<div>&nbsp; &nbsp; if (Test-Path ($WorkingDirectory + &#8220;DG_Details_Backup.csv&#8221;)) {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $filename = ($WorkingDirectory + &#8220;DG_Details_Backup.csv&#8221;)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $fileObj = get-item $filename</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $DateStamp = get-date -uformat &#8220;%Y-%m-%d@%H-%M-%S&#8221;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $extOnly = $fileObj.extension</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; if ($extOnly.length -eq 0) {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $nameOnly = $fileObj.Name</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rename-item &#8220;$fileObj&#8221; &#8220;$nameOnly-$DateStamp&#8221;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; else {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $nameOnly = $fileObj.Name.Replace( $fileObj.Extension,&#8221;)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rename-item &#8220;$fileName&#8221; &#8220;$nameOnly-$DateStamp$extOnly&#8221;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; }</div>
<div>$check | select `</div>
<div>&nbsp; &nbsp; GroupType, `</div>
<div>&nbsp; &nbsp; SamAccountName, `</div>
<div>&nbsp; &nbsp; IsDirSynced, `</div>
<div>&nbsp; &nbsp; @{label=&#8221;ManagedBy&#8221;;expression={</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; ($_.managedby `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; | % { get-mailbox -identity $_ | select-object -ExpandProperty PrimarySMTPAddress } `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; | Where-Object {$_ -like &#8220;*@*&#8221;}) -join &#8216;;&#8217;}</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; }, `</div>
<div>&nbsp; &nbsp; MemberJoinRestriction, `</div>
<div>&nbsp; &nbsp; MemberDepartRestriction, `</div>
<div>&nbsp; &nbsp; ReportToOriginatorEnabled, `</div>
<div>&nbsp; &nbsp; Description, `</div>
<div>&nbsp; &nbsp; AddressListMembership, `</div>
<div>&nbsp; &nbsp; Alias, `</div>
<div>&nbsp; &nbsp; DisplayName, `</div>
<div>&nbsp; &nbsp; PrimarySMTPAddress, `</div>
<div>&nbsp; &nbsp; @{label=&#8221;EmailAddressess&#8221;;expression={</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; ($_.EmailAddresses | Where-Object {$_ -like &#8220;*smtp:*&#8221; }) -join &#8216;;&#8217;}</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; },`</div>
<div>&nbsp; &nbsp; ExternalDirectoryObjectId, `</div>
<div>&nbsp; &nbsp; HiddenFromAddressListsEnabled, `</div>
<div>&nbsp; &nbsp; LegacyExchangeDN, `</div>
<div>&nbsp; &nbsp; MaxSendSize, `</div>
<div>&nbsp; &nbsp; MaxReceiveSize, `</div>
<div>&nbsp; &nbsp; ModeratedBy, `</div>
<div>&nbsp; &nbsp; ModerationEnabled, `</div>
<div>&nbsp; &nbsp; PoliciesIncluded, `</div>
<div>&nbsp; &nbsp; PoliciesExcluded, `</div>
<div>&nbsp; &nbsp; EmailAddressPolicyEnabled, `</div>
<div>&nbsp; &nbsp; RecipientType, `</div>
<div>&nbsp; &nbsp; RecipientTypeDetials, `</div>
<div>&nbsp; &nbsp; RequireSenderAuthenticationEnabled, `</div>
<div>&nbsp; &nbsp; WindowsEmailAddress, `</div>
<div>&nbsp; &nbsp; Identity, `</div>
<div>&nbsp; &nbsp; Id, `</div>
<div>&nbsp; &nbsp; Name, `</div>
<div>&nbsp; &nbsp; DistinguishedName, `</div>
<div>&nbsp; &nbsp; ExchangeObjectId, `</div>
<div>&nbsp; &nbsp; Guid `</div>
<div>| Export-CSV ($WorkingDirectory + &#8220;DG_Details_Backup.csv&#8221;) -NoTypeInformation</div>
<div>sleep 20</div>
<div>&nbsp; &nbsp; }</div>
<div>else {</div>
<div>&nbsp; &nbsp; Write-Host &#8220;There are no appropriate Distribution Lists to migrate. &nbsp;Cancelling migration.&#8221;</div>
<div>&nbsp; &nbsp; Break</div>
<div>}</div>
<div>Write-Host &#8220;Completed&#8221; -ForegroundColor Green</div>
<div>Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221; -ForegroundColor Cyan</div>
<div>Write-Host &#8220;Creating a backup of Distribution List Membership and placing in the Working Directory&#8221; -ForegroundColor Green</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div># Export all the Distribution Group Members to a separate file</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div>$output = @()</div>
<div>$Identities = import-csv ($WorkingDirectory + &#8220;DG_Details_Backup.csv&#8221;) | select Name,PrimarySmtpAddress,Managedby,GroupType,RecipientType</div>
<div>If ($Identities) {</div>
<div>Foreach($group in $Identities) {</div>
<div>&nbsp; &nbsp; $Members = Get-DistributionGroupMember $group.PrimarySmtpAddress -resultsize unlimited</div>
<div>&nbsp; &nbsp; if (@($Members.count) -eq 0) {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; #$managers = ($group | Select @{Name=&#8217;DistributionGroupManagers&#8217;;Expression={[string]::join(&#8220;;&#8221;, ($_.Managedby))}})</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj = New-Object PSObject</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;DisplayName&#8221; -Value EmptyGroup</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Alias&#8221; -Value EmptyGroup</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;RecipientType&#8221; -Value EmptyGroup</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Recipient OU&#8221; -Value EmptyGroup</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Primary SMTP address&#8221; -Value EmptyGroup</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Distribution Group&#8221; -Value $group.Name</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Distribution Group Primary SMTP address&#8221; -Value $group.PrimarySmtpAddress</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Distribution Group Managers&#8221; -Value $managers.DistributionGroupManagers</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Distribution Group Type&#8221; -Value $group.GroupType</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Distribution Group Recipient Type&#8221; -Value $group.RecipientType</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $output+=$UserObj</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; else {</div>
<div>&nbsp; &nbsp; Foreach($Member in $members) {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; #$managers = $group | Select @{Name=&#8217;DistributionGroupManagers&#8217;;Expression={[string]::join(&#8220;;&#8221;, ($_.Managedby))}}</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj = New-Object PSObject</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;DisplayName&#8221; -Value $Member.Name</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Alias&#8221; -Value $Member.Alias</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;RecipientType&#8221; -Value $Member.RecipientType</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Recipient OU&#8221; -Value $Member.OrganizationalUnit</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Primary SMTP address&#8221; -Value $Member.PrimarySmtpAddress</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Distribution Group&#8221; -Value $group.Name</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Distribution Group Primary SMTP address&#8221; -Value $group.PrimarySmtpAddress</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Distribution Group Managers&#8221; -Value $managers.DistributionGroupManagers</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Distribution Group Type&#8221; -Value $group.GroupType</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $userObj | Add-Member NoteProperty -Name &#8220;Distribution Group Recipient Type&#8221; -Value $group.RecipientType</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $output+=$UserObj</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp;}</div>
<div>&nbsp; &nbsp;# We don&#8217;t want to overwrite an existing backup set &#8211; rename any existing files with a time stamp</div>
<div>&nbsp; &nbsp; if (Test-Path ($WorkingDirectory + &#8220;DG_Members_Backup.csv&#8221;)) {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $filename = ($WorkingDirectory + &#8220;DG_Members_Backup.csv&#8221;)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $fileObj = get-item $filename</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $DateStamp = get-date -uformat &#8220;%Y-%m-%d@%H-%M-%S&#8221;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $extOnly = $fileObj.extension</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; if ($extOnly.length -eq 0) {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $nameOnly = $fileObj.Name</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rename-item &#8220;$fileObj&#8221; &#8220;$nameOnly-$DateStamp&#8221;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; else {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $nameOnly = $fileObj.Name.Replace( $fileObj.Extension,&#8221;)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rename-item &#8220;$fileName&#8221; &#8220;$nameOnly-$DateStamp$extOnly&#8221;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; $output | Export-CSV ($WorkingDirectory + &#8220;DG_Members_Backup.csv&#8221;) -NoTypeInformation</div>
<div>&nbsp; &nbsp;}</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</div>
<div>sleep 15</div>
<div>Write-Host &#8220;Completed&#8221; -ForegroundColor Green</div>
<div>Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221; -ForegroundColor Cyan</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div># Create the Cloud copies of the Distribution Lists</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div>Write-Host &#8220;Creating Cloud copies of each AD Synced Distribution List&#8221; -ForegroundColor Green</div>
<div>$Identities = import-csv ($WorkingDirectory + &#8220;DG_Details_Backup.csv&#8221;) | select -expandproperty PrimarySmtpAddress</div>
<div># Create the cloud versions</div>
<div>If ($Identities) {</div>
<div>&nbsp; &nbsp; foreach ($group in $identities) {</div>
<div>&nbsp; &nbsp; If (((Get-DistributionGroup $group -Resultsize Unlimited -ErrorAction &#8216;SilentlyContinue&#8217;).IsValid) -eq $true) {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $OldDG = Get-DistributionGroup $group</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; [System.IO.Path]::GetInvalidFileNameChars() | ForEach {$Group = $Group.Replace($_,&#8217;_&#8217;)}</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $OldName = [string]$OldDG.Name</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $OldDisplayName = [string]$OldDG.DisplayName</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $OldPrimarySmtpAddress = [string]$OldDG.PrimarySmtpAddress</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $OldAlias = [string]$OldDG.Alias</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ((![string]$OldDG.managedby) -or ([string]$OldDG.managedby -eq &#8220;Organization Management&#8221;)) {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [string]$OldDG.managedby=$ManagedByDefault</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $OldMembers = (Get-DistributionGroupMember $OldDG.PrimarySmtpAddress).primarysmtpaddress &#8220;EmailAddress&#8221; &gt; &#8220;$ExportDirectory\$OldName.csv&#8221;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $OldDG.EmailAddresses &gt;&gt; &#8220;$ExportDirectory\$OldName.csv&#8221;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &#8220;x500:&#8221;+$OldDG.LegacyExchangeDN &gt;&gt; &#8220;$ExportDirectory\$OldName.csv&#8221;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; Write-Host &#8221; &nbsp;Creating Group: Cloud-$OldDisplayName&#8221; -ForegroundColor Green</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; New-DistributionGroup `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -Name &#8220;Cloud-$OldName&#8221; `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -Alias &#8220;Cloud-$OldAlias&#8221; `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -DisplayName &#8220;Cloud-$OldDisplayName&#8221; `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -ManagedBy $OldDG.ManagedBy `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -Members $OldMembers `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -PrimarySmtpAddress &#8220;Cloud-$OldPrimarySmtpAddress&#8221; | Out-Null</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; Sleep -Seconds 3</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; Write-Host &#8221; &nbsp;Setting Values For: Cloud-$OldDisplayName&#8221; -ForegroundColor Green</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; Set-DistributionGroup `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -Identity &#8220;Cloud-$OldPrimarySmtpAddress&#8221; `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -AcceptMessagesOnlyFromSendersOrMembers $OldDG.AcceptMessagesOnlyFromSendersOrMembers `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -RejectMessagesFromSendersOrMembers $OldDG.RejectMessagesFromSendersOrMembers `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; Set-DistributionGroup `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -Identity &#8220;Cloud-$OldPrimarySmtpAddress&#8221; `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -AcceptMessagesOnlyFrom $OldDG.AcceptMessagesOnlyFrom `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -AcceptMessagesOnlyFromDLMembers $OldDG.AcceptMessagesOnlyFromDLMembers `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -BypassModerationFromSendersOrMembers $OldDG.BypassModerationFromSendersOrMembers `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -BypassNestedModerationEnabled $OldDG.BypassNestedModerationEnabled `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -CustomAttribute1 $OldDG.CustomAttribute1 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -CustomAttribute2 $OldDG.CustomAttribute2 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -CustomAttribute3 $OldDG.CustomAttribute3 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -CustomAttribute4 $OldDG.CustomAttribute4 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -CustomAttribute5 $OldDG.CustomAttribute5 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -CustomAttribute6 $OldDG.CustomAttribute6 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -CustomAttribute7 $OldDG.CustomAttribute7 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -CustomAttribute8 $OldDG.CustomAttribute8 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -CustomAttribute9 $OldDG.CustomAttribute9 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -CustomAttribute10 $OldDG.CustomAttribute10 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -CustomAttribute11 $OldDG.CustomAttribute11 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -CustomAttribute12 $OldDG.CustomAttribute12 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -CustomAttribute13 $OldDG.CustomAttribute13 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -CustomAttribute14 $OldDG.CustomAttribute14 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -CustomAttribute15 $OldDG.CustomAttribute15 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -ExtensionCustomAttribute1 $OldDG.ExtensionCustomAttribute1 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -ExtensionCustomAttribute2 $OldDG.ExtensionCustomAttribute2 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -ExtensionCustomAttribute3 $OldDG.ExtensionCustomAttribute3 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -ExtensionCustomAttribute4 $OldDG.ExtensionCustomAttribute4 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -ExtensionCustomAttribute5 $OldDG.ExtensionCustomAttribute5 `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -GrantSendOnBehalfTo $OldDG.GrantSendOnBehalfTo `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -HiddenFromAddressListsEnabled $True `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -MailTip $OldDG.MailTip `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -MailTipTranslations $OldDG.MailTipTranslations `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -MemberDepartRestriction $OldDG.MemberDepartRestriction `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -MemberJoinRestriction $OldDG.MemberJoinRestriction `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -ModeratedBy $OldDG.ModeratedBy `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -ModerationEnabled $OldDG.ModerationEnabled `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -RejectMessagesFrom $OldDG.RejectMessagesFrom `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -RejectMessagesFromDLMembers $OldDG.RejectMessagesFromDLMembers `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -ReportToManagerEnabled $OldDG.ReportToManagerEnabled `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -ReportToOriginatorEnabled $OldDG.ReportToOriginatorEnabled `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -RequireSenderAuthenticationEnabled $OldDG.RequireSenderAuthenticationEnabled `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -SendModerationNotifications $OldDG.SendModerationNotifications `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -SendOofMessageToOriginatorEnabled $OldDG.SendOofMessageToOriginatorEnabled `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -BypassSecurityGroupManagerCheck</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; sleep 3</div>
<div>&nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
<div>&nbsp; &nbsp; Else {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; Write-Host &#8221; &nbsp;ERROR: The distribution group &#8216;$Group&#8217; was not found&#8221; -ForegroundColor Red</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; Write-Host</div>
<div>&nbsp; &nbsp; }</div>
<div>}</div>
<div>}</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div># Delete all the Distribution Groups in Active Directory</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div>Write-Host &#8220;All Distribution Lists have been replicated in the Cloud with Cloud_ as a prefix&#8221; -ForegroundColor Green</div>
<div>Write-Host &#8220;Completed&#8221; -ForegroundColor Green</div>
<div>Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221; -ForegroundColor Cyan</div>
<div>Write-host &#8220;If you encountered any errors during the creation of the Cloud-Group process you may hit CTRL + C now to kill the process.&#8221; -ForegroundColor Red -BackgroundColor Black</div>
<div>Write-host &#8220;If you kill the process now to fix any issues you should remove the Cloud-Group objects from Azure AD and start fresh.&#8221; -ForegroundColor Red -BackgroundColor Black</div>
<div>Write-host &#8220;WARNING &#8211; The Azure AZ Connect Sync Schedule is currently Suspended. You must complete the script or manually restart the Schedule.&#8221; -ForegroundColor Black -BackgroundColor Red</div>
<div>Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221; -ForegroundColor Cyan</div>
<div>Write-host &#8220;Press Enter to delete the migrated Distribution Lists from Active Directory&#8221; -ForegroundColor Cyan</div>
<div>pause</div>
<div>If (test-path ($WorkingDirectory + &#8220;DG_Details_Backup.csv&#8221;)) {</div>
<div>&nbsp; &nbsp; $Identities = import-csv ($WorkingDirectory + &#8220;DG_Details_Backup.csv&#8221;) | select -expandproperty Identity</div>
<div>&nbsp; &nbsp; foreach ($group in $identities) {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; Remove-ADGroup -identity &#8220;$group&#8221; -confirm:$false</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; sleep 2</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div>}</div>
<div>Write-Host &#8220;All Distribution Lists have been removed from Active Directory&#8221; -ForegroundColor Green</div>
<div>Write-Host &#8220;Completed&#8221; -ForegroundColor Green</div>
<div>Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221; -ForegroundColor Cyan</div>
<div>sleep 15</div>
<div>Pause</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div># Initiate a Delta Sync with Azure AD Connect and set a timer of 5 minutes</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div>Write-Host &#8220;Synchronizing Changes with Azure AD Connect. &nbsp;Please allow 5 minutes for process to complete. &nbsp;You will be prompted when to continue.&#8221; -ForegroundColor Green</div>
<div>Start-AdSyncSyncCycle -PolicyType Delta</div>
<div>Write-Host &#8220;PLEASE BE PATIENT &#8211; Confirm the Distribution Lists have been removed from Office 365 Azure AD before continuing&#8221; -ForegroundColor Green</div>
<div>sleep 300</div>
<div>Write-Host &#8220;Completed&#8221; -ForegroundColor Green</div>
<div>Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221; -ForegroundColor Cyan</div>
<div>Pause</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div># Complete the process by renaming the Cloud copies to the original names</div>
<div># &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</div>
<div>Write-Host &#8220;Updating the placeholder Distribution Lists to replace the original AD synchronized Distribution Lists&#8221; -ForegroundColor Green</div>
<div>If (test-path $ExportDirectory) {</div>
<div>&nbsp; &nbsp; $Identities = import-csv ($WorkingDirectory + &#8220;DG_Details_Backup.csv&#8221;) | select -expandproperty Identity</div>
<div>&nbsp; &nbsp; foreach ($group in $identities) {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $TempDG = Get-DistributionGroup &#8220;Cloud-$Group&#8221;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $TempPrimarySmtpAddress = $TempDG.PrimarySmtpAddress</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; [System.IO.Path]::GetInvalidFileNameChars() | ForEach {$Group = $Group.Replace($_,&#8217;_&#8217;)}</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $OldAddresses = @(Import-Csv &#8220;$ExportDirectory\$Group.csv&#8221;)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $NewAddresses = $OldAddresses | ForEach {$_.EmailAddress.Replace(&#8220;X500&#8243;,&#8221;x500&#8221;)}</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $NewDGName = $TempDG.Name.Replace(&#8220;Cloud-&#8220;,&#8221;&#8221;)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $NewDGDisplayName = $TempDG.DisplayName.Replace(&#8220;Cloud-&#8220;,&#8221;&#8221;)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $NewDGAlias = $TempDG.Alias.Replace(&#8220;Cloud-&#8220;,&#8221;&#8221;)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; $NewPrimarySmtpAddress = ($NewAddresses | Where {$_ -clike &#8220;SMTP:*&#8221;}).Replace(&#8220;SMTP:&#8221;,&#8221;&#8221;)</div>
<div>&nbsp; &nbsp; Write-Host &#8220;Converting Cloud-$Group to $Group&#8221;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; Set-DistributionGroup `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -Identity $TempDG.Name `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -Name $NewDGName `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -Alias $NewDGAlias `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -DisplayName $NewDGDisplayName `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -PrimarySmtpAddress $NewPrimarySmtpAddress `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -HiddenFromAddressListsEnabled $False `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -BypassSecurityGroupManagerCheck</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; Set-DistributionGroup `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -Identity $NewDGName `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -EmailAddresses @{Add=$NewAddresses} `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -BypassSecurityGroupManagerCheck</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; Set-DistributionGroup `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -Identity $NewDGName `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -EmailAddresses @{Remove=$TempPrimarySmtpAddress} `</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -BypassSecurityGroupManagerCheck</div>
<div>&nbsp; &nbsp; sleep 3</div>
<div>&nbsp; &nbsp; }</div>
<div>&nbsp; &nbsp; }</div>
<div>Write-Host &#8220;Completed&#8221; -ForegroundColor Green</div>
<div>Write-Host &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#8221; -ForegroundColor Cyan</div>
<div># Re-Enable AD Sync Schedule</div>
<div>Set-ADSyncScheduler -SyncCycleEnabled $true</div>
<div>Write-Host &#8220;The conversion process happens in Exchange and can take a while to reflect in Azure AD&#8221;</div>
<div>Write-Host &#8220;Check to make sure that Azure AD is updated and now showing all of the Distribution Lists are converted to Cloud objects&#8221;</div>
<div>Pause</div>
</div>
</blockquote>
<div>
<div>&nbsp;</div>
</div>
<p>The post <a href="https://catastrophe.wiredwolf.com/office-365-migrating-distribution-groups/">Office 365 &#8211; Migrating Distribution Groups</a> appeared first on <a href="https://catastrophe.wiredwolf.com">Wiredwolf Canada</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PowerShell &#8211; Active Directory &#8211; New Email Domain</title>
		<link>https://catastrophe.wiredwolf.com/powershell-active-directory-new-email-domain/</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 15 Aug 2022 17:11:27 +0000</pubDate>
				<category><![CDATA[Microsoft Office 365]]></category>
		<category><![CDATA[Microsoft Server]]></category>
		<category><![CDATA[PowerShell]]></category>
		<guid isPermaLink="false">https://catastrophe.wiredwolf.com/?p=21776</guid>

					<description><![CDATA[<p>Environment: Active Directory with Azure Active Directory Connect and Exchange Online I had a job recently where I needed to change everyone's email address to a new domain but I couldn't accomplish this from Exchange Online as all the users are synchronized with Active Directory on-premises. I wrote a quick script that addresses this: &lt;#  [...]</p>
<p>The post <a href="https://catastrophe.wiredwolf.com/powershell-active-directory-new-email-domain/">PowerShell &#8211; Active Directory &#8211; New Email Domain</a> appeared first on <a href="https://catastrophe.wiredwolf.com">Wiredwolf Canada</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="fusion-fullwidth fullwidth-box fusion-builder-row-1 fusion-flex-container nonhundred-percent-fullwidth non-hundred-percent-height-scrolling" style="--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;" ><div class="fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap" style="max-width:1144px;margin-left: calc(-4% / 2 );margin-right: calc(-4% / 2 );"><div class="fusion-layout-column fusion_builder_column fusion-builder-column-0 fusion_builder_column_1_1 1_1 fusion-flex-column" style="--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:0px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;"><div class="fusion-column-wrapper fusion-flex-justify-content-flex-start fusion-content-layout-column"><div class="fusion-text fusion-text-1"><p>Environment: Active Directory with Azure Active Directory Connect and Exchange Online</p>
<p>I had a job recently where I needed to change everyone's email address to a new domain but I couldn't accomplish this from Exchange Online as all the users are synchronized with Active Directory on-premises. </p>
<p>I wrote a quick script that addresses this:</p>
<blockquote>
<p><#<br />
PowerShell<br />
Objectives<br />
– query AD with all users with a 'mail' attribute<br />
– update the 'mail' attribute to the new domain<br />
– set the proxyaddress SMTP matching the mail attribute to lowercase smtp<br />
– set the proxyaddress SMTP to the new domain</p>
<p>Author: Jason Zondag<br />
Date: 2202.08.11<br />
#><br />
# Set Variables<br />
$newMailDomain = "newdomain.com"<br />
$oldMailDomain = "olddomain.com"</p>
<p># Make sure we have AD access<br />
Import-Module ActiveDirectory</p>
<p># Set the SearchBase<br />
$SearchBase = "DC=domain,DC=local"</p>
<p># Get the required data and loop<br />
$Users = Get-ADUser -Filter "mail -like '*'" -SearchBase "$SearchBase" -ResultSetSize $null -properties mail,proxyaddresses,samaccountname,givenname,sn<br />
ForEach ($User in $Users) </p>
</blockquote>
<p>Note – you must run this script with elevated privileges. </p>
<p>I would also recommend that you add the command to stop AAD Sync during the course of running the script.</p>
</div></div></div></div></div>
<p>The post <a href="https://catastrophe.wiredwolf.com/powershell-active-directory-new-email-domain/">PowerShell &#8211; Active Directory &#8211; New Email Domain</a> appeared first on <a href="https://catastrophe.wiredwolf.com">Wiredwolf Canada</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PowerShell &#8211; Installing Modules</title>
		<link>https://catastrophe.wiredwolf.com/powershell-installing-modules/</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 05 Aug 2021 18:16:13 +0000</pubDate>
				<category><![CDATA[Microsoft Office 365]]></category>
		<category><![CDATA[Microsoft Server]]></category>
		<category><![CDATA[PowerShell]]></category>
		<guid isPermaLink="false">https://catastrophe.wiredwolf.com/?p=20974</guid>

					<description><![CDATA[<p>PowerShell is continuing to evolve.  Occasionally I come across a server that I need to install modules to and find that I cannot.  Windows Management Framework 5.1 is installed to Server 2016/2019 out of the box but it's not directly equipped to be caught up - you need to do some steps first. Open PowerShell  [...]</p>
<p>The post <a href="https://catastrophe.wiredwolf.com/powershell-installing-modules/">PowerShell &#8211; Installing Modules</a> appeared first on <a href="https://catastrophe.wiredwolf.com">Wiredwolf Canada</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>PowerShell is continuing to evolve.&nbsp; Occasionally I come across a server that I need to install modules to and find that I cannot.&nbsp; Windows Management Framework 5.1 is installed to Server 2016/2019 out of the box but it&#8217;s not directly equipped to be caught up &#8211; you need to do some steps first.</p>
<ol>
<li>Open PowerShell (as Administrator is also an option)</li>
<li>Copy/Paste:&nbsp; &nbsp;Set-ExecutionPolicy Unrestricted
<ol>
<li>Execute</li>
</ol>
</li>
<li>Copy/Paste:&nbsp; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
<ol>
<li>Execute</li>
</ol>
</li>
<li>Copy/Paste:&nbsp; Register-PSRepository -Default
<ol>
<li>Execute</li>
</ol>
</li>
<li>Copy/Paste:&nbsp; Update-Module PowerShellGet -Force
<ol>
<li>Execute</li>
</ol>
</li>
</ol>
<p>At this point you should be in good shape to add whatever modules it is you are trying to install from the repository.&nbsp;</p>
<ul>
<li>Install-Module AzureAD</li>
<li>Install-Module ExchangeOnlineManagement</li>
<li>etc</li>
</ul>
<p>&nbsp;</p>
<p>The post <a href="https://catastrophe.wiredwolf.com/powershell-installing-modules/">PowerShell &#8211; Installing Modules</a> appeared first on <a href="https://catastrophe.wiredwolf.com">Wiredwolf Canada</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Dynamic Distribution Lists</title>
		<link>https://catastrophe.wiredwolf.com/dynamic-distribution-lists/</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 08 Jun 2021 01:13:44 +0000</pubDate>
				<category><![CDATA[Microsoft Exchange]]></category>
		<category><![CDATA[Microsoft Office 365]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Exchange]]></category>
		<category><![CDATA[Office 365]]></category>
		<guid isPermaLink="false">https://catastrophe.wiredwolf.com/?p=20957</guid>

					<description><![CDATA[<p>Dynamic Distribution Lists are an easy way to maintain lists without having to constantly maintain lists.  Basic creation is simple - you can do that right from EAC and select which type of recipients in the organization should be included.   More complex options exist but are accomplished with PowerShell.  For instance, you want to create  [...]</p>
<p>The post <a href="https://catastrophe.wiredwolf.com/dynamic-distribution-lists/">Dynamic Distribution Lists</a> appeared first on <a href="https://catastrophe.wiredwolf.com">Wiredwolf Canada</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Dynamic Distribution Lists are an easy way to maintain lists without having to constantly maintain lists.&nbsp;</p>
<p>Basic creation is simple &#8211; you can do that right from EAC and select which type of recipients in the organization should be included.&nbsp;&nbsp;</p>
<p>More complex options exist but are accomplished with PowerShell.&nbsp; For instance, you want to create a distribution list that includes all Exchange Mailbox users, but you don&#8217;t want to include Shared Mailboxes, Equipment or Resource Mailboxes, or any users with attributes that match.&nbsp;&nbsp;</p>
<p>If you want to use custom attributes where you have AAD Connect there&#8217;s a bit more you need to do.&nbsp; I&#8217;ve document that here: <a href="https://catastrophe.wiredwolf.com/azure-ad-connect-and-custom-attributes/">https://catastrophe.wiredwolf.com/azure-ad-connect-and-custom-attributes/</a></p>
<p>This is where it gets a bit tricky.&nbsp; You can&#8217;t mix operators and stay sane, so it&#8217;s important to know how to format the command with not double not nor negatives (joke).</p>
<p>Creating a List:</p>
<p style="padding-left: 40px;">New-dynamicdistributiongroup -name&nbsp;&#8220;<strong><span style="color: #ff6600;">DGNAME</span></strong>&#8221; `<br />
-recipientfilter {((RecipientType -eq &#8216;UserMailbox&#8217;) `<br />
-and (CustomAttribute1 -ne &#8216;<span style="color: #ff6600;">NoMember</span>&#8216;) `<br />
-and (-not(RecipientTypeDetailsValue -eq &#8216;SharedMailbox&#8217;)) `<br />
-and (-not(RecipientTypeDetailsValue -eq &#8216;GuestMailUser&#8217;)) `<br />
-and (-not(Name -like &#8216;SystemMailbox{*&#8217;)) `<br />
-and (-not(Name -like &#8216;CAS_{*&#8217;)) `<br />
-and (-not(Company -eq &#8216;<span style="color: #ff6600;">Acme</span>&#8216;)) `<br />
-and (-not(RecipientTypeDetailsValue -eq &#8216;MailboxPlan&#8217;)) `<br />
-and (-not(RecipientTypeDetailsValue -eq &#8216;DiscoveryMailbox&#8217;)) `<br />
-and (-not(RecipientTypeDetailsValue -eq &#8216;PublicFolderMailbox&#8217;)) `<br />
-and (-not(RecipientTypeDetailsValue -eq &#8216;ArbitrationMailbox&#8217;)) `<br />
-and (-not(RecipientTypeDetailsValue -eq &#8216;AuditLogMailbox&#8217;)) `<br />
-and (-not(RecipientTypeDetailsValue -eq &#8216;AuxAuditLogMailbox&#8217;)) `<br />
-and (-not(RecipientTypeDetailsValue -eq &#8216;SupervisoryReviewPolicyMailbox&#8217;)))} `<br />
-managedby &#8220;admin@yourdomain.com&#8221; `<br />
-DisplayName &#8220;Dynamic Distribution Group Name&#8221; `<br />
-RequireSenderAuthenticationEnabled $false `<br />
-MemberDepartRestriction closed `<br />
-MemberJoinRestriction closed</p>
<p>I&#8217;ve added a couple of <span style="color: #ff6600;">options</span> as an example of how far you can go with RecipientType and RecipientTypeDetails. If synchronized with an on-premises AD you can easily add attributes to the account, such as Company, or CustomAttribute1, at which point you can use these attributes to further hone the scope of your Dynamic Distribution List.</p>
<p>If you&#8217;ve created the dynamic distribution list already you can always edit it:</p>
<p>replace new-dynamicdistributiongroup -Name &#8220;DGNAME&#8221; with set-dynamicdistributiongroup -identity &#8220;DGNAME&#8221;&nbsp;</p>
<p>Getting details from a single list &#8211; export to CSV</p>
<p>Get-Recipient -RecipientPreviewFilter (get-dynamicdistributiongroup <span style="color: #ff6600;"><strong>DGNAME</strong></span>).RecipientFilter -OrganizationalUnit $group.RecipientContainer | select Name, DisplayName, PrimarySMTPAddress, RecipientType*, WindowsLiveID | export-csv &#8220;C:\CSV-PATH\DynDG-DGNAME.CSV&#8221; -NoTypeInformation</p>
<p>The post <a href="https://catastrophe.wiredwolf.com/dynamic-distribution-lists/">Dynamic Distribution Lists</a> appeared first on <a href="https://catastrophe.wiredwolf.com">Wiredwolf Canada</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PowerShell CMDLET Limitations</title>
		<link>https://catastrophe.wiredwolf.com/powershell-cmdlet-limitations/</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 18 Feb 2021 20:26:17 +0000</pubDate>
				<category><![CDATA[Microsoft Office 365]]></category>
		<category><![CDATA[Microsoft Server]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[get-aduser]]></category>
		<category><![CDATA[office365]]></category>
		<guid isPermaLink="false">https://catastrophe.wiredwolf.com/?p=20952</guid>

					<description><![CDATA[<p>It was recently discovered that when new user accounts are set up in AD and then synchronized with Azure AD Connect, there is some 'guessing' that happens around default email address assignment if proper proxyAddresses attributes are not manually added.  Essentially it appears that Microsoft 365 will set the user's UPN or samAccountName as the  [...]</p>
<p>The post <a href="https://catastrophe.wiredwolf.com/powershell-cmdlet-limitations/">PowerShell CMDLET Limitations</a> appeared first on <a href="https://catastrophe.wiredwolf.com">Wiredwolf Canada</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>It was recently discovered that when new user accounts are set up in AD and then synchronized with Azure AD Connect, there is some &#8216;guessing&#8217; that happens around default email address assignment if proper proxyAddresses attributes are not manually added.&nbsp; Essentially it appears that Microsoft 365 will set the user&#8217;s UPN or samAccountName as the default/primary SMTP address.&nbsp;</p>
<p>That&#8217;s fine normally, because typically that&#8217;s the email address you would normally assign the user.&nbsp; That is, until the account is updated with MFA registration information, at which point the default address automatically becomes the @tenant.onmicrosoft.com extension.&nbsp; Then it becomes a big problem as the onmicrosoft.com domain is not typically routable.</p>
<p>When we uncovered this undocumented feature we realized that we were going to have to update all AD accounts where the proxyAddresses attribute field was left blank.&nbsp; Except, how to search for something that isn&#8217;t there on hundreds of accounts?</p>
<p>I discovered through a lot of trail and error that not all operators work with all cmdlets.&nbsp; Get-ADUser, for example, can handle -filter options of -eq -like -match, but cannot handle -ceq -clike or -cmatch, and has no concept at all of -notlike or -notequal.&nbsp; Suddenly the search become considerably more difficult.</p>
<p>I know there&#8217;s going to be a lot of PowerShell experts out there who&#8217;ll look at this and say &#8220;there&#8217;s a better way&#8221; but this was the best I could come up with:</p>
<blockquote><p>get-aduser -filter &#8216;enabled -eq $true&#8217; -Properties Name,DisplayName,SamAccountName,SurName,GivenName,UserPrincipalName,proxyaddresses | `<br />
Select-Object Name, DisplayName, SamAccountName, Surname, GivenName, UserPrincipalName, `<br />
@{n = &#8220;proxyAddress&#8221;; e = { $_.proxyAddresses | Where-object { $_ -clike &#8220;SMTP:*&#8221; } } }</p></blockquote>
<p>I exported the results to a CSV file, then used Excel&#8217;s Data &#8211;&gt; Filter option to filter out all found SMTP entries, leaving only blanks, which gave me the list of accounts to fix.</p>
<p>I was actually hoping to also find a way to filter out all the system accounts, but was satisfied with the AD &#8216;enabled&#8217; accounts.</p>
<p>The post <a href="https://catastrophe.wiredwolf.com/powershell-cmdlet-limitations/">PowerShell CMDLET Limitations</a> appeared first on <a href="https://catastrophe.wiredwolf.com">Wiredwolf Canada</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PowerShell and TLS 1.2</title>
		<link>https://catastrophe.wiredwolf.com/powershell-and-tls-1-2/</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 12 Feb 2021 20:01:46 +0000</pubDate>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Office 365]]></category>
		<guid isPermaLink="false">https://catastrophe.wiredwolf.com/?p=20943</guid>

					<description><![CDATA[<p>When attempting to install or import modules it's not obvious but you do need to update the TLS version that PowerShell is using. Execute this: [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Install-Module PowerShellGet -RequiredVersion 2.2.4 -SkipPublisherCheck You should only need to do this once.  Afterwards the correct settings are used on every launch.</p>
<p>The post <a href="https://catastrophe.wiredwolf.com/powershell-and-tls-1-2/">PowerShell and TLS 1.2</a> appeared first on <a href="https://catastrophe.wiredwolf.com">Wiredwolf Canada</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>When attempting to install or import modules it&#8217;s not obvious but you do need to update the TLS version that PowerShell is using.</p>
<p>Execute this:</p>
<blockquote><p>[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12<br />
Install-Module PowerShellGet -RequiredVersion 2.2.4 -SkipPublisherCheck</p></blockquote>
<p>You should only need to do this once.&nbsp; Afterwards the correct settings are used on every launch.</p>
<p>The post <a href="https://catastrophe.wiredwolf.com/powershell-and-tls-1-2/">PowerShell and TLS 1.2</a> appeared first on <a href="https://catastrophe.wiredwolf.com">Wiredwolf Canada</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
