Added a lot of stuff

This commit is contained in:
Dan Franciscus
2019-07-10 11:24:06 -04:00
parent 920ac2710c
commit 59cf4a3d7d
5 changed files with 257 additions and 1 deletions

View File

@@ -1,5 +1,13 @@
# Chocolatey-tools Release History # Chocolatey-tools Release History
## 0.4.5 - 7/10/2019
### Added
* Start-ChocoRemotemgmt - A Winforms GUI that can install,uninstall,upgrade,view, see outdated packages on remote Chocolatey clients
* Get-ChocoSourcepackages - Helper function for getting packages from multiple Chocolatey sources for Start-ChocoRemotemgmt
* Invoke-RebootPrompt - Helper function for prompting to reboot a machine remotely in Start-ChocoRemotemgmt
## 0.4.3 - 6/5/2019 ## 0.4.3 - 6/5/2019
### Fixed ### Fixed

View File

@@ -12,7 +12,7 @@
RootModule = 'Chocolatey-tools.psm1' RootModule = 'Chocolatey-tools.psm1'
# Version number of this module. # Version number of this module.
ModuleVersion = '0.4.4' ModuleVersion = '0.4.5'
# Supported PSEditions # Supported PSEditions
# CompatiblePSEditions = @() # CompatiblePSEditions = @()

View File

@@ -0,0 +1,16 @@
<#
.SYNOPSIS
Outputs all package names for one or multiple Chocolatey sources.
.EXAMPLE
Get-ChocoSourcePackages -Sources repo1,repo2
#>
function Get-ChocoSourcePackages {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string[]]$Sources
)
$Sources | ForEach-Object {
choco list --source=$_ -r | ForEach-Object {$_.split("|")[0]}
} | Sort-Object -Unique
}

View File

@@ -0,0 +1,24 @@
<#
.SYNOPSIS
Used in Start-ChocoRemotemgmt to prompt if a user wants to reboot a computer.
#>
Function Invoke-RebootPrompt {
param(
$Message = "Click OK to reboot",
$Title = "Continue or Cancel"
)
Add-Type -AssemblyName System.Windows.Forms | Out-Null
$MsgBox = [System.Windows.Forms.MessageBox]
$Decision = $MsgBox::Show($Message,$Title,"OkCancel", "Information")
If ($Decision -ne "Cancel") {
$outputBox.Text = ""
try {
$outputBox.Text = ("Rebooting " + $ComputerList.Text)
Restart-Computer -ComputerName $ComputerList.Text -Force -ErrorAction stop
}
catch {
$ErrorMessage = $_.Exception.Message
$outputBox.Text = $ErrorMessage
}
}
}

View File

@@ -0,0 +1,208 @@
#requires -modules Invoke-CommandAs
<#
.SYNOPSIS
Starts a Winforms GUI for remote management of Chocolatey clients.
.EXAMPLE
In this example, we query Active Directory for all computers which will populate the list of computers.
We also use the function Get-ChocoSourcePackages to pull all packages from Chocolatey sources configured on the local computer.
Start-ChocoRemotemgmt -ComputerName (Get-ADComputer -Filter | Select-Object -ExpandProperty Name) -Packages (Get-ChocoSourcePackages -Sources repo1,repo2)
#>
function Start-ChocoRemoteMgmt {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[string[]]$ComputerName,
[Parameter(Mandatory=$true)]
[string[]]$Packages
)
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$Form = New-Object system.Windows.Forms.Form
$Form.Text = "Chocolatey Remote Management"
$Form.TopMost = $true
$Form.Width = 757
$Form.Height = 570
$ComputerNameLabel = New-Object system.windows.Forms.Label
$ComputerNameLabel.Text = "Computer Name"
$ComputerNameLabel.AutoSize = $true
$ComputerNameLabel.Width = 25
$ComputerNameLabel.Height = 10
$ComputerNameLabel.location = new-object system.drawing.point(28,23)
$ComputerNameLabel.Font = "Microsoft Sans Serif,12"
$Form.controls.Add($ComputerNameLabel)
$ComputerList = New-Object system.windows.Forms.TextBox
$ComputerList.Width = 180
$ComputerList.Height = 20
$ComputerList.location = new-object system.drawing.point(28,55)
$ComputerList.Font = "Microsoft Sans Serif,12"
$ComputerList.AutoCompleteSource = 'CustomSource'
$ComputerList.AutoCompleteMode='SuggestAppend'
$ComputerList.AutoCompleteCustomSource=$Autocomplete
$ComputerName | ForEach-Object {$ComputerList.AutoCompleteCustomSource.AddRange($_) }
$Form.controls.Add($ComputerList)
$PackageList = New-Object system.windows.Forms.ListBox
$PackageList.Text = "PackageList"
$PackageList.Width = 325
$PackageList.Height = 129
$PackageList.Font = "Microsoft Sans Serif,12"
$PackageList.location = new-object system.drawing.point(241,54)
$Packages | ForEach-Object { $PackageList.Items.Add($_) | Out-Null }
$Form.controls.Add($PackageList)
$PackagesList = New-Object system.windows.Forms.Label
$PackagesList.Text = "Packages"
$PackagesList.AutoSize = $true
$PackagesList.Width = 25
$PackagesList.Height = 10
$PackagesList.location = new-object system.drawing.point(240,23)
$PackagesList.Font = "Microsoft Sans Serif,12"
$Form.controls.Add($PackagesList)
$ShowCurrentUser = New-Object system.windows.Forms.Button
$ShowCurrentUser.Text = "Show Current User"
$ShowCurrentUser.Width = 148
$ShowCurrentUser.Height = 34
$ShowCurrentUser.location = new-object system.drawing.point(28,149)
$ShowCurrentUser.Font = "Microsoft Sans Serif,10"
$Form.controls.Add($ShowCurrentUser)
$ShowCurrentUser.add_Click({
$outputBox.Text = ("Find current user on " + $ComputerList.Text)
if (!(Test-Connection -ComputerName $ComputerList.text -Count 2)){
$outputBox.Text = "Computer is not online"
}
else {
$CurrentUser = Invoke-Command -ComputerName $ComputerList.text -Scriptblock {
(Get-WMIObject -class Win32_ComputerSystem).username
}
$outputBox.Text = $CurrentUser
if (!$CurrentUser ) {
$outputBox.Text = "No user is logged on"
}
}
})
$InstallPackage = New-Object system.windows.Forms.Button
$InstallPackage.Text = "Install"
$InstallPackage.Width = 95
$InstallPackage.Height = 34
$InstallPackage.location = new-object system.drawing.point(240,185)
$InstallPackage.Font = "Microsoft Sans Serif,10"
$Form.controls.Add($InstallPackage)
$InstallPackage.add_Click({
$outputBox.Text = ""
$outputBox.Text = ("Installing " + $PackageList.SelectedItem + " on " + $ComputerList.Text)
Write-output "Installing"
$chocoutput = Invoke-CommandAs -AsSystem -ComputerName $ComputerList.Text -ScriptBlock {
choco install $args[0] -y -r
Write-output "Done"
$outputBox.Text = $chocoutput
}
})
$Outdatepackage = New-Object system.windows.Forms.Button
$Outdatepackage.Text = "Show Outdated"
$Outdatepackage.Width = 107
$Outdatepackage.Height = 34
$Outdatepackage.location = new-object system.drawing.point(458,185)
$Outdatepackage.Font = "Microsoft Sans Serif,10"
$Form.controls.Add($Outdatepackage)
$Outdatepackage.add_Click({
$outputBox.Text = ""
$outputBox.Text = ("Finding outdated packages" + $PackageList.SelectedItem + " on " + $ComputerList.Text)
Write-output "Listing installed packages"
$chocoutput = Invoke-CommandAs -AsSystem -ComputerName $ComputerList.Text -ScriptBlock {
choco outdated -r --ignore-unfound --ignore-pinned | Out-String
}
Write-output "Done"
$outputBox.Text = $chocoutput
})
$ListPackage = New-Object system.windows.Forms.Button
$ListPackage.Text = "Show Installed"
$ListPackage.Width = 107
$ListPackage.Height = 34
$ListPackage.location = new-object system.drawing.point(343,235)
$ListPackage.Font = "Microsoft Sans Serif,10"
$Form.controls.Add($listPackage)
$ListPackage.add_Click({
$outputBox.Text = ""
$outputBox.Text = ("Finding installed packages" + $PackageList.SelectedItem + " on " + $ComputerList.Text)
Write-output "Listing installed packages"
$chocoutput = Invoke-CommandAs -AsSystem -ComputerName $ComputerList.Text -ScriptBlock {
choco list -lo -r | Out-String }
Write-output "Done"
$outputBox.Text = $chocoutput
})
$UpgradePackage = New-Object system.windows.Forms.Button
$UpgradePackage.Text = "Upgrade"
$UpgradePackage.Width = 95
$UpgradePackage.Height = 34
$UpgradePackage.location = new-object system.drawing.point(240,235)
$UpgradePackage.Font = "Microsoft Sans Serif,10"
$Form.controls.Add($UpgradePackage)
$UpgradePackage.add_Click({
$outputBox.Text = ""
$outputBox.Text = ("Upgrading " + $PackageList.SelectedItem + " on " + $ComputerList.Text)
Write-output "Installing"
$chocoutput = Invoke-CommandAs -AsSystem -ComputerName $ComputerList.Text -ScriptBlock {
choco upgrade $args[0] -y -r
}
Write-output "Done"
$outputBox.Text = $chocoutput
})
$UninstallPackage = New-Object system.windows.Forms.Button
$UninstallPackage.Text = "Uninstall"
$UninstallPackage.Width = 107
$UninstallPackage.Height = 34
$UninstallPackage.location = new-object system.drawing.point(343,185)
$UninstallPackage.Font = "Microsoft Sans Serif,10"
$Form.controls.Add($UninstallPackage)
$UninstallPackage.add_Click({
$outputBox.Text = ""
$outputBox.Text = ("Uninstalling " + $PackageList.SelectedItem + " on " + $ComputerList.Text)
Write-output "Uinstalling"
$chocoutput = Invoke-CommandAs -AsSystem -ComputerName $ComputerList.Text -ScriptBlock {
choco uninstall $args[0] -y -f -r } -ArgumentList $PackageList.SelectedItem
Write-output "Done"
$outputBox.Text = $chocoutput
})
$RebootComputer = New-Object system.windows.Forms.Button
$RebootComputer.Text = "Reboot"
$RebootComputer.Width = 75
$RebootComputer.Height = 34
$RebootComputer.location = new-object system.drawing.point(28,95)
$RebootComputer.Font = "Microsoft Sans Serif,10"
$Form.controls.Add($RebootComputer)
$RebootComputer.add_Click({
Invoke-RebootPrompt
})
$outputBox = New-Object System.Windows.Forms.TextBox
$OutputBox.location = new-object system.drawing.point(28,284)
$outputBox.Size = New-Object System.Drawing.Size(400,200)
$outputBox.MultiLine = $True
$outputBox.ScrollBars = "Vertical"
$outputBox.Font = "Microsoft Sans Serif,12"
$Form.Controls.Add($outputBox)
$Output = New-Object system.windows.Forms.Label
$Output.Text = "Output"
$Output.AutoSize = $true
$Output.Width = 25
$Output.Height = 10
$Output.location = new-object system.drawing.point(28,252)
$Output.Font = "Microsoft Sans Serif,12"
$Form.controls.Add($Output)
[void]$Form.ShowDialog()
$Form.Dispose()
}