How to get a list of packages from one machine and install in another with Chocolatey?

前端 未结 6 2037
迷失自我
迷失自我 2021-01-31 08:23

Calling clist -l gives me a list of packages with versions:

7zip.install 16.04
ccleaner 5.28.6005
ConEmu 17.3.16.0
...

How do I ge

6条回答
  •  旧巷少年郎
    2021-01-31 08:57

    Since you want to omit the version I used the choco upgrade:

    # Filter for selecting packages, if empty will match all.
    # I do this at times to see whats installed for my company packages
    $PkgPrefix = ""
    
    $cmd = "cup -y "
    Test-WSMan $server | Out-Null
    $session = New-PSSession -ComputerName $server -Credential ( Import-Clixml -Path $CredenitalFile ) -Verbose -Authentication Negotiate
    
    $(clist -lo -r --id-starts-with "$PkgPrefix" )| % { $cmd += "$($_.Split( "|" )[0]),"}
    
    Invoke-Command -Session $session -ScriptBlock $cmd
    

    As Gary suggested, a configuration file might be an easier solution to maintain. I server up my configurations on a web-server, so I can just shell in and execute one command to install everything and have the ability to make a simple XSL style sheet for viewing.

    cinst -y $( ( [xml]( Invoke-WebRequest -Uri http://softwareList.config) ).packages.package | Select id ).id
    

    Or you could just save it locally and call it with all the information:

    (iwr -Uri http://softwareList.config).content | Out-File "$($env:LOCALAPPDATA)\list.config" -Encoding utf8;
    cinst "$($env:LOCALAPPDATA)\list.config -y
    

提交回复
热议问题