Solved

Powershell syntax error

Posted on 2013-02-02
2
708 Views
Last Modified: 2013-02-02
Hi Guys, im trying to populate a mnemonic where the $nemonic is a populate by a given parameter. Im almost there i think but i get the error below the code. Thanks

function mnemonicpath {
param(
    [Parameter(Mandatory=$true)]
    $mnemonic
    )
Move-DatabasePath -Identity 'Mailbox Database $mnemonic' -EdbFilePath 'D:\Program Files\Microsoft\Exchange Server\V14\Mailbox\"Mailbox Database $mnemonic\Mailbox Database $mnemonic.edb"' -LogFolderPath 'D:\Program Files\Microsoft\Exchange Server\V14\Mailbox\Mailbox Database $mnemonic'



Move-DatabasePath : Cannot bind parameter 'EdbFilePath'. Cannot convert value "D:\Program Files\Microsoft\Exchange Serv
er\V14\Mailbox\"Mailbox Database $mnemonic\Mailbox Database $mnemonic.edb"" to type "Microsoft.Exchange.Data.EdbFilePat
h". Error: ""D:\Program Files\Microsoft\Exchange Server\V14\Mailbox\"Mailbox Database $mnemonic\Mailbox Database $mnemo
nic.edb"" is not an acceptable path. You must use an absolute, local, long file path, that does not contain '~'.
Parameter name: path"
At C:\it\Install Exchange.ps1:88 char:70
+ Move-DatabasePath -Identity 'Mailbox Database $mnemonic' -EdbFilePath <<<<  'D:\Program Files\Microsoft\Exchange Serv
er\V14\Mailbox\"Mailbox Database $mnemonic\Mailbox Database $mnemonic.edb"' -LogFolderPath 'D:\Program Files\Microsoft\
Exchange Server\V14\Mailbox\Mailbox Database $mnemonic'
    + CategoryInfo          : InvalidArgument: (:) [Move-DatabasePath], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Exchange.Management.SystemConfigurationTasks.Mo
   veDatabasePath
}
0
Comment
Question by:cwstad2
[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
2 Comments
 
LVL 5

Accepted Solution

by:
coraxal earned 500 total points
ID: 38846342
I think your problem is the use of the single quote when you should be using double quotes because you want the contents of the variable and not the literal name of the variable. In other words, anytime you use single quotes, Powershell will not evaluate the variable(s) and will return the string instead (i.e. $var1 = "Value" will return the literal string $var). Double quotes will evaluate and will return the contents of the variable (i.e. $var1 will return the content of $var1, which is "Value". So having said that, here's one way your function can look:
function mnemonicpath 
{
	param
	(
	    [Parameter(Mandatory=$true)]
	    [string]
		$mnemonic
	)
	
	$mbxDbName = "Mailbox Database $mnemonic"
	$edbFilePath = "D:\Program Files\Microsoft\Exchange Server\V14\Mailbox\$mbxDbName\$mbxDbName.edb"
	$logFolderPath = "D:\Program Files\Microsoft\Exchange Server\V14\Mailbox\$mbxDbName"
	
	Move-DatabasePath -Identity $mbxDbName -EdbFilePath $edbFilePath -LogFolderPath $logFolderPath
}

Open in new window

0
 
LVL 15

Author Closing Comment

by:cwstad2
ID: 38846492
Excellent thanks, im just starting out wirth PS this has helped me greatly
0

Featured Post

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
how to add IIS SMTP to handle application/Scanner relays into office 365.

718 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