Solved

Microsoft Exchange PowerShell

Posted on 2013-11-20
7
471 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 71

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 19

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 19

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 19

Author Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

733 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