【问题标题】:Any ideas on why i am receiving this error? Any help appreciated. Thnx关于我为什么收到此错误的任何想法?任何帮助表示赞赏。谢谢
【发布时间】:2021-08-06 22:52:50
【问题描述】:
Uninstalling : 
The term 'C:\temp\install\Deploy-Application.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, 
or if a path was included, verify that the path is correct and try again.
    + CategoryInfo          : ObjectNotFound: (C:\temp\install\Deploy-Application.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    + PSComputerName        : WKPF26YSKX

这是运行的代码:

function Install-File {
    Invoke-Command `
        -Session $global:session `
        -ScriptBlock{ 
        
    if( -not (Test-Path -Path "V:\") ) {
                New-PSDrive -Name "V" -PSProvider "FileSystem" -Root "\\lounaswps01\idrive\D907ATS" -Credential (Get-Credential -Credential "slb8031a") -Scope global

            } 
         

            $Global:certRequestID = $global:objTemp.CRID

        # Assign server path and local path variables w/ given CR ID
             $serverPath = "v:\" + $Global:certRequestID
            $localPath = "C:\temp\" + $Global:certRequestID

          
            dir $serverPath
            dir $localPath

          
          #Copy-Item -Path $serverPath -Destination $localPath -Recurse -Force | Out-Host
            

        # 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 "
                }

                
                    Write-Host "`nUninstalling ${certRequestID}: "
                    Invoke-Expression -Command " ${localPath}install\Deploy-Application.exe -DeployMode 'Silent' -DeploymentType 'Uninstall'  | Out-Host"
                    #Start-process -FilePath "${localPath}\install\Deploy-Application.exe" -argumentList "-DeployMode Silent -DeploymentType Uninstall" -wait -noNewWindow

                
                    Write-Host "`nInstalling ${certRequestID}: "
                    Invoke-Expression -Command " ${localPath}\install\Deploy-Application.exe -DeployMode 'Silent'  | Out-Host "
                    
            }
        # Offer to delete files from host
             $prompt = Read-Host -Prompt "`nDelete ${certRequestID} from the user's temp folder? (y/n)"
            if($prompt.ToLower() -eq "y") {
                Write-Host "`nDeleting files..."
                Remove-Item -LiteralPath $localPath -Recurse -Force  
        }
        }

【问题讨论】:

  • 嗯,它表明$global:objTemp.CRID 解析为$null 或远程会话中的空字符串。看起来有些东西(可能是另一个函数?)应该针对远程会话运行以首先设置这些值?
  • 是的,它应该在远程会话中安装软件。所以“C:\temp\install\Deploy-Application.exe”应该是“C:\temp\SOFTWARE\install\Deploy-Application.exe”,但由于某种原因它没有拉 CRID @MathiasR.Jessen 感谢您的帮助

标签: powershell error-handling powershell-2.0 powershell-3.0 powershell-remoting


【解决方案1】:

您在卸载的其中一行中缺少反斜杠?

Invoke-Expression -Command " ${localPath}install\Deploy-Application.exe 

应阅读:

Invoke-Expression -Command " ${localPath}\install\Deploy-Application.exe 

【讨论】:

    猜你喜欢
    • 2022-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-11
    • 2020-08-10
    • 1970-01-01
    • 2020-09-22
    • 2021-09-10
    相关资源
    最近更新 更多