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

x
?
Solved

Powershell syntax error

Posted on 2013-02-02
2
Medium Priority
?
724 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 2000 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

618 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