[PS][EX2010] E-mails Recieved per day of Month Report
.Synopsis
E-mail Counting Script v1 by ELAU 10/10/19
– Script counts emails received for each day of the current month
.DESCRIPTION
– Script pulls days of the month and counts number of emails received for each day of the current month or days specified into a HTML report.
– Script allows option to e-mail report
.EXAMPLE
– Run count.ps1 without parameters will prompt for required options
.EXAMPLE
– Specify days to go back without sending email report
count.ps1 -mailbox <mailbox to search> -day <days to search back from today>
.EXAMPLE
– Specify days to go back with sending email report
count.ps1 -mailbox <mailbox to search> -day <days to search back from today> -emailto <report to send to>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
<# .Synopsis E-mail Counting Script v1 by EPIC 10/10/19 - Script counts emails received for each day of the current month .DESCRIPTION - Script pulls days of the month and counts number of emails received for each day of the current month or days specified into a HTML report. - Script allows option to e-mail report .EXAMPLE - Run count.ps1 without parameters will prompt for required options .EXAMPLE - Specify days to go back count.ps1 -mailbox <mailbox to search> -day <days to search back from today> .EXAMPLE - Specify days to go back and email report count.ps1 -mailbox <mailbox to search> -day <days to search back from today> -emailto <report to send to> #> # Parameters Param( [Parameter(position=1)] [string]$mailbox, [Parameter(position=2)] [string]$day, [Parameter(position=3)] [string]$emailto ) # Setup Variables $smtpServer = "smtpserver.com" $emailFrom = "from@address.com" $subject = "Recieved e-mails per day" $Path = "c:\temp\test.html" [INT]$year = (Get-date).ToString("yy") [INT]$month = (Get-date).ToString("MM") $monthheader = (Get-date).ToString("MMMM,yyyy") # Prompts for input if no parmeters provided if (!$day) { [INT]$day = (Get-date).ToString("dd") [INT]$days = [datetime]::DaysInMonth($year,$month) } if (!$mailbox) { $mailbox = Read-Host -Prompt "Mailbox to Search (user@firstrepublic.com)" } If ($emailto) { $email = "sure" } elseif (!$emailto) { $email = Read-Host -Prompt "E-mail Report : Yes or No" while("yes","no" -notcontains $email) { $email = Read-Host -Prompt "E-mail Report : Yes or No" } } if ($email -eq "yes") { $emailTo = Read-Host -Prompt "E-mail to send Report (user@firstrepublic.com)" } #HTML HEADER $head = @" <title>E-mail Report</title> <style type="text/css"> table, td { border: 1px solid black; border-collapse:collapse;} tr:nth-child(odd) { background-color:lightgrey; } th { color:black; text-align:left; border: 1px solid black; font:normal 16px verdana, arial, helvetica, sans-serif; font-weight:bold; background-color: #6495ED; padding-left:6px; padding-right:6px; } </style> "@ # HTML TABLE HEADER $body += @" <table> <tr><th colspan="2">$monthheader - $mailbox</th></tr> <tr> <td>Date</td> <td>E-mails Recieved</td> </tr> "@ # Performs the search and adds HTML ROWs $i=1 Do { $start = ((get-date -hour 0 -Minute 0 -Second 0).adddays(-($day-$i+1))) $shortstart = ((get-date).adddays(-($day-$i+1)).ToString("MM-dd-yyyy")) $end = ((get-date -hour 0 -Minute 0 -Second 0).adddays(-($day-($i)))) $emails = Get-TransportServer | Get-MessageTrackingLog -ResultSize Unlimited -Start $start -End $end -EventId "Receive" -Recipient $mailbox $count = ($emails | Measure-Object).count $body += @" <tr> <td>$shortstart</td> <td>$count</td> </tr> "@ $i++ } While ($i -le $day) # HTML FOOTER $body += @" </table> "@ # Add HTML together and ouputs report $HTML = $head + $body $HTML | Out-File $Path # Sends e-mail if email is requested if ($email -eq "yes" -or $email -eq "sure") { Send-MailMessage -From $emailFrom -To $emailTo -Subject $Subject -Body $HTML -BodyAsHtml -SmtpServer $smtpServer -EA Stop 2>> $errorlog } |
[PS] [EX2010] Recoverable Folder Size Report
Recoverable Folder Size Report v1
- Crawls all mailboxes and pulls the recoverableitemsquota size
- Displays top 10 in HTML report
- Full CSV report is generated
- E-mails report with full report
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# Setup E-mail Parameters $smtpServer = "host.server.com" $emailFrom = "from@address.com" $emailTo = @('<to@address.com>') $subject = "Top Recoverable Folder Size - $date" $output = "c:\temp\output.csv" #Import Exchange 2010 Module Add-PSSnapin Microsoft.Exchange.Management.Powershell.E2010 -ErrorAction SilentlyContinue #Setup Variables [INT] $RQ = 0 [INT] $RW = 0 [INT] $DIQ = "30" [INT] $DIW = "20" $Path = "c:\temp\test.html" # #Exclusion #Check if all Database Quota matches default $Q = @(Get-mailboxdatabase | foreach {$_.recoverableitemsquota.value.tobytes()/1Gb}) foreach ($IQ in $Q) { If ($IQ -notmatch "$DIQ") { write-host $IQ + "is not set to default settings" $RQ++ } } If ($RQ -ge 1) { echo "default is not set for 1 or more mailboxes"} #Check if all Database Quota matches warning default $W = @(Get-mailboxdatabase | foreach {$_.RecoverableItemsWarningQuota.value.tobytes()/1Gb}) foreach ($IW in $W) { If ($IW -notmatch "$DIW") { write-host $IW + "is not set to default settings" $RW++ } } If ($RW -ge 1) { echo "storage default is not set for 1 or more mailboxes"} $sort = @() $output = "c:\temp\output.csv" $mailboxes = Get-mailbox -resultsize unlimited Foreach ($m in $mailboxes) { $size = Get-MailboxFolderStatistics $m -FolderScope RecoverableItems | ?{$_.Identity -match "Recoverable Items"} $sort = New-Object psobject -Property @{ mailbox = $m.alias mailboxdn = $m.distinguishedname recoversize = [math]::round($size.folderandsubfoldersize.tobytes() /1Gb, 3) } $sort | Export-Csv c:\temp\output.csv -notypeinformation -append $sort ="" } $output = "c:\temp\output.csv" $mailboxesorted = import-csv $output | sort-Object {[INT]$_.recoversize} -Descending | select -First 10 $DiskDetailHTML += "<table>" $DiskDetailHTML += "<tr><th>Mailbox</th><th>Mailbox Database</th><th>Mailbox ARC</th><th>Litigation Hold</th><th>Recoverablesize</th><th width=""400px"">Usage</th></tr>`n" #loop through all mailboxes Foreach ($mbx in $mailboxesorted) { $mbxinfo = get-mailbox $mbx.mailboxdn #grab recoverable folder stats $stat = Get-MailboxFolderStatistics $mbxinfo -FolderScope RecoverableItems | ?{$_.Identity -match "Recoverable Items"} #DB $db = $mbxinfo.database #ARC $arcdb = $mbxinfo.archivedatabase #LIT $lit = $mbxinfo.litigationholdenabled #recoveravle folder size to GB $calcrsize = $stat.folderandsubfoldersize.tobytes()/1GB $rsize = ($calcrsize).ToString("#.#######") $alias = $mbxinfo.alias #percentage $calcpercent = ($rsize/$diq) $percent = ($calcpercent).ToString("P") -replace '\s','' $fpercent = (1-$calcpercent).ToString("P") -replace '\s','' if ($percent -lt 0.01) { # $DiskDetailHTML += "<TR> <TD>$alias</TD> <TD>$db</TD> <TD>$arcdb</TD> <TD>$lit</TD> <TD>$rsize GB</TD> <TD> <table width=""100%""> <tr> <td width=""100%"" bgcolor=""green"" align=""Center"">$fpercent</td> </tr> </table> </td></tr>`n" } else { $DiskDetailHTML += "<TR> <TD>$alias</TD> <TD>$db</TD> <TD>$arcdb</TD> <TD>$lit</TD> <TD>$rsize GB</TD> <TD> <table width=""100%""> <tr> <td width=""$percent"" bgcolor=""Red"" align=""Center"">$percent</td> <td width=""$fpercent"" bgcolor=""green"" align=""Center"">$fpercent</td> </tr> </table> </td></tr>`n" # } } #Define static HTML $HeaderHTML = @" <html> <head> <style type='text/css'> body { background-color:#DCDCDC; } table { border:1px solid gray; font:normal 12px verdana, arial, helvetica, sans-serif; border-collapse: collapse; padding-left:30px; padding-right:30px; } th { color:black; text-align:left; border: 1px solid black; font:normal 16px verdana, arial, helvetica, sans-serif; font-weight:bold; background-color: #6495ED; padding-left:6px; padding-right:6px; } td { border: 1px solid black; padding-left:6px; padding-right:6px; } a.detail { cursor:pointer; color:#1E90FF; text-decoration:underline; } </style> </head> <body> <h1>Recoverable Folder Size Report</h1> <p> "@ #Define Footer HTML $FooterHTML = @" </table> </div> </body> </html> "@ #Combine all the HTML fragments and save to a file $HTML = $HeaderHTML + $DiskDetailHTML + $FooterHTML $HTML | Out-File $Path #> Send-MailMessage -From $emailFrom -To $emailTo -Subject $Subject -Attachment $output -Body $HTML -BodyAsHtml -SmtpServer $smtpServer -EA Stop 2>> $errorlog |
[EXCH] Event ID: 9646 User exceeded the maximum of 500 objects of type “objtFolder”.
Shared mailboxes setup in cache mode will download entire content of the mailbox and will register every folder in each cached mailbox toward the objtFolder type limit on the server that’s running Exchange Server. By default, objtFolder limit is set to 500 per-mailbox limit. Once the limit is exhausted, user will start experiencing the symptoms below:
Symptoms:
– Inbox does not update automatically.
– Folder status bar shows “This folder was last updated on …” instead of “All folders are up to date” message displayed.
– Viewing items in secondary mailbox, new folders and items may not appear or seem to be missing.
– Deleted items still appear in the secondary mailbox like shadow items.
– Degraded performance or random hangs.
Exchange Server (Application log) – Error shows:
Event ID: 9646
Type: Error
Source: MSExchangeIS
Description:
Mapi session “/o=First Organization/ou=Administrative Group/cn=Recipients/cn=user”
exceeded the maximum of 500 objects of type “objtFolder”.
Solution 1: Disable Automap and seperate OST for caching (Preferred method)
1. Remove mailbox permissions
Remove-MailboxPermission -Identity <Mailbox ID1> -User <Mailbox ID2> -AccessRights FullAccess
2. Readd shared mailbox permissions without Automatpping
Add-MailboxPermission -Iden
tity <Mailbox ID1> -User <Mailbox ID2>-AccessRights FullAccess -AutoMapping:$false
3. Readd Mailbox from Mail item in Control Panel.
4.Select your profile, and then click Properties.
5.Click E-mail Accounts.
6.On the E-mail tab of the Account Settings dialog box, click New.
7.In the Choose Service section of the Add New Account dialog box, click E-mail Account, and then click Next.
8. Fill in the e-mail with the shard mailbox
9.Click Finish, click Close, click Close, and then click OK.
10.Start Outlook.
Solution 2: Disable caching of all shared folders (placing shared mailbox in Online Mode)
1.On the File tab, click Account Settings in the Account Settings list.
2.In the Account Settings dialog box, click the E-mail tab and then double-click your Microsoft Exchange Server account.
3.In the Change Account dialog box, click More Settings.
4.In the Microsoft Exchange dialog box, click the Advanced tab.
5.Click to clear the Download shared folders check box.
6.Click OK two times.
7.Click Next, click Finish, and then click Close.
8.Restart Outlook.
Solution 3: Increase the objtFolder count using Registry Key
. Open Registry Editor and navigate to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MSExchangeIS
2. Right click ParametersSystem and create New -> Key
3. Enter MaxObjsPerMapiSession and confirm creation of the new sub-key
4. Right click newly created key, create new DWORD value called objtFolder and give it a decimal value bigger than default 500.
5. Create another DWORD value called objtFolderView and give it the same value.
References:
- https://support.microsoft.com/en-us/help/3115602/performance-and-synchronization-problems-when-you-work-with-folders-in
- https://support.microsoft.com/en-us/help/2646504/how-to-remove-automapping-for-a-shared-mailbox-in-office-365
- https://exutils.blogspot.com/2011/06/exceeded-maximum-of-750-objects-of-type.html
[EX2010][PS] Recover mail items from Exchange
How do I recover an item after its been deleted? So long as the recoverable items purge duration has not exceeded, you can run the below command to pull e-mails.
For more specific searchquery, reference Advanced Query Syntax (AQS).
1 2 3 4 5 6 7 8 |
#type search example Search-mailbox -identity <guid> -SearchQuery 'kind:<type>' -SearchDumpsterOnly -TargetMailbox "<destination mailbox>" -TargetFolder "<destination folder>" -loglevel full $multiple criteria search example: Search-mailbox -identity <guid> -SearchQuery 'kind:<type> AND subject "<subject>"' -SearchDumpsterOnly -TargetMailbox "<destination mailbox>" -TargetFolder "<destination folder>" -loglevel full |
- Meetings
- Tasks
- Notes
- Docs
- Journals
- Contacts
- IM
[PS] Enable TLS 1.2 as default in Powershell
Check Supported protocol
[Net.ServicePointManager]::SecurityProtocol
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Change Net Frame to use TLS 1.2
Set-ItemProperty -Path ‘HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319’ -Name ‘SchUseStrongCrypto’ -Value ‘1’ -Type DWord
Set-ItemProperty -Path ‘HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319’ -Name ‘SchUseStrongCrypto’ -Value ‘1’ -Type DWord
[EX2010] Litigation Hold (Legal Hold)
Litigation Hold (Legal Hold)
Used to preserve mailbox and electronically stored information in anticipation of legal proceedings, investigations, and unspecified reasons. Organizations may be required to inform when a user is placed on litigation hold.
Specifications:
- Requires Discovery Management or Legal Hold Mgmt (RBAC) to place a mailbox in legal hold
- Option to enable or disable, no option in 2010 to set start and end dates
- Original copies are maintained when modified
- LitigationHoldDate and LitigationHoldOwner attribute is created when enabled
- Migration to O365: mailboxes on Litigation Hold are preserved after a mailbox is moved
Storage:
When a user deletes a folder other than in the Delete Items folder, the message is ‘moved’. When a user deletes from the Deleted Items folder or does a Shift+Delete (Permanent Deletion), the message disappears from the user’s view, is a ‘soft delete’ and moved to Purge sub-folder of the Recoverable Items folder (Recoverable Items folder is also known as the dumpster in previous versions of Exchange). Recoverable Items folder retains items configured on the mailbox database with a default of 14 days. If Litigation is not enabled, items are purged forever based on reaching the quota limit, or longer than the default or set period.
- Default Quota for Recoverable Items Folder, Warning: 20GB, Items: 30 GB
- MFA continues to process the mailbox
- Deleted items are moved retained in a hidden folder called, Recoverable Items (dumpster) with its own storage, and does not count toward the mailbox quota.
- Recoverable Items folder has 3 sub-folders:
- Deletions: Soft Deleted items are moved here, visible from Recoverable Deleted Items (Visible to users)
- Purges: Deleted items from the Recoverable Items are moved here. Deleted Items exceeding the delete item retention period configured on mailbox database or mailbox are also purged here by MFA. Litigation Hold prevents deletion of items from this folder when enabled. (Not visible to users)
- Versions: Original copies of mailbox items are copied here by process called copy on write, where in specific properties changes on the item will create a copy. (Not Visible to users)
Enable and Disabling Litigation Hold:
1 2 |
Set-Mailbox joe@contoso.com -LitigationHoldEnabled $true Set-Mailbox joe@contoso.com -LitigationHoldEnabled $false |
Checking Sizing for mailboxes in litigation hold:
1 |
Get-Mailbox -ResultSize Unlimited -Filter {LitigationHoldEnabled -eq $true} | Get-MailboxFolderStatistics –FolderScope RecoverableItems | Format-Table Identity,FolderAndSubfolderSize -Auto |
Updating the Size for Recoverable Items when quota is reached:
1 |
Set-Mailbox “Mailbox User” –RecoverableItemsWarningQuota 40GB –RecoverableItemsQuota 50GB |
Processing all Mailboxes in litigation hold:
1 |
Get-Mailbox –Filter {LitigationHoldEnabled –eq $true} | Start-ManagedFolderAssistant |
References:
[PS] Write powershell errors to a text file
Method 1: Try, Catch, Finally
Try: Try to execute a command
Catch: Catches any errors, triggers only for Terminating Errors, so you may need to set a ErrorAction -Stop (EA) for errors that are not terminating.
Finally: Runs regardless if a error occurs.
1 2 3 |
Try { Set-Mailbox -Identity -PrimarySmtpAddress -EA STOP } Catch { $_ | Out-File C:\errors.txt -Append } Finally { Echo "runs no matter what"} |
Method 2: Output error directly to error log
1 |
Set-Mailbox -PrimarySmtpAddress <primarysmtpaddress> 2>> C:\errors.txt |
Method 3: Customize a out-file to a error log
1 2 3 |
"this occurred" | out-file c:\error.log -append $x | out-file c:\error.log -append ${get-date) | out-file c:\error.log -append |
[EXCH] The Cluster service cannot be started. Event ID 1090
1 |
The Cluster service cannot be started. An attempt to read configuration data from the Windows registry failed with error '2'. Please use the Failover Cluster Management snap-in to ensure that this machine is a member of a cluster. If you intend to add this machine to an existing cluster use the Add Node Wizard. Alternatively, if this machine has been configured as a member of a cluster, it will be necessary to restore the missing configuration data that is necessary for the Cluster Service to identify that it is a member of a cluster. Perform a System State Restore of this machine in order to restore the configuration data. |
- Check the Status of Mailbox Servers by running Get-DatabaseAvaliabilityGroup | FL
- Inspect servers in stopped and started state
- If a mailbox is in a stopped state, you can attempt to stop the individual server by running: Stop-DatabaseAvaliabilityGroup -identity <cluster> -mailboxserver <mailbox server>
- Check the status of the Fail-over Cluster Service Manager
- Launch Fail-over Cluster Service Manager > Manage a Cluster > Enter <cluster>
- Expand the <cluster>, review Nodes
- If a node is stopped, attempt to ‘Start Cluster Service’
- If Cluster Service fails to start, run : Stop-DatabaseAvaliabilityGroup -identity <cluster> -mailboxserver <mailbox server> and perform a Set-DatabaseAvalibilityGroup -identity <cluster>
- If the mailbox server fails to be evicted, reboot the server; ensure mailbox databases are dismounted first or maintenance mode is effective.
- After the restarting, Perform a force cleanup of the cluster from the failed server.
- Log into the failed server, Run Cluster Node “ServerName” /forcecleanup from an elevated command prompt.
- Once the cleanup is successful, Attempt to re-add or remove the failed server back into the cluster. You can also try running Start-DatabaseAvailabilityGroup “DAG Name” –MailboxServer “FailedServer” or Stop-DatabaseAvailabilityGroup “DAG Name” –MailboxServer “FailedServer”
[O365][PS] Exchange Online Powershell Module and connecting to Exchange Online
Example 1:
1 2 3 4 5 6 7 8 9 |
Import-Module (Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter '*ExoPowershellModule.dll' -Recurse | Foreach{(Get-ChildItem -Path $_.Directory -Filter CreateExoPSSession.ps1)} | Sort-Object LastWriteTime | Select-Object -Last 1).FullName $User = "epic@onmicrosoft.com" $PasswordFile = "c:\o365\Password.txt" $KeyFile = "c:\o365\AES.key" $key = Get-Content $KeyFile $MyCredential = New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList $User, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key) $proxysettings = New-PSSessionOption -ProxyAccessType IEConfig connect-exopssession -pssessionoption $proxysettings -credential $MyCredential |
Example 2:
1 2 3 4 5 6 7 8 9 |
$targetdir = (dir $env:LOCALAPPDATA”\Apps\2.0\” -Include CreateExoPSSession.ps1,Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse | Group Directory | ? {$_.Count -eq 2}).Values | sort LastWriteTime -Descending | select -First 1 | select -ExpandProperty FullName import-Module $targetdir\CreateExoPSSession.ps1 $User = "elau@onmicrosoft.com" $PasswordFile = "c:\o365\Password.txt" $KeyFile = "c:\o365\AES.key" $key = Get-Content $KeyFile $MyCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key) $proxysettings = New-PSSessionOption -ProxyAccessType IEConfig connect-exopssession -pssessionoption $proxysettings -credential $MyCredential |
Troubleshooting Errors:
- New-ExoPSSession : user_realm_discovery_failed: User realm discovery failed
1 2 3 4 5 6 |
New-ExoPSSession : user_realm_discovery_failed: User realm discovery failed At C:\Users\adm_elau\AppData\Local\Apps\2.0\806D2EJM.EAP\C421GW28.ARQ\micr..tion_1975b8453054a2b5_0010.0000_b9d3168c8e461adc\CreateExoPSSession.ps1:301 char:30 + ... PSSession = New-ExoPSSession -UserPrincipalName $UserPrincipalName.Va ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [New-ExoPSSession], AdalServiceException + FullyQualifiedErrorId : Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException,Microsoft.Exchange.Management.ExoPowershellSnapin.NewExoPSSession |
-
- Check proxy settings in IE
- New-ExoPSSession: The SSL certificate could not be checked for revocation.
1 2 3 4 5 6 7 |
New-ExoPSSession : [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following error message : The server certificate on the destination computer (outlook.office365.com:443) has the following errors: The SSL certificate could not be checked for revocation. The server used to check for revocation might be unreachable. For more information, see the about_Remote_Troubleshooting Help topic. At line:1 char:12 + $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri ht ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException + FullyQualifiedErrorId : 12175,PSSessionOpenFailed |
-
- Set winhttpbyusingsetproxycommand:
- Show: netsh winhttp show proxy
- Set Proxy: netsh winhttp set proxy <proxy url or ip>:<port>
- Reset Proxy: netsh winhttp reset proxy
- Set winhttpbyusingsetproxycommand:
[PS] Creating a Key File and Password File
Creating a Key File and Password File
With PowerShell, we can generate a 256-bit AES encryption key:
Creating the AES.key
1 2 3 4 |
$KeyFile = "C:\o365\AES.key" $Key = New-Object Byte[] 32 # You can use 16, 24, or 32 for AES [Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($Key) $Key | out-file $KeyFile |
Creating the password file
1 2 3 4 5 |
$PasswordFile = "Password.txt" $KeyFile = "AES.key" $Key = Get-Content $KeyFile $Password = "P@ssword1" | ConvertTo-SecureString -AsPlainText -Force $Password | ConvertFrom-SecureString -key $Key | Out-File $PasswordFile |
Using the key and password file
1 |
$User = "username"$PasswordFile = "c:\o365\Password.txt"$KeyFile = "c:\o365\AES.key"$key = Get-Content $KeyFile$MyCredential = New-Object -TypeName System.Management.Automation.PSCredential ` -ArgumentList $User, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key) |