Advertisement
adamchilcott

DKIM.ps1

Jan 13th, 2019
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. #------------------------------------------------------------------------------
  4. # THIS CODE AND ANY ASSOCIATED INFORMATION ARE PROVIDED “AS IS” WITHOUT
  5. # WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  6. # LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
  7. # FOR A PARTICULAR PURPOSE. THE ENTIRE RISK OF USE, INABILITY TO USE, OR
  8. # RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
  9. #
  10. #------------------------------------------------------------------------------
  11. # Author: Eyal Doron
  12. # Version: 1.2
  13. # Last Modified Date: 19/12/2017  
  14. # Last Modified By: eyal@o365info.com
  15. # Web site: o365info.com
  16. # Article name: Get the value of the DKIM record for a Domain, using PowerShell | Office 365 | Part 7#10
  17. # Article URL: http://o365info.com/get-the-value-of-the-dkim-record-for-a-domain-using-powershell-office-365-part-7-10/
  18. # sn -AA0016789DFSdAVXDSXCV
  19. #------------------------------------------------------------------------------
  20. # Hope that you enjoy it !
  21. # And, may the force of PowerShell will be with you  :-)
  22. # ------------------------------------------------------------------------------
  23.  
  24. #------------------------------------------------------------------------------
  25. # PowerShell Functions
  26. #------------------------------------------------------------------------------
  27.  
  28. function checkConnection ()
  29. {
  30.         $a = Get-PSSession
  31.         if ($a.ConfigurationName -ne "Microsoft.Exchange")
  32.         {
  33.            
  34.             write-host     'You are not connected to Exchange Online PowerShell ;-(         '
  35.             write-host      'Please connect using the Menu option 1) Login to Office 365 + Exchange Online using Remote PowerShell        '
  36.             #Read-Host "Press Enter to continue..."
  37.             Add-Type -AssemblyName System.Windows.Forms
  38.             [System.Windows.Forms.MessageBox]::Show("You are not connected to Exchange Online PowerShell ;-( `nSelect menu 1 to connect `nPress OK to continue...", "o365info.com PowerShell script", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Warning)
  39.             Clear-Host
  40.             break
  41.         }
  42. }
  43.  
  44.  
  45.  
  46. Function Disconnect-ExchangeOnline {Get-PSSession | Where-Object {$_.ConfigurationName -eq "Microsoft.Exchange"} | Remove-PSSession}
  47.  
  48.  
  49. Function Set-AlternatingRows {
  50.        <#
  51.        
  52.        #>
  53.     [CmdletBinding()]
  54.        Param(
  55.              [Parameter(Mandatory=$True,ValueFromPipeline=$True)]
  56.         [string]$Line,
  57.        
  58.            [Parameter(Mandatory=$True)]
  59.              [string]$CSSEvenClass,
  60.        
  61.         [Parameter(Mandatory=$True)]
  62.            [string]$CSSOddClass
  63.        )
  64.        Begin {
  65.              $ClassName = $CSSEvenClass
  66.        }
  67.        Process {
  68.              If ($Line.Contains("<tr>"))
  69.              {      $Line = $Line.Replace("<tr>","<tr class=""$ClassName"">")
  70.                     If ($ClassName -eq $CSSEvenClass)
  71.                     {      $ClassName = $CSSOddClass
  72.                     }
  73.                     Else
  74.                     {      $ClassName = $CSSEvenClass
  75.                     }
  76.              }
  77.              Return $Line
  78.        }
  79. }
  80.  
  81.  
  82.  
  83.  
  84. #------------------------------------------------------------------------------
  85. # Genral
  86. #------------------------------------------------------------------------------
  87. $FormatEnumerationLimit = -1
  88. $Date = Get-Date
  89. $Datef = Get-Date -Format "\Da\te dd-MM-yyyy \Ti\me H-mm"
  90. #------------------------------------------------------------------------------
  91. # PowerShell console window Style
  92. #------------------------------------------------------------------------------
  93.  
  94. $pshost = get-host
  95. $pswindow = $pshost.ui.rawui
  96.  
  97.     $newsize = $pswindow.buffersize
  98.    
  99.     if($newsize.height){
  100.         $newsize.height = 3000
  101.         $newsize.width = 150
  102.         $pswindow.buffersize = $newsize
  103.     }
  104.  
  105.     $newsize = $pswindow.windowsize
  106.     if($newsize.height){
  107.         $newsize.height = 50
  108.         $newsize.width = 150
  109.         $pswindow.windowsize = $newsize
  110.     }
  111.  
  112. #------------------------------------------------------------------------------
  113. # HTML Style start
  114. #------------------------------------------------------------------------------
  115. $Header = @"
  116. <style>
  117. Body{font-family:segoe ui,arial;color:black; }
  118.  
  119. H1 {font-size: 26px; font-weight:bold;width: 70% text-transform: uppercase; color: #0000A0; background:#2F5496 ; color: #ffffff; padding: 10px 10px 10px 10px ; border: 3px solid #00B0F0;}
  120. H2{ background:#F2F2F2 ; padding: 10px 10px 10px 10px ; color: #013366; margin-top:35px;margin-bottom:25px;font-size: 22px;padding:5px 15px 5px 10px; }
  121.  
  122. .TextStyle {font-size: 26px; font-weight:bold ; color:black; }
  123.  
  124. TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
  125. TH {border-width: 1px;padding: 5px;border-style: solid;border-color: #d1d3d4;background-color:#0072c6 ;color:white;}
  126. TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
  127.  
  128. .odd  { background-color:#ffffff; }
  129. .even { background-color:#dddddd; }
  130.  
  131.  
  132.  
  133. .note0
  134. {width: 50%;padding:15px 15px 15px 15px;font-size: 1.1em;margin-top:15px;margin-bottom:45px;border-top: 3px dashed #2F5496;border-bottom: 3px dashed #2F5496;background: #F2F2F2;line-height: 1.6;
  135. }
  136.  
  137.  
  138. .o365info {height: 90px;padding-top:5px;padding-bottom:5px;margin-top:20px;margin-bottom:20px;border-top: 3px dashed #002060;border-bottom: 3px dashed #002060;background: #00CCFF;font-size: 120%;font-weight:bold;background:#00CCFF url(http://o365info.com/wp-content/files/PowerShell-Images/o365info120.png) no-repeat 680px -5px;
  139. }
  140.  
  141. </style>
  142.  
  143. "@
  144.  
  145. $EndReport = "<div class=o365info>  This report was created by using <a href= http://o365info.com target=_blank>o365info.com</a> PowerShell script </div>"
  146.  
  147.  
  148. #-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  149.  
  150.  
  151.  
  152.  
  153. #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  154. # Exchange Online DKIM Settings PowerShell - Script menu
  155. #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  156.  
  157. $Loop = $true
  158. While ($Loop)
  159. {
  160.     write-host
  161.     write-host +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  162.     write-host   "Exchange Online DKIM Settings PowerShell - Script menu"
  163.     write-host +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  164.     write-host
  165.     write-host -ForegroundColor white  '----------------------------------------------------------------------------------------------'
  166.     write-host -ForegroundColor white  -BackgroundColor DarkCyan     'Connect Exchange Online using Remote PowerShell        '
  167.     write-host -ForegroundColor white  '----------------------------------------------------------------------------------------------'
  168.     write-host -ForegroundColor Yellow ' 1) Login to Exchange Online using Remote PowerShell '
  169.     write-host
  170.     write-host -ForegroundColor green '----------------------------------------------------------------------------------------------'
  171.     write-host -ForegroundColor white  -BackgroundColor DarkGreen   'SECTION A: View and Export information about DKIM DNS records settings      '
  172.     write-host -ForegroundColor green '----------------------------------------------------------------------------------------------'
  173.     write-host                                              ' 2) View and Export information about the DKIM CNAME record synatx for a specific Domain name '
  174.     write-host                                              ' 3) View and Export information about the DKIM CNAME record synatx for a All Domain names '
  175.     write-host -ForegroundColor green  '----------------------------------------------------------------------------------------------'
  176.     write-host -ForegroundColor white  -BackgroundColor DarkRed   'SECTION B: Disable DKIM signing policy  '
  177.     write-host -ForegroundColor green  '----------------------------------------------------------------------------------------------'
  178.     write-host                                              ' 4) Disable the DKIM signing policy for a specific Domain name '
  179.     write-host -ForegroundColor green  '----------------------------------------------------------------------------------------------'
  180.     write-host -ForegroundColor white  -BackgroundColor Blue   'SECTION C: Enable DKIM signing policy  '
  181.     write-host -ForegroundColor green  '----------------------------------------------------------------------------------------------'
  182.     write-host                                              ' 5) Enable the DKIM signing policy for a specific Domain name  '
  183.     write-host -ForegroundColor green  '----------------------------------------------------------------------------------------------'
  184.     write-host -ForegroundColor white  -BackgroundColor Blue   'SECTION D: Create DKIM selectors configuration in Exchange Online   '
  185.     write-host -ForegroundColor green  '----------------------------------------------------------------------------------------------'
  186.     write-host                                              ' 6) Enable the DKIM signing policy for a specific Domain name  '
  187.     write-host -ForegroundColor green  '----------------------------------------------------------------------------------------------'
  188.  
  189.     write-host -ForegroundColor white  -BackgroundColor DarkCyan 'End of PowerShell - Script menu '
  190.     write-host -ForegroundColor green  '----------------------------------------------------------------------------------------------'
  191.     write-host -ForegroundColor Yellow            "20)  Disconnect PowerShell session"
  192.     write-host
  193.     write-host -ForegroundColor Yellow            "21) Exit the PowerShell script menu (Or use the keyboard combination - CTRL + C)"
  194.     write-host
  195.  
  196.     $opt = Read-Host "Select an option [1-21]"
  197.     write-host $opt
  198.     switch ($opt)
  199.  
  200.  
  201. {
  202.  
  203.  
  204.  
  205. #===============================================================================================================
  206. # Step -00 | Connect to Windows Azure Active Directory  & Exchange Online using Remote PowerShell
  207. #===============================================================================================================
  208.  
  209.        
  210.  
  211.    
  212. 1
  213. {
  214.  
  215. #####################################################################
  216. # Connect Exchange Online using Remote PowerShell
  217. #####################################################################
  218.  
  219. # information
  220. clear-host
  221.  
  222. write-host
  223. write-host
  224. write-host  -ForegroundColor Magenta    oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                        
  225. write-host  -ForegroundColor white      Information                                                                                          
  226. write-host  -ForegroundColor white      ------------------------------------------------------------------------------------------                                                                
  227. write-host  -ForegroundColor white      'To be able to use the PowerShell menus in the script,  '
  228. write-host  -ForegroundColor white      'you will need to Login to Exchange Online using Remote PowerShell. '
  229. write-host  -ForegroundColor white      'In the credentials windows that appear,   '
  230. write-host  -ForegroundColor white      'provide your Office 365 Global Administrator credentials.  '
  231. write-host  -ForegroundColor white      ------------------------------------------------------------------------------------------  
  232. write-host  -ForegroundColor white      'The PowerShell command that we use is: '
  233. write-host  -ForegroundColor Cyan       '$UserCredential = Get-Credential '
  234. write-host  -ForegroundColor Cyan       '$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection '
  235. write-host  -ForegroundColor Cyan       'Import-PSSession $Session '
  236. write-host
  237. write-host  -ForegroundColor Magenta    oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                          
  238. write-host
  239. write-host
  240.  
  241. Disconnect-ExchangeOnline
  242. # Specify your administrative user credentials on the line below
  243.  
  244. $user = “Provide credentials”
  245.  
  246. $UserCredential = Get-Credential -Credential $user
  247.  
  248. $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
  249.  
  250. Import-PSSession $Session
  251.  
  252. #------------------------------------------------------------------------------
  253. # Object Properties Array
  254. #------------------------------------------------------------------------------
  255. # DKIM Domain name properties
  256. $global:Array1  = "Domain","Enabled"
  257.  
  258. $global:Array2  = "Domain","Selector1CNAME","Selector2CNAME"
  259.  
  260. }
  261.  
  262.  
  263.        
  264.  
  265. #=========================================================================================
  266. # SECTION A: View and Export information about DKIM DNS records settings
  267. #=========================================================================================
  268.  
  269.  
  270. 2
  271. {
  272.  
  273. ##########################################################################
  274. # View and Export information about the DKIM CNAME record synatx for a specific Domain name
  275. ##########################################################################
  276.  
  277. # information
  278. checkConnection
  279.  
  280. clear-host
  281.  
  282. write-host
  283. write-host
  284. write-host  -ForegroundColor Magenta    oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                              
  285. write-host  -ForegroundColor white      Introduction                                                                                          
  286. write-host  -ForegroundColor white      --------------------------------------------------------------------------------------                                                              
  287. write-host  -ForegroundColor white      'This option will:  '
  288. write-host  -ForegroundColor white      'View and Export information about the DKIM CNAME record synatx for a specific Domain name '
  289. write-host  -ForegroundColor white      --------------------------------------------------------------------------------------  
  290. write-host  -ForegroundColor white      'The export command will:   '
  291. write-host  -ForegroundColor white      '1. Export the required information to the following path =>' -NoNewline;Write-Host ' C:\INFO\DKIM Record settings  ' -ForegroundColor Cyan  
  292. write-host  -ForegroundColor white      '2. Save all of the exported information to diffrent file formats: TXT and HTML. '
  293. write-host  -ForegroundColor white      'Note - Be patient, the operation can take a long time. '
  294. write-host  -ForegroundColor white      ------------------------------------------------------------------------------------------  
  295. write-host  -ForegroundColor white      'The PowerShell command that we use is: '
  296. write-host  -ForegroundColor Cyan       'Get-DkimSigningConfig <Domain name> | FL *CNAME '
  297. write-host  -ForegroundColor Magenta    oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                        
  298. write-host
  299.  
  300. # User input   
  301.  
  302. write-host -ForegroundColor white   'User input '
  303. write-host -ForegroundColor white   ----------------------------------------------------------------------------
  304. write-host -ForegroundColor Yellow  "You will need to provide 1 parameter:"  
  305. write-host
  306. write-host -ForegroundColor Yellow  "1.  Doamin name"  
  307. write-host -ForegroundColor Yellow  "This is the name of the Domain for which you asking to get Information about DKIM DNS record syntax"  
  308. write-host -ForegroundColor Yellow  "For example:  o365info.com"
  309. write-host
  310. $Domain  = Read-Host "Type the The Doamin name "
  311. write-host
  312. write-host
  313.  
  314.  
  315. $DKIMSelector = Get-DkimSigningConfig $Domain
  316. $DKIMSelector.Selector1CNAME
  317. $DKIMSelector.Selector2CNAME
  318.  
  319. $SelectorA = $DKIMSelector.Selector1CNAME
  320. $SelectorB = $DKIMSelector.Selector2CNAME
  321.                    
  322. $Selector1 =
  323. "<div class=note0>
  324. 1. The first part (the top part) of the CNAME record is:
  325. <div class='TextStyle'> Selector1._domainkey </div>
  326.  
  327. </br>
  328.  
  329. 2. The second part of the CNAME record is:
  330. <div class='TextStyle'> $SelectorA </div>
  331. </br>
  332. <img src='http://o365info.com/wp-content/gallery/get-the-value-of-the-dkim-record-for-a-domain-using-powershell-office-365-part-7-10/Creating-CNAME-record-for-DKIM-in-Office-365-Selector1.domainkey-01-1.jpg'/>
  333.  
  334. </div>"
  335.  
  336.  
  337. $Selector2 = "<div class=note0>
  338. 1. The first part (the top part) of the CNAME record is:
  339. <div class='TextStyle'> Selector2._domainkey </div>
  340. </br>
  341.  
  342. 2. The second part of the CNAME record is:
  343.  
  344.  
  345. <div class='TextStyle'> $SelectorB </div>
  346.  
  347.  
  348. </br>
  349. <img src='http://o365info.com/wp-content/gallery/get-the-value-of-the-dkim-record-for-a-domain-using-powershell-office-365-part-7-10/Creating-CNAME-record-for-DKIM-in-Office-365-Selector2.domainkey-02.jpg' />
  350.  
  351. </div>"
  352.  
  353.  
  354. # Display Information about Audit settings
  355.  
  356. write-host
  357. write-host -------------------------------------------------------------------------------------------------
  358. write-host -ForegroundColor white  -BackgroundColor Blue   Display information about DKIM host names: "$Domain".ToUpper()
  359. write-host -------------------------------------------------------------------------------------------------
  360. Get-DkimSigningConfig $Domain | Select-Object  $global:Array2     | Out-String
  361. write-host -------------------------------------------------------------------------------------------------
  362.  
  363. write-host
  364. write-host  -ForegroundColor Magenta    oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                              
  365. write-host  -ForegroundColor white      Introduction                                                                                          
  366. write-host  -ForegroundColor white      --------------------------------------------------------------------------------------                                                              
  367. write-host  -ForegroundColor white      'To be able to create the required DNS records for your Office 365 DKIM implementation '
  368. write-host  -ForegroundColor white      'for the domain name $Domain   '
  369. write-host  -ForegroundColor white      'You will need to create 2 CNAME records.'
  370. write-host  -ForegroundColor white      'The syntax of the 2 CNAME records is: '
  371. write-host  -ForegroundColor Magenta    oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                        
  372. write-host
  373.  
  374. write-host
  375. write-host -------------------------------------------------------------------------------------------------
  376. write-host -ForegroundColor white  -BackgroundColor Blue   CNAME record 1 -  "$Domain".ToUpper()
  377. write-host -------------------------------------------------------------------------------------------------
  378. write-host  -ForegroundColor white      'The first part (the “top” part) of the CNAME record is:'
  379. write-host  -ForegroundColor Yellow     'Selector1._domainkey   '
  380. write-host  
  381. write-host  -ForegroundColor white      'The second part of the CNAME record is:'
  382. write-host  -ForegroundColor Yellow     $DKIMSelector.Selector1CNAME  
  383. write-host -------------------------------------------------------------------------------------------------
  384.  
  385. write-host
  386. write-host -------------------------------------------------------------------------------------------------
  387. write-host -ForegroundColor white  -BackgroundColor Blue   CNAME record 2 -  "$Domain".ToUpper()
  388. write-host -------------------------------------------------------------------------------------------------
  389. write-host  -ForegroundColor white      'The first part (the “top” part) of the CNAME record is:'
  390. write-host  -ForegroundColor Yellow     'Selector1._domainkey   '
  391. write-host  
  392. write-host  -ForegroundColor white      'The second part of the CNAME record is:'
  393. write-host  -ForegroundColor Yellow     $DKIMSelector.Selector2CNAME  
  394. write-host -------------------------------------------------------------------------------------------------
  395.  
  396.  
  397. #---------------------------------------------------------------------------------------------------
  398. # Create folders Structure that contain the exported information to TXT and HTML files
  399. #---------------------------------------------------------------------------------------------------
  400.  
  401. $A20 =    "C:\INFO\DKIM Record settings"
  402.  
  403. #---------------------------------------------------------------------------------------------------
  404. # Create the required folders in Drive C:
  405. #---------------------------------------------------------------------------------------------------
  406.  
  407. write-host  -ForegroundColor white      'Creating folder structure for storing information on C:\INFO\DKIM Record settings '   
  408.  
  409. if (!(Test-Path -path $A20))
  410. {New-Item $A20 -type directory}
  411.  
  412. #---------------------------------------------------------------------------------------------------
  413. # Export xxx to a files
  414. #---------------------------------------------------------------------------------------------------
  415.  
  416. write-host -ForegroundColor green  'Export  DKIM informaiton to a files - File Format - HTML + TEXT'
  417. write-host
  418.  
  419. ###TXT####
  420. Get-DkimSigningConfig $Domain | Format-list *CNAME | Out-File $A20\"information about the DKIM host name record for $Domain.txt" -Encoding utf8
  421. ##########
  422.  
  423. ###HTML####
  424. Get-DkimSigningConfig $Domain | Select-Object   Domain,Selector1CNAME,Selector2CNAME | ConvertTo-Html -head $Header -Body  "<H1>information about the DKIM host name record for $Domain   |  $Datef </H1>"  | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd | Out-File $A20\"information about the DKIM host name record for $Domain.htm"
  425. Add-Content $A20\"information about the DKIM host name record for $Domain.htm" $Selector1
  426. Add-Content $A20\"information about the DKIM host name record for $Domain.htm" $Selector2
  427. Add-Content $A20\"information about the DKIM host name record for $Domain.htm" $EndReport
  428. ##########
  429. #---------------------------------------------------------------------------------------------------
  430.  
  431.  
  432. # End the Command
  433. write-host
  434. write-host
  435. Read-Host "Press Enter to continue..."
  436. write-host
  437. write-host
  438.  
  439. }
  440.  
  441.  
  442.  
  443. 3
  444. {
  445.  
  446. ##########################################################################
  447. # View and Export information about the DKIM CNAME record synatx for a All Domain names
  448. ##########################################################################
  449.  
  450. # information
  451. checkConnection
  452.  
  453. clear-host
  454.  
  455. write-host
  456. write-host
  457. write-host  -ForegroundColor Magenta    oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                              
  458. write-host  -ForegroundColor white      Introduction                                                                                          
  459. write-host  -ForegroundColor white      --------------------------------------------------------------------------------------                                                              
  460. write-host  -ForegroundColor white      'This option will:  '
  461. write-host  -ForegroundColor white      'View and Export information about the DKIM CNAME record synatx for a All Domain names  '
  462. write-host  -ForegroundColor white      --------------------------------------------------------------------------------------  
  463. write-host  -ForegroundColor white      'The export command will:   '
  464. write-host  -ForegroundColor white      '1. Export the required information to the following path =>' -NoNewline;Write-Host ' C:\INFO\DKIM Record settings  ' -ForegroundColor Cyan  
  465. write-host  -ForegroundColor white      '2. Save all of the exported information to diffrent file formats: TXT and HTML. '
  466. write-host  -ForegroundColor white      'Note - Be patient, the operation can take a long time. '
  467. write-host  -ForegroundColor white      ------------------------------------------------------------------------------------------  
  468. write-host  -ForegroundColor white      'The PowerShell command that we use is: '
  469. write-host  -ForegroundColor Cyan       'Get-DkimSigningConfig | FL  Domain,Selector1CNAME,Selector2CNAME    '
  470. write-host  -ForegroundColor Magenta    oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                        
  471. write-host
  472.  
  473. # Display Information about Audit settings
  474.  
  475. write-host
  476. write-host -------------------------------------------------------------------------------------------------
  477. write-host -ForegroundColor white  -BackgroundColor Blue   Display information about DKIM host names: "$Domain".ToUpper()
  478. write-host -------------------------------------------------------------------------------------------------
  479. Get-DkimSigningConfig | Select-Object  $global:Array2 | Out-String
  480. write-host -------------------------------------------------------------------------------------------------
  481.  
  482. #---------------------------------------------------------------------------------------------------
  483. # Create folders Structure that contain the exported information to TXT and HTML files
  484. #---------------------------------------------------------------------------------------------------
  485.  
  486. $A20 =    "C:\INFO\DKIM Record settings"
  487.  
  488. #---------------------------------------------------------------------------------------------------
  489. # Create the required folders in Drive C:
  490. #---------------------------------------------------------------------------------------------------
  491.  
  492. write-host  -ForegroundColor white      'Creating folder structure for storing information on C:\INFO\DKIM\All Domains '   
  493.  
  494. if (!(Test-Path -path $A20))
  495. {
  496. New-Item $A20 -type directory
  497. }
  498.  
  499. #---------------------------------------------------------------------------------------------------
  500. # Export Information about DKIM DNS record syntax to files
  501. #---------------------------------------------------------------------------------------------------
  502.  
  503. write-host -ForegroundColor green  'Export  DKIM informaiton to a files - File Format - HTML + TEXT'
  504. write-host
  505.  
  506. ###TXT####
  507. Get-DkimSigningConfig | Format-List *CNAME | Out-File $A20\"Information about the DKIM host name record for for ALL Domain names.txt" -Encoding utf8
  508. ##########
  509.  
  510. ###HTML####
  511. Get-DkimSigningConfig |  Select-Object  $global:Array2 | ConvertTo-Html -post $EndReport -head $Header -Body  "<H1>Information about the DKIM host name record for for ALL Domain names  |  $Datef </H1>"  | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd | Out-File $A20\"Information about the DKIM host name record for for ALL Domain names.htm"
  512. ##########
  513.  
  514. #---------------------------------------------------------------------------------------------------
  515.  
  516.  
  517.  
  518.  
  519. #---------------------------------------------------------------------------------------------------
  520. #
  521. #---------------------------------------------------------------------------------------------------
  522.  
  523. ###TXT####
  524. Get-DkimSigningConfig | Format-List *CNAME | Out-File $A20\"Get-DkimSigningConfig for ALL Domain names.txt" -Encoding utf8
  525. ##########
  526.  
  527. ###HTML####
  528. Get-DkimSigningConfig | ConvertTo-Html -post $EndReport -head $Header -Body  "<H1>Get-DkimSigningConfig for ALL Domain names   |  $Datef </H1>"  | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd | Out-File $A20\"Get-DkimSigningConfig for ALL Domain names.htm"
  529. ##########
  530.  
  531. #---------------------------------------------------------------------------------------------------
  532.  
  533.  
  534. #Section 5: End the Command
  535. write-host
  536. write-host
  537. Read-Host "Press Enter to continue..."
  538. write-host
  539. write-host
  540.  
  541. }
  542.  
  543.  
  544. #=========================================================================================
  545. # SECTION B:  Disable DKIM signing policy
  546. #=========================================================================================
  547.  
  548. 4
  549. {
  550.  
  551. ##########################################################################
  552. # Disable the DKIM signing policy for a specific Domain name
  553. ##########################################################################
  554.  
  555. # information
  556. checkConnection
  557.  
  558. clear-host
  559.  
  560. write-host
  561. write-host
  562. write-host  -ForegroundColor Magenta    oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                              
  563. write-host  -ForegroundColor white      Introduction                                                                                          
  564. write-host  -ForegroundColor white      --------------------------------------------------------------------------------------                                                              
  565. write-host  -ForegroundColor white      'This option will:  '
  566. write-host  -ForegroundColor white      'Disable the DKIM signing policy for a specific Domain name'
  567. write-host  -ForegroundColor white      ------------------------------------------------------------------------------------------  
  568. write-host  -ForegroundColor white      'The PowerShell command that we use is: '
  569. write-host  -ForegroundColor Cyan       'Set-DkimSigningConfig -Identity <Domain name> -Enabled $False '
  570. write-host  -ForegroundColor Magenta    oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                        
  571. write-host
  572.  
  573.  
  574. # Display Information about DKIM settings for each existing Domain
  575.  
  576. write-host
  577. write-host -------------------------------------------------------------------------------------------------
  578. write-host -ForegroundColor white  -BackgroundColor Blue   Display Information about DKIM settings for each existing Domain
  579. write-host -------------------------------------------------------------------------------------------------
  580. Get-DkimSigningConfig | Format-List  Domain  | Out-String
  581. write-host -------------------------------------------------------------------------------------------------
  582.  
  583.  
  584.  
  585. # User input   
  586.  
  587. write-host -ForegroundColor white   'User input '
  588. write-host -ForegroundColor white   ----------------------------------------------------------------------------
  589. write-host -ForegroundColor Yellow  "You will need to provide 1 parameter:"  
  590. write-host
  591. write-host -ForegroundColor Yellow  "1.  Doamin name"
  592. write-host -ForegroundColor Yellow  "This is the name of the Domain for which you asking to Disable DKIM signature"  
  593. write-host -ForegroundColor Yellow  "For example:  o365info.com"
  594. write-host
  595. $Domain  = Read-Host "Type the The Doamin name "
  596. write-host
  597. write-host
  598.  
  599. # Display Information about DKIM settings for Specific Domain name  |=> BEFORE the update
  600.  
  601. write-host
  602. write-host -------------------------------------------------------------------------------------------------
  603. write-host -ForegroundColor white  -BackgroundColor Blue   Display information about: "$Domain".ToUpper() policy => BEFORE the update
  604. write-host -------------------------------------------------------------------------------------------------
  605. Get-DkimSigningConfig $Domain | Select-Object  $global:Array1  | Out-String
  606. write-host -------------------------------------------------------------------------------------------------
  607.  
  608. # PowerShell Command
  609.  
  610. Set-DkimSigningConfig -Identity $Domain -Enabled $False
  611.  
  612. # Display Information about DKIM settings for Specific Domain name | => AFTER the update
  613.  
  614. write-host
  615. write-host -------------------------------------------------------------------------------------------------
  616. write-host -ForegroundColor white  -BackgroundColor Blue   Display information about: "$Domain".ToUpper() policy => AFTER the update
  617. write-host -------------------------------------------------------------------------------------------------
  618. Get-DkimSigningConfig $Domain | Select-Object  $global:Array1  | Out-String
  619. write-host -------------------------------------------------------------------------------------------------
  620.  
  621. #Section 5: End the Command
  622. write-host
  623. write-host
  624. Read-Host "Press Enter to continue..."
  625. write-host
  626. write-host
  627.  
  628. }
  629.  
  630.  
  631.  
  632. #=========================================================================================
  633. # SECTION C:  Enable DKIM signing policy
  634. #=========================================================================================
  635.  
  636. 5
  637. {
  638.  
  639. ##########################################################################
  640. # Enable the DKIM signing policy for a specific Domain name
  641. ##########################################################################
  642.  
  643. # information
  644. checkConnection
  645.  
  646. clear-host
  647.  
  648. write-host
  649. write-host
  650. write-host  -ForegroundColor Magenta    oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                              
  651. write-host  -ForegroundColor white      Introduction                                                                                          
  652. write-host  -ForegroundColor white      --------------------------------------------------------------------------------------                                                              
  653. write-host  -ForegroundColor white      'This option will:  '
  654. write-host  -ForegroundColor white      'Enable the DKIM signing policy for a specific Domain name '
  655. write-host  -ForegroundColor white      ------------------------------------------------------------------------------------------  
  656. write-host  -ForegroundColor white      'The PowerShell command that we use is: '
  657. write-host  -ForegroundColor Cyan       'Set-DkimSigningConfig -Identity <Domain name> -Enabled $True '
  658. write-host  -ForegroundColor Magenta    oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                        
  659. write-host
  660.  
  661.  
  662. # Display Information about DKIM settings for each existing Domain
  663.  
  664. write-host
  665. write-host -------------------------------------------------------------------------------------------------
  666. write-host -ForegroundColor white  -BackgroundColor Blue   Display Information about DKIM settings for each existing Domain
  667. write-host -------------------------------------------------------------------------------------------------
  668. Get-DkimSigningConfig | Format-List  Domain  | Out-String
  669. write-host -------------------------------------------------------------------------------------------------
  670.  
  671.  
  672. # User input   
  673.  
  674. write-host -ForegroundColor white   'User input '
  675. write-host -ForegroundColor white   ----------------------------------------------------------------------------
  676. write-host -ForegroundColor Yellow  "You will need to provide 1 parameter:"  
  677. write-host
  678. write-host -ForegroundColor Yellow  "1.  Doamin name"
  679. write-host -ForegroundColor Yellow  "This is the name of the Domain for which you asking to Enable DKIM signature"  
  680. write-host -ForegroundColor Yellow  "For example:  o365info.com"
  681. write-host
  682. $Domain  = Read-Host "Type the The Doamin name "
  683. write-host
  684. write-host
  685.  
  686. # Display Information about DKIM settings for Specific Domain name  |=> BEFORE the update
  687.  
  688. write-host
  689. write-host -------------------------------------------------------------------------------------------------
  690. write-host -ForegroundColor white  -BackgroundColor Blue   Display information about: "$Domain".ToUpper() policy => BEFORE the update
  691. write-host -------------------------------------------------------------------------------------------------
  692. Get-DkimSigningConfig $Domain | Select-Object  $global:Array1  | Out-String
  693. write-host -------------------------------------------------------------------------------------------------
  694.  
  695.  
  696. # PowerShell Command
  697.  
  698. Set-DkimSigningConfig -Identity $Domain -Enabled $True
  699.  
  700. # Display Information about DKIM settings for Specific Domain name | => AFTER the update
  701.  
  702. write-host
  703. write-host -------------------------------------------------------------------------------------------------
  704. write-host -ForegroundColor white  -BackgroundColor Blue   Display information about: "$Domain".ToUpper() policy => AFTER the update
  705. write-host -------------------------------------------------------------------------------------------------
  706. Get-DkimSigningConfig $Domain | Select-Object  $global:Array1  | Out-String
  707. write-host -------------------------------------------------------------------------------------------------
  708.  
  709. # End the Command
  710. write-host
  711. write-host
  712. Read-Host "Press Enter to continue..."
  713. write-host
  714. write-host
  715.  
  716. }
  717.  
  718.  
  719.  
  720.  
  721.  
  722. #=========================================================================================
  723. # SECTION D: Create DKIM selectors configuration in Exchange Online
  724. #=========================================================================================
  725.  
  726. 6
  727. {
  728.  
  729. ##########################################################################
  730. # Enable the DKIM signing policy for a specific Domain name
  731. ##########################################################################
  732.  
  733. # information
  734. checkConnection
  735.  
  736. clear-host
  737.  
  738. write-host
  739. write-host
  740. write-host  -ForegroundColor Magenta    oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                              
  741. write-host  -ForegroundColor white      Introduction                                                                                          
  742. write-host  -ForegroundColor white      --------------------------------------------------------------------------------------                                                              
  743. write-host  -ForegroundColor white      'This option will:  '
  744. write-host  -ForegroundColor white      'Enable the DKIM signing policy for a specific Domain name'
  745. write-host  -ForegroundColor white      ------------------------------------------------------------------------------------------  
  746. write-host  -ForegroundColor white      'The PowerShell command that we use is: '
  747. write-host  -ForegroundColor Cyan       'New-DkimSigningConfig -DomainNam <Domain name> -Enabled $True '
  748. write-host  -ForegroundColor Magenta    oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo                                        
  749. write-host
  750.  
  751.  
  752. # Display Information about DKIM settings for each existing Domain
  753.  
  754. write-host
  755. write-host -------------------------------------------------------------------------------------------------
  756. write-host -ForegroundColor white  -BackgroundColor Blue   Display Information about DKIM settings for each existing Domain
  757. write-host -------------------------------------------------------------------------------------------------
  758. Get-DkimSigningConfig | Format-List  Domain  | Out-String
  759. write-host -------------------------------------------------------------------------------------------------
  760.  
  761.  
  762. # User input   
  763.  
  764. write-host -ForegroundColor white   'User input '
  765. write-host -ForegroundColor white   ----------------------------------------------------------------------------
  766. write-host -ForegroundColor Yellow  "You will need to provide 1 parameter:"  
  767. write-host
  768. write-host -ForegroundColor Yellow  "1.  Doamin name"
  769. write-host -ForegroundColor Yellow  "This is the name of the Domain for which you asking to  Create DKIM selectors configuration in Exchange Online "  
  770. write-host -ForegroundColor Yellow  "For example:  o365info.com"
  771. write-host
  772. $Domain  = Read-Host "Type the The Doamin name "
  773. write-host
  774. write-host
  775.  
  776. # Display Information about DKIM settings for Specific Domain name  |=> BEFORE the update
  777.  
  778. write-host
  779. write-host -------------------------------------------------------------------------------------------------
  780. write-host -ForegroundColor white  -BackgroundColor Blue   Display information about: "$Domain".ToUpper() policy => BEFORE the update
  781. write-host -------------------------------------------------------------------------------------------------
  782. Get-DkimSigningConfig $Domain | Select-Object  $global:Array1  | Out-String
  783. write-host -------------------------------------------------------------------------------------------------
  784.  
  785.  
  786. # PowerShell Command
  787.  
  788. New-DkimSigningConfig -DomainName $Domain
  789.  
  790. # Display Information about DKIM settings for Specific Domain name | => AFTER the update
  791.  
  792. write-host
  793. write-host -------------------------------------------------------------------------------------------------
  794. write-host -ForegroundColor white  -BackgroundColor Blue   Display information about: "$Domain".ToUpper() policy => AFTER the update
  795. write-host -------------------------------------------------------------------------------------------------
  796. Get-DkimSigningConfig $Domain | Select-Object  $global:Array1  | Out-String
  797. write-host -------------------------------------------------------------------------------------------------
  798.  
  799. # End the Command
  800. write-host
  801. write-host
  802. Read-Host "Press Enter to continue..."
  803. write-host
  804. write-host
  805.  
  806. }
  807.  
  808.  
  809.  
  810.  
  811. #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  812. # Section END
  813. #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  814.  
  815.  
  816. #+++++++++++++++++++
  817. # Step -05 Finish  
  818. ##++++++++++++++++++
  819.  
  820.    
  821. 20{
  822.  
  823. ##########################################
  824. # Disconnect PowerShell session  
  825. ##########################################
  826.  
  827.  
  828. write-host -ForegroundColor Yellow Choosing this option will Disconnect the current PowerShell session
  829.  
  830. Disconnect-ExchangeOnline
  831.  
  832. write-host
  833. write-host
  834.  
  835. #———— Indication ———————
  836.  
  837. if ($lastexitcode -eq 0)
  838. {
  839. write-host -------------------------------------------------------------
  840. write-host "The command complete successfully !" -ForegroundColor Yellow
  841. write-host "The PowerShell session is disconnected" -ForegroundColor Yellow
  842. write-host -------------------------------------------------------------
  843. }
  844. else
  845.  
  846. {
  847. write-host "The command Failed :-(" -ForegroundColor red
  848.  
  849. }
  850.  
  851. #———— End of Indication ———————
  852.  
  853.  
  854. }
  855.  
  856.  
  857.  
  858.  
  859. 21
  860. {
  861.  
  862. ##########################################
  863. # Exit  
  864. ##########################################
  865.  
  866.  
  867. $Loop = $true
  868. Exit
  869. }
  870.  
  871. }
  872.  
  873.  
  874. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement