Initial
This commit is contained in:
40
.github/ISSUE_TEMPLATE/Bug_report.md
vendored
Normal file
40
.github/ISSUE_TEMPLATE/Bug_report.md
vendored
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Prerequisites**
|
||||||
|
|
||||||
|
Put an X between the brackets on each line to confirm you have completed them:
|
||||||
|
|
||||||
|
- [ ] The issue is still present in the latest version of the module.
|
||||||
|
- [ ] The issue has not been previously reported.
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Screenshots or Transcripts**
|
||||||
|
If applicable, add screenshots or PowerShell transcripts to help explain your problem. You can use ```Start-Transcript``` and ```Stop-Transcript``` to record the steps you have performed.
|
||||||
|
|
||||||
|
**System Details**
|
||||||
|
|
||||||
|
- Operating System: [Windows | Linux | MacOS]
|
||||||
|
- Operating System Version (Version and Build, eg Windows 10 Build 1709):
|
||||||
|
- PowerShell Version: [Use ```Get-Host```]
|
||||||
|
- Architecture for PowerShell Session: [64bit | 32bit]
|
||||||
|
- Is this system an Azure Automation Worker?: [No, Hybrid Worker, Azure Worker]
|
||||||
|
- Other loaded modules: [Include the output of ```Get-Module```]
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here. Is there any other information like system configuration or data that might help us understand the problem.
|
||||||
20
.github/ISSUE_TEMPLATE/Feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/Feature_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Examples of how the solution would work**
|
||||||
|
Some simple PowerShell examples of how the solution would work.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
||||||
28
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
28
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
### Requirements
|
||||||
|
|
||||||
|
* This template is required. Any request that does not include enough information may be closed at the maintainers' discretion.
|
||||||
|
* Have you (put an X between the brackets on each line to confirm):
|
||||||
|
* [ ] Written new test cases to ensure no regression bugs occur?
|
||||||
|
* [ ] Ensured all test cases are now passing?
|
||||||
|
* [ ] Ensured that PowerShell Script Analyser issues and warnings are completely resolved?
|
||||||
|
* [ ] Updated any help or documentation that may be impacted by your changes?
|
||||||
|
|
||||||
|
### Description of the Change
|
||||||
|
|
||||||
|
[ We must be able to understand the design of your change from this description. If we cannot get a good idea of what the code will be doing from the description here, the pull request may be closed at the maintainers' discretion. Keep in mind that the maintainer reviewing this PR may not be familiar with or have worked with the code here recently, so please walk us through the concepts. ]
|
||||||
|
|
||||||
|
### Testing
|
||||||
|
|
||||||
|
[ Please describe the testing you have performed ]
|
||||||
|
|
||||||
|
### Associated/Resolved Issues
|
||||||
|
|
||||||
|
[ Enter any applicable issues here ]
|
||||||
|
|
||||||
|
> Note: By creating a pull request, you are expected to comply with this project's Code of Conduct.
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
This template is based upon the work by the Atom project, https://github.com/atom/atom/
|
||||||
|
|
||||||
|
-->
|
||||||
48
.vscode/settings.json
vendored
Normal file
48
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
//
|
||||||
|
// Custom Settings for Project
|
||||||
|
//
|
||||||
|
// These are here so that anyone potentially modifying the code base has the same editor experience, this ensures that the code will follow the same structure.
|
||||||
|
|
||||||
|
// Controls how the editor should render whitespace characters, possibilities are 'none', 'boundary', and 'all'. The 'boundary' option does not render single spaces between words.
|
||||||
|
"editor.renderWhitespace": "all", // Default: none
|
||||||
|
|
||||||
|
// Controls whether the editor should render control characters
|
||||||
|
"editor.renderControlCharacters": true, // Default: false
|
||||||
|
|
||||||
|
// Number of spaces for tabs
|
||||||
|
"editor.tabSize": 4, // Default: 4
|
||||||
|
|
||||||
|
// Use spaces not tabs
|
||||||
|
"editor.insertSpaces": true, // Default: true
|
||||||
|
|
||||||
|
// When enabled, will trim trailing whitespace when you save a file.
|
||||||
|
"files.trimTrailingWhitespace": true, // Default: false
|
||||||
|
|
||||||
|
// Does not reformat one-line code blocks, such as "if (...) {...} else {...}".
|
||||||
|
"powershell.codeFormatting.ignoreOneLineBlock": false, // Default: True
|
||||||
|
|
||||||
|
// Adds a newline (line break) after a closing brace.
|
||||||
|
"powershell.codeFormatting.newLineAfterCloseBrace": true, // Default: True
|
||||||
|
|
||||||
|
// Adds a newline (line break) after an open brace.
|
||||||
|
"powershell.codeFormatting.newLineAfterOpenBrace": true, // Default: True
|
||||||
|
|
||||||
|
// Places open brace on the same line as its associated statement.
|
||||||
|
"powershell.codeFormatting.openBraceOnSameLine": true, // Default: True
|
||||||
|
|
||||||
|
// Adds a space after a separator (',' and ';').
|
||||||
|
"powershell.codeFormatting.whitespaceAfterSeparator": true, // Default: True
|
||||||
|
|
||||||
|
// Adds spaces before and after an operator ('=', '+', '-', etc.).
|
||||||
|
"powershell.codeFormatting.whitespaceAroundOperator": true, // Default: True
|
||||||
|
|
||||||
|
// Adds a space between a keyword and its associated scriptblock expression.
|
||||||
|
"powershell.codeFormatting.whitespaceBeforeOpenBrace": true, // Default: True
|
||||||
|
|
||||||
|
// Adds a space between a keyword (if, elseif, while, switch, etc) and its associated conditional expression.
|
||||||
|
"powershell.codeFormatting.whitespaceBeforeOpenParen": true, // Default: True
|
||||||
|
|
||||||
|
// Align assignment statements in a hashtable or a DSC Configuration.
|
||||||
|
"powershell.codeFormatting.alignPropertyValuePairs": true // Default: True
|
||||||
|
}
|
||||||
65
.vscode/tasks.json
vendored
Normal file
65
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
// Available variables which can be used inside of strings.
|
||||||
|
// ${workspaceRoot}: the root folder of the team
|
||||||
|
// ${file}: the current opened file
|
||||||
|
// ${relativeFile}: the current opened file relative to workspaceRoot
|
||||||
|
// ${fileBasename}: the current opened file's basename
|
||||||
|
// ${fileDirname}: the current opened file's dirname
|
||||||
|
// ${fileExtname}: the current opened file's extension
|
||||||
|
// ${cwd}: the current working directory of the spawned process
|
||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "0.1.0",
|
||||||
|
|
||||||
|
// Start PowerShell
|
||||||
|
"windows": {
|
||||||
|
"command": "${env:windir}\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
|
||||||
|
"args": [ "-NoProfile", "-ExecutionPolicy", "Bypass" ]
|
||||||
|
},
|
||||||
|
"linux": {
|
||||||
|
"command": "/usr/bin/powershell",
|
||||||
|
"args": [ "-NoProfile" ]
|
||||||
|
},
|
||||||
|
"osx": {
|
||||||
|
"command": "/usr/local/bin/powershell",
|
||||||
|
"args": [ "-NoProfile" ]
|
||||||
|
},
|
||||||
|
|
||||||
|
// The command is a shell script
|
||||||
|
"isShellCommand": true,
|
||||||
|
|
||||||
|
// Show the output window always
|
||||||
|
"showOutput": "always",
|
||||||
|
|
||||||
|
// Associate with test task runner
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"taskName": "Test",
|
||||||
|
"suppressTaskName": true,
|
||||||
|
"isTestCommand": true,
|
||||||
|
"showOutput": "always",
|
||||||
|
"args": [
|
||||||
|
"Write-Host 'Invoking Pester'; Invoke-Pester -PesterOption @{IncludeVSCodeMarker=$true};",
|
||||||
|
"Invoke-Command { Write-Host 'Completed Test task in task runner.' }"
|
||||||
|
],
|
||||||
|
"problemMatcher": [
|
||||||
|
{
|
||||||
|
"owner": "powershell",
|
||||||
|
"fileLocation": ["absolute"],
|
||||||
|
"severity": "error",
|
||||||
|
"pattern": [
|
||||||
|
{
|
||||||
|
"regexp": "^\\s*(\\[-\\]\\s*.*?)(\\d+)ms\\s*$",
|
||||||
|
"message": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"regexp": "^\\s+at\\s+[^,]+,\\s*(.*?):\\s+line\\s+(\\d+)$",
|
||||||
|
"file": 1,
|
||||||
|
"line": 2
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
19
CHANGELOG.md
Normal file
19
CHANGELOG.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Chocolatey-tools Release History
|
||||||
|
|
||||||
|
## Version Number - Release Date
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* First item fixed
|
||||||
|
* Second item fixed
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* New item added
|
||||||
|
* Another new item added
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* Feature changed
|
||||||
|
* Tests added
|
||||||
|
|
||||||
124
Chocolatey-tools.psd1
Normal file
124
Chocolatey-tools.psd1
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
#
|
||||||
|
# Module manifest for module 'Chocolatey-tools'
|
||||||
|
#
|
||||||
|
# Generated by: Dan Franciscus
|
||||||
|
#
|
||||||
|
# Generated on: 4/25/2019
|
||||||
|
#
|
||||||
|
|
||||||
|
@{
|
||||||
|
|
||||||
|
# Script module or binary module file associated with this manifest.
|
||||||
|
RootModule = 'Chocolatey-tools.psm1'
|
||||||
|
|
||||||
|
# Version number of this module.
|
||||||
|
ModuleVersion = '0.1'
|
||||||
|
|
||||||
|
# Supported PSEditions
|
||||||
|
# CompatiblePSEditions = @()
|
||||||
|
|
||||||
|
# ID used to uniquely identify this module
|
||||||
|
GUID = 'a4e9d9bb-de0f-4f79-b1b4-535b681ab285'
|
||||||
|
|
||||||
|
# Author of this module
|
||||||
|
Author = 'Dan Franciscus'
|
||||||
|
|
||||||
|
# Company or vendor of this module
|
||||||
|
CompanyName = 'Dan Franciscus'
|
||||||
|
|
||||||
|
# Copyright statement for this module
|
||||||
|
Copyright = '(c) 2019 Dan Franciscus. All rights reserved.'
|
||||||
|
|
||||||
|
# Description of the functionality provided by this module
|
||||||
|
Description = 'PowerShell module for managing Chocolatey'
|
||||||
|
|
||||||
|
# Minimum version of the Windows PowerShell engine required by this module
|
||||||
|
# PowerShellVersion = ''
|
||||||
|
|
||||||
|
# Name of the Windows PowerShell host required by this module
|
||||||
|
# PowerShellHostName = ''
|
||||||
|
|
||||||
|
# Minimum version of the Windows PowerShell host required by this module
|
||||||
|
# PowerShellHostVersion = ''
|
||||||
|
|
||||||
|
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||||
|
# DotNetFrameworkVersion = ''
|
||||||
|
|
||||||
|
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||||
|
# CLRVersion = ''
|
||||||
|
|
||||||
|
# Processor architecture (None, X86, Amd64) required by this module
|
||||||
|
# ProcessorArchitecture = ''
|
||||||
|
|
||||||
|
# Modules that must be imported into the global environment prior to importing this module
|
||||||
|
# RequiredModules = @()
|
||||||
|
|
||||||
|
# Assemblies that must be loaded prior to importing this module
|
||||||
|
# RequiredAssemblies = @()
|
||||||
|
|
||||||
|
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
|
||||||
|
# ScriptsToProcess = @()
|
||||||
|
|
||||||
|
# Type files (.ps1xml) to be loaded when importing this module
|
||||||
|
# TypesToProcess = @()
|
||||||
|
|
||||||
|
# Format files (.ps1xml) to be loaded when importing this module
|
||||||
|
# FormatsToProcess = @()
|
||||||
|
|
||||||
|
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
|
||||||
|
# NestedModules = @()
|
||||||
|
|
||||||
|
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
|
||||||
|
FunctionsToExport = '*'
|
||||||
|
|
||||||
|
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
||||||
|
CmdletsToExport = '*'
|
||||||
|
|
||||||
|
# Variables to export from this module
|
||||||
|
VariablesToExport = '*'
|
||||||
|
|
||||||
|
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
|
||||||
|
AliasesToExport = '*'
|
||||||
|
|
||||||
|
# DSC resources to export from this module
|
||||||
|
# DscResourcesToExport = @()
|
||||||
|
|
||||||
|
# List of all modules packaged with this module
|
||||||
|
# ModuleList = @()
|
||||||
|
|
||||||
|
# List of all files packaged with this module
|
||||||
|
# FileList = @()
|
||||||
|
|
||||||
|
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
|
||||||
|
PrivateData = @{
|
||||||
|
|
||||||
|
PSData = @{
|
||||||
|
|
||||||
|
# Tags applied to this module. These help with module discovery in online galleries.
|
||||||
|
# Tags = @()
|
||||||
|
|
||||||
|
# A URL to the license for this module.
|
||||||
|
# LicenseUri = ''
|
||||||
|
|
||||||
|
# A URL to the main website for this project.
|
||||||
|
# ProjectUri = ''
|
||||||
|
|
||||||
|
# A URL to an icon representing this module.
|
||||||
|
# IconUri = ''
|
||||||
|
|
||||||
|
# ReleaseNotes of this module
|
||||||
|
# ReleaseNotes = ''
|
||||||
|
|
||||||
|
} # End of PSData hashtable
|
||||||
|
|
||||||
|
} # End of PrivateData hashtable
|
||||||
|
|
||||||
|
# HelpInfo URI of this module
|
||||||
|
# HelpInfoURI = ''
|
||||||
|
|
||||||
|
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
|
||||||
|
# DefaultCommandPrefix = ''
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
19
Chocolatey-tools.psm1
Normal file
19
Chocolatey-tools.psm1
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Taken from http://overpoweredshell.com/Working-with-Plaster/
|
||||||
|
|
||||||
|
$functionFolders = @('functions', 'internal', 'classes')
|
||||||
|
ForEach ($folder in $functionFolders)
|
||||||
|
{
|
||||||
|
$folderPath = Join-Path -Path $PSScriptRoot -ChildPath $folder
|
||||||
|
If (Test-Path -Path $folderPath)
|
||||||
|
{
|
||||||
|
Write-Verbose -Message "Importing from $folder"
|
||||||
|
$functions = Get-ChildItem -Path $folderPath -Filter '*.ps1'
|
||||||
|
ForEach ($function in $functions)
|
||||||
|
{
|
||||||
|
Write-Verbose -Message " Importing $($function.BaseName)"
|
||||||
|
. $function.providerpath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$publicFunctions = (Get-ChildItem -Path "$PSScriptRoot\functions" -Filter '*.ps1').BaseName
|
||||||
|
Export-ModuleMember -Function $publicFunctions
|
||||||
9
LICENSE.md
Normal file
9
LICENSE.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Dan Franciscus
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
59
README.MD
Normal file
59
README.MD
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
# Chocolatey-tools
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
PowerShell module for managing Chocolatey
|
||||||
|
|
||||||
|
Authored by Dan Franciscus
|
||||||
|
|
||||||
|
## Installing
|
||||||
|
|
||||||
|
The easiest way to get Chocolatey-tools is using the [PowerShell Gallery](https://powershellgallery.com/packages/Chocolatey-tools/)!
|
||||||
|
|
||||||
|
### Inspecting the module
|
||||||
|
|
||||||
|
Best practice is that you inspect modules prior to installing them. You can do this by saving the module to a local path:
|
||||||
|
|
||||||
|
``` PowerShell
|
||||||
|
PS> Save-Module -Name Chocolatey-tools -Path <path>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Installing the module
|
||||||
|
|
||||||
|
Once you trust a module, you can install it using:
|
||||||
|
|
||||||
|
``` PowerShell
|
||||||
|
PS> Install-Module -Name Chocolatey-tools
|
||||||
|
```
|
||||||
|
|
||||||
|
### Updating Chocolatey-tools
|
||||||
|
|
||||||
|
Once installed from the PowerShell Gallery, you can update it using:
|
||||||
|
|
||||||
|
``` PowerShell
|
||||||
|
PS> Update-Module -Name Chocolatey-tools
|
||||||
|
```
|
||||||
|
|
||||||
|
### Uninstalling Chocolatey-tools
|
||||||
|
|
||||||
|
To uninstall Chocolatey-tools:
|
||||||
|
|
||||||
|
``` PowerShell
|
||||||
|
PS> Uninstall-Module -Name Chocolatey-tools
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contributing to Chocolatey-tools
|
||||||
|
|
||||||
|
Interested in contributing? Read how you can [Contribute](contributing.md) to Chocolatey-tools
|
||||||
|
|
||||||
|
This project maintains a [Code of Conduct](code-of-conduct.md) that establishes how the project is governed and how everyone involved is expected to behave. You can report unacceptable behavior to [dfranciscus@cnjcomputing.com](mailto:dfranciscus@cnjcomputing.com).
|
||||||
|
|
||||||
|
## Release History
|
||||||
|
|
||||||
|
A detailed release history is contained in the [Change Log](CHANGELOG.md).
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Chocolatey-tools is provided under the [MIT license](LICENSE.md).
|
||||||
46
code-of-conduct.md
Normal file
46
code-of-conduct.md
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to creating a positive environment include:
|
||||||
|
|
||||||
|
* Using welcoming and inclusive language
|
||||||
|
* Being respectful of differing viewpoints and experiences
|
||||||
|
* Gracefully accepting constructive criticism
|
||||||
|
* Focusing on what is best for the community
|
||||||
|
* Showing empathy towards other community members
|
||||||
|
|
||||||
|
Examples of unacceptable behavior by participants include:
|
||||||
|
|
||||||
|
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||||
|
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||||
|
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||||
|
|
||||||
|
## Our Responsibilities
|
||||||
|
|
||||||
|
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||||
|
|
||||||
|
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at dfranciscus@cnjcomputing.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||||
|
|
||||||
|
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||||
|
|
||||||
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
|
||||||
122
contributing.md
Normal file
122
contributing.md
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
See an issue that you can help with? Have an idea for the next great feature? Thanks for taking the time to contribute!!!
|
||||||
|
|
||||||
|
Here are some guidelines for contributing to this project. They are not hard rules, just guidelines.
|
||||||
|
|
||||||
|
## Code of Conduct
|
||||||
|
|
||||||
|
This project maintains a [code of conduct](code-of-conduct.md) that establishes how the project is governed and how everyone involved is expected to behave.
|
||||||
|
|
||||||
|
You can report unacceptable behavior to [dfranciscus@cnjcomputing.com](mailto:dfranciscus@cnjcomputing.com).
|
||||||
|
|
||||||
|
## TL;DR
|
||||||
|
|
||||||
|
* Check if any bugs/issues/features have been previously reported/requested before creating a new issue.
|
||||||
|
* Ensure you are using the LATEST version before raising a new issue.
|
||||||
|
* Ensure you complete the Pull Request template when raising a new PR.
|
||||||
|
|
||||||
|
## Reporting Bugs/Issues
|
||||||
|
|
||||||
|
The reality is that code will contain bugs, even with thorough testing, issues can get through. Following these guidelines will help the maintainers to understand the issue you have encountered, reproduce the problem and fix it! You might even find that you don't need to create one.
|
||||||
|
|
||||||
|
> **Note:** If you find an issue that is Closed that seems like what you are experiencing, please open a **new** issue and include a link to the previous issue in your description.
|
||||||
|
|
||||||
|
### Before you file a bug report
|
||||||
|
|
||||||
|
* **Ensure you are running the latest version of the module.** If you are running an older version of the module, try updating the module and testing if the issue remains. If you installed the module from the [PowerShell Gallery](https://powershellgallery.com), use this command to update the module: ``` PS> Update-Module -Name Chocolatey-tools ```.
|
||||||
|
* **Ensure that you are using the CMDLet correctly.** Have you checked the help? Sometimes we assume we know how a specific function or CMDLet works, and it turns out we are wrong. The command ```Get-Help``` is your friend!
|
||||||
|
* **Has the issue been reported before?** You might not be the only person who has reported the issue. Check out the [Issues][Issues] and look through any current Issues that may match the issue you are experiencing.
|
||||||
|
|
||||||
|
### Submitting a (good) bug report
|
||||||
|
|
||||||
|
Bugs and problems are tracked using [GitHub issues](https://guides.github.com/features/issues/). To submit a bug, create an issue and provide the information requested in [the template](ISSUE_TEMPLATE.md). The template will help the maintainers to resolve issues faster.
|
||||||
|
|
||||||
|
Here are some tips on ensuring you create an excellent bug report:
|
||||||
|
|
||||||
|
* **Bugs should be actionable**, that is, something that can be fixed as part of this project. Issues with Windows, .Net or PowerShell might not be solvable within this project.
|
||||||
|
* **Use a clear descriptive title** for the issue that describes the issue.
|
||||||
|
* **Describe the exact steps to reproduce the issue** and include as many details as possible. People often leave things out as they think they might not be important, but every little detail counts! When listing what steps or commands you executed, **don't just say what you did, try to explain how you did it**. Be as detailed as possible, it is safe to say that more is usually better.
|
||||||
|
* **Provide specific examples**, include specific steps you have taken, link to files or other copy/pastable snippets. If you are providing snippets of code, ensure you use Markdown Code Blocks. <>TODO: link<> If you can, provide the exact steps/code you were executing when the issue happened.
|
||||||
|
* **PowerShell Transcripts can be extremely useful** so please include those where possible. You can start a transcript with ```Start-Transcript``` and end it with ```Stop-Transcript```.
|
||||||
|
* **Screenshots and Gifs** can also be extemely useful, however transcripts are preferred.
|
||||||
|
* **If there is private/confidential information**, feel free to remove that from any logs/transcripts/images, but remember to highlight where you have done so.
|
||||||
|
* **Describe the behavior you observed after following the steps you described** and then clearly state what the problem is with this behavior. Sometimes it isn't clear why something is an issue.
|
||||||
|
* **Describe what behaviour you would expect** others might be expecting different behaviors.
|
||||||
|
* **Include stack traces where possible**. If you have access to the Exception, the ```ScriptStackTrace``` and other properties may point to where the problem is.
|
||||||
|
* **Include details about your environment** including Windows/Linux/Mac OSX version, PowerShell versions and 64/32 bit environments. If you are using Azure Automation, please ensure you mention if this is the Azure Worker or a Hybrid Worker. It can also help to include any other modules you might be using.
|
||||||
|
* **Subscribe to notifications** so you can answer any follow-up questions, and assist in testing the final fixes for the issue.
|
||||||
|
* **Just because you think the issue might be easy, doesn't mean it is so**. Issues can be quite complex when you actually look into them, resolution may take time so be patient.
|
||||||
|
|
||||||
|
## Suggesting New Features and Enhancements
|
||||||
|
|
||||||
|
Got a killer idea for a new feature? Maybe you want to suggest a minor improvement or some totally new features? These guidelines will help maintainers understand your suggestion!
|
||||||
|
|
||||||
|
### Before you submit an enhancement suggestion
|
||||||
|
|
||||||
|
* **Ensure you are running the latest version of the module.** The feature you require might be included in a new version of the module. If you installed the module from the Gallery, use this command to update the module: ``` PS> Update-Module -Name Chocolatey-tools ```.
|
||||||
|
* **Ensure that you are using the CMDLet correctly.** Have you checked the help? Perhaps the feature has already been implemented but you just haven't discovered it yet! The command ```Get-Help``` is your friend!
|
||||||
|
* **Has the feature been requested before?** You might not be the only person who has requested this new feature. If it has, add a comment to the existing issue instead of opening a new one. Be sure to checkout closed issues as well, the feature may have been previously implemented or rejected.
|
||||||
|
|
||||||
|
### Submitting a (good) enhancement suggestion
|
||||||
|
|
||||||
|
Enhancements are tracked via [GitHub issues](https://guides.github.com/features/issues/) just as bugs are. To submit a suggestion, create an issue and provide the information requested in [the template](ISSUE_TEMPLATE.md).
|
||||||
|
|
||||||
|
Here are some tips on ensuring you create an excellent suggestion:
|
||||||
|
|
||||||
|
* **Enhancements should be actionable**, that is, something that can/should be included in the project. Does the enhancement fall inside or outside the scope of the module? Modules should closely align to a specific set of activities, for instance a database query CMDLet probably shouldn't be included in a module relating to network connections.
|
||||||
|
* **Use a clear descriptive title** for the issue that describes the suggestion.
|
||||||
|
* **Describe the new functionality or enhancement**, provide a step-by-step description of how it would function.
|
||||||
|
* **Describe the current behavior and expected behavior** you would like to see.
|
||||||
|
* **Provide specific examples** including how the feature would work, error handling, validation, etc.
|
||||||
|
* **Describe why this would be useful** to implement this suggestion. Is this something other users might want or just something you require?
|
||||||
|
* **Subscribe to notifications** so you can answer any follow-up questions, and assist in testing the final fixes for the issue.
|
||||||
|
* **Just because you think the feature might be easy to implement, doesn't mean it is so**. New features could be simple, or they might require significant effort to implement, please be patient.
|
||||||
|
|
||||||
|
## Code Contributions
|
||||||
|
|
||||||
|
### Your First Contribution
|
||||||
|
|
||||||
|
Looking to make your first contribution? Congratulations, you are taking the first steps into an amazing journey.
|
||||||
|
|
||||||
|
Don't know where to start? You can start by looking through the issues for the **Beginner** and **Help Wanted** tags:
|
||||||
|
* **Beginner** are simple and should only take a few lines of code and tests to complete.
|
||||||
|
* **Help Wanted** are more involved and will take more effort to complete.
|
||||||
|
|
||||||
|
### Pull Requests
|
||||||
|
|
||||||
|
Pull requests are always more than welcome. When creating a pull request, ensure that you complete [the template](PULL_REQUEST_TEMPLATE.md).
|
||||||
|
|
||||||
|
Here are a few guidelines that should be followed:
|
||||||
|
|
||||||
|
* Each pull request should accomplish a clear goal. Ensure that you clearly state in the request what it accomplishes.
|
||||||
|
* Bug fixes: What was the bug? How did you fix it?
|
||||||
|
* New features: What is it? How is it used?
|
||||||
|
* Provide a high level explanation of what you are changing, it makes it easier to review.
|
||||||
|
* Keep requests small, as it:
|
||||||
|
* Makes reviews easier.
|
||||||
|
* Makes testing easier.
|
||||||
|
* Helps review conflicts more easily.
|
||||||
|
* Ensure that all Pester tests pass and there are no failures.
|
||||||
|
* Ensure that there are no errors or warnings with PowerShell Script Analyzer
|
||||||
|
* Any new code needs to have tests created:
|
||||||
|
* Bug fixes: Consider test cases that would have failed before the change but pass now.
|
||||||
|
* New features: Test cases need to ensure that new features function correctly and existing features still function as previously expected.
|
||||||
|
* Ensure that any code you write aligns with community style guides.
|
||||||
|
* Don't include issue numbers in the PR title.
|
||||||
|
* Ensure that your branch is up-to-date to reduce the merge conflicts that could occur.
|
||||||
|
### Things that might get your Pull Request rejected
|
||||||
|
|
||||||
|
There are often things in Pull Requests that might lead to a pull request being rejected, these include:
|
||||||
|
|
||||||
|
* Malicious code.
|
||||||
|
* Code that breaks previous functionality in a way that could be avoided.
|
||||||
|
* Code that doesn't align with community style recommendations.
|
||||||
|
* Code that fails Pester tests or PowerShell Script analyser.
|
||||||
|
* Code that is obviously plagiarised.
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
This is based upon the work by the Atom project, https://github.com/atom/atom/
|
||||||
|
|
||||||
|
-->
|
||||||
38
functions/Get-ChocoOutdatedPackages.ps1
Normal file
38
functions/Get-ChocoOutdatedPackages.ps1
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<#
|
||||||
|
.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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
45
functions/Get-ChocoPackageMetaData.ps1
Normal file
45
functions/Get-ChocoPackageMetaData.ps1
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
46
functions/Invoke-BoxStarterRemoteUpgrade.ps1
Normal file
46
functions/Invoke-BoxStarterRemoteUpgrade.ps1
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
function Invoke-BoxStarterRemoteUpgrade {
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string[]]$ComputerName,
|
||||||
|
[pscredential]$Credential,
|
||||||
|
[string[]]$AdditionalPackages,
|
||||||
|
[string[]]$ExcludedPackages,
|
||||||
|
[string]$ScriptPath,
|
||||||
|
[int]$JobTimeout
|
||||||
|
)
|
||||||
|
|
||||||
|
#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
|
||||||
|
Install-BoxstarterPackage -ComputerName $ComputerName -PackageName $ScriptPath
|
||||||
|
#Upgrade computers in parallel with Boxstarter
|
||||||
|
# $ComputerName | ForEach-Object {
|
||||||
|
# start-process -RedirectStandardOutput C:\scripts\powershell\$_.txt -FilePath powershell -ArgumentList "-windowstyle hidden Install-BoxstarterPackage -ComputerName $_ -PackageName $ScriptPath" -PassThru
|
||||||
|
# }
|
||||||
|
}
|
||||||
47
functions/Invoke-ChocoInternalizePackage.ps1
Normal file
47
functions/Invoke-ChocoInternalizePackage.ps1
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<#
|
||||||
|
.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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
76
functions/Invoke-ChocoRemoteUpgrade.ps1
Normal file
76
functions/Invoke-ChocoRemoteUpgrade.ps1
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<#
|
||||||
|
.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,
|
||||||
|
[string[]]$AdditionalPackages,
|
||||||
|
[string[]]$ExcludedPackages,
|
||||||
|
[switch]$RebootifPending,
|
||||||
|
[int]$JobTimeout
|
||||||
|
# [System.Management.Automation.ScriptBlock]$Config
|
||||||
|
)
|
||||||
|
process {
|
||||||
|
Invoke-Command -ComputerName $ComputerName -ScriptBlock {
|
||||||
|
choco config set virusScannerType VirusTotal | out-null
|
||||||
|
choco feature enable -n virusCheck | out-null
|
||||||
|
choco config set commandExecutionTimeoutSeconds 1800 | out-null
|
||||||
|
choco feature enable -n reduceInstalledPackageSpaceUsage | out-null
|
||||||
|
choco feature enable -n reduceOnlyNupkgSize | out-null
|
||||||
|
choco feature enable -n useRememberedArgumentsForUpgrades | out-null
|
||||||
|
choco feature enable -n adminOnlyExecutionForNewCommand | out-null
|
||||||
|
choco feature enable -n adminOnlyExecutionForDownloadCommand | out-null
|
||||||
|
# choco source disable --name=chocolatey | out-null
|
||||||
|
|
||||||
|
#Get list of locally installed packages to upgrade
|
||||||
|
$packages = [System.Collections.ArrayList]@(choco outdated -r --ignore-unfound --ignore-pinned | Foreach-Object {
|
||||||
|
($_.split("|"))[0]})
|
||||||
|
|
||||||
|
foreach ($ExcludedPackage in $ExcludedPackages)
|
||||||
|
{
|
||||||
|
if ($packages -contains $ExcludedPackage)
|
||||||
|
{
|
||||||
|
$packages.Remove($ExcludedPackage) | Out-Null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($AddedBasePackage in $AdditionalPackage)
|
||||||
|
{
|
||||||
|
if ($packages -notcontains $AddedBasePackage)
|
||||||
|
{
|
||||||
|
$packages.Add($AddedBasePackage) | 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
|
||||||
|
Test-PendingReboot -ComputerName $ComputerName -SkipConfigurationManagerClientCheck | Where-Object {$_.IsRebootpending -eq $True } | ForEach-Object {
|
||||||
|
Restart-Computer -ComputerName $_.ComputerName -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
39
functions/Invoke-ChocoUpgradeIntPackage.ps1
Normal file
39
functions/Invoke-ChocoUpgradeIntPackage.ps1
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<#
|
||||||
|
.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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
44
functions/Push-ChocoIntPackage.ps1
Normal file
44
functions/Push-ChocoIntPackage.ps1
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<#
|
||||||
|
.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,
|
||||||
|
[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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
34
functions/Test-ChocoUpgradeTrigger.ps1
Normal file
34
functions/Test-ChocoUpgradeTrigger.ps1
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<#
|
||||||
|
.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,
|
||||||
|
[System.Management.Automation.PSCredential]$Credential
|
||||||
|
)
|
||||||
|
process {
|
||||||
|
foreach ($Package in $PackageNames){
|
||||||
|
if ($TriggerPackages -contains $Package.Name){
|
||||||
|
Write-Output "Creating scheduled task"
|
||||||
|
Disable-ScheduledTask -TaskName 'Triggered Choco Upgrade' | Unregister-ScheduledTask -Confirm:$False
|
||||||
|
$Time = New-ScheduledTaskTrigger -At '11:59 PM' -Once
|
||||||
|
$PS = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument "-file $UpgradeScriptPath"
|
||||||
|
Register-ScheduledTask -User $Credential.UserName -Description 'This task is created when a popular third party software should be updated on clients' -TaskName 'Triggered Choco Upgrade' -Trigger $Time -Action $PS -Password $Credential.GetNetworkCredential().password -RunLevel Highest
|
||||||
|
Exit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
tests/Feature.Tests.ps1
Normal file
19
tests/Feature.Tests.ps1
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
$script:ModuleName = 'Chocolatey-tools'
|
||||||
|
|
||||||
|
# Removes all versions of the module from the session before importing
|
||||||
|
Get-Module $ModuleName | Remove-Module
|
||||||
|
|
||||||
|
$ModuleBase = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
|
||||||
|
# For tests in .\Tests subdirectory
|
||||||
|
if ((Split-Path $ModuleBase -Leaf) -eq 'Tests') {
|
||||||
|
$ModuleBase = Split-Path $ModuleBase -Parent
|
||||||
|
}
|
||||||
|
|
||||||
|
## This variable is for the VSTS tasks and is to be used for referencing any mock artifacts
|
||||||
|
$Env:ModuleBase = $ModuleBase
|
||||||
|
|
||||||
|
Import-Module $ModuleBase\$ModuleName.psd1 -PassThru -ErrorAction Stop | Out-Null
|
||||||
|
Describe "Basic function feature tests" -Tags Build {
|
||||||
|
|
||||||
|
}
|
||||||
2
tests/Help.Exceptions.txt
Normal file
2
tests/Help.Exceptions.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
|
||||||
95
tests/Help.Tests.ps1
Normal file
95
tests/Help.Tests.ps1
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
$script:ModuleName = 'Chocolatey-tools'
|
||||||
|
|
||||||
|
# Removes all versions of the module from the session before importing
|
||||||
|
Get-Module $ModuleName | Remove-Module
|
||||||
|
|
||||||
|
$ModuleBase = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
|
||||||
|
# Get the list of functions we are not going to run tests against
|
||||||
|
$FunctionHelpTestExceptions = Get-Content -Path "$ModuleBase\Help.Exceptions.txt"
|
||||||
|
|
||||||
|
# For tests in .\Tests subdirectory
|
||||||
|
if ((Split-Path $ModuleBase -Leaf) -eq 'Tests') {
|
||||||
|
$ModuleBase = Split-Path $ModuleBase -Parent
|
||||||
|
}
|
||||||
|
|
||||||
|
$Module = Import-Module $ModuleBase\$ModuleName.psd1 -PassThru -ErrorAction Stop
|
||||||
|
$commands = Get-Command -Module $module -CommandType Cmdlet, Function, Workflow # Not alias
|
||||||
|
|
||||||
|
## When testing help, remember that help is cached at the beginning of each session.
|
||||||
|
## To test, restart session.
|
||||||
|
|
||||||
|
foreach ($command in $commands) {
|
||||||
|
$commandName = $command.Name
|
||||||
|
|
||||||
|
# Skip all functions that are on the exclusions list
|
||||||
|
if ($script:FunctionHelpTestExceptions -contains $commandName) { continue } ## may not be correct check with a function that needs exceptions
|
||||||
|
|
||||||
|
# The module-qualified command fails on Microsoft.PowerShell.Archive cmdlets
|
||||||
|
$Help = Get-Help $commandName -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
Describe "Test help for $commandName" -Tag Help {
|
||||||
|
|
||||||
|
# If help is not found, synopsis in auto-generated help is the syntax diagram
|
||||||
|
It "should not be auto-generated" {
|
||||||
|
$Help.Synopsis | Should Not BeLike '*`[`<CommonParameters`>`]*'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Should be a description for every function
|
||||||
|
It "gets description for $commandName" {
|
||||||
|
$Help.Description | Should Not BeNullOrEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
# Should be at least one example
|
||||||
|
It "gets example code from $commandName" {
|
||||||
|
($Help.Examples.Example | Select-Object -First 1).Code | Should Not BeNullOrEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
# Should be at least one example description
|
||||||
|
It "gets example help from $commandName" {
|
||||||
|
($Help.Examples.Example.Remarks | Select-Object -First 1).Text | Should Not BeNullOrEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
Context "Test parameter help for $commandName" {
|
||||||
|
|
||||||
|
$Common = 'Debug', 'ErrorAction', 'ErrorVariable', 'InformationAction', 'InformationVariable', 'OutBuffer', 'OutVariable',
|
||||||
|
'PipelineVariable', 'Verbose', 'WarningAction', 'WarningVariable'
|
||||||
|
|
||||||
|
$parameters = $command.ParameterSets.Parameters | Sort-Object -Property Name -Unique | Where-Object Name -notin $common
|
||||||
|
$parameterNames = $parameters.Name
|
||||||
|
$HelpParameterNames = $Help.Parameters.Parameter.Name | Sort-Object -Unique
|
||||||
|
|
||||||
|
foreach ($parameter in $parameters) {
|
||||||
|
$parameterName = $parameter.Name
|
||||||
|
$parameterHelp = $Help.parameters.parameter | Where-Object Name -EQ $parameterName
|
||||||
|
|
||||||
|
# Should be a description for every parameter
|
||||||
|
It "gets help for parameter: $parameterName : in $commandName" {
|
||||||
|
$parameterHelp.Description.Text | Should Not BeNullOrEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
# Required value in Help should match IsMandatory property of parameter
|
||||||
|
It "help for $parameterName parameter in $commandName has correct Mandatory value" {
|
||||||
|
$codeMandatory = $parameter.IsMandatory.toString()
|
||||||
|
$parameterHelp.Required | Should Be $codeMandatory
|
||||||
|
}
|
||||||
|
|
||||||
|
# Parameter type in Help should match code
|
||||||
|
It "help for $commandName has correct parameter type for $parameterName" {
|
||||||
|
$codeType = $parameter.ParameterType.Name
|
||||||
|
# To avoid calling Trim method on a null object.
|
||||||
|
$helpType = if ($parameterHelp.parameterValue) { $parameterHelp.parameterValue.Trim() }
|
||||||
|
$helpType | Should be $codeType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($helpParm in $HelpParameterNames) {
|
||||||
|
# Shouldn't find extra parameters in help.
|
||||||
|
It "finds help parameter in code: $helpParm" {
|
||||||
|
$helpParm -in $parameterNames | Should Be $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
0
tests/Project.Exceptions.txt
Normal file
0
tests/Project.Exceptions.txt
Normal file
49
tests/Project.Tests.ps1
Normal file
49
tests/Project.Tests.ps1
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
if (-not(Get-Module -ListAvailable -Name "PSScriptAnalyzer")) {
|
||||||
|
Write-Warning "Installing latest version of PSScriptAnalyzer"
|
||||||
|
# Install PSScriptAnalyzer
|
||||||
|
Install-Module PSScriptAnalyzer -Force -Scope CurrentUser
|
||||||
|
}
|
||||||
|
|
||||||
|
$script:ModuleName = 'Chocolatey-tools'
|
||||||
|
|
||||||
|
$ModuleBase = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
|
||||||
|
# Get the list of Pester Tests we are going to skip
|
||||||
|
$PesterTestExceptions = Get-Content -Path "$ModuleBase\Project.Exceptions.txt"
|
||||||
|
|
||||||
|
# For tests in .\Tests subdirectory
|
||||||
|
if ((Split-Path $ModuleBase -Leaf) -eq 'Tests') {
|
||||||
|
$ModuleBase = Split-Path $ModuleBase -Parent
|
||||||
|
}
|
||||||
|
|
||||||
|
Describe "PSScriptAnalyzer rule-sets" -Tag Build , ScriptAnalyzer {
|
||||||
|
|
||||||
|
$Rules = Get-ScriptAnalyzerRule
|
||||||
|
$scripts = Get-ChildItem $ModuleBase -Include *.ps1, *.psm1, *.psd1 -Recurse | Where-Object fullname -notmatch 'classes'
|
||||||
|
|
||||||
|
foreach ( $Script in $scripts )
|
||||||
|
{
|
||||||
|
Context "Script '$($script.FullName)'" {
|
||||||
|
|
||||||
|
foreach ( $rule in $rules )
|
||||||
|
{
|
||||||
|
# Skip all rules that are on the exclusions list
|
||||||
|
if ($PesterTestExceptions -contains $rule.RuleName) { continue }
|
||||||
|
It "Rule [$rule]" {
|
||||||
|
|
||||||
|
(Invoke-ScriptAnalyzer -Path $script.FullName -IncludeRule $rule.RuleName ).Count | Should Be 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Describe "General project validation: $moduleName" -Tags Build {
|
||||||
|
BeforeAll {
|
||||||
|
Get-Module $ModuleName | Remove-Module
|
||||||
|
}
|
||||||
|
It "Module '$moduleName' can import cleanly" {
|
||||||
|
{Import-Module $ModuleBase\$ModuleName.psd1 -force } | Should Not Throw
|
||||||
|
}
|
||||||
|
}
|
||||||
10
tests/README_TESTS.md
Normal file
10
tests/README_TESTS.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Understanding Tests
|
||||||
|
|
||||||
|
This template comes with the following files:
|
||||||
|
|
||||||
|
* **Feature.Tests.ps1** - Place tests of the features of the module within this file.
|
||||||
|
* **Help.Exceptions.txt** - If there are functions you wish to exclude from the Comment Based Help tests, place their names in this file.
|
||||||
|
* **Help.Tests.ps1** - Performs tests on the Comment Based Help for public functions within the module. You shouldn't need to edit this file.
|
||||||
|
* **Project.Exceptions.txt** - If there are specific PowerShell Script Analyser tests you wish to disable, place their names in this file. I recommend however to use the exclusions listed at the top of your functions.
|
||||||
|
* **Project.Tests.ps1** - Tests that your module meets all PowerShell Script Analyser tests. Also tests that the module successfully loads.
|
||||||
|
* **Unit.Tests.ps1** - This provides a basic structure for your unit tests. Best practice is to copy this file for each function/CMDLet within the module. This structure allows for the execution of the tests for a specific function/CMDLet.
|
||||||
27
tests/Unit.Tests.ps1
Normal file
27
tests/Unit.Tests.ps1
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
$script:ModuleName = 'Chocolatey-tools'
|
||||||
|
|
||||||
|
# Removes all versions of the module from the session before importing
|
||||||
|
Get-Module $ModuleName | Remove-Module
|
||||||
|
|
||||||
|
$ModuleBase = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
|
|
||||||
|
# For tests in .\Tests subdirectory
|
||||||
|
if ((Split-Path $ModuleBase -Leaf) -eq 'Tests') {
|
||||||
|
$ModuleBase = Split-Path $ModuleBase -Parent
|
||||||
|
}
|
||||||
|
|
||||||
|
## This variable is for the VSTS tasks and is to be used for referencing any mock artifacts
|
||||||
|
$Env:ModuleBase = $ModuleBase
|
||||||
|
|
||||||
|
Import-Module $ModuleBase\$ModuleName.psd1 -PassThru -ErrorAction Stop | Out-Null
|
||||||
|
|
||||||
|
# InModuleScope runs the test in module scope.
|
||||||
|
# It creates all variables and functions in module scope.
|
||||||
|
# As a result, test has access to all functions, variables and aliases
|
||||||
|
# in the module even if they're not exported.
|
||||||
|
InModuleScope $script:ModuleName {
|
||||||
|
Describe "Basic function unit tests" -Tags Build , Unit{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user