?
Solved

Microsoft Exchange PowerShell

Posted on 2013-11-20
7
Medium Priority
?
491 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
WatchGuard's M Series Appliances - Miecom Approved

WatchGuard's newest M series appliances were put to the test by Miercom.  We had great results and outperformed all of our competitors in both stateless and stateful traffic throghput scenarios! Ready to see how your UTM appliance stacked up? Download the Miercom Report!

 
LVL 40

Accepted Solution

by:
Subsun earned 1200 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 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