├── LICENSE ├── README.md ├── RobustCloudCommand.psd1 └── RobustCloudCommand.psm1 /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Canthv0 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Start-RobustCloudCommand 2 | 3 | ## Recommended Install 4 | Start-RobustCloudCommand is published to the PowershellGallery and should be installed from there. 5 | https://www.powershellgallery.com/packages/RobustCloudCommand 6 | 7 | Install-Module -Name RobustCloudCommand 8 | 9 | ## Manual Install 10 | If the client doesn't have access to the internet directly then: 11 | 12 | * Download the module from https://github.com/Canthv0/RobustCloudCommand/releases 13 | * Extract the Zip file to a known location 14 | * From powershell in the extracted path run `Import-Module robustcloudcommand.psd1` 15 | * Change to a different directory than the one with the psd1 file 16 | 17 | ## Synopsis 18 | Generic wrapper script that tries to ensure that a script block successfully finishes execution in O365 against a large object count. 19 | 20 | Works well with intense operations that may cause throttling 21 | 22 | ## Description 23 | Wrapper script that tries to ensure that a script block successfully finishes execution in O365 against a large object count. 24 | 25 | It accomplishes this by doing the following: 26 | * Monitors the health of the Remote powershell session and restarts it as needed. 27 | * Restarts the session every X number seconds to ensure a valid connection. 28 | * Attempts to work past session related errors and will skip objects that it can't process. 29 | * Attempts to calculate throttle exhaustion and sleep a sufficient time to allow throttle recovery 30 | 31 | ## Cmdlet Options 32 | 33 | Switch | Description|Default 34 | -------|-------|------- 35 | AutomaticThrottle|Value used to calculate time needed for throttle recovery|0.25 36 | IdentifyingProperty|Property on recipient objects to identity the object in the log|"DisplayName","Name","Identity",
"PrimarySMTPAddress","Alias","GUID" 37 | LogFile|Location and name of logfile|NA 38 | ManualThrottle|Set number of seconds to delay between loops|None 39 | NonInteractive|Suppresses screen output|False 40 | Recipients|Collection of Objects to operate on|NA 41 | ResetSeconds|Number of seconds between session rebuild|870 42 | ScriptBlock|Operation to run on provided objects|NA 43 | UserPrincipalName|UPN of the user that will be connecting to Exchange online.|NA 44 | 45 | ## Outputs 46 | Creates the log file specified in -logfile. 47 | Contains a record of all actions taken by the script. 48 | 49 | ## Example 1 50 | ``` 51 | invoke-command -scriptblock {Get-mailbox -resultsize unlimited | select-object -property Displayname,PrimarySMTPAddress,Identity} -session (get-pssession) | export-csv c:\temp\mbx.csv 52 | $mbx = import-csv c:\temp\mbx.csv 53 | $cred = get-Credential 54 | .\Start-RobustCloudCommand.ps1 -Credential $cred -recipients $mbx -logfile C:\temp\out.log -ScriptBlock {Set-Clutter -identity $input.PrimarySMTPAddress.tostring() -enable:$false} 55 | ``` 56 | 57 | Gets all mailboxes from the service returning only Displayname,Identity, and PrimarySMTPAddress. Exports the results to a CSV 58 | Imports the CSV into a variable 59 | Gets your O365 Credential 60 | Executes the script setting clutter to off using Legacy Credentials 61 | 62 | ## Example 2 63 | ``` 64 | invoke-command -scriptblock {Get-mailbox -resultsize unlimited | select-object -property Displayname,PrimarySMTPAddress,Identity} -session (get-pssession) | export-csv c:\temp\recipients.csv 65 | $recipients = import-csv c:\temp\recipients.csv 66 | Start-RobustCloudCommand -recipients $recipients -logfile C:\temp\out.log -ScriptBlock {Get-MobileDeviceStatistics -mailbox $input.PrimarySMTPAddress.tostring() | Select-Object -Property @{Name = "PrimarySMTPAddress";Expression={$input.PrimarySMTPAddress.tostring()}},DeviceType,LastSuccessSync,FirstSyncTime | Export-Csv c:\temp\stats.csv -Append } 67 | ``` 68 | 69 | Gets All Recipients and exports them to a CSV (for restart ability) 70 | Imports the CSV into a variable 71 | Executes the script to gather EAS Device statistics and output them to a csv file using ADAL with support for MFA -------------------------------------------------------------------------------- /RobustCloudCommand.psd1: -------------------------------------------------------------------------------- 1 | # 2 | # Module manifest for module 'StartRobustCloudCommand' 3 | # 4 | # Generated by: matbyrd 5 | # 6 | # Generated on: 5/8/2019 7 | # 8 | 9 | @{ 10 | 11 | # Script module or binary module file associated with this manifest. 12 | RootModule = '.\RobustCloudCommand.psm1' 13 | 14 | # Version number of this module. 15 | ModuleVersion = '2.1.0' 16 | 17 | # Supported PSEditions 18 | # CompatiblePSEditions = @() 19 | 20 | # ID used to uniquely identify this module 21 | GUID = 'da2c264a-562e-427a-906c-61d85163b321' 22 | 23 | # Author of this module 24 | Author = 'matbyrd@microsoft.com' 25 | 26 | # Company or vendor of this module 27 | CompanyName = 'Matthew Byrd' 28 | 29 | # Copyright statement for this module 30 | Copyright = '(c) 2019 matbyrd@microsoft.com All rights reserved.' 31 | 32 | # Description of the functionality provided by this module 33 | Description = ' 34 | Generic wrapper script that tries to ensure that a script block successfully finishes execution in O365 against a large object count. 35 | 36 | Works well with intense operations that may cause throttling' 37 | 38 | # Minimum version of the Windows PowerShell engine required by this module 39 | PowerShellVersion = '5.0' 40 | 41 | # Name of the Windows PowerShell host required by this module 42 | # PowerShellHostName = '' 43 | 44 | # Minimum version of the Windows PowerShell host required by this module 45 | # PowerShellHostVersion = '' 46 | 47 | # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. 48 | # DotNetFrameworkVersion = '' 49 | 50 | # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. 51 | # CLRVersion = '' 52 | 53 | # Processor architecture (None, X86, Amd64) required by this module 54 | # ProcessorArchitecture = '' 55 | 56 | # Modules that must be imported into the global environment prior to importing this module 57 | RequiredModules = @(@{ModuleName = 'ExchangeOnlineManagement'; ModuleVersion = '2.0.4'; }) 58 | 59 | # Assemblies that must be loaded prior to importing this module 60 | # RequiredAssemblies = @() 61 | 62 | # Script files (.ps1) that are run in the caller's environment prior to importing this module. 63 | # ScriptsToProcess = @() 64 | 65 | # Type files (.ps1xml) to be loaded when importing this module 66 | # TypesToProcess = @() 67 | 68 | # Format files (.ps1xml) to be loaded when importing this module 69 | # FormatsToProcess = @() 70 | 71 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 72 | # NestedModules = @() 73 | 74 | # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. 75 | FunctionsToExport = 'Start-RobustCloudCommand' 76 | 77 | # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. 78 | CmdletsToExport = @() 79 | 80 | # Variables to export from this module 81 | # VariablesToExport = '*' 82 | 83 | # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. 84 | AliasesToExport = @() 85 | 86 | # DSC resources to export from this module 87 | # DscResourcesToExport = @() 88 | 89 | # List of all modules packaged with this module 90 | # ModuleList = @() 91 | 92 | # List of all files packaged with this module 93 | # FileList = @() 94 | 95 | # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. 96 | PrivateData = @{ 97 | 98 | PSData = @{ 99 | 100 | # Tags applied to this module. These help with module discovery in online galleries. 101 | Tags = @('O365', 'Exchange', 'Online', 'Batch', 'Bulk', 'Throttle', 'Robust') 102 | 103 | # A URL to the license for this module. 104 | LicenseUri = 'https://github.com/Canthv0/RobustCloudCommand/blob/master/LICENSE' 105 | 106 | # A URL to the main website for this project. 107 | ProjectUri = 'https://github.com/Canthv0/RobustCloudCommand' 108 | 109 | # A URL to an icon representing this module. 110 | # IconUri = '' 111 | 112 | # ReleaseNotes of this module 113 | ReleaseNotes = ' 114 | 2.0.1 - Corrected and issue with -showbanner in connect-exchnageonline not being properly interprted 115 | 2.0.0 - Added new mandatory switch -UserPrincipalName 116 | 2.0.0 - Added dependancy on ExchangeOnlineManagement module 2.0.4 and higher 117 | 2.0.0 - Remove dependency on legacy module cloudconnect 118 | ' 119 | 120 | } # End of PSData hashtable 121 | 122 | } # End of PrivateData hashtable 123 | 124 | # HelpInfo URI of this module 125 | # HelpInfoURI = '' 126 | 127 | # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. 128 | # DefaultCommandPrefix = '' 129 | 130 | } 131 | 132 | -------------------------------------------------------------------------------- /RobustCloudCommand.psm1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Canthv0/RobustCloudCommand/2bb5897c184399d516cdf82a9981173e6e2026b7/RobustCloudCommand.psm1 --------------------------------------------------------------------------------