PowerShell, термин «xxxxxx» не распознается как имя командлета - PullRequest
0 голосов
/ 10 марта 2020

Итак, у меня есть следующий скрипт PowerShell, который устанавливает стороннее дополнение в программу под названием M-Files. Этот скрипт отлично работал пару дней go, затем я попытался запустить его сегодня, ничего не меняя, и он дал мне пару ошибок, как показано ниже.

Я новичок в этом, поэтому я сделал несколько исследования и не нашли ничего, что помогло бы.

К вашему сведению: Пытался сделать это решение, и это не помогло, у меня не работают процессоры PowerShell, поэтому я ' m не выходит за пределы.

Сценарий:

# Application details
$appFilePath = "bin\Debug\ACV.mfappx"
$appGuid = "e9982d4b-e705-4016-a99c-dfd4bbe3fadc"

# Target vault
$vaultName = "IDIRMEGA"

# Connection details 
$authType = 1 # 1 = MFAuthTypeLoggedOnWindowsUser
$userName = ""
$password = ""
$domain = ""
$spn = ""
$protocolSequence = "ncacn_ip_tcp"
$networkAddress = "localhost"
$endpoint = 2266
$encryptedConnection = $false
$localComputerName = ""

Write-Host "Connecting to Vault..."

# Load M-Files API
$null = [System.Reflection.Assembly]::LoadWithPartialName("Interop.MFilesAPI")

# Connect to M-Files Server
$server = new-object MFilesAPI.MFilesServerApplicationClass
$tzi = new-object MFilesAPI.TimeZoneInformationClass
$tzi.LoadWithCurrentTimeZone()
$null = $server.ConnectAdministrativeEx( $tzi, $authType, $userName, $password, $domain, $spn, $protocolSequence, $networkAddress, $endpoint, $encryptedConnection, $localComputerName )

# Get the target vault
$vaultOnServer = $server.GetOnlineVaults().GetVaultByName( $vaultName )

# Login to vault
$vault = $vaultOnServer.LogIn()

# Try to uninstall existing application
try
{
    Write-Host "Checking for previous installation of ACV..."

    # Uninstall
    $vault.CustomApplicationManagementOperations.UninstallCustomApplication( $appGuid );

    Write-Host "Restarting after uninstall..."

    # Restart vault. The installation seems to fail, if the vault is not restarted after uninstall.
    $server.VaultManagementOperations.TakeVaultOffline( $vaultOnServer.GUID, $true )
    $server.VaultManagementOperations.BringVaultOnline( $vaultOnServer.GUID )

    # Login to vault again.
    $vault = $vaultOnServer.LogIn()
}
catch {}

Write-Host "Installing ACV..."

# Install application. The vault should not have the application installed at this point.
$vault.CustomApplicationManagementOperations.InstallCustomApplication( $appFilePath )

Write-Host "Restarting after install..."

# Restart vault
$server.VaultManagementOperations.TakeVaultOffline( $vaultOnServer.GUID, $true )
$server.VaultManagementOperations.BringVaultOnline( $vaultOnServer.GUID )

Ошибка:

1>  Write-Host : The term 'Write-Host' is not recognized as the name of a cmdlet, function, script file, or operable progra
1>  m. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
1>  At C:\Users\Konica Minolta\source\repos\ACV\ACV\install-application.ps1:20 char:1
1>  + Write-Host "Connecting to Vault..."
1>  + ~~~~~~~~~~
1>      + CategoryInfo          : ObjectNotFound: (Write-Host:String) [], CommandNotFoundException
1>      + FullyQualifiedErrorId : CommandNotFoundException
1>   
1>  new-object : The term 'new-object' is not recognized as the name of a cmdlet, function, script file, or operable progra
1>  m. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
1>  At C:\Users\Konica Minolta\source\repos\ACV\ACV\install-application.ps1:26 char:11
1>  + $server = new-object MFilesAPI.MFilesServerApplicationClass
1>  +           ~~~~~~~~~~
1>      + CategoryInfo          : ObjectNotFound: (new-object:String) [], CommandNotFoundException
1>      + FullyQualifiedErrorId : CommandNotFoundException
1>   
1>  new-object : The term 'new-object' is not recognized as the name of a cmdlet, function, script file, or operable progra
1>  m. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
1>  At C:\Users\Konica Minolta\source\repos\ACV\ACV\install-application.ps1:27 char:8
1>  + $tzi = new-object MFilesAPI.TimeZoneInformationClass
1>  +        ~~~~~~~~~~
1>      + CategoryInfo          : ObjectNotFound: (new-object:String) [], CommandNotFoundException
1>      + FullyQualifiedErrorId : CommandNotFoundException
1>   
1>  You cannot call a method on a null-valued expression.
1>  At C:\Users\Konica Minolta\source\repos\ACV\ACV\install-application.ps1:28 char:1
1>  + $tzi.LoadWithCurrentTimeZone()
1>  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>      + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
1>      + FullyQualifiedErrorId : InvokeMethodOnNull
1>   
1>  You cannot call a method on a null-valued expression.
1>  At C:\Users\Konica Minolta\source\repos\ACV\ACV\install-application.ps1:29 char:1
1>  + $null = $server.ConnectAdministrativeEx( $tzi, $authType, $userName,  ...
1>  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>      + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
1>      + FullyQualifiedErrorId : InvokeMethodOnNull
1>   
1>  You cannot call a method on a null-valued expression.
1>  At C:\Users\Konica Minolta\source\repos\ACV\ACV\install-application.ps1:32 char:1
1>  + $vaultOnServer = $server.GetOnlineVaults().GetVaultByName( $vaultName ...
1>  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>      + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
1>      + FullyQualifiedErrorId : InvokeMethodOnNull
1>   
1>  You cannot call a method on a null-valued expression.
1>  At C:\Users\Konica Minolta\source\repos\ACV\ACV\install-application.ps1:35 char:1
1>  + $vault = $vaultOnServer.LogIn()
1>  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>      + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
1>      + FullyQualifiedErrorId : InvokeMethodOnNull
1>   
1>  Write-Host : The term 'Write-Host' is not recognized as the name of a cmdlet, function, script file, or operable progra
1>  m. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
1>  At C:\Users\Konica Minolta\source\repos\ACV\ACV\install-application.ps1:56 char:1
1>  + Write-Host "Installing ACV..."
1>  + ~~~~~~~~~~
1>      + CategoryInfo          : ObjectNotFound: (Write-Host:String) [], CommandNotFoundException
1>      + FullyQualifiedErrorId : CommandNotFoundException
1>   
1>  You cannot call a method on a null-valued expression.
1>  At C:\Users\Konica Minolta\source\repos\ACV\ACV\install-application.ps1:59 char:1
1>  + $vault.CustomApplicationManagementOperations.InstallCustomApplication ...
1>  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>      + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
1>      + FullyQualifiedErrorId : InvokeMethodOnNull
1>   
1>  Write-Host : The term 'Write-Host' is not recognized as the name of a cmdlet, function, script file, or operable progra
1>  m. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
1>  At C:\Users\Konica Minolta\source\repos\ACV\ACV\install-application.ps1:61 char:1
1>  + Write-Host "Restarting after install..."
1>  + ~~~~~~~~~~
1>      + CategoryInfo          : ObjectNotFound: (Write-Host:String) [], CommandNotFoundException
1>      + FullyQualifiedErrorId : CommandNotFoundException
1>   
1>  You cannot call a method on a null-valued expression.
1>  At C:\Users\Konica Minolta\source\repos\ACV\ACV\install-application.ps1:64 char:1
1>  + $server.VaultManagementOperations.TakeVaultOffline( $vaultOnServer.GU ...
1>  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>      + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
1>      + FullyQualifiedErrorId : InvokeMethodOnNull
1>   
1>  You cannot call a method on a null-valued expression.
1>  At C:\Users\Konica Minolta\source\repos\ACV\ACV\install-application.ps1:65 char:1
1>  + $server.VaultManagementOperations.BringVaultOnline( $vaultOnServer.GU ...
1>  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>      + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
1>      + FullyQualifiedErrorId : InvokeMethodOnNull
1>   
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

1 Ответ

1 голос
/ 10 марта 2020

Как лучший путь проверки проблемы, содержащий модули:

1) Проверьте $env:psmodulePath в powershell cli или ISE, он должен содержать путь к каталогу с вашими модулями (если он пуст, вы должны добавить путь)

2) Для модулей ручной загрузки, которые не были найдены / загружаются автоматически, используйте Import-Module командлет

3) Вы можете настроить свой psprofile для его загрузки config_psprofile

...