Solved

Powershell syntax error

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

803 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