Solved

Microsoft Exchange PowerShell

Posted on 2013-11-20
7
415 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now