简体   繁体   中英

How to install multiple packages using install-package cmdlet in powershell?

I'm setting up a package installation solution for my school. All of your packages are .msi. We are using powershell package manager to install everything. I want to be able to push the packages one shot one after another remotely from a remote server.

When installing one package at a time providing the exact path of the msi, it works. However, all my attempts to make a huge automated install failed as my code doesn't accept wildcars (the *).

Here is my code:

$Computers = Get-Content -Path "E:\servername\share\computer\test.txt"
$SharePath = "\\server.domain.ca\share\repo\MSI"
$Cred = Get-Credential $env:USERNAME


foreach ($Computer in $Computers)
    {
        $Computer
        Invoke-Command -ComputerName $Computer -Credential $Cred  -ScriptBlock {
        $null = New-PSDrive -Credential $using:Cred server -Root (Split-Path -Parent $using:SharePath) -PSProvider FileSystem
        Install-Package '\\servername\share\repo\MSI\*.msi'}
    }

The error I have is The specified name ****** should not contain any wildcard characters.

I want to be able to install my packages in one go.... got any idea how to do it?

您可以使用Get-Item获取与通配符匹配的所有文件,并使用循环来安装每个包:

Get-Item '\\servername\share\repo\MSI\*.msi' | foreach { Install-Package $_ }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM