Removed old function folder
This commit is contained in:
@@ -1,38 +1,38 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Short description
|
Short description
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Long description
|
Long description
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Example of how to use this cmdlet
|
Example of how to use this cmdlet
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Another example of how to use this cmdlet
|
Another example of how to use this cmdlet
|
||||||
#>
|
#>
|
||||||
function Get-ChocoOutdatedPackages {
|
function Get-ChocoOutdatedPackages {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
)
|
)
|
||||||
Write-Verbose "Getting local outdated packages"
|
Write-Verbose "Getting local outdated packages"
|
||||||
$OutdatedPackages = (choco outdated -r --ignore-pinned --ignore-unfound --timeout=60)
|
$OutdatedPackages = (choco outdated -r --ignore-pinned --ignore-unfound --timeout=60)
|
||||||
if ($LASTEXITCODE -eq 1){
|
if ($LASTEXITCODE -eq 1){
|
||||||
Write-Verbose -Message 'Error getting outdated packages'
|
Write-Verbose -Message 'Error getting outdated packages'
|
||||||
$OutdatedPackages
|
$OutdatedPackages
|
||||||
Exit
|
Exit
|
||||||
}
|
}
|
||||||
#If no updated packages are available then exit
|
#If no updated packages are available then exit
|
||||||
if ($LASTEXITCODE -eq 0){
|
if ($LASTEXITCODE -eq 0){
|
||||||
Write-Verbose -Message 'No new packages available. Exiting'
|
Write-Verbose -Message 'No new packages available. Exiting'
|
||||||
Exit
|
Exit
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# $NewPackages =
|
# $NewPackages =
|
||||||
foreach ($NewPackage in $OutdatedPackages){
|
foreach ($NewPackage in $OutdatedPackages){
|
||||||
[PSCustomObject]@{
|
[PSCustomObject]@{
|
||||||
Name = $NewPackage.Split('|')[0]
|
Name = $NewPackage.Split('|')[0]
|
||||||
CurrentVersion = $NewPackage.Split('|')[1]
|
CurrentVersion = $NewPackage.Split('|')[1]
|
||||||
Version = $NewPackage.Split('|')[2]
|
Version = $NewPackage.Split('|')[2]
|
||||||
Pinned = $NewPackage.Split('|')[3]
|
Pinned = $NewPackage.Split('|')[3]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,69 +1,45 @@
|
|||||||
Function Get-ChocoPackageMetaData {
|
Function Get-ChocoPackageMetaData {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Return package metadata from a given Chocolatey Package(s)
|
Return package metadata from a given Chocolatey Package(s)
|
||||||
|
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Reads the contents of the nupkg and extracts metadata from the nuspec contained within it
|
Reads the contents of the nupkg and extracts metadata from the nuspec contained within it
|
||||||
|
|
||||||
.PARAMETER ChocolateyPackage
|
.PARAMETER ChocolateyPackage
|
||||||
The chocolatey package(s) you wish to extract data from
|
The chocolatey package(s) you wish to extract data from
|
||||||
|
|
||||||
.PARAMETER AdditonalInformation
|
.EXAMPLE
|
||||||
Return more information about the package than the default ID and Version
|
Get-ChocoPackageMetaData -ChocolateyPackage C:\Packages\googlechrome.nupkg
|
||||||
|
|
||||||
.EXAMPLE
|
.NOTES
|
||||||
Get-ChocoPackageMetaData -ChocolateyPackage C:\Packages\googlechrome.nupkg
|
Written by Stephen Valdinger of Chocolatey Software for Dan Franciscus
|
||||||
|
#>
|
||||||
.EXAMPLE
|
|
||||||
Get-ChocoPackageMetaData -ChocolateyPackage C:\Packages\googlechrome.nupkg -AdditionalInformation Owners,Description,ProjectUrl,Dependencies
|
[cmdletBinding()]
|
||||||
.NOTES
|
Param(
|
||||||
Written by Stephen Valdinger of Chocolatey Software for Dan Franciscus
|
[ValidateScript({Test-Path $_})]
|
||||||
|
[String[]]
|
||||||
#>
|
$ChocolateyPackage
|
||||||
|
)
|
||||||
[cmdletBinding()]
|
|
||||||
Param(
|
begin { $null = Add-Type -Assemblyname "System.IO.Compression.Filesystem" }
|
||||||
[ValidateScript({Test-Path $_})]
|
|
||||||
[String[]]
|
process {
|
||||||
$ChocolateyPackage,
|
Foreach($package in $ChocolateyPackage){
|
||||||
|
$obj = @{}
|
||||||
[Parameter()]
|
$entry = [IO.Compression.Zipfile]::OpenRead($package).Entries |
|
||||||
[String[]]
|
Where-Object { $_.Name -match "nuspec" }
|
||||||
[ValidateSet('Authors','Description','ProjectUrl','Owners','Licenseurl','Iconurl','Dependencies')]
|
$stream = $entry.Open()
|
||||||
$AdditionalInformation
|
$reader = New-Object IO.StreamReader($stream)
|
||||||
)
|
$text = $reader.ReadToEnd()
|
||||||
|
[xml]$xml = $text
|
||||||
begin { $null = Add-Type -Assemblyname "System.IO.Compression.Filesystem" }
|
$obj.Add("Name","$($xml.package.metadata.id)")
|
||||||
|
$obj.Add("Version","$($xml.package.metadata.version)")
|
||||||
process {
|
$reader.Close()
|
||||||
Foreach($package in $ChocolateyPackage){
|
$stream.Close()
|
||||||
$obj = [ordered]@{}
|
[pscustomobject]$obj
|
||||||
$entry = [IO.Compression.Zipfile]::OpenRead($package).Entries |
|
|
||||||
Where-Object { $_.Name -match "nuspec" }
|
}
|
||||||
$stream = $entry.Open()
|
}
|
||||||
$reader = New-Object IO.StreamReader($stream)
|
|
||||||
$text = $reader.ReadToEnd()
|
|
||||||
[xml]$xml = $text
|
|
||||||
$obj.Add("Name","$($xml.package.metadata.id)")
|
|
||||||
$obj.Add("Version","$($xml.package.metadata.version)")
|
|
||||||
|
|
||||||
Foreach($member in $AdditionalInformation){
|
|
||||||
|
|
||||||
if($member -eq 'Dependencies'){
|
|
||||||
$obj.Add("$member",$($xml.package.metadata.dependencies.dependency | Select-Object Id,Version))
|
|
||||||
}
|
|
||||||
|
|
||||||
else{
|
|
||||||
$obj.Add("$member",$($xml.package.metadata.$($member)))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$reader.Close()
|
|
||||||
$stream.Close()
|
|
||||||
[pscustomobject]$obj
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,52 +1,52 @@
|
|||||||
function Invoke-BoxStarterRemoteUpgrade {
|
function Invoke-BoxStarterRemoteUpgrade {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string[]]$ComputerName,
|
[string[]]$ComputerName,
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[pscredential]$Credential,
|
[pscredential]$Credential,
|
||||||
[string[]]$AdditionalPackages,
|
[string[]]$AdditionalPackages,
|
||||||
[string[]]$ExcludedPackages,
|
[string[]]$ExcludedPackages,
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string]$ScriptPath,
|
[string]$ScriptPath,
|
||||||
[switch]$Parallel
|
[switch]$Parallel
|
||||||
)
|
)
|
||||||
|
|
||||||
#Create dynamic upgrade list
|
#Create dynamic upgrade list
|
||||||
Invoke-Command -ArgumentList $AdditionalPackages,$ExcludedPackages,$ScriptPath -ComputerName $ComputerName -ScriptBlock {
|
Invoke-Command -ArgumentList $AdditionalPackages,$ExcludedPackages,$ScriptPath -ComputerName $ComputerName -ScriptBlock {
|
||||||
param (
|
param (
|
||||||
$AdditionalPackages,
|
$AdditionalPackages,
|
||||||
$ExcludedPackages,
|
$ExcludedPackages,
|
||||||
$ScriptPath
|
$ScriptPath
|
||||||
)
|
)
|
||||||
if (Test-Path $ScriptPath) {
|
if (Test-Path $ScriptPath) {
|
||||||
Remove-Item $ScriptPath -Force
|
Remove-Item $ScriptPath -Force
|
||||||
}
|
}
|
||||||
$packages = [System.Collections.ArrayList]@(choco outdated -r --ignore-unfound --ignore-pinned | Foreach-Object {
|
$packages = [System.Collections.ArrayList]@(choco outdated -r --ignore-unfound --ignore-pinned | Foreach-Object {
|
||||||
($_.split("|"))[0]
|
($_.split("|"))[0]
|
||||||
})
|
})
|
||||||
foreach ($AddedPackage in $AdditionalPackages){
|
foreach ($AddedPackage in $AdditionalPackages){
|
||||||
if ($packages -notcontains $AddedPackage){
|
if ($packages -notcontains $AddedPackage){
|
||||||
$packages.Add($AddedPackage) | Out-Null
|
$packages.Add($AddedPackage) | Out-Null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($ExcludedPackage in $ExcludedPackages){
|
foreach ($ExcludedPackage in $ExcludedPackages){
|
||||||
if ($packages -contains $ExcludedPackage){
|
if ($packages -contains $ExcludedPackage){
|
||||||
$packages.Remove($ExcludedPackage) | Out-Null
|
$packages.Remove($ExcludedPackage) | Out-Null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$Packages | ForEach-Object {
|
$Packages | ForEach-Object {
|
||||||
Add-Content $ScriptPath -Value "choco upgrade $_ -r -y --timeout=600"
|
Add-Content $ScriptPath -Value "choco upgrade $_ -r -y --timeout=600"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#Upgrade computers with Boxstarter
|
#Upgrade computers with Boxstarter
|
||||||
if (!$Parallel){
|
if (!$Parallel){
|
||||||
Install-BoxstarterPackage -ComputerName $ComputerName -PackageName $ScriptPath
|
Install-BoxstarterPackage -ComputerName $ComputerName -PackageName $ScriptPath -DelegateChocoSources
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#Upgrade computers in parallel with Boxstarter
|
#Upgrade computers in parallel with Boxstarter
|
||||||
$ComputerName | ForEach-Object {
|
$ComputerName | ForEach-Object {
|
||||||
start-process -RedirectStandardOutput C:\Windows\Temp\$_.txt -FilePath powershell -ArgumentList "-windowstyle hidden Install-BoxstarterPackage -ComputerName $_ -PackageName $ScriptPath" -PassThru
|
start-process -RedirectStandardOutput C:\Windows\Temp\$_.txt -FilePath powershell -ArgumentList "-windowstyle hidden Install-BoxstarterPackage -ComputerName $_ -PackageName $ScriptPath" -PassThru
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,47 +1,47 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Short description
|
Short description
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Long description
|
Long description
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Example of how to use this cmdlet
|
Example of how to use this cmdlet
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Another example of how to use this cmdlet
|
Another example of how to use this cmdlet
|
||||||
#>
|
#>
|
||||||
function Invoke-ChocoInternalizePackage {
|
function Invoke-ChocoInternalizePackage {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true,ValueFromPipeline=$True)]
|
[Parameter(Mandatory=$true,ValueFromPipeline=$True)]
|
||||||
[pscustomobject[]]$PackageNames,
|
[pscustomobject[]]$PackageNames,
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string]$Path,
|
[string]$Path,
|
||||||
[switch]$PurgeWorkingDirectory
|
[switch]$PurgeWorkingDirectory
|
||||||
)
|
)
|
||||||
begin {
|
begin {
|
||||||
if ($PurgeWorkingDirectory){
|
if ($PurgeWorkingDirectory){
|
||||||
Get-ChildItem -Path $Path -Recurse | Remove-Item -Recurse -Force
|
Get-ChildItem -Path $Path -Recurse | Remove-Item -Recurse -Force
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
process {
|
process {
|
||||||
Set-Location $Path
|
Set-Location $Path
|
||||||
foreach ($Package in $PackageNames){
|
foreach ($Package in $PackageNames){
|
||||||
Write-Verbose ("Downloading " + $Package.Name)
|
Write-Verbose ("Downloading " + $Package.Name)
|
||||||
$Date = Get-Date
|
$Date = Get-Date
|
||||||
choco download $Package.Name --internalize --no-progress --internalize-all-urls --source chocolatey -r | Write-Verbose
|
choco download $Package.Name --internalize --no-progress --internalize-all-urls --source chocolatey -r | Write-Verbose
|
||||||
$DownloadedPackages = Get-ChildItem -Path $Path | Where-Object {$_.Extension -eq '.nupkg' -AND $_.LastWriteTime -gt $Date} | Select-Object -ExpandProperty FullName
|
$DownloadedPackages = Get-ChildItem -Path $Path | Where-Object {$_.Extension -eq '.nupkg' -AND $_.LastWriteTime -gt $Date} | Select-Object -ExpandProperty FullName
|
||||||
if ($LASTEXITCODE -ne 0){
|
if ($LASTEXITCODE -ne 0){
|
||||||
$Result = 'Internalize Failed'
|
$Result = 'Internalize Failed'
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$Result = 'Internalize Success'
|
$Result = 'Internalize Success'
|
||||||
}
|
}
|
||||||
Write-Verbose ($Package.Name + ' internalize failed')
|
Write-Verbose ($Package.Name + ' internalize failed')
|
||||||
[PSCustomObject]@{
|
[PSCustomObject]@{
|
||||||
Name = $Package.Name
|
Name = $Package.Name
|
||||||
Result = $Result
|
Result = $Result
|
||||||
Version = $Package.Version
|
Version = $Package.Version
|
||||||
NuGetpkgs = $DownloadedPackages
|
NuGetpkgs = $DownloadedPackages
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,58 +1,69 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Short description
|
Short description
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Long description
|
Long description
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Example of how to use this cmdlet
|
Example of how to use this cmdlet
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Another example of how to use this cmdlet
|
Another example of how to use this cmdlet
|
||||||
#>
|
#>
|
||||||
function Invoke-ChocoRemoteUpgrade {
|
function Invoke-ChocoRemoteUpgrade {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string[]]$ComputerName,
|
[string[]]$ComputerName,
|
||||||
[string[]]$AdditionalPackages,
|
[pscredential]$Credential,
|
||||||
[string[]]$ExcludedPackages,
|
[string[]]$AdditionalPackages,
|
||||||
[switch]$RebootifPending
|
[string[]]$ExcludedPackages,
|
||||||
)
|
[switch]$RebootifPending
|
||||||
process {
|
)
|
||||||
Invoke-Command -ComputerName $ComputerName -ScriptBlock {
|
process {
|
||||||
#Get list of locally installed packages to upgrade
|
#Create dynamic upgrade list
|
||||||
$packages = [System.Collections.ArrayList]@(choco outdated -r --ignore-unfound --ignore-pinned | Foreach-Object {
|
Invoke-Command -ArgumentList $AdditionalPackages,$ExcludedPackages,$ScriptPath,$Credential -ComputerName $ComputerName -ScriptBlock {
|
||||||
($_.split("|"))[0]})
|
param (
|
||||||
|
$AdditionalPackages,
|
||||||
foreach ($ExcludedPackage in $ExcludedPackages){
|
$ExcludedPackages,
|
||||||
if ($packages -contains $ExcludedPackage){
|
$ScriptPath
|
||||||
$packages.Remove($ExcludedPackage) | Out-Null
|
)
|
||||||
}
|
$packages = [System.Collections.ArrayList]@(choco outdated -r --ignore-unfound --ignore-pinned | Foreach-Object {
|
||||||
}
|
($_.split("|"))[0]
|
||||||
foreach ($AddedBasePackage in $AdditionalPackage){
|
})
|
||||||
if ($packages -notcontains $AddedBasePackage){
|
if ($AdditionalPackages){
|
||||||
$packages.Add($AddedBasePackage) | Out-Null
|
foreach ($AddedPackage in $AdditionalPackages){
|
||||||
}
|
if ($packages -notcontains $AddedPackage){
|
||||||
}
|
$packages.Add($AddedPackage) | Out-Null
|
||||||
foreach ($package in $packages){
|
}
|
||||||
choco upgrade $package -r -y --timeout=600 | Out-File ("c:\Windows\Temp\choco-" + $package + ".txt")
|
}
|
||||||
if ($LASTEXITCODE -ne 0){
|
}
|
||||||
$Result = 'Failed'
|
if ($ExcludedPackages){
|
||||||
}
|
foreach ($ExcludedPackage in $ExcludedPackages){
|
||||||
else{
|
if ($packages -contains $ExcludedPackage){
|
||||||
$Result = 'Success'
|
$packages.Remove($ExcludedPackage) | Out-Null
|
||||||
}
|
}
|
||||||
[PSCustomObject]@{
|
}
|
||||||
Name = $Package
|
}
|
||||||
Result = $Result
|
foreach ($package in $packages){
|
||||||
Computer = $Env:COMPUTERNAME
|
choco upgrade $package -r -y --timeout=600 | Out-File ("c:\Windows\Temp\choco-" + $package + ".txt")
|
||||||
}
|
if ($LASTEXITCODE -ne 0){
|
||||||
}
|
$Result = 'Failed'
|
||||||
}
|
}
|
||||||
#Restart machines with pending Reboot
|
else{
|
||||||
if ($RebootifPending){
|
$Result = 'Success'
|
||||||
Test-PendingReboot -ComputerName $ComputerName -SkipConfigurationManagerClientCheck | Where-Object {$_.IsRebootpending -eq $True } | ForEach-Object {
|
}
|
||||||
Restart-Computer -ComputerName $_.ComputerName -Force
|
[PSCustomObject]@{
|
||||||
}
|
Name = $Package
|
||||||
}
|
Result = $Result
|
||||||
}
|
Computer = $Env:COMPUTERNAME
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#Restart machines with pending Reboot
|
||||||
|
if ($RebootifPending){
|
||||||
|
Test-PendingReboot -ComputerName $ComputerName -SkipConfigurationManagerClientCheck | Where-Object {$_.IsRebootpending -eq $True } | ForEach-Object {
|
||||||
|
"Rebooting $($_.ComputerName)"
|
||||||
|
Restart-Computer -ComputerName $_.ComputerName -Force
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,39 +1,39 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Short description
|
Short description
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Long description
|
Long description
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Example of how to use this cmdlet
|
Example of how to use this cmdlet
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Another example of how to use this cmdlet
|
Another example of how to use this cmdlet
|
||||||
#>
|
#>
|
||||||
function Invoke-ChocoUpgradeIntPackage {
|
function Invoke-ChocoUpgradeIntPackage {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true,ValueFromPipeline=$True)]
|
[Parameter(Mandatory=$true,ValueFromPipeline=$True)]
|
||||||
[pscustomobject[]]$PackageNames,
|
[pscustomobject[]]$PackageNames,
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string]$Path
|
[string]$Path
|
||||||
)
|
)
|
||||||
process {
|
process {
|
||||||
foreach ($Package in $PackageNames){
|
foreach ($Package in $PackageNames){
|
||||||
Write-Verbose ("Upgrading " + $Package.Name)
|
Write-Verbose ("Upgrading " + $Package.Name)
|
||||||
choco upgrade $Package.Name --source $Path --no-progress -y -r | Write-Verbose
|
choco upgrade $Package.Name --source $Path --no-progress -y -r | Write-Verbose
|
||||||
#If failure detected in output continue to next package
|
#If failure detected in output continue to next package
|
||||||
if ($LASTEXITCODE -ne 0){
|
if ($LASTEXITCODE -ne 0){
|
||||||
$Result = 'Upgrade Failed'
|
$Result = 'Upgrade Failed'
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$Result = 'Upgrade Success'
|
$Result = 'Upgrade Success'
|
||||||
}
|
}
|
||||||
Write-Verbose ($Package.Name + ' Upgrade failed')
|
Write-Verbose ($Package.Name + ' Upgrade failed')
|
||||||
[PSCustomObject]@{
|
[PSCustomObject]@{
|
||||||
Name = $Package.Name
|
Name = $Package.Name
|
||||||
Result = $Result
|
Result = $Result
|
||||||
Version = $Package.Version
|
Version = $Package.Version
|
||||||
NuGetpkgs = $Package.NuGetpkgs
|
NuGetpkgs = $Package.NuGetpkgs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,45 +1,45 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Short description
|
Short description
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Long description
|
Long description
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Example of how to use this cmdlet
|
Example of how to use this cmdlet
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Another example of how to use this cmdlet
|
Another example of how to use this cmdlet
|
||||||
#>
|
#>
|
||||||
function Push-ChocoIntPackage {
|
function Push-ChocoIntPackage {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true,ValueFromPipeline=$True)]
|
[Parameter(Mandatory=$true,ValueFromPipeline=$True)]
|
||||||
[pscustomobject[]]$PackageNames,
|
[pscustomobject[]]$PackageNames,
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string]$Path,
|
[string]$Path,
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string]$RepositoryURL,
|
[string]$RepositoryURL,
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[ValidateNotNull()]
|
[ValidateNotNull()]
|
||||||
[System.Management.Automation.PSCredential]$ApiKey
|
[System.Management.Automation.PSCredential]$ApiKey
|
||||||
)
|
)
|
||||||
process {
|
process {
|
||||||
foreach ($Package in $PackageNames){
|
foreach ($Package in $PackageNames){
|
||||||
foreach ($NuPkg in $Package.NuGetpkgs) {
|
foreach ($NuPkg in $Package.NuGetpkgs) {
|
||||||
$MetaData = Get-ChocoPackageMetaData -ChocolateyPackage $NuPkg
|
$MetaData = Get-ChocoPackageMetaData -ChocolateyPackage $NuPkg
|
||||||
choco push $NuPkg --force --source $RepositoryURL --api-key $ApiKey.GetNetworkCredential().Password --timeout=3600 | Write-Verbose
|
choco push $NuPkg --force --source $RepositoryURL --api-key $ApiKey.GetNetworkCredential().Password --timeout=3600 | Write-Verbose
|
||||||
if ($LASTEXITCODE -ne 0){
|
if ($LASTEXITCODE -ne 0){
|
||||||
$Result = 'Push Failed'
|
$Result = 'Push Failed'
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$Result = 'Push Success'
|
$Result = 'Push Success'
|
||||||
}
|
}
|
||||||
Write-Verbose "$($MetaData.Name) push failed"
|
Write-Verbose "$($MetaData.Name) push failed"
|
||||||
[PSCustomObject]@{
|
[PSCustomObject]@{
|
||||||
Name = $MetaData.Name
|
Name = $MetaData.Name
|
||||||
Result = $Result
|
Result = $Result
|
||||||
Version = $MetaData.Version
|
Version = $MetaData.Version
|
||||||
NuGetPackage = $NuPkg
|
NuGetPackage = $NuPkg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,37 +1,37 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Short description
|
Short description
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Long description
|
Long description
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Example of how to use this cmdlet
|
Example of how to use this cmdlet
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Another example of how to use this cmdlet
|
Another example of how to use this cmdlet
|
||||||
#>
|
#>
|
||||||
function Test-ChocoUpgradeTrigger {
|
function Test-ChocoUpgradeTrigger {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory=$true,ValueFromPipeline=$True)]
|
[Parameter(Mandatory=$true,ValueFromPipeline=$True)]
|
||||||
[pscustomobject[]]$PackageNames,
|
[pscustomobject[]]$PackageNames,
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string[]]$TriggerPackages,
|
[string[]]$TriggerPackages,
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string]$UpgradeScriptPath,
|
[string]$UpgradeScriptPath,
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[string]$TriggeredTime,
|
[string]$TriggeredTime,
|
||||||
[Parameter(Mandatory=$true)]
|
[Parameter(Mandatory=$true)]
|
||||||
[System.Management.Automation.PSCredential]$Credential
|
[System.Management.Automation.PSCredential]$Credential
|
||||||
)
|
)
|
||||||
process {
|
process {
|
||||||
foreach ($Package in $PackageNames){
|
foreach ($Package in $PackageNames){
|
||||||
if ($TriggerPackages -contains $Package.Name){
|
if ($TriggerPackages -contains $Package.Name){
|
||||||
Write-Output "Creating scheduled task"
|
Write-Output "Creating scheduled task for $($Package.Name)"
|
||||||
Disable-ScheduledTask -TaskName 'Triggered Choco Upgrade' | Unregister-ScheduledTask -Confirm:$False
|
Disable-ScheduledTask -TaskName 'Triggered Choco Upgrade' | Unregister-ScheduledTask -Confirm:$False
|
||||||
$Time = New-ScheduledTaskTrigger -At $TriggeredTime -Once
|
$Time = New-ScheduledTaskTrigger -At $TriggeredTime -Once
|
||||||
$PS = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument "-file $UpgradeScriptPath"
|
$PS = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument "-file $UpgradeScriptPath"
|
||||||
Register-ScheduledTask -User $Credential.UserName -Description 'This task is created when a certain third party software should be updated on clients' -TaskName 'Triggered Choco Upgrade' -Trigger $Time -Action $PS -Password $Credential.GetNetworkCredential().password -RunLevel Highest
|
Register-ScheduledTask -User $Credential.UserName -Description 'This task is created when a certain third party software should be updated on clients' -TaskName 'Triggered Choco Upgrade' -Trigger $Time -Action $PS -Password $Credential.GetNetworkCredential().password -RunLevel Highest
|
||||||
Exit
|
Exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
Short description
|
|
||||||
.DESCRIPTION
|
|
||||||
Long description
|
|
||||||
.EXAMPLE
|
|
||||||
Example of how to use this cmdlet
|
|
||||||
.EXAMPLE
|
|
||||||
Another example of how to use this cmdlet
|
|
||||||
#>
|
|
||||||
function Get-ChocoOutdatedPackages {
|
|
||||||
[CmdletBinding()]
|
|
||||||
param(
|
|
||||||
)
|
|
||||||
Write-Verbose "Getting local outdated packages"
|
|
||||||
$OutdatedPackages = (choco outdated -r --ignore-pinned --ignore-unfound --timeout=60)
|
|
||||||
if ($LASTEXITCODE -eq 1){
|
|
||||||
Write-Verbose -Message 'Error getting outdated packages'
|
|
||||||
$OutdatedPackages
|
|
||||||
Exit
|
|
||||||
}
|
|
||||||
#If no updated packages are available then exit
|
|
||||||
if ($LASTEXITCODE -eq 0){
|
|
||||||
Write-Verbose -Message 'No new packages available. Exiting'
|
|
||||||
Exit
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
# $NewPackages =
|
|
||||||
foreach ($NewPackage in $OutdatedPackages){
|
|
||||||
[PSCustomObject]@{
|
|
||||||
Name = $NewPackage.Split('|')[0]
|
|
||||||
CurrentVersion = $NewPackage.Split('|')[1]
|
|
||||||
Version = $NewPackage.Split('|')[2]
|
|
||||||
Pinned = $NewPackage.Split('|')[3]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
Function Get-ChocoPackageMetaData {
|
|
||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
Return package metadata from a given Chocolatey Package(s)
|
|
||||||
|
|
||||||
.DESCRIPTION
|
|
||||||
Reads the contents of the nupkg and extracts metadata from the nuspec contained within it
|
|
||||||
|
|
||||||
.PARAMETER ChocolateyPackage
|
|
||||||
The chocolatey package(s) you wish to extract data from
|
|
||||||
|
|
||||||
.EXAMPLE
|
|
||||||
Get-ChocoPackageMetaData -ChocolateyPackage C:\Packages\googlechrome.nupkg
|
|
||||||
|
|
||||||
.NOTES
|
|
||||||
Written by Stephen Valdinger of Chocolatey Software for Dan Franciscus
|
|
||||||
#>
|
|
||||||
|
|
||||||
[cmdletBinding()]
|
|
||||||
Param(
|
|
||||||
[ValidateScript({Test-Path $_})]
|
|
||||||
[String[]]
|
|
||||||
$ChocolateyPackage
|
|
||||||
)
|
|
||||||
|
|
||||||
begin { $null = Add-Type -Assemblyname "System.IO.Compression.Filesystem" }
|
|
||||||
|
|
||||||
process {
|
|
||||||
Foreach($package in $ChocolateyPackage){
|
|
||||||
$obj = @{}
|
|
||||||
$entry = [IO.Compression.Zipfile]::OpenRead($package).Entries |
|
|
||||||
Where-Object { $_.Name -match "nuspec" }
|
|
||||||
$stream = $entry.Open()
|
|
||||||
$reader = New-Object IO.StreamReader($stream)
|
|
||||||
$text = $reader.ReadToEnd()
|
|
||||||
[xml]$xml = $text
|
|
||||||
$obj.Add("Name","$($xml.package.metadata.id)")
|
|
||||||
$obj.Add("Version","$($xml.package.metadata.version)")
|
|
||||||
$reader.Close()
|
|
||||||
$stream.Close()
|
|
||||||
[pscustomobject]$obj
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
function Invoke-BoxStarterRemoteUpgrade {
|
|
||||||
[CmdletBinding()]
|
|
||||||
param(
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[string[]]$ComputerName,
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[pscredential]$Credential,
|
|
||||||
[string[]]$AdditionalPackages,
|
|
||||||
[string[]]$ExcludedPackages,
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[string]$ScriptPath,
|
|
||||||
[switch]$Parallel
|
|
||||||
)
|
|
||||||
|
|
||||||
#Create dynamic upgrade list
|
|
||||||
Invoke-Command -ArgumentList $AdditionalPackages,$ExcludedPackages,$ScriptPath -ComputerName $ComputerName -ScriptBlock {
|
|
||||||
param (
|
|
||||||
$AdditionalPackages,
|
|
||||||
$ExcludedPackages,
|
|
||||||
$ScriptPath
|
|
||||||
)
|
|
||||||
if (Test-Path $ScriptPath) {
|
|
||||||
Remove-Item $ScriptPath -Force
|
|
||||||
}
|
|
||||||
$packages = [System.Collections.ArrayList]@(choco outdated -r --ignore-unfound --ignore-pinned | Foreach-Object {
|
|
||||||
($_.split("|"))[0]
|
|
||||||
})
|
|
||||||
foreach ($AddedPackage in $AdditionalPackages){
|
|
||||||
if ($packages -notcontains $AddedPackage){
|
|
||||||
$packages.Add($AddedPackage) | Out-Null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($ExcludedPackage in $ExcludedPackages){
|
|
||||||
if ($packages -contains $ExcludedPackage){
|
|
||||||
$packages.Remove($ExcludedPackage) | Out-Null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$Packages | ForEach-Object {
|
|
||||||
Add-Content $ScriptPath -Value "choco upgrade $_ -r -y --timeout=600"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#Upgrade computers with Boxstarter
|
|
||||||
if (!$Parallel){
|
|
||||||
Install-BoxstarterPackage -ComputerName $ComputerName -PackageName $ScriptPath -DelegateChocoSources
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
#Upgrade computers in parallel with Boxstarter
|
|
||||||
$ComputerName | ForEach-Object {
|
|
||||||
start-process -RedirectStandardOutput C:\Windows\Temp\$_.txt -FilePath powershell -ArgumentList "-windowstyle hidden Install-BoxstarterPackage -ComputerName $_ -PackageName $ScriptPath" -PassThru
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
Short description
|
|
||||||
.DESCRIPTION
|
|
||||||
Long description
|
|
||||||
.EXAMPLE
|
|
||||||
Example of how to use this cmdlet
|
|
||||||
.EXAMPLE
|
|
||||||
Another example of how to use this cmdlet
|
|
||||||
#>
|
|
||||||
function Invoke-ChocoInternalizePackage {
|
|
||||||
[CmdletBinding()]
|
|
||||||
param(
|
|
||||||
[Parameter(Mandatory=$true,ValueFromPipeline=$True)]
|
|
||||||
[pscustomobject[]]$PackageNames,
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[string]$Path,
|
|
||||||
[switch]$PurgeWorkingDirectory
|
|
||||||
)
|
|
||||||
begin {
|
|
||||||
if ($PurgeWorkingDirectory){
|
|
||||||
Get-ChildItem -Path $Path -Recurse | Remove-Item -Recurse -Force
|
|
||||||
}
|
|
||||||
}
|
|
||||||
process {
|
|
||||||
Set-Location $Path
|
|
||||||
foreach ($Package in $PackageNames){
|
|
||||||
Write-Verbose ("Downloading " + $Package.Name)
|
|
||||||
$Date = Get-Date
|
|
||||||
choco download $Package.Name --internalize --no-progress --internalize-all-urls --source chocolatey -r | Write-Verbose
|
|
||||||
$DownloadedPackages = Get-ChildItem -Path $Path | Where-Object {$_.Extension -eq '.nupkg' -AND $_.LastWriteTime -gt $Date} | Select-Object -ExpandProperty FullName
|
|
||||||
if ($LASTEXITCODE -ne 0){
|
|
||||||
$Result = 'Internalize Failed'
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$Result = 'Internalize Success'
|
|
||||||
}
|
|
||||||
Write-Verbose ($Package.Name + ' internalize failed')
|
|
||||||
[PSCustomObject]@{
|
|
||||||
Name = $Package.Name
|
|
||||||
Result = $Result
|
|
||||||
Version = $Package.Version
|
|
||||||
NuGetpkgs = $DownloadedPackages
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
Short description
|
|
||||||
.DESCRIPTION
|
|
||||||
Long description
|
|
||||||
.EXAMPLE
|
|
||||||
Example of how to use this cmdlet
|
|
||||||
.EXAMPLE
|
|
||||||
Another example of how to use this cmdlet
|
|
||||||
#>
|
|
||||||
function Invoke-ChocoRemoteUpgrade {
|
|
||||||
[CmdletBinding()]
|
|
||||||
param(
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[string[]]$ComputerName,
|
|
||||||
[pscredential]$Credential,
|
|
||||||
[string[]]$AdditionalPackages,
|
|
||||||
[string[]]$ExcludedPackages,
|
|
||||||
[switch]$RebootifPending
|
|
||||||
)
|
|
||||||
process {
|
|
||||||
#Create dynamic upgrade list
|
|
||||||
Invoke-Command -ArgumentList $AdditionalPackages,$ExcludedPackages,$ScriptPath,$Credential -ComputerName $ComputerName -ScriptBlock {
|
|
||||||
param (
|
|
||||||
$AdditionalPackages,
|
|
||||||
$ExcludedPackages,
|
|
||||||
$ScriptPath
|
|
||||||
)
|
|
||||||
$packages = [System.Collections.ArrayList]@(choco outdated -r --ignore-unfound --ignore-pinned | Foreach-Object {
|
|
||||||
($_.split("|"))[0]
|
|
||||||
})
|
|
||||||
if ($AdditionalPackages){
|
|
||||||
foreach ($AddedPackage in $AdditionalPackages){
|
|
||||||
if ($packages -notcontains $AddedPackage){
|
|
||||||
$packages.Add($AddedPackage) | Out-Null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($ExcludedPackages){
|
|
||||||
foreach ($ExcludedPackage in $ExcludedPackages){
|
|
||||||
if ($packages -contains $ExcludedPackage){
|
|
||||||
$packages.Remove($ExcludedPackage) | Out-Null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($package in $packages){
|
|
||||||
choco upgrade $package -r -y --timeout=600 | Out-File ("c:\Windows\Temp\choco-" + $package + ".txt")
|
|
||||||
if ($LASTEXITCODE -ne 0){
|
|
||||||
$Result = 'Failed'
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$Result = 'Success'
|
|
||||||
}
|
|
||||||
[PSCustomObject]@{
|
|
||||||
Name = $Package
|
|
||||||
Result = $Result
|
|
||||||
Computer = $Env:COMPUTERNAME
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#Restart machines with pending Reboot
|
|
||||||
if ($RebootifPending){
|
|
||||||
Test-PendingReboot -ComputerName $ComputerName -SkipConfigurationManagerClientCheck | Where-Object {$_.IsRebootpending -eq $True } | ForEach-Object {
|
|
||||||
"Rebooting $($_.ComputerName)"
|
|
||||||
Restart-Computer -ComputerName $_.ComputerName -Force
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
Short description
|
|
||||||
.DESCRIPTION
|
|
||||||
Long description
|
|
||||||
.EXAMPLE
|
|
||||||
Example of how to use this cmdlet
|
|
||||||
.EXAMPLE
|
|
||||||
Another example of how to use this cmdlet
|
|
||||||
#>
|
|
||||||
function Invoke-ChocoUpgradeIntPackage {
|
|
||||||
[CmdletBinding()]
|
|
||||||
param(
|
|
||||||
[Parameter(Mandatory=$true,ValueFromPipeline=$True)]
|
|
||||||
[pscustomobject[]]$PackageNames,
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[string]$Path
|
|
||||||
)
|
|
||||||
process {
|
|
||||||
foreach ($Package in $PackageNames){
|
|
||||||
Write-Verbose ("Upgrading " + $Package.Name)
|
|
||||||
choco upgrade $Package.Name --source $Path --no-progress -y -r | Write-Verbose
|
|
||||||
#If failure detected in output continue to next package
|
|
||||||
if ($LASTEXITCODE -ne 0){
|
|
||||||
$Result = 'Upgrade Failed'
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$Result = 'Upgrade Success'
|
|
||||||
}
|
|
||||||
Write-Verbose ($Package.Name + ' Upgrade failed')
|
|
||||||
[PSCustomObject]@{
|
|
||||||
Name = $Package.Name
|
|
||||||
Result = $Result
|
|
||||||
Version = $Package.Version
|
|
||||||
NuGetpkgs = $Package.NuGetpkgs
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
Short description
|
|
||||||
.DESCRIPTION
|
|
||||||
Long description
|
|
||||||
.EXAMPLE
|
|
||||||
Example of how to use this cmdlet
|
|
||||||
.EXAMPLE
|
|
||||||
Another example of how to use this cmdlet
|
|
||||||
#>
|
|
||||||
function Push-ChocoIntPackage {
|
|
||||||
[CmdletBinding()]
|
|
||||||
param(
|
|
||||||
[Parameter(Mandatory=$true,ValueFromPipeline=$True)]
|
|
||||||
[pscustomobject[]]$PackageNames,
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[string]$Path,
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[string]$RepositoryURL,
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[ValidateNotNull()]
|
|
||||||
[System.Management.Automation.PSCredential]$ApiKey
|
|
||||||
)
|
|
||||||
process {
|
|
||||||
foreach ($Package in $PackageNames){
|
|
||||||
foreach ($NuPkg in $Package.NuGetpkgs) {
|
|
||||||
$MetaData = Get-ChocoPackageMetaData -ChocolateyPackage $NuPkg
|
|
||||||
choco push $NuPkg --force --source $RepositoryURL --api-key $ApiKey.GetNetworkCredential().Password --timeout=3600 | Write-Verbose
|
|
||||||
if ($LASTEXITCODE -ne 0){
|
|
||||||
$Result = 'Push Failed'
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$Result = 'Push Success'
|
|
||||||
}
|
|
||||||
Write-Verbose "$($MetaData.Name) push failed"
|
|
||||||
[PSCustomObject]@{
|
|
||||||
Name = $MetaData.Name
|
|
||||||
Result = $Result
|
|
||||||
Version = $MetaData.Version
|
|
||||||
NuGetPackage = $NuPkg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
Short description
|
|
||||||
.DESCRIPTION
|
|
||||||
Long description
|
|
||||||
.EXAMPLE
|
|
||||||
Example of how to use this cmdlet
|
|
||||||
.EXAMPLE
|
|
||||||
Another example of how to use this cmdlet
|
|
||||||
#>
|
|
||||||
function Test-ChocoUpgradeTrigger {
|
|
||||||
[CmdletBinding()]
|
|
||||||
param(
|
|
||||||
[Parameter(Mandatory=$true,ValueFromPipeline=$True)]
|
|
||||||
[pscustomobject[]]$PackageNames,
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[string[]]$TriggerPackages,
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[string]$UpgradeScriptPath,
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[string]$TriggeredTime,
|
|
||||||
[Parameter(Mandatory=$true)]
|
|
||||||
[System.Management.Automation.PSCredential]$Credential
|
|
||||||
)
|
|
||||||
process {
|
|
||||||
foreach ($Package in $PackageNames){
|
|
||||||
if ($TriggerPackages -contains $Package.Name){
|
|
||||||
Write-Output "Creating scheduled task for $($Package.Name)"
|
|
||||||
Disable-ScheduledTask -TaskName 'Triggered Choco Upgrade' | Unregister-ScheduledTask -Confirm:$False
|
|
||||||
$Time = New-ScheduledTaskTrigger -At $TriggeredTime -Once
|
|
||||||
$PS = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument "-file $UpgradeScriptPath"
|
|
||||||
Register-ScheduledTask -User $Credential.UserName -Description 'This task is created when a certain third party software should be updated on clients' -TaskName 'Triggered Choco Upgrade' -Trigger $Time -Action $PS -Password $Credential.GetNetworkCredential().password -RunLevel Highest
|
|
||||||
Exit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user