tag:blogger.com,1999:blog-19742455273682088242024-03-13T09:55:11.485-04:00Beyond Next Solutions BLOGIT Consulting solutions focusing on Microsoft server technologies such as Exchange Server, Active Directory, Security, SharePoint, Virtualization, System Center, XenServer, XenDesktop, and much more.Unknownnoreply@blogger.comBlogger2125tag:blogger.com,1999:blog-1974245527368208824.post-76077669096652325412012-09-21T15:14:00.000-04:002012-09-21T15:23:32.913-04:00PowerShell Script - Mailbox Folder Import and Migration Verification<br />
<div style="font-family: 'Segoe UI', Verdana, Arial; font-size: 13px;">
I have used this script in the past to verify that mailbox content was imported or migrated successfully. Basically, all it does is look for mailboxes that have an empty Inbox, Sent Items, Contacts, or Calendar folder. If a mailbox is found with at least one of these folders being empty, it adds the mailbox to a report with the count of each folder, then generates a CSV report at the end.</div>
<div style="font-family: 'Segoe UI', Verdana, Arial; font-size: 13px;">
The list of mailboxes to check can be one of the following:</div>
<ol style="font-family: 'Segoe UI', Verdana, Arial; font-size: 13px; margin-left: 40px; padding-left: 0px;">
<li style="padding-bottom: 10px;">CSV file - the script only looks for a column of emailAddress.</li>
<li style="padding-bottom: 10px;">By specifying an OU of users to check</li>
<li style="padding-bottom: 10px;">All mailboxes in the Exchange org.</li>
</ol>
<div style="font-family: 'Segoe UI', Verdana, Arial; font-size: 13px;">
The only required switch is -OutFile which requires a valid file name and path for the CSV file.</div>
<div style="font-family: 'Segoe UI', Verdana, Arial; font-size: 13px;">
I have tested this script on Exchange 2010 SP1, Windows 2008 R2, and PowerShell 2.0 in both production and a lab environment. If you run into any issues please post a comment or question.</div>
<div style="font-family: 'Segoe UI', Verdana, Arial; font-size: 13px;">
<br /></div>
<div style="font-family: 'Segoe UI', Verdana, Arial; font-size: 13px;">
Script Name: MbxImpMigCheck.ps1<br />
Download: <a href="http://gallery.technet.microsoft.com/scriptcenter/Mailbox-Folder-Import-and-24a62dc3">http://gallery.technet.microsoft.com/scriptcenter/Mailbox-Folder-Import-and-24a62dc3</a></div>
<div style="font-family: 'Segoe UI', Verdana, Arial; font-size: 13px;">
<br /></div>
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><#</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">.SYNOPSIS</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Reports on mailboxes with an empty Inbox, Calendar, Contact, or Sent Items folder. </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">This is very useful as a quick check to see if migrated or imported mailboxes have empty</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">folders, but does NOT verify that ALL data was successfully migrated/imported. It does serve</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">well as a quick reference on mailboxes that may have blatantly failed during migration/import.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">.DESCRIPTION</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">The list of mailboxes to evaluate can be sourced from a CSV, a particular OU, or all mailboxes</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">in the current Exchange organization. For each mailbox, we check to see if any of the following</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">mail folders (and their subfolders) are empty: Inbox, Sent Items, Contacts, Calendar. If any of</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">these are reported as having zero items, we add the mailbox's email address and each folder's</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">item count to a CSV.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">.PARAMETER OutFile</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Specifies the full path and filename to store the CSV formatted report. This is REQUIRED.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">.PARAMETER CSV</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Specifies the full path and filename of the CSV to be used as input. The CSV used here only </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">requires the emailAddress field in the header and for each mailbox. If both -CSV and -OU are used</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">together, -OU will be ignored.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">.PARAMETER OU</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Specifies the canonical name of the AD Organizational Unit containing mailboxes to be inspected.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">This is the same as the -OrganizationalUnit parameter of the Get-Mailbox cmdlet in Exchange 2010.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">If both -CSV and -OU are used together, -OU will be ignored.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">.EXAMPLE</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">./MbxImpMigCheck.ps1 -OutFile c:\Temp\report.csv</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Generates a report on any mailbox in the Exchange Organization that has an empty Inbox,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Sent Items, Contacts, or Calendar folder, and saves the report as a CSV in C:\Temp\report.csv</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">WARNING: This can take a while to run in large environments</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">.EXAMPLE</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">./MbxImpMigCheck.ps1 -OutFile c:\Temp\report.csv -CSV c:\Temp\inputFile.csv</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Generates a report on any mailbox in the CSV that has an empty Inbox, Sent Items, Contacts, or </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Calendar folder, and saves the report as a CSV in C:\Temp\report.csv</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">.EXAMPLE</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">./MbxImpMigCheck.ps1 -OutFile c:\Temp\report.csv -OU "ou=mailboxes,dc=domain,dc=com"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Generates a report on any mailbox in the Mailboxes OU of the domain.com domain that has an empty </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Inbox, Sent Items, Contacts, or Calendar folder, and saves the report as a CSV in C:\Temp\report.csv</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">.NOTES</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Author: Trent Nevius (trent@beyond-next.com)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">PowerShell Modules required: [Exchange 2010]</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Tested PowerShell version: [2.0]</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Tested software: Microsoft Exchange 2010 SP1 on Windows 2008 R2</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">.LINK</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">http://gallery.technet.microsoft.com/scriptcenter/Mailbox-Folder-Import-and-24a62dc3</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"># Define Parameters</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Param(</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>[string] $CSV = "",</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>[string] $OU = "",</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>[string] $OutFile</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"># Ensure the OutFile parameter was supplied</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">if ($OutFile -eq "") {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Write-Host "`nMissing parameter: The -OutFile parameter is required. Please re-run this script with a valid path and filename for the -OutFile parameter.`n"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>exit</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"># Define array variables</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$Results = @("emailAddress,Inbox,SentItems,Calendar,Contacts`n")</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$Mailboxes = @()</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">if ($CSV -ne "") {Import-CSV -Path $CSV | foreach {$Mailboxes += Get-Mailbox $_.emailAddress}}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">elseif ($OU -ne "") {$Mailboxes = Get-Mailbox -OrganizationalUnit $OU}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">else {$Mailboxes = Get-Mailbox -ResultSize unlimited}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">foreach ($mailbox in $Mailboxes) {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$CalendarCount = (get-mailboxfolderstatistics $mailbox.alias -FolderScope Calendar).ItemsInFolderAndSubfolders</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$InboxCount = (get-mailboxfolderstatistics $mailbox.alias -FolderScope Inbox).ItemsInFolderAndSubfolders</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$ContactCount = (get-mailboxfolderstatistics $mailbox.alias -FolderScope Contacts).ItemsInFolderAndSubfolders</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>$SentCount = (get-mailboxfolderstatistics $mailbox.alias -FolderScope SentItems).ItemsInFolderAndSubfolders</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> if (($CalenderCount -eq 0) -or ($InboxCount -eq 0) -or ($ContactCount -eq 0) -or ($SentCount -eq 0)) {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> $Results += $mailbox.PrimarySMTPAddress.ToString() + ",$InboxCount,$SentCount,$CalendarCount,$ContactCount`n"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">$Results > $OutFile</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">Write-Host "`nReport Complete, results output formatted as CSV to " $Outfile</span><br />
<div style="font-family: 'Segoe UI', Verdana, Arial; font-size: 13px;">
<br /></div>
<br />Unknownnoreply@blogger.com18tag:blogger.com,1999:blog-1974245527368208824.post-59802402924263541772011-09-20T21:30:00.002-04:002011-09-20T22:41:01.836-04:00SCVMM "Migration Failed"- how to clearWhen working with Microsoft SCVMM (System Center Virtual Machine Manager) in a Hyper-V virtualization environment, we have run across scenarios in which the failed migration of a VM from one host to another may leave the VM in a failed state. Specifically, in the SCVMM console, the VM has a red 'X' beside it with the "Migration failed" under the status column. While the VM is in this failed state, SCVMM will only allow you to Repair, Delete, or View networking of the VM. Furthermore, if you right-click the VM and select 'Repair', the option to 'Ignore' is unavailable, and the 'Retry' and 'Undo' options fail. Even though you may have corrected the problem outside of VMM, for example using the Hyper-V Manager console, the repair options yield no results.<br />
<br />
We have read many articles and posts on how to deal with this scenario, such as removing the host from VMM and adding it back. Or using SQL Server Management Studio to hide failed jobs (NOT a good idea as it can eventually lead to poor SCVMM performance since the VMM cleanup process will skip old jobs that are hidden!). Once you have corrected the problem and exhausted all possibilities to remedy the situation, here is a handy PowerShell script that will help you out of this jam, which we pieced together specifically for this situation.<br />
<br />
First, a little peek under the hood:<br />
<br />
- When the migration fails, the ObjectState field in SQL for the VM gets set to 220, indicating a failed state.<br />
- If the ObjectState field for a VM is set to 0 (zero) or 1, SCVMM will re-check the VM state. If you have repaired the VM and set the ObjectState in the VirtualManagerDB to 0, VMM will immediately notice the VM has been fixed, and all is well.<br />
<br />
<b><u><span class="Apple-style-span" style="color: red;">WARNING</span></u></b><br />
I have created this script and used it in a production environment, but use it at your own risk. Be sure to back up the VMM database just before using this so you have an out.<br />
<br />
<b>Script name</b>: Clear-VMMFailState.ps1<br />
<b>PS Requirements</b>: I have only tested this under PowerShell 2.0, and have verified that it doesn't require any special PS modules such as the VMM or SQL modules. It worked fine for us in the out-of-box PowerShell in Win2008R2 with no modules loaded. This should also work remotely with no problem.<br />
<br />
We encourage feedback on your experience with this script, and any suggestions you may have on how to improve it.<br />
<br />
Script Help (<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">get-help ./Clear-VMMFailState.ps1 -Detailed</span>)<br />
=====================================================================<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><b>Synopsis</b>:</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">This script will clear the failed state of a Virtual Machine in VMM.</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><b>Description</b>:</span><br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">!!!WARNING!!! back up your VMM SQL database before using this script. You have been warned!</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">This should only be used under the following circumstances:</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>- If a failure in a VMM job has a VM in a 'Failed' state</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>- AND -</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>- The repair function in VMM won't allow you to 'Ignore'</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>- AND - </span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>- The repair function in VMM fails when performing a 'Retry' or 'Discard'</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>- AND -</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>- You have corrected the issue outside of VMM (such as with Hyper-V Manager MMC etc.)</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>- AND -</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><span class="Apple-tab-span" style="white-space: pre;"> </span>- You have already tried refreshing the VMM Server, VM Host, and VM from within the VMM console or shell</span><br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Parameters:</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">-VMname <String> - the name of the Virtual Machine (as it appears in SCVMM)</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">-VmmDBserver <String> - this is the FQDN of the server that hosts the SQL instance of the SCVMM database</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">- VmmDBname <String> - this is the Database name of the SCVMM database; if not specified, this defaults to the value of 'VirtualManagerDB'</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">-IntegratedAuth <Switch> - if this switch is specified, integrated Windows authentication is used for the connection to the SCVMM database. If not specified, you must use the -UserName and -Password switches to authenticate to SQL</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">-UserName <String> - The username used to authenticate to the SCVMM database. If not using the -IntegratedAuth switch, this is required</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">-Password <String> - Password for the user specified with -UserName</span><br />
<br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Example 1:</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">./Clear-VMMFailState.ps1 -VMname TestVM01 -VmmDBserver VmmSQLserver.domain.com -IntegratedAuth</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">>> Connects to the SQL server that hosts the SCVMM database (VmmSQLserver.domain.com) and the default VMM database (VirtualManagerDB) using Integrated Authentication with currently logged on credentials, then clears the failed state of the Virtual Machine named 'TestVM01'.</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Example 2:</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">./Clear-VMMFailState.ps1 -VMname TestVM01 -VmmDBserver VmmSQLserver.domain.com -VmmDBname MyVmmDB -UserName domain.com\vmmAdmin -Password MyPassWord</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">>> Connects to the SQL server that hosts the SCVMM database (VmmSQLserver.domain.com) and the VMM database named 'MyVmmDB' using the specified username and password, then clears the failed state of the Virtual Machine named 'TestVM01'.</span><br />
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<span class="Apple-style-span" style="font-family: inherit;">And now for the script... <a href="http://powershell.com/cs/media/p/12426.aspx">http://powershell.com/cs/media/p/12426.aspx</a></span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br /></span>Unknownnoreply@blogger.com6