get-mailbox -ResultSize Unlimited | Get-MailboxStatistics | where {$_.TotalItemSize -ge 4GB} |Sort-Object TotalItemSize -Descending |Select-Object DisplayName,TotalItemSize
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://ts-mail01.x.com/PowerShell/ -Authentication Kerberos -Credential $UserCredential
Import-PSSession $Session
$ScriptblockText = 'get-mailbox -ResultSize Unlimited | Get-MailboxStatistics | where {$_.TotalItemSize -ge 4GB} |Sort-Object TotalItemSize -Descending |Select-Object DisplayName,TotalItemSize'
$ScriptBlock = [scriptblock]::create($ScriptBlockText)
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://ts-mail01.x.com/PowerShell/ -Authentication Kerberos -Credential $UserCredential
Invoke-Command -Session $Session -ScriptBlock $ScriptBlock
Script block literals are not allowed in restricted language mode or a Data section.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : ScriptBlockNotSupportedInDataSection
get-mailbox -ResultSize Unlimited | Get-MailboxStatistics | ? { ([Microsoft.Exchange.Data.ByteQuantifiedSize] $_.TotalItemSize).ToGB() -gt 4 }
but not in an imported session (because that doesn't know about the full Exchange types).
? : Unable to find type [Microsoft.Exchange.Data.ByteQuantifiedSize].
At line:1 char:61
+ ... tatistics | ? { ([Microsoft.Exchange.Data.ByteQuantifiedSize] $_.Tota ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Excha...eQuantifiedSize:TypeName) [Where-Object], RuntimeEx
ception
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.WhereObjectCommand
but not in an imported session
$GMSize = get-mailbox -ResultSize Unlimited | Get-MailboxStatistics | where {$_.TotalItemSize -ge "4GB"} | Select-Object DisplayName,TotalItemSize, ItemCount, Database, TotalDeletedItemSize,DeletedItemCount, LastLoggedOnUserAccount, LastLogonTime, LastLogoffTime
$GMSize | Select-String "GB" | Format-List
# load the IIS module
Import-Module WebAdministration
# get the path to the exchange server installation directory
# and create a new folder for the exadmin application
$path = ‘HKLM:\SOFTWARE\Microsoft\ExchangeServer\v14\Setup’
$exbin = Join-Path (Get-ItemProperty $path).MsiInstallPath ClientAccess
$folder = New-Item -Path $exbin\exadmin -ItemType Directory -Force
# copy the web.config file to the new directory, load it (as xml) and
# change the language mode (from RestrictedLanguage) to FullLanguage
Copy-Item $exbin\PowerShell\web.config $folder.FullName -Force
$wconfig = Get-Content $exbin\exadmin\web.config
$wconfig.configuration.appSettings.add.value = 'FullLanguage'
$wconfig.Save("$exbin\exadmin\web.config")
# Create a new IIS application pool, and start it
$pool = New-WebAppPool -Name exadmin
# Configure the exadmin app pool to run under the LocalSystem account (0)
Set-ItemProperty IIS:\AppPools\exadmin -Name ProcessModel -Value @{identityType=0}
# start app pool
Start-WebAppPool -Name exadmin
# Create a new IIS Web Application.
$application = New-WebApplication -Name exadmin -Site 'Default Web Site' -PhysicalPath "$exbin\exadmin" -ApplicationPool $pool.name
#Set the application SSL settings to accept client certificates (if they are provided)
Set-WebConfigurationProperty -Filter //security/access –Name SslFlags -Value SslNegotiateCert -PSPath IIS:\ -Location 'Default Web Site/exadmin'
# create new end point configuration and allow administrators to remotely run commands
# a dialog is shown with the local administrators group selected, and we can add
# users/groups we want to have access to the end point
#Get-PSSessionConfiguration exadmin | Unregister-PSSessionConfiguration -Force
Register-PSSessionConfiguration -Name exadmin -Force
Set-PSSessionConfiguration -Name exadmin -ShowSecurityDescriptorUI -Force
# testing the new environment, uncomment and change database identity
# create a fan-in session (notice we are connecting to exadmin) and try to
# invoke the ToBytes method – it works
#$sb = { (Get-MailboxDatabase -Status -Identity 'Mailbox Database 0311695863').DatabaseSize.ToBytes() }
#$uri = ‘http://dc1.homelab.com/exadmin’
#$session = New-PSSession -ConfigurationName Microsoft.Exchange –ConnectionUri $uri
#Invoke-Command $session –ScriptBlock $sb