Solved

Powershell syntax error

Posted on 2013-02-02
2
694 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
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

Can’t get the mobile email signature right?

Not having any luck when trying to create an email signature for mobile devices? Does the formatting keep messing up? Make sure you have great email signatures on all devices by using Exclaimer Cloud - Signatures for Office 365.

Question has a verified solution.

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

Suggested Solutions

Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
Read this checklist to learn more about the 15 things you should never include in an email signature.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

861 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

30 Experts available now in Live!

Get 1:1 Help Now