Powershell 无法绑定参数 ForegroundColor [英] Powershell cannot bind parameter ForegroundColor

查看:59
本文介绍了Powershell 无法绑定参数 ForegroundColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了以下 Powershell 脚本,希望用于将文件复制到网络共享.

I have created the following Powershell script which I hope to use to copy files to a network share.

function Copy-Deploy
{
 param(
  [Parameter(Position=0,Mandatory=$true,HelpMessage="Path to scripts")]
  [Alias("pth")]
  [string]$ScriptPath,

  [Parameter(Position=1,Mandatory=$true,HelpMessage="Deployment script filename")]
  [Alias("dep")]
  [string]$PowershellDeploymentScript,

  [Parameter(Position=2,Mandatory=$true,HelpMessage="MSI filename")]
  [Alias("m")]
  [string]$MSI,

  [Parameter(Position=3,Mandatory=$true,HelpMessage="Filename of the MSBuild script (.btdfproj)")]
  [Alias("msb")]
  [string]$MSBuildScript,

  [Parameter(Position=4,HelpMessage="UNC path to target server folder")]
  [Alias("server")]
  [string]$TargetServerPath

  )

 $ErrorActionPreference="Stop"

 #Step 1 : copy the MSI, .btdfproj script and control powershell script to the remote server
 Write-Host " Going to enter the mis script block"
 $misScript =
 {
    Write-Host " Path+Filename = {0}({1})" -f $ScriptPath, $PowershellDeploymentScript
    Write-Host " Going to copy files" 
    Write-Host " ScriptPath = $ScriptPath"
    Write-Host " PowershellDeploymentScript = $PowershellDeploymentScript"
    Write-Host " MSI = $MSI"
    Write-Host " MSBuildScript = $MSBuildScript"
    Write-Host " TargetServerPath = $TargetServerPath"


    Copy-Item -Path "$ScriptPath" + "$PowershellDeploymentScript" -Destination "$TargetServerPath"
    Copy-Item -Path "$ScriptPath" + "$MSI" -Destination "$TargetServerPath"
    Copy-Item -Path "$ScriptPath" + "$MSBuildScript" -Destination "$TargetServerPath"
 }
 Invoke-Command -scriptblock $misScript

 #Step2 : Execute the powershell script ExecuteBizTalkAppMSI.ps1 remotely on the target server
 #using syntax... invoke-command -computer $MachineName -command { $TargetServerPath + ExecuteBizTalkAppMSI.ps1 }" 

}

我使用以下行从 Powershell ISE 运行此脚本:

I run this script from the Powershell ISE with the following line:

Copy-Deploy "C:\Builds\3\x.Int.MIS\SupportBTDF\Sources\x.Int.MIS\Dev\V1.0\Src\Solutions\MIS\x.Int.MIS.Deployment\" "ExecuteBizTalkAppMSI.ps1" "bin\debug\x.Int.MIS-3.0.0.msi" "x.Int.MIS.Deployment.btdfproj" "\\d-vasbiz01\BizTalkDeployment"

然后我收到以下错误:

Cannot bind parameter 'ForegroundColor'. Cannot convert value "C:\Builds\3\x.Int.MIS\SupportBTDF\Sources\x.Int.MIS\Dev\V1.0\Src\Solutions\MIS\x.Int.MIS.Deployment\,ExecuteBizTalkAppMSI.ps1" to type "System.ConsoleColor" due to invalid enumeration values. Specify one of the following enumeration values and try again. The possible enumeration values are "Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta, DarkYellow, Gray, DarkGray, Blue, Green, Cyan, Red, Magenta, Yellow, White".At C:\Builds\3\x.Int.MIS\SupportBTDF\Sources\x.Int.MIS\Dev\V1.0\Src\Solutions\MIS\x.Int.MIS.Deployment\CopyDeployScriptThenExecute.ps1:79 char:16

谁能告诉我我哪里出错了?

Could anyone please tell me where I went wrong?

推荐答案

行:

Write-Host " Path+Filename = {0}({1})" -f $ScriptPath, $PowershellDeploymentScript

是问题所在.

这样写:

Write-Host (" Path+Filename = {0}({1})" -f $ScriptPath, $PowershellDeploymentScript)

-f 被当作 -ForegroundColor 参数而不是字符串格式运算符.

The -f was being taken as the -ForegroundColor parameter than the string format operator.

这篇关于Powershell 无法绑定参数 ForegroundColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆