使用new-psdrive名称作为msdeploy源参数的源变量不起作用

时间:2016-04-04 19:32:13

标签: powershell msdeploy webdeploy

//创建一个新的PowerShell驱动器

$psw = ConvertTo-SecureString %deployment.password% -AsPlainText -force
$cred = new-object -TypeName System.Management.Automation.PSCredential -ArgumentList "MyUser, $psw
New-PSDrive -Credential $cred -Name ImportFolder -PSProvider FileSystem -Root \\MyShare\Exchange\MyFolder

//创建完整的源路径

$sourcePath = ImportFolder:\$versionPath\audio

//使用msdeploy和$ sourcePath

进行部署
$path = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe";
$verb = "-verb:sync";
$src = "-source:contentPath=`"$sourcePath`"";
$dest = "-dest:contentPath=%TargetIISPath%,wmsvc='%Computername%:%deployment.iis.port%/msdeploy.axd',username=%system.Username%,password=%system.Password%";
Invoke-Expression "&'$path' --% $verb $src $dest -verbose -allowUntrusted";

Remove-PSDrive ImportFolder

我收到错误:

The term 'ImportFolder:\$versionPath\audio' is not recognized as the name of a 
[21:07:32][Step 6/7] cmdlet, function, script file, or operable program. Check the spelling of the 
[21:07:32][Step 6/7] name, or if a path was included, verify that the path is correct and try 
[21:07:32][Step 6/7] again.At 

问题是msdeploy假定sourcePath ImportFolder的字面命名为" ImportFolder"但实际上它是一个带有映射路径的PowerShell驱动器......

我该如何解决?

我不想使用" net use X:\ path"因为它在我的环境中有缺陷。

1 个答案:

答案 0 :(得分:0)

这可能有点旧,但您可以使用带有字母的名称为您的PSDrive,然后您可以使用该驱动器号与msdeploy

New-PSDrive -Credential $cred -Name "X" -PSProvider FileSystem -Root \\MyShare\Exchange\MyFolder

$sourcePath = "X:\$versionPath\audio"