Make PowershellGet a trusted repository

After installing PowershellGet you can make us of this powerful repository to find modules and scripts you need for your personal happiness or current tasks you have to do with PowerShell.

Click here to learn how to install PowerShellGet on your computer

After you’ve installed PowershellGet and start installing modules, you always see warnings like this:

AzurePS4

As the message is already telling you (yep, sometimes it is really a good idea to read the messages on the screen 😉 ), you can trust the repo to avoid that message in future. For those who still don’t like reading PowerShell messages and prefer reading this article, here is the command:

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

Install PowerShellGet on your computer

PowerShell is continuously evolving, that means that for some modules you don’t get an installer anymore. You have to use PowershellGet.

But how to get it? In the following table I’ve summarized the ways:

Scenario Install instructions
Windows 10
Windows Server 2016
Included in Windows Management Framework (WMF) 5.0. This is aready shipped and ready-to-go with the Windows OS
I want to upgrade to PowerShell 5
  1. Install the latest version of WMF
  2. Run the following command:
    Install-Module PowerShellGet -Force
I am running on a version of Windows with PowerShell 3 or PowerShell 4 Get the PackageManagement modules

  1. Run the following command:
    Install-Module PowerShellGet -Force

Read the official article on docs.microsoft.com.

Now you can issue the following command to see how powerful this module is to find the module of your needs:

Get-Command -Module PowershellGet

Using a Mac or Linux? No problem. Read this article first to learn how to use PowerShell on your device.

Four Success Factors for Driving Microsoft 365 Adoption

This is a really great article / blog series you should read about how to successfully adopting Office 365 and Microsoft 365. Why is this important? Because the adoption of a new technology is a major change and needs a lot of aspects to be aware of and a lot of people to talk to.

This blog series is written by Cyril Belikoff, Senior Director of Office Marketing

Welcome to our blog series about the four success factors for driving Microsoft 365 adoption. In this series I will share insights from our most successful customers, Microsoft and 3rd party research, and proven bes…

Source: Four Success Factors for Driving Microsoft 365 Adoption

New-MailboxImportRequest raising “Error details: Access to the path is denied”

Importing PSTs to an Exchange on-premises mailbox is a cool feature because it helps you to get rid of old legacy PSTs which can cause you a lot of trouble (e.g. corrupted because saved on a network share, accidentially deleted because of hardware switch, etc etc etc).

But sometimes the command to start a new import can drive you crazy as well:

New-MailboxImportRequest

Follow the official documentation for this command to see how powerful it is and how to use it. So when you execute the command you may face the following error:

newmailboximportrequesterror

The error text says:

Unable to open PST file '\\SERVER\c$\Exported PSTs\PSTNAME.pst'. Error details: Access to the path
'\\SERVER\c$\Exported PSTs\PSTNAME.pst' is denied.
 + CategoryInfo : NotSpecified: (:) [New-MailboxImportRequest], RemotePermanentException
 + FullyQualifiedErrorId : [Server=EXCHANGESERVER,RequestId=078dc502-aecb-4122-8e22-f96c1c6141f8,TimeStamp=28.11.2017 10:
 34:01] [FailureCategory=Cmdlet-RemotePermanentException] 7B1A4B04,Microsoft.Exchange.Management.RecipientTasks.New
 MailboxImportRequest
 + PSComputerName : EXCHANGESERVER.FQDN

So the next thing you do is to check the permissions on the folder and they normally look like this:

newmailboximportrequestpermissions

If you read the official documentation very careful, there is a small hint:

You need to grant the following permission to the group Exchange Trusted Subsystem to the network share where you want to export or import PST files:

  • To import PST files from the share: Read permission
  • To save exported PST files to the share: Read/Write permission.

If you don’t grant this permission, you will receive an error message stating that Exchange is unable to establish a connection to the PST file on the network share.

Oh looks like reading the documentation was a good idea, because now the request is being created and the import starts. I personally prefer sharing the folder directly with a $-share. Don’t forget to edit the folder permissions and the sharing permissions. In my case it only worked when I set both:

newmailboximportrequestsuccess

This permission may not be set for a variety of reasons, e.g. a topology with many ActiveDirectory Domains where Exchange is installed in one of the domains, an interrupted permission inheritance or similar.

No matter where it comes from, now you know how to fix it. Happy importing 🙂

Use PowerShell to fill Exchange Mailbox(es) with data

Sometimes you have the need to fill up an Exchange Mailbox up to a certain level, e.g. to test migration speeds. In this post you find a tiny script which can do that for you. All you need is a folder with many files in it and a limit which you want to reach for your mailbox.

[CmdletBinding()]
param( 
 [Parameter(Mandatory=$true)][String]$Recipient, 
 [Parameter(Mandatory=$true)][Int32]$SizeInMB, 
 [Parameter(Mandatory=$true)][String]$FilesFolder, 
 [Parameter(Mandatory=$true)][String]$O365Sender
)
$ErrorActionPreference = 'SilentlyContinue'

[Double]$totalsize = 0
[Double]$attsize = 0
$pw = Read-Host ("Please enter the password for " + $O365Sender) -AsSecureString | ConvertFrom-Securestring
$creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $O365Sender, ($pw | ConvertTo-SecureString)
#$files = Get-ChildItem -Path $FilesFolder -Exclude "*.mp4" -Recurse
$files = Get-ChildItem -Path $FilesFolder -include "*.pptx" -Recurse
$mailcount = 1
while ($totalsize -lt $SizeInMB)
{ 
 $attachment = $files[(Get-Random -Minimum 0 -Maximum ($files.Count - 1))].FullName 
 $attsize = ((Get-Item $attachment).Length / 1000000) 
 $totalsize += $attsize 
 Write-Host ("Sending mail number " + $mailcount.ToString() + "; total size: " + $totalsize.ToString()) 
 Send-MailMessage -From $O365Sender -to $Recipient -Attachments $attachment -SmtpServer smtp.office365.com -Credential $creds -UseSsl -Subject ("Mail number " + $mailcount.ToString() + " via PowerShell script") -port 587 -body "<br><h1>Hallo</h1><br><br>Dies ist eine automatische Mail<br><br>Regards,<br>Your PowerShell Bot" -BodyAsHtml  
 $mailcount++
}

As you see, the script is designed to send mails from an Office 365 Exchange Online Mailbox. It is using the SMTP client submission of Exchange Online. So you are limited to 30 messages per minute (by Nov 17th 2017, this limit may change any time).

The parameters of the script:

  • $recipient: The smtp address of the mailbox which should be filled.
  • $SizeInMB: The amount of data which will be sent. The script counts how many MBs are sent and will stop when it reaches the limit. It doesn’t check the actual mailox size so the result maybe lower because of single instance store technologies or similar.
  • $FilesFolder: The folder with data for the email attachments. The script will pick a random pptx-file from this folder and send it via email. If you’d like other file types than pptx, just change the search filter. I’ve decided for pptx files because they are often large and I have tons of them. If you need tons of files, try the Ignite downloader.
  • $O365Sender: The sign in name of the mailbox from where you want to send the emails.

With some small adjustements you can use the script also with an on-premises mailbox as a sender. Happy mailbox filling 🙂

Feel free to download the script from my GitHub Page: PowerShell-ExchangeOnline GitHub Repository