Update pwsh style to latest community standards #52
26
.drone.yml
26
.drone.yml
@ -11,18 +11,32 @@ steps:
|
|||||||
- name: Environments
|
- name: Environments
|
||||||
image: mcr.microsoft.com/powershell:latest
|
image: mcr.microsoft.com/powershell:latest
|
||||||
commands:
|
commands:
|
||||||
- pwsh -NonInteractive -c "& {Import-Module './tools/DroneIO.psm1' -Verbose; Invoke-ShowEnv -Verbose}"
|
- |
|
||||||
- pwsh -NonInteractive -c "& {Import-Module './tools/DroneIO.psm1' -Verbose; Invoke-InstallDependencies -Verbose}"
|
pwsh -NonInteractive -c "& {
|
||||||
|
Import-Module './tools/DroneIO.psm1' -Verbose;
|
||||||
|
Invoke-ShowEnv -Verbose
|
||||||
|
}"
|
||||||
|
|
||||||
- name: LintTests
|
- name: LintTests
|
||||||
image: mcr.microsoft.com/powershell:latest
|
image: mcr.microsoft.com/powershell:latest
|
||||||
commands:
|
commands:
|
||||||
- pwsh -NonInteractive -c "& {Import-Module './tools/DroneIO.psm1'; Invoke-InstallDependencies}"
|
- |
|
||||||
- pwsh -NonInteractive -c "& {Import-Module './tools/DroneIO.psm1'; Invoke-Linter}"
|
pwsh -NonInteractive -c "& {
|
||||||
|
Import-Module './tools/DroneIO.psm1';
|
||||||
|
Invoke-InstallDependencies;
|
||||||
|
Invoke-Linter
|
||||||
|
}"
|
||||||
|
|
||||||
- name: UnitTests
|
- name: UnitTests
|
||||||
image: mcr.microsoft.com/powershell:latest
|
image: mcr.microsoft.com/powershell:latest
|
||||||
commands:
|
commands:
|
||||||
- pwsh -NonInteractive -c "& {Import-Module './tools/DroneIO.psm1'; Invoke-InstallDependencies}"
|
- |
|
||||||
- pwsh -NonInteractive -c "& {Import-Module './tools/DroneIO.psm1'; Invoke-UnitTests}"
|
pwsh -NonInteractive -c "& {
|
||||||
|
Import-Module './tools/DroneIO.psm1';
|
||||||
|
Invoke-InstallDependencies;
|
||||||
|
Invoke-UnitTest
|
||||||
|
}"
|
||||||
|
|
||||||
- name: coverage
|
- name: coverage
|
||||||
image: plugins/codecov
|
image: plugins/codecov
|
||||||
settings:
|
settings:
|
||||||
|
31
.editorconfig
Normal file
31
.editorconfig
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
end_of_line = crlf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
|
||||||
|
[*.yml]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[{.gitattributes,.gitignore,.gitkeep}]
|
||||||
|
end_of_line = lf
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
22
.gitattributes
vendored
22
.gitattributes
vendored
@ -1,2 +1,24 @@
|
|||||||
|
# images
|
||||||
|
*.jpg binary
|
||||||
|
*.jpeg binary
|
||||||
|
*.bmp binary
|
||||||
|
*.tiff binary
|
||||||
|
*.png binary
|
||||||
|
*.svg binary
|
||||||
|
*.ico binary
|
||||||
|
|
||||||
|
# binary files
|
||||||
|
*.exe binary
|
||||||
|
*.dll binary
|
||||||
|
|
||||||
|
# PowerShell specific
|
||||||
|
*.ps1 working-tree-encoding=UTF-8
|
||||||
|
*.psm1 working-tree-encoding=UTF-8
|
||||||
|
*.psd1 working-tree-encoding=UTF-8
|
||||||
|
|
||||||
|
# set markdown to lf for online editing
|
||||||
|
*.md working-tree-encoding=UTF-8
|
||||||
|
|
||||||
|
# Vendor resources config
|
||||||
src/Vendor/libressl255/* filter=lfs diff=lfs merge=lfs -text
|
src/Vendor/libressl255/* filter=lfs diff=lfs merge=lfs -text
|
||||||
*.pfx filter=lfs diff=lfs merge=lfs -text
|
*.pfx filter=lfs diff=lfs merge=lfs -text
|
||||||
|
15
.gitignore
vendored
15
.gitignore
vendored
@ -1,3 +1,18 @@
|
|||||||
# Don't local track test builds
|
# Don't local track test builds
|
||||||
bin/PSCredentialStore.zip
|
bin/PSCredentialStore.zip
|
||||||
bin/PSCredentialStore/*
|
bin/PSCredentialStore/*
|
||||||
|
|
||||||
|
# Basic ignore patterns
|
||||||
|
*.log
|
||||||
|
*.secret
|
||||||
|
|
||||||
|
# data dir related prod files
|
||||||
|
data/*.csv
|
||||||
|
|
||||||
|
# Ignore templ build artifacts
|
||||||
|
/bin/*
|
||||||
|
!bin/.gitkeep
|
||||||
|
|
||||||
|
# Ignore Unit Test result files
|
||||||
|
coverage.xml
|
||||||
|
testResults.xml
|
||||||
|
42
.vscode/cSpell.json
vendored
42
.vscode/cSpell.json
vendored
@ -1,40 +1,22 @@
|
|||||||
// cSpell Settings
|
// cSpell Settings
|
||||||
{
|
{
|
||||||
// Version of the setting file. Always 0.1
|
// Version of the setting file. Always 0.1
|
||||||
"version": "0.1",
|
"version": "0.2",
|
||||||
// language - current active spelling language
|
// language - current active spelling language
|
||||||
"language": "en",
|
"language": "en,de,de-DE",
|
||||||
// words - list of words to be always considered correct
|
// words - list of words to be always considered correct
|
||||||
"words": [
|
"words": [],
|
||||||
"Cmdlet",
|
|
||||||
"Cmdlets",
|
|
||||||
"GUID",
|
|
||||||
"Hashtable",
|
|
||||||
"Httpclient",
|
|
||||||
"Multipart",
|
|
||||||
"NTFS",
|
|
||||||
"Params",
|
|
||||||
"Ponduit",
|
|
||||||
"Repo",
|
|
||||||
"Veyor",
|
|
||||||
"appveyor",
|
|
||||||
"callsign",
|
|
||||||
"choco",
|
|
||||||
"chocolatey",
|
|
||||||
"codecoverage",
|
|
||||||
"creds",
|
|
||||||
"formdata",
|
|
||||||
"googlemail",
|
|
||||||
"notlike",
|
|
||||||
"notmatch",
|
|
||||||
"powershellgallery",
|
|
||||||
"testresults",
|
|
||||||
"wildcards"
|
|
||||||
],
|
|
||||||
// flagWords - list of words to be always considered incorrect
|
// flagWords - list of words to be always considered incorrect
|
||||||
// This is useful for offensive words and common spelling errors.
|
// This is useful for offensive words and common spelling errors.
|
||||||
// For example "hte" should be "the"
|
// For example "hte" should be "the"
|
||||||
"flagWords": [
|
"flagWords": [],
|
||||||
"hte"
|
"dictionaryDefinitions": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"path": "./dictionaries/default.txt"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dictionaries": [
|
||||||
|
"default"
|
||||||
]
|
]
|
||||||
}
|
}
|
0
.vscode/dictionaries/default.txt
vendored
Normal file
0
.vscode/dictionaries/default.txt
vendored
Normal file
13
.vscode/extensions.json
vendored
Normal file
13
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"streetsidesoftware.code-spell-checker",
|
||||||
|
"streetsidesoftware.code-spell-checker-german",
|
||||||
|
"hediet.vscode-drawio",
|
||||||
|
"editorconfig.editorconfig",
|
||||||
|
"eamodio.gitlens",
|
||||||
|
"vscode-icons-team.vscode-icons",
|
||||||
|
"redhat.vscode-xml",
|
||||||
|
"redhat.vscode-yaml",
|
||||||
|
"ryanluker.vscode-coverage-gutters"
|
||||||
|
]
|
||||||
|
}
|
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@ -42,7 +42,7 @@
|
|||||||
"type": "PowerShell",
|
"type": "PowerShell",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "PowerShell Interactive Session",
|
"name": "PowerShell Interactive Session",
|
||||||
"cwd": ""
|
"cwd": "${workspaceRoot}"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
31
.vscode/pwsh.code-snippets
vendored
Normal file
31
.vscode/pwsh.code-snippets
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
// Place your PowerShell-Module workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
|
||||||
|
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
|
||||||
|
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
|
||||||
|
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
|
||||||
|
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
|
||||||
|
// Placeholders with the same ids are connected.
|
||||||
|
// Example:
|
||||||
|
// "Print to console": {
|
||||||
|
// "scope": "javascript,typescript",
|
||||||
|
// "prefix": "log",
|
||||||
|
// "body": [
|
||||||
|
// "console.log('$1');",
|
||||||
|
// "$2"
|
||||||
|
// ],
|
||||||
|
// "description": "Log output to console"
|
||||||
|
// }
|
||||||
|
// PSScriptAnalyzder Rule Suppression
|
||||||
|
"Rule Suppression": {
|
||||||
|
"scope": "powershell",
|
||||||
|
"prefix": "[Diag",
|
||||||
|
"description": "Suppresses Scriptanalyzer Rules",
|
||||||
|
"body": [
|
||||||
|
"[Diagnostics.CodeAnalysis.SuppressMessageAttribute(",
|
||||||
|
" '${1|PSProvideCommentHelp,PSAvoidLongLines,PSAvoidUsingWriteHost,PSUseShouldProcessForStateChangingFunctions|}',",
|
||||||
|
" '',",
|
||||||
|
" Justification = '${justification}'",
|
||||||
|
")]"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
45
.vscode/settings.json
vendored
45
.vscode/settings.json
vendored
@ -1,34 +1,15 @@
|
|||||||
// Place your settings in this file to overwrite default and user settings.
|
|
||||||
{
|
{
|
||||||
// Set basic file related options:
|
|
||||||
"files.encoding": "utf8",
|
"files.encoding": "utf8",
|
||||||
"files.eol": "\r\n",
|
"files.eol": "auto",
|
||||||
"files.trimTrailingWhitespace": true,
|
"files.trimTrailingWhitespace": true,
|
||||||
"files.insertFinalNewline": true,
|
"files.insertFinalNewline": true,
|
||||||
// Formation and editor options
|
|
||||||
"editor.renderWhitespace": "boundary",
|
"editor.renderWhitespace": "boundary",
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"editor.formatOnType": true,
|
"editor.formatOnType": true,
|
||||||
"editor.rulers": [
|
"editor.rulers": [
|
||||||
116
|
116
|
||||||
],
|
],
|
||||||
// powershell general
|
"cSpell.enabled": true,
|
||||||
"powershell.startAutomatically": true,
|
|
||||||
"powershell.useX86Host": false,
|
|
||||||
"powershell.enableProfileLoading": true,
|
|
||||||
"powershell.scriptAnalysis.enable": true,
|
|
||||||
// powershell code Formatting
|
|
||||||
"powershell.codeFormatting.openBraceOnSameLine": true,
|
|
||||||
"powershell.codeFormatting.newLineAfterOpenBrace": true,
|
|
||||||
"powershell.codeFormatting.newLineAfterCloseBrace": true,
|
|
||||||
"powershell.codeFormatting.whitespaceBeforeOpenBrace": true,
|
|
||||||
"powershell.codeFormatting.whitespaceBeforeOpenParen": true,
|
|
||||||
"powershell.codeFormatting.whitespaceAroundOperator": true,
|
|
||||||
"powershell.codeFormatting.whitespaceAfterSeparator": true,
|
|
||||||
"powershell.codeFormatting.ignoreOneLineBlock": true,
|
|
||||||
"powershell.codeFormatting.alignPropertyValuePairs": true,
|
|
||||||
"powershell.codeFormatting.preset": "Custom",
|
|
||||||
// cspell spellchecker options
|
|
||||||
"cSpell.enabledLanguageIds": [
|
"cSpell.enabledLanguageIds": [
|
||||||
"c",
|
"c",
|
||||||
"cpp",
|
"cpp",
|
||||||
@ -46,6 +27,26 @@
|
|||||||
"text",
|
"text",
|
||||||
"typescript",
|
"typescript",
|
||||||
"typescriptreact",
|
"typescriptreact",
|
||||||
|
"yaml",
|
||||||
"yml"
|
"yml"
|
||||||
]
|
],
|
||||||
|
"cSpell.language": "en,de,de-DE",
|
||||||
|
// powershell general
|
||||||
|
"powershell.startAutomatically": true,
|
||||||
|
"powershell.useX86Host": false,
|
||||||
|
"powershell.enableProfileLoading": true,
|
||||||
|
"powershell.scriptAnalysis.enable": true,
|
||||||
|
// powershell code Formatting
|
||||||
|
"powershell.codeFormatting.openBraceOnSameLine": true,
|
||||||
|
"powershell.codeFormatting.newLineAfterOpenBrace": true,
|
||||||
|
"powershell.codeFormatting.newLineAfterCloseBrace": true,
|
||||||
|
"powershell.codeFormatting.whitespaceBeforeOpenBrace": true,
|
||||||
|
"powershell.codeFormatting.whitespaceBeforeOpenParen": true,
|
||||||
|
"powershell.codeFormatting.whitespaceAroundOperator": true,
|
||||||
|
"powershell.codeFormatting.whitespaceAfterSeparator": true,
|
||||||
|
"powershell.codeFormatting.ignoreOneLineBlock": true,
|
||||||
|
"powershell.codeFormatting.alignPropertyValuePairs": true,
|
||||||
|
"powershell.scriptAnalysis.settingsPath": "./tools/PSScriptAnalyzerSettings.psd1",
|
||||||
|
"coverage-gutters.showGutterCoverage": false,
|
||||||
|
"coverage-gutters.showLineCoverage": true
|
||||||
}
|
}
|
||||||
|
145
.vscode/tasks.json
vendored
145
.vscode/tasks.json
vendored
@ -1,56 +1,121 @@
|
|||||||
|
// A task runner that invokes Pester to run all Pester tests under the
|
||||||
|
// current workspace folder.
|
||||||
|
// NOTE: This Test task runner requires an updated version of Pester (>=4.0.3)
|
||||||
|
// in order for the problemMatcher to find failed test information (message, line, file).
|
||||||
|
// If you don't have that version, you can update Pester from the PowerShell Gallery
|
||||||
|
// with this command:
|
||||||
|
//
|
||||||
|
// PS C:\> Update-Module Pester
|
||||||
|
//
|
||||||
|
// If that gives an error like:
|
||||||
|
// "Module 'Pester' was not installed by using Install-Module, so it cannot be updated."
|
||||||
|
// then execute:
|
||||||
|
//
|
||||||
|
// PS C:\> Install-Module Pester -Scope CurrentUser -Force
|
||||||
|
//
|
||||||
|
// NOTE: The Clean, Build and Publish tasks require PSake. PSake can be installed
|
||||||
|
// from the PowerShell Gallery with this command:
|
||||||
|
//
|
||||||
|
// PS C:\> Install-Module PSake -Scope CurrentUser -Force
|
||||||
|
//
|
||||||
|
// Available variables which can be used inside of strings:
|
||||||
|
// ${workspaceFolder} the path of the workspace folder that contains the tasks.json file
|
||||||
|
// ${workspaceFolderBasename} the name of the workspace folder that contains the tasks.json file without any slashes (/)
|
||||||
|
// ${file} the current opened file
|
||||||
|
// ${relativeFile} the current opened file relative to the workspace folder containing the file
|
||||||
|
// ${fileBasename} the current opened file's basename
|
||||||
|
// ${fileBasenameNoExtension} the current opened file's basename without the extension
|
||||||
|
// ${fileDirname} the current opened file's dirname
|
||||||
|
// ${fileExtname} the current opened file's extension
|
||||||
|
// ${cwd} the task runner's current working directory on startup
|
||||||
|
// ${lineNumber} the current selected line number in the active file
|
||||||
{
|
{
|
||||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
|
||||||
// for the documentation about the tasks.json format
|
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
// Start PowerShell
|
//"windows": {
|
||||||
"windows": {
|
// "options": {
|
||||||
"command": "${env:windir}/System32/WindowsPowerShell/v1.0/powershell.exe",
|
// "shell": {
|
||||||
|
// // switch back to windows powershell 5.1
|
||||||
|
// // "executable": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
|
||||||
|
// "executable": "pwsh.exe",
|
||||||
|
// "args": [
|
||||||
|
// "-NoProfile",
|
||||||
|
// "-ExecutionPolicy",
|
||||||
|
// "Bypass",
|
||||||
|
// "-Command"
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//},
|
||||||
|
"linux": {
|
||||||
|
"options": {
|
||||||
|
"shell": {
|
||||||
|
"executable": "/usr/bin/pwsh",
|
||||||
"args": [
|
"args": [
|
||||||
"-NoProfile",
|
"-NoProfile",
|
||||||
"-ExecutionPolicy",
|
"-Command"
|
||||||
"Bypass"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"linux": {
|
|
||||||
"command": "/usr/bin/powershell",
|
|
||||||
"args": [
|
|
||||||
"-NoProfile"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"osx": {
|
|
||||||
"command": "/usr/local/bin/powershell",
|
|
||||||
"args": [
|
|
||||||
"-NoProfile"
|
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
//"osx": {
|
||||||
|
// "options": {
|
||||||
|
// "shell": {
|
||||||
|
// "executable": "/usr/local/bin/pwsh",
|
||||||
|
// "args": [
|
||||||
|
// "-NoProfile",
|
||||||
|
// "-Command"
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//},
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"taskName": "Test",
|
"label": "DroneIO: Invoke-Linter",
|
||||||
"suppressTaskName": true,
|
"type": "shell",
|
||||||
"args": [
|
"command": [
|
||||||
"Write-Host 'Invoking Pester...'; $ProgressPreference = 'SilentlyContinue'; Invoke-Pester -Script ( Get-ChildItem -Path '.\\tests\\*.Tests.ps1' -Recurse | Sort-Object -Property Name ) -EnableExit $flase -PesterOption @{IncludeVSCodeMarker=$true};",
|
"Import-Module ./tools/DroneIO.psm1;",
|
||||||
"Invoke-Command { Write-Host 'Completed Test task in task runner.' }"
|
"Invoke-Linterq | Format-Table -AutoSize"
|
||||||
],
|
],
|
||||||
"problemMatcher": "$pester",
|
"group": "test",
|
||||||
"group": {
|
"problemMatcher": [
|
||||||
"kind": "test",
|
"$pester"
|
||||||
"isDefault": true
|
]
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"taskName": "DebugBuild",
|
"label": "DroneIO: Invoke-UnitTest",
|
||||||
"suppressTaskName": true,
|
"type": "shell",
|
||||||
"args": [
|
"command": [
|
||||||
"Write-Host 'Invoking Build...';",
|
"Remove-Item ./coverage.xml -ErrorAction 'SilentlyContinue';",
|
||||||
"Write-Host -Object 'Test previous builds.' -ForegroundColor Blue;",
|
"Remove-Item ./testResults.xml -ErrorAction 'SilentlyContinue';",
|
||||||
"If (Test-Path -Path '.\\bin\\PSCredentialStore.zip') { Remove-Item -Path '.\\bin\\PSCredentialStore.zip' -Verbose};",
|
"Import-Module ./tools/DroneIO.psm1;",
|
||||||
"Copy-Item -Path '.\\src\\' -Destination '.\\bin\\PSCredentialStore' -Recurse -Verbose -Force;",
|
"Invoke-UnitTest -CoverageFormat 'CoverageGutters' -Verbosity 'Debug'"
|
||||||
"Compress-Archive -Path '.\\src\\*' -DestinationPath '.\\bin\\PSCredentialStore.zip' -Update -Verbose;"
|
|
||||||
],
|
],
|
||||||
"group": {
|
"group": "test",
|
||||||
"kind": "build",
|
"problemMatcher": [
|
||||||
"isDefault": true
|
"$pester"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Add dictionary item",
|
||||||
|
"type": "shell",
|
||||||
|
"command": [
|
||||||
|
"$DefaultFile = Get-ChildItem -Path './.vscode/dictionaries/default.txt';",
|
||||||
|
"$Content = Get-Content -Path $DefaultFile;",
|
||||||
|
"$Content += '${input:DictionaryItem}';",
|
||||||
|
"$Content = $Content | Sort-Object -Unique;",
|
||||||
|
"Set-Content -Value $Content -Path $DefaultFile"
|
||||||
|
],
|
||||||
|
"group": "none",
|
||||||
|
"problemMatcher": [
|
||||||
|
"$pester"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"id": "DictionaryItem",
|
||||||
|
"type": "promptString",
|
||||||
|
"description": "Input for dictionary file default.txt"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
71
README.md
71
README.md
@ -1,18 +1,42 @@
|
|||||||
[![AppVeyor branch](https://img.shields.io/appveyor/ci/OCram85/PSCredentialStore/master.svg?style=plastic "Master Branch Build Status")](https://ci.appveyor.com/project/OCram85/pscredentialstore/branch/master)
|
<p align="right">
|
||||||
[![AppVeyor tests branch](https://img.shields.io/appveyor/tests/OCram85/PSCredentialStore/master.svg?style=plastic "Pester Tests Results")](https://ci.appveyor.com/project/OCram85/pscredentialstore/branch/master/tests)
|
<img src="http://forthebadge.com/images/badges/built-with-love.svg">
|
||||||
[![Coveralls github](https://img.shields.io/coveralls/github/OCram85/PSCredentialStore.svg?style=plastic "Coveralls.io Coverage Report")](https://coveralls.io/github/OCram85/PSCredentialStore?branch=master)
|
<img src="http://forthebadge.com/images/badges/for-you.svg">
|
||||||
[![codecov](https://codecov.io/gh/OCram85/PSCredentialStore/branch/master/graph/badge.svg)](https://codecov.io/gh/OCram85/PSCredentialStore)
|
</p>
|
||||||
[![PowerShell Gallery](https://img.shields.io/powershellgallery/v/PSCredentialStore.svg?style=plastic "PowershellGallery Published Version")](https://www.powershellgallery.com/packages/PSCredentialStore)
|
|
||||||
[![PowerShell Gallery](https://img.shields.io/powershellgallery/vpre/PSCredentialStore.svg?label=latest%20preview&style=plastic "PowershellGallery Latest Preview Version")](https://www.powershellgallery.com/packages/PSCredentialStore)
|
|
||||||
[![PowerShell Gallery](https://img.shields.io/powershellgallery/dt/PSCredentialStore.svg?style=plastic "PowershellGallery Downloads")](https://www.powershellgallery.com/packages/PSCredentialStore)
|
|
||||||
|
|
||||||
![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)
|
<p align="center">
|
||||||
![forthebadge](http://forthebadge.com/images/badges/for-you.svg)
|
<a href="https://github.com/OCram85/PSCredentialStore/">
|
||||||
|
<img src="https://raw.githubusercontent.com/OCram85/PSCredentialStore/master/assets/social-logo.png" alt="PSCredentialStore" />
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
![social-logo](/assets/social-logo.png)
|
<h1 align="center">
|
||||||
|
PSCredentialStore
|
||||||
|
</h1>
|
||||||
|
|
||||||
:key: General
|
<p align="center">
|
||||||
=======
|
🔐 A simple credential manager to store and reuse multiple PSCredential objects.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://cloud.drone.io/OCram85/PSCredentialStore">
|
||||||
|
<img src="https://cloud.drone.io/api/badges/OCram85/PSCredentialStore/status.svg" alt="Master Branch Build Status">
|
||||||
|
</a>
|
||||||
|
<a href="https://codecov.io/gh/OCram85/PSCredentialStore">
|
||||||
|
<img src="https://codecov.io/gh/OCram85/PSCredentialStore/branch/master/graph/badge.svg" alt="CodeCov">
|
||||||
|
</a>
|
||||||
|
<a href="https://www.powershellgallery.com/packages/PSCredentialStore">
|
||||||
|
<img src="https://img.shields.io/powershellgallery/v/PSCredentialStore.svg?style=plastic" alt="PowershellGallery Published Version">
|
||||||
|
</a>
|
||||||
|
<a href="https://www.powershellgallery.com/packages/PSCredentialStore">
|
||||||
|
<img src="https://img.shields.io/powershellgallery/vpre/PSCredentialStore.svg?label=latest%20preview&style=plastic" />
|
||||||
|
</a>
|
||||||
|
<a href="https://www.powershellgallery.com/packages/PSCredentialStore">
|
||||||
|
<img src="https://img.shields.io/powershellgallery/dt/PSCredentialStore.svg?style=plastic" />
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
## :key: General
|
||||||
|
|
||||||
The PSCredentialStore is a simple credential manager for `PSCredential` objects. It stores PSCredentials in a simple json
|
The PSCredentialStore is a simple credential manager for `PSCredential` objects. It stores PSCredentials in a simple json
|
||||||
file. You can choose between a private and shared credential store. The private one exists in your profile and can
|
file. You can choose between a private and shared credential store. The private one exists in your profile and can
|
||||||
@ -30,14 +54,12 @@ For more details read the [about_PSCredentialStore](/docs/about_PSCredentialStor
|
|||||||
|
|
||||||
You can find the [reference](/docs/PSCredentialStore.md) in the /docs/ path as well.
|
You can find the [reference](/docs/PSCredentialStore.md) in the /docs/ path as well.
|
||||||
|
|
||||||
:vulcan_salute: Requirements
|
## :vulcan_salute: Requirements
|
||||||
============
|
|
||||||
|
|
||||||
- PowerShell >= `5.1`
|
- PowerShell >= `5.1`
|
||||||
- .NET Framework >= `4.6` or .NET Core >= `1.0`
|
- .NET Framework >= `4.6` or .NET Core >= `1.0`
|
||||||
|
|
||||||
:bomb: About Security
|
## :bomb: About Security
|
||||||
============
|
|
||||||
|
|
||||||
>This section explains some security topics and the the design decisions we made to balance the usage and security needs.
|
>This section explains some security topics and the the design decisions we made to balance the usage and security needs.
|
||||||
|
|
||||||
@ -66,21 +88,16 @@ Here is s brief hierarchy description of the certificate location: *(First match
|
|||||||
| Shared (Linux) | `LocalMachine`\\`My` |
|
| Shared (Linux) | `LocalMachine`\\`My` |
|
||||||
| | `LocalMachine`\\`Root` |
|
| | `LocalMachine`\\`Root` |
|
||||||
|
|
||||||
|
## :hammer_and_wrench: Installation
|
||||||
|
|
||||||
|
### :artificial_satellite: PowerShellGallery.com (Recommended Way)
|
||||||
:hammer_and_wrench: Installation
|
|
||||||
============
|
|
||||||
|
|
||||||
:artificial_satellite: PowerShellGallery.com (Recommended Way)
|
|
||||||
---------------------------------------
|
|
||||||
|
|
||||||
* Make sure you use PowerShell 5.1 or higher with `$PSVersionTable`.
|
* Make sure you use PowerShell 5.1 or higher with `$PSVersionTable`.
|
||||||
* Use the builtin PackageManagement and install with: `Import-Module PowerShellGet; Install-Module 'PSCredentialStore' -Repository 'PSGallery'`
|
* Use the builtin PackageManagement and install with: `Import-Module PowerShellGet; Install-Module 'PSCredentialStore' -Repository 'PSGallery'`
|
||||||
* Additionally use the `-AllowPrerelease` switch until we publish the final release!
|
* Additionally use the `-AllowPrerelease` switch until we publish the final release!
|
||||||
* Done. Start exploring the Module with `Import-Module PSCredentialStore ; Get-Command -Module PSCredentialStore`
|
* Done. Start exploring the Module with `Import-Module PSCredentialStore ; Get-Command -Module PSCredentialStore`
|
||||||
|
|
||||||
:building_construction: Manual Way
|
### :building_construction: Manual Way
|
||||||
----------
|
|
||||||
|
|
||||||
* Take a look at the [Latest Release](https://github.com/OCram85/PSCredentialStore/releases/latest) page.
|
* Take a look at the [Latest Release](https://github.com/OCram85/PSCredentialStore/releases/latest) page.
|
||||||
* Download the `PSCredentialStore.zip`.
|
* Download the `PSCredentialStore.zip`.
|
||||||
@ -88,8 +105,7 @@ Here is s brief hierarchy description of the certificate location: *(First match
|
|||||||
* Don't forget to change the NTFS permission flag in the context menu.
|
* Don't forget to change the NTFS permission flag in the context menu.
|
||||||
* Start with `Import-Module PSCredentialStore`
|
* Start with `Import-Module PSCredentialStore`
|
||||||
|
|
||||||
:sparkles: Quick Start
|
### :sparkles: Quick Start
|
||||||
-----------
|
|
||||||
|
|
||||||
**1.** First we need a blank credential store. You can decide between a *private* or *shared* store. The private
|
**1.** First we need a blank credential store. You can decide between a *private* or *shared* store. The private
|
||||||
Credential Store can only be accessed with your profile on the machine you created it.
|
Credential Store can only be accessed with your profile on the machine you created it.
|
||||||
@ -155,8 +171,7 @@ Connect-To -RemoteHost "exchange1.myside.local" -Type ExchangeHTTPS
|
|||||||
Connect-To -RemoteHost "ubuntu.myside.local" -Type SCP
|
Connect-To -RemoteHost "ubuntu.myside.local" -Type SCP
|
||||||
```
|
```
|
||||||
|
|
||||||
:pushpin: Credits
|
### :pushpin: Credits
|
||||||
-------
|
|
||||||
|
|
||||||
A huge thanks to all the people who helped with their projects and indirect contributions which made this possible!
|
A huge thanks to all the people who helped with their projects and indirect contributions which made this possible!
|
||||||
|
|
||||||
|
42
_.travis.yml
42
_.travis.yml
@ -1,42 +0,0 @@
|
|||||||
|
|
||||||
language: csharp
|
|
||||||
dotnet: 2.2.101
|
|
||||||
mono: none
|
|
||||||
|
|
||||||
git:
|
|
||||||
depth: 1000
|
|
||||||
|
|
||||||
os:
|
|
||||||
- linux
|
|
||||||
# Disable OSX bulds for now
|
|
||||||
# - osx
|
|
||||||
|
|
||||||
sudo: required
|
|
||||||
|
|
||||||
dist: xenial
|
|
||||||
osx_image: xcode8.1
|
|
||||||
|
|
||||||
matrix:
|
|
||||||
fast_finish: true
|
|
||||||
|
|
||||||
|
|
||||||
#addons:
|
|
||||||
# artifacts:
|
|
||||||
# paths: ./dist/PowerShellGet.zip
|
|
||||||
|
|
||||||
|
|
||||||
install:
|
|
||||||
# Default 2.0.0 Ruby is buggy
|
|
||||||
# Default bundler version is buggy
|
|
||||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
|
|
||||||
rvm install ruby-2.3.3;
|
|
||||||
rvm --default use 2.3.3;
|
|
||||||
fi
|
|
||||||
- bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh)
|
|
||||||
- pushd tools
|
|
||||||
- chmod +x travis.sh
|
|
||||||
- popd
|
|
||||||
|
|
||||||
script:
|
|
||||||
- echo "TRAVIS_EVENT_TYPE value $TRAVIS_EVENT_TYPE"
|
|
||||||
- ./tools/travis.sh
|
|
74
appveyor.yml
74
appveyor.yml
@ -1,74 +0,0 @@
|
|||||||
# pre release version:
|
|
||||||
version: 1.0.{build}
|
|
||||||
|
|
||||||
#cache:
|
|
||||||
|
|
||||||
#branches:
|
|
||||||
# only:
|
|
||||||
# - master
|
|
||||||
# - dev
|
|
||||||
# - debug
|
|
||||||
|
|
||||||
skip_tags: true
|
|
||||||
|
|
||||||
image: Visual Studio 2019
|
|
||||||
|
|
||||||
# Install pester module and init the Appveyor support.
|
|
||||||
|
|
||||||
# Enable RDP connection for debugging
|
|
||||||
#init:
|
|
||||||
# - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
|
|
||||||
|
|
||||||
install:
|
|
||||||
- ps: Import-Module .\tools\AppVeyor.psm1
|
|
||||||
- ps: Invoke-InstallDependencies
|
|
||||||
|
|
||||||
environment:
|
|
||||||
NuGetToken:
|
|
||||||
secure: 835qfZIkC9mE7QhkYfOZVAdR8rZhPvxG8BO4CbeaelRQOhlqmaSr8G1DWRJzZ/bS
|
|
||||||
CoverallsToken:
|
|
||||||
secure: eTjWqHL48MBr8wp1rSgLrXHdtpfDV/uClacP3svlWJfCvn/zVokpuaMnWM5RoyIY
|
|
||||||
CodeCovToken:
|
|
||||||
secure: LJOvamWIlVORDE7120KcmWVkHxOFYBSN99linyICXXmXLtYm81K/31YeMGiPlgTm
|
|
||||||
|
|
||||||
build: false
|
|
||||||
|
|
||||||
before_build:
|
|
||||||
- ps: Invoke-AppVeyorBumpVersion
|
|
||||||
|
|
||||||
build_script:
|
|
||||||
- ps: Invoke-AppVeyorBuild
|
|
||||||
|
|
||||||
test_script:
|
|
||||||
- ps: |
|
|
||||||
$CodeCoverage = Invoke-AppVeyorTests
|
|
||||||
if ($null -ne $Env:CoverallsToken) {
|
|
||||||
Invoke-CoverageReport -PesterCoverageReport $CodeCoverage
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Write-Warning "No CoverallsToken found. This build seems to be triggered by a PR. Skipping this step..."
|
|
||||||
}
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
#- provider: GitHub
|
|
||||||
# auth_token:
|
|
||||||
# secure: M+bBX5/nKdJB0eViP7xtrLVTwf3vGDUA9N2MMprZp2i+9ZR3CBVcJnSzJWUmalhB
|
|
||||||
# artifact: PSCredentialStore.zip # upload all NuGet packages to release assets
|
|
||||||
# draft: true
|
|
||||||
# prerelease: true
|
|
||||||
# on:
|
|
||||||
# branch: dev
|
|
||||||
- provider: GitHub
|
|
||||||
auth_token:
|
|
||||||
secure: M+bBX5/nKdJB0eViP7xtrLVTwf3vGDUA9N2MMprZp2i+9ZR3CBVcJnSzJWUmalhB
|
|
||||||
artifact: PSCredentialStore.zip # upload all NuGet packages to release assets
|
|
||||||
draft: false
|
|
||||||
prerelease: false
|
|
||||||
on:
|
|
||||||
branch: master # build release on master branch changes
|
|
||||||
|
|
||||||
after_deploy:
|
|
||||||
- ps: Invoke-AppVeyorPSGallery -OnBranch 'master'
|
|
||||||
# Pause build until `lock` on desktop is deleted.
|
|
||||||
#on_finish:
|
|
||||||
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
|
|
@ -20,15 +20,8 @@ function Get-CSCertificate {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Get-CSCertificate -Type 'Shared' -Thumbprint '12334456'
|
Get-CSCertificate -Type 'Shared' -Thumbprint '12334456'
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Get-CSCertificate.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
[OutputType([System.Security.Cryptography.X509Certificates.X509Certificate2])]
|
[OutputType([System.Security.Cryptography.X509Certificates.X509Certificate2])]
|
||||||
param (
|
param (
|
||||||
@ -42,8 +35,8 @@ function Get-CSCertificate {
|
|||||||
[string]$Thumbprint
|
[string]$Thumbprint
|
||||||
)
|
)
|
||||||
|
|
||||||
begin {
|
begin {}
|
||||||
}
|
|
||||||
process {
|
process {
|
||||||
if ($Type -eq 'Private') {
|
if ($Type -eq 'Private') {
|
||||||
Get-CSPfXCertificate -Thumbprint $Thumbprint -StoreName 'My' -StoreLocation 'CurrentUser'
|
Get-CSPfXCertificate -Thumbprint $Thumbprint -StoreName 'My' -StoreLocation 'CurrentUser'
|
||||||
@ -69,6 +62,5 @@ function Get-CSCertificate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end {
|
end {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -21,17 +21,9 @@ function Import-CSCertificate {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Import-CSCertificate -Type 'Private' -Path (Join-Path -Path $Env:APPDATA -ChildItem 'PfxCertificate.pfx')
|
Import-CSCertificate -Type 'Private' -Path (Join-Path -Path $Env:APPDATA -ChildItem 'PfxCertificate.pfx')
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Import-CSCertificate.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
[OutputType()]
|
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
|
@ -35,15 +35,8 @@ function New-CSCertAttribute {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
New-CSCertAttribute -Country 'DE' -State 'BW' -City 'Karlsruhe' -Organization 'AwesomeIT' -OrganizationalUnitName '' -CommonName 'MyPrivateCert'
|
New-CSCertAttribute -Country 'DE' -State 'BW' -City 'Karlsruhe' -Organization 'AwesomeIT' -OrganizationalUnitName '' -CommonName 'MyPrivateCert'
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : New-CSCertAttribute.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
[OutputType('PSCredentialStore.Certificate.Attribute')]
|
[OutputType('PSCredentialStore.Certificate.Attribute')]
|
||||||
param (
|
param (
|
||||||
@ -76,9 +69,8 @@ function New-CSCertAttribute {
|
|||||||
[ValidateNotNull()]
|
[ValidateNotNull()]
|
||||||
[int]$Days = 365
|
[int]$Days = 365
|
||||||
)
|
)
|
||||||
begin {
|
begin {}
|
||||||
|
|
||||||
}
|
|
||||||
process {
|
process {
|
||||||
return [PSCustomObject]@{
|
return [PSCustomObject]@{
|
||||||
PSTypeName = 'PSCredentialStore.Certificate.Attribute'
|
PSTypeName = 'PSCredentialStore.Certificate.Attribute'
|
||||||
@ -94,6 +86,5 @@ function New-CSCertAttribute {
|
|||||||
Days = $Days
|
Days = $Days
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end {
|
end {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -23,15 +23,8 @@ function New-CSCertificate {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
New-CSCertificate -CRTAttribute $CRTAttribute -KeyName './myprivate.key' -CertName './mycert.pfx'
|
New-CSCertificate -CRTAttribute $CRTAttribute -KeyName './myprivate.key' -CertName './mycert.pfx'
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : New-CSCertificate.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding(SupportsShouldProcess = $true)]
|
[CmdletBinding(SupportsShouldProcess = $true)]
|
||||||
[OutputType()]
|
[OutputType()]
|
||||||
param (
|
param (
|
||||||
@ -70,6 +63,7 @@ function New-CSCertificate {
|
|||||||
|
|
||||||
$Env:OPENSSL_CONF = Join-Path $ModuleBase -ChildPath '/openssl.conf'
|
$Env:OPENSSL_CONF = Join-Path $ModuleBase -ChildPath '/openssl.conf'
|
||||||
}
|
}
|
||||||
|
|
||||||
process {
|
process {
|
||||||
$SubjPattern = "/C={0}/ST={1}/L={2}/O={3}/OU={4}/CN={5}"
|
$SubjPattern = "/C={0}/ST={1}/L={2}/O={3}/OU={4}/CN={5}"
|
||||||
$SubjValues = @(
|
$SubjValues = @(
|
||||||
|
@ -17,15 +17,8 @@ function Test-CSCertificate {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Test-CSCertificate -Type 'Shared'
|
Test-CSCertificate -Type 'Shared'
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Test-CSCertificate.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
[OutputType([bool])]
|
[OutputType([bool])]
|
||||||
param (
|
param (
|
||||||
|
@ -26,34 +26,26 @@ function Use-CSCertificate {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Use-CSCertificate -Path 'C:\cert.pfx'
|
Use-CSCertificate -Path 'C:\cert.pfx'
|
||||||
|
|
||||||
.NOTES
|
|
||||||
File Name : Use-CSCertificate.ps1
|
|
||||||
Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
[CmdletBinding(DefaultParameterSetName = "Private")]
|
|
||||||
[OutputType()]
|
[CmdletBinding(DefaultParameterSetName = 'Private')]
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Private')]
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$Path,
|
[string]$Path,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$CredentialStore,
|
[string]$CredentialStore,
|
||||||
|
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
||||||
[switch]$Shared,
|
[switch]$Shared,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Private')]
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[Switch]$UseCertStore
|
[switch]$UseCertStore
|
||||||
)
|
)
|
||||||
begin {}
|
begin {}
|
||||||
|
|
||||||
@ -74,11 +66,11 @@ function Use-CSCertificate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($PSCmdlet.ParameterSetName -eq "Private") {
|
if ($PSCmdlet.ParameterSetName -eq 'Private') {
|
||||||
$StorePath = Get-DefaultCredentialStorePath
|
$StorePath = Get-DefaultCredentialStorePath
|
||||||
$CS = Get-CredentialStore
|
$CS = Get-CredentialStore
|
||||||
}
|
}
|
||||||
elseif ($PSCmdlet.ParameterSetName -eq "Shared" ) {
|
elseif ($PSCmdlet.ParameterSetName -eq 'Shared' ) {
|
||||||
if (!($PSBoundParameters.ContainsKey('CredentialStore'))) {
|
if (!($PSBoundParameters.ContainsKey('CredentialStore'))) {
|
||||||
$StorePath = Get-DefaultCredentialStorePath -Shared
|
$StorePath = Get-DefaultCredentialStorePath -Shared
|
||||||
$CS = Get-CredentialStore -Shared
|
$CS = Get-CredentialStore -Shared
|
||||||
|
@ -58,28 +58,20 @@ function Connect-To {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Connect-To -RemoteHost "exchange01.myside.local" -Type ExchangeHTTPS
|
Connect-To -RemoteHost "exchange01.myside.local" -Type ExchangeHTTPS
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Connect-To.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding(DefaultParameterSetName = "Private")]
|
[CmdletBinding(DefaultParameterSetName = 'Private')]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Private')]
|
||||||
[string]$RemoteHost,
|
[string]$RemoteHost,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Private')]
|
||||||
[string]$Identifier,
|
[string]$Identifier,
|
||||||
|
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Private')]
|
||||||
[ValidateSet(
|
[ValidateSet(
|
||||||
'CiscoUcs',
|
'CiscoUcs',
|
||||||
'FTP',
|
'FTP',
|
||||||
@ -92,29 +84,29 @@ function Connect-To {
|
|||||||
)]
|
)]
|
||||||
[string]$Type,
|
[string]$Type,
|
||||||
|
|
||||||
[Parameter(Mandatory = $False, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $False, ParameterSetName = 'Shared')]
|
||||||
[Parameter(Mandatory = $False, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $False, ParameterSetName = 'Private')]
|
||||||
[PSCredential]$Credentials,
|
[PSCredential]$Credentials,
|
||||||
|
|
||||||
[Parameter(Mandatory = $true, ParameterSetNAme = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetNAme = 'Shared')]
|
||||||
[switch]$Shared,
|
[switch]$Shared,
|
||||||
|
|
||||||
[Parameter(Mandatory = $False, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $False, ParameterSetName = 'Shared')]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$Path,
|
[string]$Path,
|
||||||
|
|
||||||
[Parameter(Mandatory = $False, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $False, ParameterSetName = 'Private')]
|
||||||
[Parameter(Mandatory = $False, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $False, ParameterSetName = 'Shared')]
|
||||||
[switch]$PassThru
|
[switch]$PassThru
|
||||||
)
|
)
|
||||||
|
|
||||||
begin {
|
begin {
|
||||||
# Set the CredentialStore for private, shared or custom mode.
|
# Set the CredentialStore for private, shared or custom mode.
|
||||||
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
||||||
if ($PSCmdlet.ParameterSetName -eq "Private") {
|
if ($PSCmdlet.ParameterSetName -eq 'Private') {
|
||||||
$Path = Get-DefaultCredentialStorePath
|
$Path = Get-DefaultCredentialStorePath
|
||||||
}
|
}
|
||||||
elseif ($PSCmdlet.ParameterSetName -eq "Shared") {
|
elseif ($PSCmdlet.ParameterSetName -eq 'Shared') {
|
||||||
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
||||||
$Path = Get-DefaultCredentialStorePath -Shared
|
$Path = Get-DefaultCredentialStorePath -Shared
|
||||||
}
|
}
|
||||||
@ -155,7 +147,7 @@ function Connect-To {
|
|||||||
catch {
|
catch {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unable to look up credential store item for RemoteHost {0}/Identifier {1}!" -f $RemoteHost, $Identifier
|
Message = "Unable to look up credential store item for RemoteHost {0}/Identifier {1}!" -f $RemoteHost, $Identifier
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -164,10 +156,10 @@ function Connect-To {
|
|||||||
$creds = $Credentials
|
$creds = $Credentials
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($creds.UserName -eq "" -or $creds.Password.GetType().Name -ne "SecureString") {
|
if ($creds.UserName -eq "" -or $creds.Password.GetType().Name -ne 'SecureString') {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Please provide valid credentials for RemoteHost {0}!" -f $RemoteHost
|
Message = "Please provide valid credentials for RemoteHost {0}!" -f $RemoteHost
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -176,13 +168,13 @@ function Connect-To {
|
|||||||
"CiscoUcs" {
|
"CiscoUcs" {
|
||||||
try {
|
try {
|
||||||
$handle = Connect-Ucs -Name $RemoteHost -Credential $creds -ErrorAction Stop
|
$handle = Connect-Ucs -Name $RemoteHost -Credential $creds -ErrorAction Stop
|
||||||
$ExecutionContext.SessionState.PSVariable.Set("DefaultUcs", $handle)
|
$ExecutionContext.SessionState.PSVariable.Set('DefaultUcs', $handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
catch {
|
catch {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -207,7 +199,7 @@ function Connect-To {
|
|||||||
# Check the connection state and find out if the session is still open.
|
# Check the connection state and find out if the session is still open.
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Connection to {0} using Type {1} was established. But now it seems to be lost!" -f $RemoteHost, $Type
|
Message = "Connection to {0} using Type {1} was established. But now it seems to be lost!" -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -221,7 +213,7 @@ function Connect-To {
|
|||||||
# Write a error message to the log.
|
# Write a error message to the log.
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -235,7 +227,7 @@ function Connect-To {
|
|||||||
# Write a error message to the log.
|
# Write a error message to the log.
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -255,7 +247,7 @@ function Connect-To {
|
|||||||
# Write a error message to the log.
|
# Write a error message to the log.
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -274,7 +266,7 @@ function Connect-To {
|
|||||||
# Write a error message to the log.
|
# Write a error message to the log.
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -293,7 +285,7 @@ function Connect-To {
|
|||||||
# Write a error message to the log.
|
# Write a error message to the log.
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -314,7 +306,7 @@ function Connect-To {
|
|||||||
# Write a error message to the log.
|
# Write a error message to the log.
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -323,7 +315,7 @@ function Connect-To {
|
|||||||
# Check the connection state and find out if the session is still open.
|
# Check the connection state and find out if the session is still open.
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Connection to {0} using Type {1} was established. But now it seems to be lost!" -f $RemoteHost, $Type
|
Message = "Connection to {0} using Type {1} was established. But now it seems to be lost!" -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -332,7 +324,7 @@ function Connect-To {
|
|||||||
# Write a error message to the log.
|
# Write a error message to the log.
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
|
@ -49,14 +49,6 @@ function Disconnect-From {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Disconnect-From -RemoteHost "exchange01.myside.local" -Type ExchangeHTTPS
|
Disconnect-From -RemoteHost "exchange01.myside.local" -Type ExchangeHTTPS
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Disconnect-From.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
@ -81,6 +73,9 @@ function Disconnect-From {
|
|||||||
[switch]$Force
|
[switch]$Force
|
||||||
)
|
)
|
||||||
|
|
||||||
|
begin {}
|
||||||
|
|
||||||
|
process {
|
||||||
switch -Regex ($Type) {
|
switch -Regex ($Type) {
|
||||||
"VMware" {
|
"VMware" {
|
||||||
try {
|
try {
|
||||||
@ -96,7 +91,7 @@ function Disconnect-From {
|
|||||||
# Write a error message to the log.
|
# Write a error message to the log.
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
|
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -115,7 +110,7 @@ function Disconnect-From {
|
|||||||
# Write a error message to the log.
|
# Write a error message to the log.
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
|
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -127,8 +122,8 @@ function Disconnect-From {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "There is no open WinSCP Session"
|
Message = 'There is no open WinSCP Session'
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -139,7 +134,7 @@ function Disconnect-From {
|
|||||||
try {
|
try {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Setting {0} to `$null, which will disconnect NetAppFAS" -f $Global:CurrentNcController
|
Message = "Setting {0} to `$null, which will disconnect NetAppFAS" -f $Global:CurrentNcController
|
||||||
ErrorAction = "Continue"
|
ErrorAction = 'Continue'
|
||||||
}
|
}
|
||||||
Write-Verbose @MessageParams
|
Write-Verbose @MessageParams
|
||||||
$Global:CurrentNcController = $null
|
$Global:CurrentNcController = $null
|
||||||
@ -149,7 +144,7 @@ function Disconnect-From {
|
|||||||
# Write a error message to the log.
|
# Write a error message to the log.
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
|
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -164,7 +159,7 @@ function Disconnect-From {
|
|||||||
# Write a error message to the log.
|
# Write a error message to the log.
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
|
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -177,7 +172,7 @@ function Disconnect-From {
|
|||||||
catch {
|
catch {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
|
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -188,8 +183,8 @@ function Disconnect-From {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "There is no open WinSCP Session"
|
Message = 'There is no open WinSCP Session'
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -198,9 +193,12 @@ function Disconnect-From {
|
|||||||
# Write a error message to the log.
|
# Write a error message to the log.
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
|
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end {}
|
||||||
|
}
|
||||||
|
@ -21,14 +21,6 @@ function Test-CSConnection {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Test-CMConnection -RemoteHost "vcr01.internal.net" -Type VMware
|
Test-CMConnection -RemoteHost "vcr01.internal.net" -Type VMware
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Test-CSConnection.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
@ -38,7 +30,7 @@ function Test-CSConnection {
|
|||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$RemoteHost,
|
[string]$RemoteHost,
|
||||||
|
|
||||||
[Parameter(Mandatory = $True)]
|
[Parameter(Mandatory = $true)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[ValidateSet("CiscoUcs", "FTP", "NetAppFAS", "VMware")]
|
[ValidateSet("CiscoUcs", "FTP", "NetAppFAS", "VMware")]
|
||||||
[string]$Type
|
[string]$Type
|
||||||
|
@ -29,33 +29,25 @@ function Get-CredentialStoreItem {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
$myCreds = Get-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx01.myside.local"
|
$myCreds = Get-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx01.myside.local"
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Get-CredentialStoreItem.ps1
|
|
||||||
- Author : Messing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding(DefaultParameterSetName = "Private")]
|
[CmdletBinding(DefaultParameterSetName = 'Private')]
|
||||||
[OutputType([PSCredential])]
|
[OutputType([PSCredential])]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Private')]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$RemoteHost,
|
[string]$RemoteHost,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Private')]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$Identifier,
|
[string]$Identifier,
|
||||||
|
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
||||||
[switch]$Shared,
|
[switch]$Shared,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$Path
|
[string]$Path
|
||||||
)
|
)
|
||||||
@ -63,10 +55,10 @@ function Get-CredentialStoreItem {
|
|||||||
begin {
|
begin {
|
||||||
# Set the CredentialStore for private, shared or custom mode.
|
# Set the CredentialStore for private, shared or custom mode.
|
||||||
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
||||||
if ($PSCmdlet.ParameterSetName -eq "Private") {
|
if ($PSCmdlet.ParameterSetName -eq 'Private') {
|
||||||
$Path = Get-DefaultCredentialStorePath
|
$Path = Get-DefaultCredentialStorePath
|
||||||
}
|
}
|
||||||
elseif ($PSCmdlet.ParameterSetName -eq "Shared") {
|
elseif ($PSCmdlet.ParameterSetName -eq 'Shared') {
|
||||||
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
||||||
$Path = Get-DefaultCredentialStorePath -Shared
|
$Path = Get-DefaultCredentialStorePath -Shared
|
||||||
}
|
}
|
||||||
@ -85,7 +77,7 @@ function Get-CredentialStoreItem {
|
|||||||
$CS = Get-CredentialStore -Shared -Path $Path
|
$CS = Get-CredentialStore -Shared -Path $Path
|
||||||
$CSMembers = Get-Member -InputObject $CS
|
$CSMembers = Get-Member -InputObject $CS
|
||||||
# Let's first check if the given remote host exists as object property
|
# Let's first check if the given remote host exists as object property
|
||||||
if (($CSMembers.MemberType -eq "NoteProperty") -and ($CSMembers.Name -contains $CredentialName)) {
|
if (($CSMembers.MemberType -eq 'NoteProperty') -and ($CSMembers.Name -contains $CredentialName)) {
|
||||||
if ($null -eq $CS.PfxCertificate) {
|
if ($null -eq $CS.PfxCertificate) {
|
||||||
$Cert = Get-CSCertificate -Type $CS.Type -Thumbprint $CS.Thumbprint
|
$Cert = Get-CSCertificate -Type $CS.Type -Thumbprint $CS.Thumbprint
|
||||||
}
|
}
|
||||||
@ -106,16 +98,16 @@ function Get-CredentialStoreItem {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$MsgParams = @{
|
$MsgParams = @{
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
Message = "Could not find credentials for the given remote host: {0}" -f $RemoteHost
|
Message = 'Could not find credentials for the given remote host: {0}' -f $RemoteHost
|
||||||
}
|
}
|
||||||
Write-Error @MsgParams
|
Write-Error @MsgParams
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$MsgParams = @{
|
$MsgParams = @{
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
Message = "The given credential store ({0}) does not exist!" -f $Path
|
Message = 'The given credential store ({0}) does not exist!' -f $Path
|
||||||
}
|
}
|
||||||
Write-Error @MsgParams
|
Write-Error @MsgParams
|
||||||
}
|
}
|
||||||
|
@ -33,25 +33,17 @@ function New-CredentialStoreItem {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
New-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx01.myside.local"
|
New-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx01.myside.local"
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : New-CredentialStoreItem.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding(DefaultParameterSetName = "Private")]
|
[CmdletBinding(DefaultParameterSetName = 'Private')]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Private')]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$RemoteHost,
|
[string]$RemoteHost,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Private')]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$Identifier,
|
[string]$Identifier,
|
||||||
|
|
||||||
@ -59,10 +51,10 @@ function New-CredentialStoreItem {
|
|||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[PSCredential]$Credential,
|
[PSCredential]$Credential,
|
||||||
|
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
||||||
[switch]$Shared,
|
[switch]$Shared,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$Path
|
[string]$Path
|
||||||
|
|
||||||
@ -72,10 +64,10 @@ function New-CredentialStoreItem {
|
|||||||
begin {
|
begin {
|
||||||
# Set the CredentialStore for private, shared or custom mode.
|
# Set the CredentialStore for private, shared or custom mode.
|
||||||
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
||||||
if ($PSCmdlet.ParameterSetName -eq "Private") {
|
if ($PSCmdlet.ParameterSetName -eq 'Private') {
|
||||||
$Path = Get-DefaultCredentialStorePath
|
$Path = Get-DefaultCredentialStorePath
|
||||||
}
|
}
|
||||||
elseif ($PSCmdlet.ParameterSetName -eq "Shared") {
|
elseif ($PSCmdlet.ParameterSetName -eq 'Shared') {
|
||||||
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
||||||
$Path = Get-DefaultCredentialStorePath -Shared
|
$Path = Get-DefaultCredentialStorePath -Shared
|
||||||
}
|
}
|
||||||
@ -96,7 +88,7 @@ function New-CredentialStoreItem {
|
|||||||
|
|
||||||
$CSContent = Get-CredentialStore -Shared -Path $Path
|
$CSContent = Get-CredentialStore -Shared -Path $Path
|
||||||
|
|
||||||
$CurrentDate = Get-Date -UFormat "%Y-%m-%d %H:%M:%S"
|
$CurrentDate = Get-Date -Format 'u'
|
||||||
|
|
||||||
if ($Identifier -ne "") {
|
if ($Identifier -ne "") {
|
||||||
$CredentialName = $RemoteHost = "{0}/{1}" -f $Identifier, $RemoteHost
|
$CredentialName = $RemoteHost = "{0}/{1}" -f $Identifier, $RemoteHost
|
||||||
@ -119,7 +111,7 @@ function New-CredentialStoreItem {
|
|||||||
|
|
||||||
if (Get-Member -InputObject $CSContent -Name $CredentialName -Membertype Properties) {
|
if (Get-Member -InputObject $CSContent -Name $CredentialName -Membertype Properties) {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "The given host already exists. Nothing to do here."
|
Message = 'The given host already exists. Nothing to do here.'
|
||||||
}
|
}
|
||||||
Write-Warning @MessageParams
|
Write-Warning @MessageParams
|
||||||
}
|
}
|
||||||
@ -139,8 +131,8 @@ function New-CredentialStoreItem {
|
|||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Couldn't add item into credential store!"
|
Message = 'Could not add item into credential store!'
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -148,15 +140,13 @@ function New-CredentialStoreItem {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Please Provide at least a valid user!"
|
Message = 'Please Provide at least a valid user!'
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end {
|
end {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,30 +37,22 @@ function Remove-CredentialStoreItem {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Remove-CredentialStoreItem -RemoteHost "esx01.myside.local" -Identifier svc
|
Remove-CredentialStoreItem -RemoteHost "esx01.myside.local" -Identifier svc
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Remove-CredentialStoreItem.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding(DefaultParameterSetName = "Private")]
|
[CmdletBinding(DefaultParameterSetName = 'Private')]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Private')]
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
||||||
[string]$RemoteHost,
|
[string]$RemoteHost,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Private')]
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[string]$Identifier,
|
[string]$Identifier,
|
||||||
|
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
||||||
[switch]$Shared,
|
[switch]$Shared,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$Path
|
[string]$Path
|
||||||
)
|
)
|
||||||
@ -68,10 +60,10 @@ function Remove-CredentialStoreItem {
|
|||||||
begin {
|
begin {
|
||||||
# Set the CredentialStore for private, shared or custom mode.
|
# Set the CredentialStore for private, shared or custom mode.
|
||||||
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
||||||
if ($PSCmdlet.ParameterSetName -eq "Private") {
|
if ($PSCmdlet.ParameterSetName -eq 'Private') {
|
||||||
$Path = Get-DefaultCredentialStorePath
|
$Path = Get-DefaultCredentialStorePath
|
||||||
}
|
}
|
||||||
elseif ($PSCmdlet.ParameterSetName -eq "Shared") {
|
elseif ($PSCmdlet.ParameterSetName -eq 'Shared') {
|
||||||
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
||||||
$Path = Get-DefaultCredentialStorePath -Shared
|
$Path = Get-DefaultCredentialStorePath -Shared
|
||||||
}
|
}
|
||||||
@ -82,8 +74,8 @@ function Remove-CredentialStoreItem {
|
|||||||
# Lets do a quick test on the given CredentialStore.
|
# Lets do a quick test on the given CredentialStore.
|
||||||
if (-not(Test-CredentialStore -Shared -Path $Path)) {
|
if (-not(Test-CredentialStore -Shared -Path $Path)) {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Could not add anything into the given CredentialStore."
|
Message = 'Could not add anything into the given CredentialStore.'
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -105,7 +97,7 @@ function Remove-CredentialStoreItem {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "The given CredentialStoreItem does not exist."
|
Message = 'The given CredentialStoreItem does not exist.'
|
||||||
}
|
}
|
||||||
Write-Warning @MessageParams
|
Write-Warning @MessageParams
|
||||||
}
|
}
|
||||||
|
@ -34,34 +34,26 @@ function Set-CredentialStoreItem {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Set-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx01.myside.local" -Identifier svc
|
Set-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx01.myside.local" -Identifier svc
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Set-CredentialStoreItem.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding(DefaultParameterSetName = "Private")]
|
[CmdletBinding(DefaultParameterSetName = 'Private')]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Private')]
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
||||||
[string]$RemoteHost,
|
[string]$RemoteHost,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Private')]
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[string]$Identifier,
|
[string]$Identifier,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ValueFromPipeline = $true)]
|
[Parameter(Mandatory = $false, ValueFromPipeline = $true)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[PSCredential]$Credential,
|
[PSCredential]$Credential,
|
||||||
|
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
||||||
[switch]$Shared,
|
[switch]$Shared,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$Path
|
[string]$Path
|
||||||
)
|
)
|
||||||
@ -69,10 +61,10 @@ function Set-CredentialStoreItem {
|
|||||||
begin {
|
begin {
|
||||||
# Set the CredentialStore for private, shared or custom mode.
|
# Set the CredentialStore for private, shared or custom mode.
|
||||||
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
||||||
if ($PSCmdlet.ParameterSetName -eq "Private") {
|
if ($PSCmdlet.ParameterSetName -eq 'Private') {
|
||||||
$Path = Get-DefaultCredentialStorePath
|
$Path = Get-DefaultCredentialStorePath
|
||||||
}
|
}
|
||||||
elseif ($PSCmdlet.ParameterSetName -eq "Shared") {
|
elseif ($PSCmdlet.ParameterSetName -eq 'Shared') {
|
||||||
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
||||||
$Path = Get-DefaultCredentialStorePath -Shared
|
$Path = Get-DefaultCredentialStorePath -Shared
|
||||||
}
|
}
|
||||||
@ -83,8 +75,8 @@ function Set-CredentialStoreItem {
|
|||||||
# Lets do a quick test on the given CredentialStore.
|
# Lets do a quick test on the given CredentialStore.
|
||||||
if (-not(Test-CredentialStore -Shared -Path $Path)) {
|
if (-not(Test-CredentialStore -Shared -Path $Path)) {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Could not add anything into the given CredentailStore."
|
Message = 'Could not add anything into the given CredentailStore.'
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
@ -92,7 +84,7 @@ function Set-CredentialStoreItem {
|
|||||||
# Read the file content based on the given ParameterSetName
|
# Read the file content based on the given ParameterSetName
|
||||||
$CSContent = Get-CredentialStore -Shared -Path $Path
|
$CSContent = Get-CredentialStore -Shared -Path $Path
|
||||||
|
|
||||||
$CurrentDate = Get-Date -UFormat "%Y-%m-%d %H:%M:%S"
|
$CurrentDate = Get-Date -Format 'u'
|
||||||
|
|
||||||
if ($Identifier -ne "") {
|
if ($Identifier -ne "") {
|
||||||
$CredentialName = $RemoteHost = "{0}/{1}" -f $Identifier, $RemoteHost
|
$CredentialName = $RemoteHost = "{0}/{1}" -f $Identifier, $RemoteHost
|
||||||
@ -129,8 +121,8 @@ function Set-CredentialStoreItem {
|
|||||||
}
|
}
|
||||||
Else {
|
Else {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Please Provide at least a valid user!"
|
Message = 'Please Provide at least a valid user!'
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
|
@ -29,25 +29,18 @@ function Test-CredentialStoreItem {
|
|||||||
[None]
|
[None]
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
If (Test-CredentialStoreItem -RemoteHost "Default") {
|
if (Test-CredentialStoreItem -RemoteHost "Default") {
|
||||||
Get-CredentialStoreItem -RemoteHost "Default"
|
Get-CredentialStoreItem -RemoteHost "Default"
|
||||||
}
|
}
|
||||||
Else {
|
else {
|
||||||
Write-Warning ("The given Remote Host {0} does not exist in the credential Store!" -f $RemoteHost)
|
Write-Warning ("The given Remote Host {0} does not exist in the credential Store!" -f $RemoteHost)
|
||||||
}
|
}
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Test-CredentialStoreItem.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
[CmdletBinding(DefaultParameterSetName = "Private")]
|
|
||||||
[OutputType([Boolean])]
|
[CmdletBinding(DefaultParameterSetName = 'Private')]
|
||||||
|
[OutputType([bool])]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[string]$Path = "{0}\PSCredentialStore\CredentialStore.json" -f $env:ProgramData,
|
[string]$Path = "{0}\PSCredentialStore\CredentialStore.json" -f $env:ProgramData,
|
||||||
|
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
@ -58,17 +51,17 @@ function Test-CredentialStoreItem {
|
|||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]$Identifier,
|
[string]$Identifier,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[switch]$Shared
|
[switch]$Shared
|
||||||
)
|
)
|
||||||
|
|
||||||
begin {
|
begin {
|
||||||
# Set the CredentialStore for private, shared or custom mode.
|
# Set the CredentialStore for private, shared or custom mode.
|
||||||
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
||||||
if ($PSCmdlet.ParameterSetName -eq "Private") {
|
if ($PSCmdlet.ParameterSetName -eq 'Private') {
|
||||||
$Path = Get-DefaultCredentialStorePath
|
$Path = Get-DefaultCredentialStorePath
|
||||||
}
|
}
|
||||||
elseif ($PSCmdlet.ParameterSetName -eq "Shared") {
|
elseif ($PSCmdlet.ParameterSetName -eq 'Shared') {
|
||||||
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
||||||
$Path = Get-DefaultCredentialStorePath -Shared
|
$Path = Get-DefaultCredentialStorePath -Shared
|
||||||
}
|
}
|
||||||
@ -86,7 +79,7 @@ function Test-CredentialStoreItem {
|
|||||||
if (Test-CredentialStore -Shared -Path $Path) {
|
if (Test-CredentialStore -Shared -Path $Path) {
|
||||||
$CS = Get-CredentialStore -Shared -Path $Path
|
$CS = Get-CredentialStore -Shared -Path $Path
|
||||||
$CSMembers = Get-Member -InputObject $CS
|
$CSMembers = Get-Member -InputObject $CS
|
||||||
if (($CSMembers.MemberType -eq "NoteProperty") -and ($CSMembers.Name -contains $CredentialName)) {
|
if (($CSMembers.MemberType -eq 'NoteProperty') -and ($CSMembers.Name -contains $CredentialName)) {
|
||||||
return $true
|
return $true
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -95,15 +88,13 @@ function Test-CredentialStoreItem {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$MsgParams = @{
|
$MsgParams = @{
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
Message = "The given credential store ({0}) does not exist!" -f $Path
|
Message = "The given credential store ({0}) does not exist!" -f $Path
|
||||||
}
|
}
|
||||||
Write-Error @MsgParams
|
Write-Error @MsgParams
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end {
|
end {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
CompanyName = ''
|
CompanyName = ''
|
||||||
|
|
||||||
# Copyright statement for this module
|
# Copyright statement for this module
|
||||||
Copyright = '(c) 2020 OCram85. All rights reserved.'
|
Copyright = '(c) 2022 OCram85. All rights reserved.'
|
||||||
|
|
||||||
# Description of the functionality provided by this module
|
# Description of the functionality provided by this module
|
||||||
Description = 'A simple credential manager to store and reuse multiple credential objects.'
|
Description = 'A simple credential manager to store and reuse multiple credential objects.'
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
#endregion module-definition
|
#endregion module-definition
|
||||||
Set-Variable -Name "CSVersion" -Value "2.0.0" -Option Constant -Scope 'Script' -ErrorAction Stop
|
Set-Variable -Name "CSVersion" -Value "2.0.0" -Option Constant -Scope 'Script' -ErrorAction Stop
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region dot-sourcing
|
#region dot-sourcing
|
||||||
# dot-sourcing all module functions. The export is handled via manifest file.
|
# dot-sourcing all module functions. The export is handled via manifest file.
|
||||||
|
|
||||||
|
14
src/PSModule.Tests.ps1
Normal file
14
src/PSModule.Tests.ps1
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
Describe 'Test module meta' {
|
||||||
|
It 'Test manifest file' {
|
||||||
|
$ManifestFile = (Get-Item -Path "./src/*.psd1").FullName
|
||||||
|
Test-ModuleManifest -Path $ManifestFile | Should -Be $true
|
||||||
|
}
|
||||||
|
It 'Import Module' {
|
||||||
|
$ManifestFile = (Get-Item -Path "./src/*.psd1").FullName
|
||||||
|
{ Import-Module $ManifestFile } | Should -Not -Throw
|
||||||
|
}
|
||||||
|
# Dummy test to force pester error
|
||||||
|
#It 'Force Pester Error' {
|
||||||
|
# $true | Should -BeFalse
|
||||||
|
#}
|
||||||
|
}
|
@ -23,15 +23,8 @@ function Get-CSPfxCertificate {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Get-CSPfxCertificate -Thumbprint '12345678' -StoreName 'My' -StoreLocation 'CurrentUser'
|
Get-CSPfxCertificate -Thumbprint '12345678' -StoreName 'My' -StoreLocation 'CurrentUser'
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Get-CSPfxCertificate.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
[OutputType([System.Security.Cryptography.X509Certificates.X509Certificate2])]
|
[OutputType([System.Security.Cryptography.X509Certificates.X509Certificate2])]
|
||||||
param (
|
param (
|
||||||
|
@ -14,15 +14,8 @@ function Get-DefaultCredentialStorePath {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
$Path = Get-DefaultCredentialStorePath
|
$Path = Get-DefaultCredentialStorePath
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Get-DefaultCredentialStorePath.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
[OutputType([string])]
|
[OutputType([string])]
|
||||||
param (
|
param (
|
||||||
|
@ -6,20 +6,12 @@ function Get-ModuleBase {
|
|||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This is just a wrapper for enabling pester tests.
|
This is just a wrapper for enabling pester tests.
|
||||||
|
|
||||||
|
|
||||||
.OUTPUTS
|
.OUTPUTS
|
||||||
Returns the base path as string
|
Returns the base path as string
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Get-ModuleBase.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
[OutputType()]
|
[OutputType([string])]
|
||||||
param ()
|
param ()
|
||||||
begin {}
|
begin {}
|
||||||
process {
|
process {
|
||||||
|
@ -14,14 +14,6 @@ function Get-RandomAESKey {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
.\Get-RandomAESKey
|
.\Get-RandomAESKey
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Get-RandomAESKey.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
|
@ -13,21 +13,14 @@ function Get-TempDir {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Get-TempDir
|
Get-TempDir
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Get-TempDir.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
[OutputType([string])]
|
[OutputType([string])]
|
||||||
param ()
|
param ()
|
||||||
begin {
|
|
||||||
|
|
||||||
}
|
begin {}
|
||||||
|
|
||||||
process {
|
process {
|
||||||
if ($IsLinux) {
|
if ($IsLinux) {
|
||||||
return (Resolve-Path -Path '/tmp/').Path
|
return (Resolve-Path -Path '/tmp/').Path
|
||||||
@ -35,10 +28,14 @@ function Get-TempDir {
|
|||||||
if ($IsMacOS) {
|
if ($IsMacOS) {
|
||||||
return (Resolve-Path -Path '/tmp/').Path
|
return (Resolve-Path -Path '/tmp/').Path
|
||||||
}
|
}
|
||||||
elseif (($isWindows) -or ($PSVersionTable.PSVersion.Major -lt 6) -or ($PSVersionTable.PSEdition -eq 'Desktop')) {
|
elseif (
|
||||||
|
($isWindows) -or
|
||||||
|
($PSVersionTable.PSVersion.Major -lt 6) -or
|
||||||
|
($PSVersionTable.PSEdition -eq 'Desktop')
|
||||||
|
) {
|
||||||
return (Resolve-Path -Path $env:TEMP).Path
|
return (Resolve-Path -Path $env:TEMP).Path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end {
|
|
||||||
}
|
end {}
|
||||||
}
|
}
|
||||||
|
@ -22,17 +22,9 @@ function Import-CSPfxCertificate {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Import-CSPfxCertificate -Path (Join-Path -Path $Env:APPDATA -ChildPath '/PSCredentialStore.pfx')
|
Import-CSPfxCertificate -Path (Join-Path -Path $Env:APPDATA -ChildPath '/PSCredentialStore.pfx')
|
||||||
|
|
||||||
.NOTES
|
|
||||||
File Name : Import-CSPfxCertificate.ps1
|
|
||||||
Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
[OutputType()]
|
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
@ -68,6 +60,7 @@ function Import-CSPfxCertificate {
|
|||||||
)]
|
)]
|
||||||
[string]$OpenFlags = 'ReadWrite'
|
[string]$OpenFlags = 'ReadWrite'
|
||||||
)
|
)
|
||||||
|
|
||||||
begin {
|
begin {
|
||||||
$Store = [System.Security.Cryptography.X509Certificates.X509Store]::new($StoreName, $StoreLocation)
|
$Store = [System.Security.Cryptography.X509Certificates.X509Store]::new($StoreName, $StoreLocation)
|
||||||
try {
|
try {
|
||||||
@ -77,6 +70,7 @@ function Import-CSPfxCertificate {
|
|||||||
$_.Exception.Message | Write-Error -ErrorAction Stop
|
$_.Exception.Message | Write-Error -ErrorAction Stop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
process {
|
process {
|
||||||
try {
|
try {
|
||||||
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new(
|
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new(
|
||||||
|
@ -38,15 +38,8 @@ function Resolve-Dependency {
|
|||||||
If (-not (Resolve-Dependency -Name 'VMware')) {
|
If (-not (Resolve-Dependency -Name 'VMware')) {
|
||||||
Write-Error -Message ("Could not resolve the optional dependencies defined for {0}" -f 'VMware') -ErrorAction 'Stop'
|
Write-Error -Message ("Could not resolve the optional dependencies defined for {0}" -f 'VMware') -ErrorAction 'Stop'
|
||||||
}
|
}
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : ResolveDependency.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[OutputType([bool])]
|
[OutputType([bool])]
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param (
|
param (
|
||||||
@ -86,6 +79,5 @@ function Resolve-Dependency {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end {
|
end {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -23,15 +23,8 @@ function Test-CSPfxCertificate {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Test-CSPfxCertificate -Thumbprint '12345678' -StoreName 'My' -StoreLocation 'CurrentUser'
|
Test-CSPfxCertificate -Thumbprint '12345678' -StoreName 'My' -StoreLocation 'CurrentUser'
|
||||||
|
|
||||||
.NOTES
|
|
||||||
File Name : Test-CSPfxCertificate.ps1
|
|
||||||
Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
[OutputType([bool])]
|
[OutputType([bool])]
|
||||||
param (
|
param (
|
||||||
|
@ -32,15 +32,8 @@ function Test-Module {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
.\Test-Dependency -Name 'VMware.PowerCLI' -Type 'Module' -StopIfFails
|
.\Test-Dependency -Name 'VMware.PowerCLI' -Type 'Module' -StopIfFails
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Test-Module.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[OutputType([bool])]
|
[OutputType([bool])]
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param (
|
param (
|
||||||
@ -56,6 +49,7 @@ Could not find the required {0} called {1}. Please install the required {0} to r
|
|||||||
[Parameter(Mandatory = $false)]
|
[Parameter(Mandatory = $false)]
|
||||||
[switch]$StopIfFails
|
[switch]$StopIfFails
|
||||||
)
|
)
|
||||||
|
|
||||||
begin {}
|
begin {}
|
||||||
|
|
||||||
process {
|
process {
|
||||||
|
@ -23,23 +23,16 @@ function Get-CredentialStore {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
$CSContent = Get-CredentialStore -Path "C:\TMP\mystore.json"
|
$CSContent = Get-CredentialStore -Path "C:\TMP\mystore.json"
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Get-CredentialStore.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding(DefaultParameterSetName = "Private")]
|
[CmdletBinding(DefaultParameterSetName = 'Private')]
|
||||||
[OutputType("PSCredentialStore.Store")]
|
[OutputType('PSCredentialStore.Store')]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
|
|
||||||
[string]$Path,
|
[string]$Path,
|
||||||
|
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
||||||
[switch]$Shared
|
[switch]$Shared
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -48,10 +41,10 @@ function Get-CredentialStore {
|
|||||||
process {
|
process {
|
||||||
# Set the CredentialStore for private, shared or custom mode.
|
# Set the CredentialStore for private, shared or custom mode.
|
||||||
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
||||||
if ($PSCmdlet.ParameterSetName -eq "Private") {
|
if ($PSCmdlet.ParameterSetName -eq 'Private') {
|
||||||
$Path = Get-DefaultCredentialStorePath
|
$Path = Get-DefaultCredentialStorePath
|
||||||
}
|
}
|
||||||
elseif ($PSCmdlet.ParameterSetName -eq "Shared") {
|
elseif ($PSCmdlet.ParameterSetName -eq 'Shared') {
|
||||||
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
||||||
$Path = Get-DefaultCredentialStorePath -Shared
|
$Path = Get-DefaultCredentialStorePath -Shared
|
||||||
}
|
}
|
||||||
@ -61,21 +54,21 @@ function Get-CredentialStore {
|
|||||||
try {
|
try {
|
||||||
$FileContent = Get-Content -Path $Path -Raw
|
$FileContent = Get-Content -Path $Path -Raw
|
||||||
$CS = ConvertFrom-Json $FileContent
|
$CS = ConvertFrom-Json $FileContent
|
||||||
$CS.PSObject.TypeNames.Insert(0, "PSCredentialStore.Store")
|
$CS.PSObject.TypeNames.Insert(0, 'PSCredentialStore.Store')
|
||||||
return $CS
|
Write-Output $CS
|
||||||
}
|
}
|
||||||
catch [System.Exception] {
|
catch [System.Exception] {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Unknown CredentialStore format. Invalid JSON file."
|
Message = 'Unknown CredentialStore format. Invalid JSON file.'
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$MessageParams = @{
|
$MessageParams = @{
|
||||||
Message = "Could not find the CredentialStore."
|
Message = 'Could not find the CredentialStore.'
|
||||||
ErrorAction = "Stop"
|
ErrorAction = 'Stop'
|
||||||
}
|
}
|
||||||
Write-Error @MessageParams
|
Write-Error @MessageParams
|
||||||
}
|
}
|
||||||
|
@ -49,49 +49,38 @@ function New-CredentialStore {
|
|||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
New-CredentialStore -Shared -Path "C:\TMP\CredentialStore.json"
|
New-CredentialStore -Shared -Path "C:\TMP\CredentialStore.json"
|
||||||
# Creates a new shared CredentialStore in the given location.
|
# Creates a new shared CredentialStore in the given location.
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : New-CredentialStore.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = "Private")]
|
[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = 'Private')]
|
||||||
[OutputType("PSCredentialStore.Store")]
|
[OutputType('PSCredentialStore.Store')]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
||||||
[switch]$Shared,
|
[switch]$Shared,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[System.IO.FileInfo]$Path,
|
[System.IO.FileInfo]$Path,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Private')]
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[Switch]$Force,
|
[switch]$Force,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Private')]
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[Switch]$PassThru,
|
[switch]$PassThru,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Private')]
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[Switch]$SkipPFXCertCreation,
|
[switch]$SkipPFXCertCreation,
|
||||||
|
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Private")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Private')]
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[Switch]$UseCertStore
|
[switch]$UseCertStore
|
||||||
)
|
)
|
||||||
|
|
||||||
begin {
|
begin {
|
||||||
# Lets get the current Date in a human readable format.
|
# Lets get the current Date in a human readable format.
|
||||||
$CurrentDate = Get-Date -UFormat "%Y-%m-%d %H:%M:%S"
|
$CurrentDate = Get-Date -Format 'u'
|
||||||
|
|
||||||
# Set latest Credential Store version
|
|
||||||
# Set-Variable -Name "CSVersion" -Value "2.0.0" -Option Constant -Scope
|
|
||||||
|
|
||||||
# test if the path input is a valid file path
|
# test if the path input is a valid file path
|
||||||
if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey('Path')) {
|
if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey('Path')) {
|
||||||
@ -119,17 +108,17 @@ function New-CredentialStore {
|
|||||||
process {
|
process {
|
||||||
# Set the CredentialStore for private, shared or custom mode.
|
# Set the CredentialStore for private, shared or custom mode.
|
||||||
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
||||||
if ($PSCmdlet.ParameterSetName -eq "Private") {
|
if ($PSCmdlet.ParameterSetName -eq 'Private') {
|
||||||
$Path = Get-DefaultCredentialStorePath
|
$Path = Get-DefaultCredentialStorePath
|
||||||
}
|
}
|
||||||
elseif ($PSCmdlet.ParameterSetName -eq "Shared") {
|
elseif ($PSCmdlet.ParameterSetName -eq 'Shared') {
|
||||||
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
||||||
$Path = Get-DefaultCredentialStorePath -Shared
|
$Path = Get-DefaultCredentialStorePath -Shared
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test if in the CredentialStore already exists.
|
# Test if in the CredentialStore already exists.
|
||||||
Write-Verbose "Test if there is already a credential store."
|
Write-Verbose 'Test if there is already a credential store.'
|
||||||
if ((Test-Path -Path $Path) -and ($Force -ne $true)) {
|
if ((Test-Path -Path $Path) -and ($Force -ne $true)) {
|
||||||
$ErrorParams = @{
|
$ErrorParams = @{
|
||||||
ErrorAction = 'Stop'
|
ErrorAction = 'Stop'
|
||||||
@ -211,11 +200,11 @@ function New-CredentialStore {
|
|||||||
Type = $null
|
Type = $null
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($PSCmdlet.ParameterSetName -eq "Shared") {
|
if ($PSCmdlet.ParameterSetName -eq 'Shared') {
|
||||||
$ObjProperties.Type = "Shared"
|
$ObjProperties.Type = 'Shared'
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$ObjProperties.Type = "Private"
|
$ObjProperties.Type = 'Private'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $SkipPFXCertCreation.IsPresent) {
|
if (! $SkipPFXCertCreation.IsPresent) {
|
||||||
@ -253,6 +242,5 @@ function New-CredentialStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end {
|
end {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,36 +16,27 @@ function Test-CredentialStore {
|
|||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Test-CredentialStore -eq $true
|
Test-CredentialStore -eq $true
|
||||||
|
|
||||||
.NOTES
|
|
||||||
- File Name : Test-CredentialStore.ps1
|
|
||||||
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
||||||
- Requires :
|
|
||||||
|
|
||||||
.LINK
|
|
||||||
https://github.com/OCram85/PSCredentialStore
|
|
||||||
#>
|
#>
|
||||||
[CmdletBinding(DefaultParameterSetName = "Private")]
|
|
||||||
|
[CmdletBinding(DefaultParameterSetName = 'Private')]
|
||||||
|
[OutputType([bool])]
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $false, ParameterSetName = 'Shared')]
|
||||||
[string]$Path,
|
[string]$Path,
|
||||||
|
|
||||||
[Parameter(Mandatory = $true, ParameterSetName = "Shared")]
|
[Parameter(Mandatory = $true, ParameterSetName = 'Shared')]
|
||||||
[switch]$Shared
|
[switch]$Shared
|
||||||
)
|
)
|
||||||
|
|
||||||
begin {
|
begin {}
|
||||||
# Set latest Credential Store version
|
|
||||||
#Set-Variable -Name "CSVersion" -Value "2.0.0" -Option Constant
|
|
||||||
}
|
|
||||||
|
|
||||||
process {
|
process {
|
||||||
# Set the CredentialStore for private, shared or custom mode.
|
# Set the CredentialStore for private, shared or custom mode.
|
||||||
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName)
|
||||||
if ($PSCmdlet.ParameterSetName -eq "Private") {
|
if ($PSCmdlet.ParameterSetName -eq 'Private') {
|
||||||
$Path = Get-DefaultCredentialStorePath
|
$Path = Get-DefaultCredentialStorePath
|
||||||
}
|
}
|
||||||
elseif ($PSCmdlet.ParameterSetName -eq "Shared") {
|
elseif ($PSCmdlet.ParameterSetName -eq 'Shared') {
|
||||||
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
if (!($PSBoundParameters.ContainsKey('Path'))) {
|
||||||
$Path = Get-DefaultCredentialStorePath -Shared
|
$Path = Get-DefaultCredentialStorePath -Shared
|
||||||
}
|
}
|
||||||
@ -53,12 +44,12 @@ function Test-CredentialStore {
|
|||||||
Write-Verbose -Message ("Path is: {0}" -f $Path)
|
Write-Verbose -Message ("Path is: {0}" -f $Path)
|
||||||
|
|
||||||
if (Test-Path $Path) {
|
if (Test-Path $Path) {
|
||||||
Write-Verbose "CredentialStore in given path found."
|
Write-Verbose 'CredentialStore in given path found.'
|
||||||
return $true
|
Write-Output $true
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Write-Verbose "The given CredentialStore does not exist!"
|
Write-Verbose 'The given CredentialStore does not exist!'
|
||||||
return $false
|
Write-Output $false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,249 +0,0 @@
|
|||||||
<#
|
|
||||||
Define the callsign of you PowerShell Module.
|
|
||||||
Callsign is used to identity:
|
|
||||||
- Module Manifest file name
|
|
||||||
- Artifact File
|
|
||||||
- Git repository name
|
|
||||||
- Module name
|
|
||||||
#>
|
|
||||||
$CALLSIGN = 'PSCredentialStore'
|
|
||||||
Write-Host ("Callsign is: {0}" -f $CALLSIGN) -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
|
|
||||||
|
|
||||||
Function Invoke-InstallDependencies() {
|
|
||||||
[CmdletBinding()]
|
|
||||||
Param()
|
|
||||||
|
|
||||||
Process {
|
|
||||||
Try {
|
|
||||||
Write-Host 'Available PS modules are:' -ForegroundColor Green -BackgroundColor Black
|
|
||||||
Get-Module -ListAvailable -Name Pester | Format-Table | Out-String
|
|
||||||
Get-PackageProvider -ListAvailable
|
|
||||||
Install-PackageProvider -Name NuGet -RequiredVersion '2.8.5.208' -Force -Verbose
|
|
||||||
Import-PackageProvider -Name NuGet -RequiredVersion '2.8.5.208' -Force
|
|
||||||
Write-Host 'Installing build deps...' -ForegroundColor Red -BackgroundColor Black
|
|
||||||
Install-Module -Name 'Pester' -Scope CurrentUser -RequiredVersion '4.10.1' -Force -SkipPublisherCheck -AllowClobber -Verbose
|
|
||||||
Install-Module -Name 'posh-git' -Scope CurrentUser -RequiredVersion '0.7.3' -Force -SkipPublisherCheck -AllowClobber
|
|
||||||
Install-Module -Name 'PSCoverage' -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber -RequiredVersion '1.2.108' -Verbose
|
|
||||||
Import-Module -Name 'posh-git'
|
|
||||||
Remove-Module -Name 'Pester' -Force -ErrorAction SilentlyContinue
|
|
||||||
Import-Module -Name 'Pester' -RequiredVersion '4.10.1' -Verbose -Force
|
|
||||||
Import-Module -Name 'PSCoverage' -RequiredVersion '1.2.108' -Verbose -Force
|
|
||||||
}
|
|
||||||
Catch {
|
|
||||||
$MsgParams = @{
|
|
||||||
Message = 'Could not install the required dependencies!'
|
|
||||||
Category = 'Error'
|
|
||||||
Details = $_.Exception.Message
|
|
||||||
}
|
|
||||||
Add-AppveyorMessage @MsgParams
|
|
||||||
Throw $MsgParams.Message
|
|
||||||
}
|
|
||||||
Write-Host 'Loaded PS modules are:' -ForegroundColor Green -BackgroundColor Black
|
|
||||||
Get-Module -Name Pester | Format-Table | Out-String
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Function Invoke-AppVeyorBumpVersion() {
|
|
||||||
[CmdletBinding()]
|
|
||||||
Param()
|
|
||||||
|
|
||||||
Write-Host "Listing Env Vars for debugging:" -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
# Filter Results to prevent exposing secure vars.
|
|
||||||
Get-ChildItem -Path "Env:*" | Where-Object { $_.name -notmatch "(NuGetToken|CoverallsToken|CodeCovToken)" } | Sort-Object -Property Name | Format-Table
|
|
||||||
|
|
||||||
Try {
|
|
||||||
$ModManifest = Get-Content -Path (".\src\{0}.psd1" -f $CALLSIGN)
|
|
||||||
$BumpedManifest = $ModManifest -replace '0.0.9999', $Env:APPVEYOR_BUILD_VERSION
|
|
||||||
Remove-Item -Path (".\src\{0}.psd1" -f $CALLSIGN)
|
|
||||||
Out-File -FilePath (".\src\{0}.psd1" -f $CALLSIGN) -InputObject $BumpedManifest -NoClobber -Encoding utf8 -Force
|
|
||||||
}
|
|
||||||
Catch {
|
|
||||||
$MsgParams = @{
|
|
||||||
Message = 'Could not bump current version into module manifest.'
|
|
||||||
Category = 'Error'
|
|
||||||
Details = $_.Exception.Message
|
|
||||||
}
|
|
||||||
Add-AppveyorMessage @MsgParams
|
|
||||||
Throw $MsgParams.Message
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Function Invoke-AppVeyorBuild() {
|
|
||||||
[CmdletBinding()]
|
|
||||||
[OutputType([PsCustomObject])]
|
|
||||||
Param()
|
|
||||||
$MsgParams = @{
|
|
||||||
Message = 'Creating build artifacts'
|
|
||||||
Category = 'Information'
|
|
||||||
Details = 'Extracting source files and compressing them into zip file.'
|
|
||||||
}
|
|
||||||
Add-AppveyorMessage @MsgParams
|
|
||||||
$CompParams = @{
|
|
||||||
Path = "{0}\src\*" -f $env:APPVEYOR_BUILD_FOLDER
|
|
||||||
DestinationPath = "{0}\bin\{1}.zip" -f $env:APPVEYOR_BUILD_FOLDER, $CALLSIGN
|
|
||||||
Update = $True
|
|
||||||
Verbose = $True
|
|
||||||
}
|
|
||||||
Compress-Archive @CompParams
|
|
||||||
$MsgParams = @{
|
|
||||||
Message = 'Pushing artifacts'
|
|
||||||
Category = 'Information'
|
|
||||||
Details = 'Pushing artifacts to AppVeyor store.'
|
|
||||||
}
|
|
||||||
Add-AppveyorMessage @MsgParams
|
|
||||||
$ArtifactPath = Join-Path -Path '.' -ChildPath ('bin/{0}.zip' -f $CALLSIGN)
|
|
||||||
Push-AppveyorArtifact $ArtifactPath
|
|
||||||
}
|
|
||||||
|
|
||||||
Function Invoke-AppVeyorTests() {
|
|
||||||
[CmdletBinding()]
|
|
||||||
Param()
|
|
||||||
|
|
||||||
$MsgParams = @{
|
|
||||||
Message = 'Starting Pester tests'
|
|
||||||
Category = 'Information'
|
|
||||||
Details = 'Now running all test found in .\tests\ dir.'
|
|
||||||
}
|
|
||||||
Add-AppveyorMessage @MsgParams
|
|
||||||
|
|
||||||
try {
|
|
||||||
Write-Host '===== Preload internal private functions =====' -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
|
|
||||||
$Privates = Get-ChildItem -Path (Join-Path -Path $Env:APPVEYOR_BUILD_FOLDER -ChildPath '/src/Private/*') -Include "*.ps1" -Recurse
|
|
||||||
foreach ($File in $Privates) {
|
|
||||||
if (Test-Path -Path $File.FullName) {
|
|
||||||
. $File.FullName
|
|
||||||
Write-Verbose -Message ('Private function dot-sourced: {0}' -f $File.FullName) -Verbose
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Write-Warning -Message ('Could not find file: {0} !' -f $File.FullName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Write-Host '===== Preload done. =====' -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
$_.Exception.Message | Write-Error
|
|
||||||
throw 'Could not load required private functions!'
|
|
||||||
}
|
|
||||||
|
|
||||||
#$testresults = Invoke-Pester -Path ( Get-ChildItem -Path ".\tests\*.Tests.ps1" -Recurse | Sort-Object -Property Name ) -ExcludeTag 'Disabled' -PassThru
|
|
||||||
$srcFiles = Get-ChildItem -Path ".\src\*.ps1" -Recurse | Sort-Object -Property 'Name' | Select-Object -ExpandProperty 'FullName'
|
|
||||||
$testFiles = Get-ChildItem -Path ".\tests\*.Tests.ps1" -Recurse | Sort-Object -Property 'Name' | Select-Object -ExpandProperty 'FullName'
|
|
||||||
$TestResults = Invoke-Pester -Path $testFiles -CodeCoverage $srcFiles -PassThru -CodeCoverageOutputFile ".\coverage.xml" -CodeCoverageOutputFileEncoding ascii -CodeCoverageOutputFileFormat JaCoCo
|
|
||||||
ForEach ($Item in $TestResults.TestResult) {
|
|
||||||
Switch ($Item.Result) {
|
|
||||||
"Passed" {
|
|
||||||
$TestParams = @{
|
|
||||||
Name = "{0}: {1}" -f $Item.Context, $Item.Name
|
|
||||||
Framework = "NUnit"
|
|
||||||
Filename = $Item.Describe
|
|
||||||
Outcome = "Passed"
|
|
||||||
Duration = $Item.Time.Milliseconds
|
|
||||||
}
|
|
||||||
Add-AppveyorTest @TestParams
|
|
||||||
}
|
|
||||||
"Failed" {
|
|
||||||
$TestParams = @{
|
|
||||||
Name = "{0}: {1}" -f $Item.Context, $Item.Name
|
|
||||||
Framework = "NUnit"
|
|
||||||
Filename = $Item.Describe
|
|
||||||
Outcome = "Failed"
|
|
||||||
Duration = $Item.Time.Milliseconds
|
|
||||||
ErrorMessage = $Item.FailureMessage
|
|
||||||
ErrorStackTrace = $Item.StackTrace
|
|
||||||
}
|
|
||||||
Add-AppveyorTest @TestParams
|
|
||||||
}
|
|
||||||
Default {
|
|
||||||
$TestParams = @{
|
|
||||||
Name = "{0}: {1}" -f $Item.Context, $Item.Name
|
|
||||||
Framework = "NUnit"
|
|
||||||
Filename = $Item.Describe
|
|
||||||
Outcome = "None"
|
|
||||||
Duration = $Item.Time.Milliseconds
|
|
||||||
ErrorMessage = $Item.FailureMessage
|
|
||||||
ErrorStackTrace = $Item.StackTrace
|
|
||||||
}
|
|
||||||
Add-AppveyorTest @TestParams
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
If ($TestResults.FailedCount -gt 0) {
|
|
||||||
$MsgParams = @{
|
|
||||||
Message = 'Pester Tests failed.'
|
|
||||||
Category = 'Error'
|
|
||||||
Details = "$($TestResults.FailedCount) tests failed."
|
|
||||||
}
|
|
||||||
Add-AppveyorMessage @MsgParams
|
|
||||||
Throw $MsgParams.Message
|
|
||||||
}
|
|
||||||
|
|
||||||
return $TestResults.CodeCoverage
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Function Invoke-CoverageReport() {
|
|
||||||
[CmdletBinding()]
|
|
||||||
Param(
|
|
||||||
[Parameter(Mandatory = $False)]
|
|
||||||
[ValidateNotNullOrEmpty()]
|
|
||||||
[String]$RepoToken = $Env:CoverallsToken,
|
|
||||||
|
|
||||||
[Parameter(Mandatory = $True)]
|
|
||||||
[ValidateNotNullOrEmpty()]
|
|
||||||
[PSCustomObject]$PesterCoverageReport
|
|
||||||
)
|
|
||||||
|
|
||||||
#$CoverageReport | Format-Custom -Depth 5 | Out-String | Write-Verbose
|
|
||||||
$CoverageReport = New-CoverageReport -CodeCoverage $PesterCoverageReport -RepoToken $RepoToken
|
|
||||||
Write-Host "CoverageReport JSON:" -ForegroundColor Yellow
|
|
||||||
#$CoverageReport | ConvertTo-Json -Depth 5 | Out-String | Write-Verbose
|
|
||||||
Publish-CoverageReport -CoverageReport $CoverageReport
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Function Invoke-AppVeyorPSGallery() {
|
|
||||||
[CmdletBinding()]
|
|
||||||
Param(
|
|
||||||
[Parameter(Mandatory = $true)]
|
|
||||||
[ValidateNotNullOrEmpty()]
|
|
||||||
[String]$OnBranch
|
|
||||||
)
|
|
||||||
Expand-Archive -Path (".\bin\{0}.zip" -f $CALLSIGN) -DestinationPath ("C:\Users\appveyor\Documents\WindowsPowerShell\Modules\{0}\" -f $CALLSIGN) -Verbose
|
|
||||||
Import-Module -Name $CALLSIGN -Verbose -Force
|
|
||||||
Write-Host "Available Package Provider:" -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
Get-PackageProvider -ListAvailable
|
|
||||||
Write-Host "Available Package Sources:" -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
Get-PackageSource
|
|
||||||
Try {
|
|
||||||
Write-Host "Try to get NuGet Provider:" -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
Get-PackageProvider -Name NuGet -ErrorAction Stop
|
|
||||||
}
|
|
||||||
Catch {
|
|
||||||
Write-Host "Installing NuGet..." -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Verbose
|
|
||||||
Import-PackageProvider NuGet -MinimumVersion '2.8.5.201' -Force
|
|
||||||
}
|
|
||||||
Try {
|
|
||||||
If ($env:APPVEYOR_REPO_BRANCH -eq 'master') {
|
|
||||||
Write-Host "try to publish module" -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
Write-Host ("Callsign is: {0}" -f $CALLSIGN) -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
Publish-Module -Name $CALLSIGN -NuGetApiKey $env:NuGetToken -Verbose -Force -AllowPrerelease
|
|
||||||
}
|
|
||||||
Else {
|
|
||||||
Write-Host "Skip publishing to PS Gallery because we are on $($env:APPVEYOR_REPO_BRANCH) branch." -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
# had to remove the publish-Module statement because it would publish although the -WhatIf is given.
|
|
||||||
# Publish-Module -Name $CALLSIGN -NuGetApiKey $env:NuGetToken -Verbose -WhatIf
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Catch {
|
|
||||||
$MsgParams = @{
|
|
||||||
Message = 'Could not deploy module to PSGallery.'
|
|
||||||
Category = 'Error'
|
|
||||||
Details = $_.Exception.Message
|
|
||||||
}
|
|
||||||
$_.Exception.Message | Write-Error
|
|
||||||
Add-AppveyorMessage @MsgParams
|
|
||||||
Throw $MsgParams.Message
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,13 @@
|
|||||||
$Global:ProgressPreference = 'SilentlyContinue'
|
$Global:ProgressPreference = 'SilentlyContinue'
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
function Invoke-ShowEnv() {
|
function Invoke-ShowEnv {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
||||||
|
'PSProvideCommentHelp',
|
||||||
|
'',
|
||||||
|
Justification = 'internal function'
|
||||||
|
)]
|
||||||
param ()
|
param ()
|
||||||
|
|
||||||
process {
|
process {
|
||||||
@ -9,17 +15,56 @@ function Invoke-ShowEnv() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Invoke-InstallDependencies() {
|
function Invoke-InstallDependencies {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
[OutputType()]
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
||||||
|
'PSProvideCommentHelp',
|
||||||
|
'',
|
||||||
|
Justification = 'internal function'
|
||||||
|
)]
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
||||||
|
'PSUseSingularNouns',
|
||||||
|
'',
|
||||||
|
Justification = 'internal function'
|
||||||
|
)]
|
||||||
param ()
|
param ()
|
||||||
|
|
||||||
process {
|
process {
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
try {
|
try {
|
||||||
Install-Module -Name 'PSScriptAnalyzer' -Scope CurrentUser -RequiredVersion '1.19.1' -Force -SkipPublisherCheck -AllowClobber -Verbose:$VerbosePreference -ErrorAction 'Stop'
|
$ParamsPSScript = @{
|
||||||
Install-Module -Name 'Pester' -Scope CurrentUser -RequiredVersion '4.10.1' -Force -SkipPublisherCheck -AllowClobber -Verbose:$VerbosePreference -ErrorAction 'Stop'
|
Name = 'PSScriptAnalyzer'
|
||||||
Install-Module -Name 'posh-git' -Scope CurrentUser -RequiredVersion '0.7.3' -Force -SkipPublisherCheck -AllowClobber -Verbose:$VerbosePreference -ErrorAction 'Stop'
|
Scope = 'CurrentUser'
|
||||||
Install-Module -Name 'PSCoverage' -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber -RequiredVersion '1.2.108' -Verbose:$VerbosePreference -ErrorAction 'Stop'
|
RequiredVersion = '1.20.0'
|
||||||
|
Force = $true
|
||||||
|
SkipPublisherCheck = $true
|
||||||
|
AllowClobber = $true
|
||||||
|
Verbose = $VerbosePreference
|
||||||
|
}
|
||||||
|
Install-Module @ParamsPSScript
|
||||||
|
|
||||||
|
$ParamsPester = @{
|
||||||
|
Name = 'Pester'
|
||||||
|
Scope = 'CurrentUser'
|
||||||
|
RequiredVersion = '5.3.3'
|
||||||
|
Force = $true
|
||||||
|
SkipPublisherCheck = $true
|
||||||
|
AllowClobber = $true
|
||||||
|
Verbose = $VerbosePreference
|
||||||
|
}
|
||||||
|
Install-Module @ParamsPester
|
||||||
|
|
||||||
|
$ParamsPosh = @{
|
||||||
|
Name = 'posh-git'
|
||||||
|
Scope = 'CurrentUser'
|
||||||
|
RequiredVersion = '1.1.0'
|
||||||
|
Force = $true
|
||||||
|
SkipPublisherCheck = $true
|
||||||
|
AllowClobber = $true
|
||||||
|
Verbose = $VerbosePreference
|
||||||
|
#ErrorAction = 'Stop'
|
||||||
|
}
|
||||||
|
Install-Module @ParamsPosh
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
$ExceParams = @{
|
$ExceParams = @{
|
||||||
@ -35,47 +80,80 @@ function Invoke-InstallDependencies() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Invoke-Linter () {
|
function Invoke-Linter {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
||||||
|
'PSProvideCommentHelp',
|
||||||
|
'',
|
||||||
|
Justification = 'internal function'
|
||||||
|
)]
|
||||||
param ()
|
param ()
|
||||||
|
|
||||||
process {
|
process {
|
||||||
Invoke-ScriptAnalyzer -Path './src/' -Recurse
|
Import-Module -Name PSScriptAnalyzer
|
||||||
|
$AnalyzerSettings = @{
|
||||||
|
Path = './src/'
|
||||||
|
Recurse = $true
|
||||||
|
Settings = './tools/PSScriptAnalyzerSettings.psd1'
|
||||||
|
ReportSummary = $true
|
||||||
|
}
|
||||||
|
Invoke-ScriptAnalyzer @AnalyzerSettings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Invoke-UnitTests {
|
function Invoke-UnitTest {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
Param()
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
||||||
|
'PSProvideCommentHelp',
|
||||||
|
'',
|
||||||
|
Justification = 'internal function'
|
||||||
|
)]
|
||||||
|
|
||||||
|
param (
|
||||||
|
[Parameter( Mandatory = $false )]
|
||||||
|
[ValidateSet('JaCoCo', 'CoverageGutters')]
|
||||||
|
[string]$CoverageFormat = 'JaCoCo',
|
||||||
|
|
||||||
|
[Parameter(Mandatory = $false)]
|
||||||
|
[ValidateSet('None', 'Normal', 'Detailed', 'Diagnostic')]
|
||||||
|
[string]$Verbosity = 'Normal',
|
||||||
|
|
||||||
|
[Parameter(Mandatory = $false)]
|
||||||
|
[switch]$PassThru,
|
||||||
|
|
||||||
|
[Parameter(Mandatory = $false)]
|
||||||
|
[ValidateNotNullOrEmpty()]
|
||||||
|
[string[]]$Tag,
|
||||||
|
|
||||||
|
[Parameter(Mandatory = $false)]
|
||||||
|
[ValidateNotNullOrEmpty()]
|
||||||
|
[string[]]$ExcludeTag
|
||||||
|
)
|
||||||
|
|
||||||
process {
|
process {
|
||||||
|
Write-Verbose -Message '===== Running Pester =====' -Verbose:$VerbosePreference
|
||||||
try {
|
$PesterConf = New-PesterConfiguration
|
||||||
Write-Host '===== Preload internal private functions =====' -ForegroundColor Black -BackgroundColor Yellow
|
$PesterConf.Run.Path = (Resolve-Path -Path './src').Path
|
||||||
|
$PesterConf.Run.Exit = $false
|
||||||
$Privates = Get-ChildItem -Path (Join-Path -Path $Env:DRONE_WORKSPACE -ChildPath '/src/Private/*') -Include "*.ps1" -Recurse -ErrorAction Stop
|
$PesterConf.Run.PassThru = $true
|
||||||
foreach ($File in $Privates) {
|
$PesterConf.CodeCoverage.Enabled = $true
|
||||||
if (Test-Path -Path $File.FullName) {
|
$PesterConf.CodeCoverage.OutputFormat = $CoverageFormat
|
||||||
. $File.FullName
|
$PesterConf.TestResult.Enabled = $true
|
||||||
Write-Verbose -Message ('Private function dot-sourced: {0}' -f $File.FullName) -Verbose
|
$CovFiles = Get-ChildItem -Path "./src/*.ps1" -Recurse | Where-Object {
|
||||||
|
$_.BaseName -notmatch '.Tests'
|
||||||
|
} | Select-Object -ExpandProperty 'FullName'
|
||||||
|
$PesterConf.CodeCoverage.Path = $CovFiles
|
||||||
|
$PesterConf.Output.Verbosity = $Verbosity
|
||||||
|
# Set Tags if given
|
||||||
|
if ($Tag) {
|
||||||
|
$PesterConf.Filter.Tag = $Tag
|
||||||
}
|
}
|
||||||
else {
|
if ($ExcludeTag) {
|
||||||
Write-Warning -Message ('Could not find file: {0} !' -f $File.FullName)
|
$PesterConf.Filter.ExcludeTag = $ExcludeTag
|
||||||
}
|
}
|
||||||
}
|
$TestResults = Invoke-Pester -Configuration $PesterConf -ErrorAction 'Stop'
|
||||||
}
|
if ($PassThru.IsPresent) {
|
||||||
catch {
|
Write-Output -InputObject $TestResults
|
||||||
$_.Exception.Message | Write-Error
|
|
||||||
throw 'Could not load required private functions!'
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host '===== Running Pester =====' -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
$srcFiles = Get-ChildItem -Path "./src/*.ps1" -Recurse | Sort-Object -Property 'Name' | Select-Object -ExpandProperty 'FullName'
|
|
||||||
$TestFiles = Get-ChildItem -Path (Join-Path -Path '.' -ChildPath './tests/*.Tests.ps1') -Recurse | Sort-Object -Property Name
|
|
||||||
$TestResults = Invoke-Pester -Path $testFiles -CodeCoverage $srcFiles -PassThru -CodeCoverageOutputFile "./coverage.xml" -CodeCoverageOutputFileEncoding ascii -CodeCoverageOutputFileFormat JaCoCo
|
|
||||||
|
|
||||||
if ($TestResults.FailedCount -gt 0) {
|
|
||||||
throw ('{0} tests failed!' -f $TestResults.FailedCount)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
141
tools/PSScriptAnalyzerSettings.psd1
Normal file
141
tools/PSScriptAnalyzerSettings.psd1
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
@{
|
||||||
|
Severity = 'Error', 'Warning', 'Information'
|
||||||
|
|
||||||
|
IncludeRules = @(
|
||||||
|
'PSAlignAssignmentStatement',
|
||||||
|
'PSAvoidAssignmentToAutomaticVariable',
|
||||||
|
'PSAvoidDefaultValueForMandatoryParameter',
|
||||||
|
'PSAvoidDefaultValueSwitchParameter',
|
||||||
|
'PSAvoidGlobalAliases',
|
||||||
|
'PSAvoidGlobalFunctions',
|
||||||
|
'PSAvoidGlobalVars',
|
||||||
|
'PSAvoidInvokingEmptyMembers',
|
||||||
|
'PSAvoidLongLines',
|
||||||
|
'PSAvoidNullOrEmptyHelpMessageAttribute',
|
||||||
|
'PSAvoidOverwritingBuiltInCmdlets',
|
||||||
|
'PSAvoidShouldContinueWithoutForce',
|
||||||
|
'PSAvoidTrailingWhitespace',
|
||||||
|
'PSAvoidUsingCmdletAliases',
|
||||||
|
'PSAvoidUsingComputerNameHardcoded',
|
||||||
|
'PSAvoidUsingConvertToSecureStringWithPlainText',
|
||||||
|
'PSAvoidUsingDeprecatedManifestFields',
|
||||||
|
'PSAvoidUsingDoubleQuotesForConstantString',
|
||||||
|
'PSAvoidUsingEmptyCatchBlock',
|
||||||
|
'PSAvoidUsingInvokeExpression',
|
||||||
|
'PSAvoidUsingPlainTextForPassword',
|
||||||
|
'PSAvoidUsingPositionalParameters',
|
||||||
|
'PSAvoidUsingUsernameAndPasswordParams',
|
||||||
|
'PSAvoidUsingWMICmdlet',
|
||||||
|
'PSAvoidUsingWriteHost',
|
||||||
|
'PSMisleadingBacktick',
|
||||||
|
'PSMissingModuleManifestField',
|
||||||
|
'PSPlaceCloseBrace',
|
||||||
|
'PSPlaceOpenBrace',
|
||||||
|
'PSPossibleIncorrectComparisonWithNull',
|
||||||
|
'PSPossibleIncorrectUsageOfAssignmentOperator',
|
||||||
|
'PSPossibleIncorrectUsageOfRedirectionOperator',
|
||||||
|
'PSProvideCommentHelp',
|
||||||
|
'PSReservedCmdletChar',
|
||||||
|
'PSReservedParams',
|
||||||
|
'PSReviewUnusedParameter',
|
||||||
|
'PSShouldProcess',
|
||||||
|
'PSUseApprovedVerbs',
|
||||||
|
'PSUseBOMForUnicodeEncodedFile',
|
||||||
|
'PSUseCmdletCorrectly',
|
||||||
|
# There is no predefined set for Pwsh7 Cmdlets
|
||||||
|
'PSUseCompatibleCmdlets',
|
||||||
|
#'PSUseCompatibleCommands',
|
||||||
|
'PSUseCompatibleSyntax',
|
||||||
|
#'PSUseCompatibleTypes',
|
||||||
|
'PSUseConsistentIndentation',
|
||||||
|
# Disable if bug in 1.19.1 version occurs.
|
||||||
|
'PSUseConsistentWhitespace',
|
||||||
|
'PSUseCorrectCasing',
|
||||||
|
'PSUseDeclaredVarsMoreThanAssignments',
|
||||||
|
'PSUseLiteralInitializerForHashtable',
|
||||||
|
'PSUseOutputTypeCorrectly',
|
||||||
|
'PSUsePSCredentialType',
|
||||||
|
'PSUseProcessBlockForPipelineCommand',
|
||||||
|
'PSUseShouldProcessForStateChangingFunctions',
|
||||||
|
'PSUseSingularNouns',
|
||||||
|
'PSUseSupportsShouldProcess',
|
||||||
|
'PSUseToExportFieldsInManifest',
|
||||||
|
'PSUseUTF8EncodingForHelpFile',
|
||||||
|
'PSUseUsingScopeModifierInNewRunspaces'
|
||||||
|
)
|
||||||
|
|
||||||
|
Rules = @{
|
||||||
|
|
||||||
|
PSAvoidLongLines = @{
|
||||||
|
Enable = $true
|
||||||
|
MaximumLineLength = 116
|
||||||
|
}
|
||||||
|
|
||||||
|
PSPlaceOpenBrace = @{
|
||||||
|
Enable = $true
|
||||||
|
OnSameLine = $true
|
||||||
|
NewLineAfter = $true
|
||||||
|
IgnoreOneLineBlock = $true
|
||||||
|
}
|
||||||
|
|
||||||
|
PSPlaceCloseBrace = @{
|
||||||
|
Enable = $true
|
||||||
|
NewLineAfter = $true
|
||||||
|
IgnoreOneLineBlock = $true
|
||||||
|
NoEmptyLineBefore = $false
|
||||||
|
}
|
||||||
|
|
||||||
|
PSProvideCommentHelp = @{
|
||||||
|
Enable = $true
|
||||||
|
ExportedOnly = $false
|
||||||
|
BlockComment = $true
|
||||||
|
VSCodeSnippetCorrection = $false
|
||||||
|
Placement = "begin"
|
||||||
|
}
|
||||||
|
|
||||||
|
PSUseCompatibleCmdlets = @{
|
||||||
|
compatibility = @(
|
||||||
|
"desktop-5.1.14393.206-windows",
|
||||||
|
"core-6.1.0-windows"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
PSUseCompatibleSyntax = @{
|
||||||
|
Enable = $true
|
||||||
|
TargetVersions = @(
|
||||||
|
"7.0",
|
||||||
|
"5.1"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
PSUseConsistentIndentation = @{
|
||||||
|
Enable = $true
|
||||||
|
Kind = 'space'
|
||||||
|
PipelineIndentation = 'IncreaseIndentationForFirstPipeline'
|
||||||
|
IndentationSize = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
PSUseConsistentWhitespace = @{
|
||||||
|
Enable = $true
|
||||||
|
CheckInnerBrace = $true
|
||||||
|
CheckOpenBrace = $true
|
||||||
|
CheckOpenParen = $true
|
||||||
|
CheckOperator = $true
|
||||||
|
CheckPipe = $true
|
||||||
|
CheckPipeForRedundantWhitespace = $false
|
||||||
|
CheckSeparator = $true
|
||||||
|
CheckParameter = $false
|
||||||
|
IgnoreAssignmentOperatorInsideHashTable = $true
|
||||||
|
}
|
||||||
|
|
||||||
|
PSAlignAssignmentStatement = @{
|
||||||
|
Enable = $true
|
||||||
|
CheckHashtable = $false
|
||||||
|
}
|
||||||
|
|
||||||
|
PSUseCorrectCasing = @{
|
||||||
|
Enable = $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,66 +0,0 @@
|
|||||||
$Global:ProgressPreference = 'SilentlyContinue'
|
|
||||||
|
|
||||||
$CALLSIGN = 'PSCredentialStore'
|
|
||||||
Write-Host ("Callsign is: {0}" -f $CALLSIGN) -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
|
|
||||||
function Invoke-InstallDependencies {
|
|
||||||
[CmdletBinding()]
|
|
||||||
Param()
|
|
||||||
|
|
||||||
process {
|
|
||||||
try {
|
|
||||||
Write-Host '===== Environment Vars: =====' -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
Get-ChildItem -Path Env:
|
|
||||||
|
|
||||||
Write-Host -Message '===== Existing Variables: =====' -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
Get-Variable -Name * | Format-Table -AutoSize
|
|
||||||
|
|
||||||
Get-PackageProvider -ListAvailable
|
|
||||||
Import-PackageProvider -Name 'NuGet' -MinimumVersion '2.8.5.208' -Verbose -Force
|
|
||||||
|
|
||||||
Install-Module -Name 'Pester' -Scope CurrentUser -RequiredVersion '4.4.2' -Force -SkipPublisherCheck -AllowClobber -Verbose
|
|
||||||
Install-Module -Name 'posh-git' -Scope CurrentUser -RequiredVersion '1.0.0-beta2' -Force -SkipPublisherCheck -AllowClobber -AllowPrerelease -Verbose
|
|
||||||
|
|
||||||
Import-Module -Name 'Pester', 'posh-git' -Verbose
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
$_.Exception.Message | Write-Error
|
|
||||||
throw 'Could not install the required dependencies!'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function Invoke-UnitTests {
|
|
||||||
[CmdletBinding()]
|
|
||||||
Param()
|
|
||||||
|
|
||||||
process {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Write-Host '===== Preload internal private functions =====' -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
|
|
||||||
$Privates = Get-ChildItem -Path (Join-Path -Path $Env:TRAVIS_BUILD_DIR -ChildPath '/src/Private/*') -Include "*.ps1" -Recurse -ErrorAction Stop
|
|
||||||
foreach ($File in $Privates) {
|
|
||||||
if (Test-Path -Path $File.FullName) {
|
|
||||||
. $File.FullName
|
|
||||||
Write-Verbose -Message ('Private function dot-sourced: {0}' -f $File.FullName) -Verbose
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Write-Warning -Message ('Could not find file: {0} !' -f $File.FullName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
$_.Exception.Message | Write-Error
|
|
||||||
throw 'Could not load required private functions!'
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host '===== Running Pester =====' -ForegroundColor Black -BackgroundColor Yellow
|
|
||||||
$TestFiles = Get-ChildItem -Path (Join-Path -Path '.' -ChildPath './tests/*.Tests.ps1') -Recurse| Sort-Object -Property Name
|
|
||||||
$TestResults = Invoke-Pester -Script $TestFiles -ExcludeTag 'Disabled' -PassThru
|
|
||||||
|
|
||||||
if ($TestResults.FailedCount -gt 0) {
|
|
||||||
throw ('{0} tests failed!' -f $TestResults.FailedCount)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
set -x
|
|
||||||
ulimit -n 4096
|
|
||||||
|
|
||||||
echo "TRAVIS_EVENT_TYPE value $TRAVIS_EVENT_TYPE"
|
|
||||||
|
|
||||||
if [ $TRAVIS_EVENT_TYPE = cron ] || [ $TRAVIS_EVENT_TYPE = api ]; then
|
|
||||||
sudo pwsh -NoProfile -NonInteractive -c "Import-Module ./tools/Travis.psm1;
|
|
||||||
Invoke-InstallDependencies;
|
|
||||||
Invoke-UnitTests;"
|
|
||||||
else
|
|
||||||
sudo pwsh -NoProfile -NonInteractive -c "Import-Module ./tools/Travis.psm1;
|
|
||||||
Invoke-InstallDependencies;
|
|
||||||
Invoke-UnitTests;"
|
|
||||||
fi
|
|
Loading…
Reference in New Issue
Block a user