Solved

Microsoft Exchange PowerShell

Posted on 2013-11-20
7
458 Views
Last Modified: 2014-03-12
I have a script to create RSG for Exchange 2007 SP3 running on Windows 2008 R2. This is a test lab.

#To set the directory

$Path = Set-Location C:\Suriya
$RSG  = Read-Host "Please provide the RSG main folder name"
$RSGUpper = $RSG.toupper()
$fullpath = $Path +  $RSGUpper
while (Test-Path $fullpath)
{
$RSG = Read-Host "Your RSG Man folder already exist, press Y to overwrite N to create a new directory"
switch($RSG)
{
"Y" {Write-Host "Overwriting $fullpath"; New-Item -Path $fullpath -Type Directory  -Force -ErrorAction SilentlyContinue;Remove-Item -Path $fullpath\* -Recurse;break }
"N" {$RSG = Read-Host "Enter New Directory Name";$RSGUpper = $RSG.toupper();$fullpath = $Path +  $RSGUpper}
}
break;
}
if (!(Test-Path $fullpath))
{
New-Item -Path $fullpath -Type Directory -ErrorAction SilentlyContinue
}

#$RSGDB  = Read-Host "Please provide the RSG DB under RSG Main folder name" 

$RSGDBUpper = ($RSGUpper.name+"DB").toupper()
$RSGDBUpper
$RSGFolder
$RSGDB = New-Item -Path $fullpath -Name ($RSGUpper+$RSGDBUpper) -Type Directory
Write-Host "Your RSG DB : $($RSGDB.name)" -ForegroundColor Magenta

#$RSGLOG  = Read-Host "Please provide the RSG LOG under RSG Main folder name" 

$RSGLOGUpper = ($RSGUpper.name+"LOG").toupper()
$RSGLOG= New-Item -Path $fullpath -Name ($RSGUpper+$RSGLOGUpper) -Type Directory
Write-Host "Your RSG LOG : $($RSGLOG.name)" -ForegroundColor Green

#Add Exchange Management Shell PSSnapin

If ((Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.Admin -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.Admin
}

If ((Get-PSSnapin -Name Microsoft.Exchange.Management.Powershell.Support -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin -Name Microsoft.Exchange.Management.Powershell.Support
}

#Create Recorvey Storage group

#$ExchName = (Get-ClusteredMailboxServerStatus).Identity
$ExchName = "EXCH07-dc01"

New-StorageGroup -Server $ExchName -Name $RSGUpper -LogFolderPath "$RSGLOG" -SystemFolderPath "$RSGDB" -Recovery | Out-Null
#Write-Host "Please provide the RSG Mabilbox Database to recove:$($RSGMDB)" -ForegroundColor Yellow
$RSGMDB = Read-Host "Please provide the RSG Mabilbox Database to recover"
$RSGMDBUpper = $RSGMDB.toupper()
New-MailboxDatabase -MailboxDatabaseToRecover $RSGMDBUpper -StorageGroup ("$ExchName" +"\" + $RSGUpper) -EdbFilePath ("$RSGDB" +"\"+"$RSGMDBUpper"+".EDB") | Out-Null
Set-MailboxDatabase -Identity ("$ExchName" +"\" + $RSGUpper+"\"+$RSGMDBUpper) -AllowFileRestore:$True

#Generate Output

$RSGFolderDetails = Get-StorageGroup -Identity ("$ExchName" +"\" + $RSGUpper)
$RSGDBDetails     = Get-MailboxDatabase -Identity ("$ExchName" +"\" + $RSGUpper+"\"+$RSGMDBUpper)

#$FinalOutput = @()

$Output = New-Object PSObject

$Output | Add-Member -MemberType NoteProperty -Name 'Allow File Restore'    -Value $RSGDBDetails.allowfilerestore
$Output | Add-Member -MemberType NoteProperty -Name 'Log Folder Path'       -Value $RSGFolderDetails.logfolderpath
$Output | Add-Member -MemberType NoteProperty -Name 'System Folder Path'    -Value $RSGFolderDetails.systemfolderpath
$Output | Add-Member -MemberType NoteProperty -Name 'Server'                -Value $ExchName

#$FinalOutput += $Output

#$FinalOutput | Format-Table "Server","Allow File Restore","Log Folder Path","System Folder Path"

$Output #| Format-Table 'Allow File Restore','Log Folder Path','System Folder Path','Server'

Set-Location C:\

Open in new window


Script work well until the last part to display the result. It show error:

The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or not in
the correct sequence. This is likely caused by a user-specified "format-table" command which is conflictin
g with the default formatting.
    + CategoryInfo          : InvalidData: (:) [out-lineoutput], InvalidOperationException
    + FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOu
tputCommand
0
Comment
Question by:suriyaehnop
  • 3
  • 3
7 Comments
 
LVL 70

Expert Comment

by:Chris Dent
ID: 39665212
Which line is throwing that error? It will tell you and since all your formatting commands are commented out it's not all that easy to tell.

Chris
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39665792
0
 
LVL 18

Author Comment

by:suriyaehnop
ID: 39691769
Chris,

Line 76, if i changed to $FinalOutput only, it will show the result in format list

Subsun,

I saw the link, but how to apply workaround on the script?
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 40

Accepted Solution

by:
Subsun earned 400 total points
ID: 39692099
Workaround is explained in bug report...
Use explicit formatting throughout a script
For example in your code (Line 25  & 26) you didn't use any explicit formatting which might be causing issue.. So try..

$RSGDBUpper | Out-Default
$RSGFolder | Out-Default

Or try to use write-host to display the objects on screen..

Write-host $RSGDBUpper
Write-host $RSGFolder

If you find any issue, please post the exact code which you are using now, so we can test it..
0
 
LVL 18

Author Comment

by:suriyaehnop
ID: 39692109
Actually $RSGDBUpper & $RSGFolder (Line 25  & 26) can be removed. it mean nothing, the reason why i put this is for testing while creating this code.

:)
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39692117
Did you test by removing the lines? or is there any other line in your script which you didn't define the formating?
0
 
LVL 18

Author Comment

by:suriyaehnop
ID: 39692119
let me test it out and will update soon
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
This video discusses moving either the default database or any database to a new volume.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question