【问题标题】:Is there any solution to this powershell script issue? I've tried many different solutions这个powershell脚本问题有什么解决方案吗?我尝试了许多不同的解决方案
【发布时间】:2021-05-07 16:50:46
【问题描述】:
$serverPath = "${V:\} + $Global:certRequestID "
        $localPath = "${C:\temp\} + $Global:certRequestID "



    # Check for atsinst.bat first - run it if it exists. Else offer uninstall/install options
        
            if(Test-Path -LiteralPath "${localPath}\install\atsinst.bat") {
                Invoke-Expression -Command "${localPath}\install\atsinst.bat -DeployMode 'Silent' " | Out-Host
            }

            Else{
                Copy-Item -Path $serverPath -Destination $localPath -Recurse -Force | Out-Host
                
                Write-Host "`nUninstalling ${certRequestID}: "
                Invoke-Expression -Command "${localPath}Deploy-Application.exe" -DeployMode 'Silent' -DeploymentType 'Uninstall' | Out-Host
            

            
                Write-Host "`nInstalling ${certRequestID}: "
                Invoke-Expression -Command "${localPath}Deploy-Application.exe" -DeployMode 'Silent' | Out-Host
                }
            
        }

目前我收到此错误:

找不到与参数名称“DeployMode”匹配的参数。 + CategoryInfo : InvalidArgument: (:) [Invoke-Expression], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeExpressionCommand + PSComputerName : WKPF26YSKX

【问题讨论】:

    标签: c# powershell error-handling command


    【解决方案1】:

    您需要在整个 -Command 参数周围加上双引号。我认为第二个问题是您必须在命令前面使用dot source operator. 例如一个点和一个空格)来执行它,例如

    Invoke-Expression -Command ". ${localPath}Deploy-Application.exe -DeployMode 'Silent' -DeploymentType 'Uninstall'" | Out-Host
    
    ...
    
    Invoke-Expression -Command ". ${localPath}Deploy-Application.exe -DeployMode 'Silent'" | Out-Host
    
       
    

    【讨论】:

    • 嗯,我这样做了,现在我收到以下错误正在安装:术语“-DeployMode”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。 + CategoryInfo : ObjectNotFound: (-DeployMode:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException + PSComputerName : WKPF26YSKX
    • 在命令前尝试dot sourcing。这告诉 PowerShell 执行以下 .exe。 (见编辑)
    猜你喜欢
    • 2021-01-17
    • 2021-01-10
    • 2021-02-26
    • 2021-10-14
    • 2012-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多