Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Microsoft Exchange PowerShell

Posted on 2013-11-20
7
Medium Priority
?
501 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

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!

Question has a verified solution.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
I don't pretend to be an expert at this, but I have found a few things that are useful. I hope that sharing them here will help others, so they will not have to face some rather hard choices. Since I felt this to be a topic of enough importance and…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Suggested Courses

598 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