Solved

Powershell syntax error

Posted on 2013-02-02
2
692 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
Comment Utility
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
Comment Utility
Excellent thanks, im just starting out wirth PS this has helped me greatly
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

7 Experts available now in Live!

Get 1:1 Help Now