WinRM can be a very useful tool (even if it is somewhat of a challenge to set-up [esp if you want to use CredSSP]. I am however finding it more and more useful to execute cmdlets for Powershell modules you cant easily install; An example is the Operations Manager 2012 cmdlets that are only installed with the Console.
For a maintance mode script we recently used (similar to this one) I found myself tripping over one of the following errors when attempting to remotely connect to my SCOM server and put a group into maintenance mode:
Processing data from remote server failed with the following error message: TheWSMan Providor host did not return a proper response. A Providor in the host process may have behaved improperly. For more information, see the about help _Remoting_troubleshooting help topic.
Processing data for a remote command failed with the following error message: Deserialized objects exceed the memory quota. For more information, see
the about_Remote_Troubleshooting Help topic
These messages are nice and generic with no real hint to the cause. So why does it happen?
When attempting to run up the OperationsManager Module (and subsequantly connect to the SCOM SDK) to run cmdlets we will exhaust the 150MB defualt WSMan memory allocation. In order to continue we will need to exend the “MaxMemoryPerShellMb” allocation Run the following to view/alter these values:
#View Existing WSMan MaxMemory Value
#Set new WSMan MaxMemory Value to 1 Gb
Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1024 -Force
A neat feature of Exchange is the ability to run up a search across mailboxes within an organization from Powershell using the Search-Mailbox cmdlet and delete inappropriate or harmful messages using the -DeleteContent parameter. Fortunately these features exist in Office 365 if you are an Exchange Online Administrator
While administrators can use the Multi-Mailbox search feature in the Exchange control panel UI to locate mail, you may discover you are unable to remove messages directly without some PowerShell magic.
The below script requires you add your admin account to the “Discovery Management” role from Roles & Auditing on the Exchange Control Panel (ECP).
#Every mailbox within the Organisation
[string]$decision = "n"
Write-Host "This script requires the `"Discovery Management`" Exchange Role-Group PLUS `"Mailbox Import Export`" Role assigned to your Exchange onlineAdmin Account `nPlease add it before proceeding:"
Write-Host "`n`nEnter Administration Credentials"
$LiveCred = Get-Credential
#Pass Creds to Outlook.com and generate PS Session
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
#Import PS Session/Grab MSOL Cmdlets
$Subject = Read-Host "Please Enter a Message Subject to be deleted from ALL mailboxes:"
$decision = Read-Host "Are you sure youi want to delete messages with the subject " $Subject " (Y/N)?"
if ($decision -eq "y")
Write-Host "Deleting" $Subject
Get-Mailbox -ResultSize unlimited | Search-Mailbox -SearchQuery "subject:$Subject" -DeleteContent -Confirm
Write-Host "Nothing deleted"
Write-Host "Connection to MSOL closed"
Warning: Use the above script with caution; When using the DeleteContent parameter, messages are permanently deleted from the user’s mailbox and cannot be recovered. (It could also take some time to run over a big Office365 Tenant)
See related Office 365 help article here: here: http://help.outlook.com/en-ca/140/gg315525.aspx