From 58b91b72128c9bf7fc1d2927121d39a00737167f Mon Sep 17 00:00:00 2001 From: OCram85 Date: Mon, 5 Mar 2018 08:43:06 +0100 Subject: [PATCH 01/32] skip coverage report for PRs --- tools/AppVeyor.psm1 | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/AppVeyor.psm1 b/tools/AppVeyor.psm1 index de78763..7cdebf0 100644 --- a/tools/AppVeyor.psm1 +++ b/tools/AppVeyor.psm1 @@ -153,13 +153,17 @@ Function Invoke-CoverageReport() { [ValidateNotNullOrEmpty()] [String]$RepoToken = $Env:CoverallsToken ) - - Import-Module ('.\src\{0}.psm1' -f $CALLSIGN) -Verbose -Force - $FileMap = New-PesterFileMap -SourceRoot '.\src' -PesterRoot '.\tests' - $CoverageReport = New-CoverageReport -PesterFileMap $FileMap -RepoToken $RepoToken - Write-Host "CoverageReport JSON:" -ForegroundColor Yellow - $CoverageReport | Out-String | Write-Host - Publish-CoverageReport -CoverageReport $CoverageReport + if ( $null -ne $RepoToken) { + Import-Module ('.\src\{0}.psm1' -f $CALLSIGN) -Verbose -Force + $FileMap = New-PesterFileMap -SourceRoot '.\src' -PesterRoot '.\tests' + $CoverageReport = New-CoverageReport -PesterFileMap $FileMap -RepoToken $RepoToken + Write-Host "CoverageReport JSON:" -ForegroundColor Yellow + $CoverageReport | Out-String | Write-Host + Publish-CoverageReport -CoverageReport $CoverageReport + } + else { + Write-Warning 'CoverallsToken var given but empty. This run is triggered by a PR. Skipping coverage report...' + } } Function Invoke-AppVeyorPSGallery() { -- 2.40.1 From d45e42c2b1859d49ffe817cdef9b711c15aba39f Mon Sep 17 00:00:00 2001 From: OCram85 Date: Mon, 5 Mar 2018 08:52:51 +0100 Subject: [PATCH 02/32] Revert "skip coverage report for PRs" This reverts commit 58b91b72128c9bf7fc1d2927121d39a00737167f. --- tools/AppVeyor.psm1 | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tools/AppVeyor.psm1 b/tools/AppVeyor.psm1 index 7cdebf0..de78763 100644 --- a/tools/AppVeyor.psm1 +++ b/tools/AppVeyor.psm1 @@ -153,17 +153,13 @@ Function Invoke-CoverageReport() { [ValidateNotNullOrEmpty()] [String]$RepoToken = $Env:CoverallsToken ) - if ( $null -ne $RepoToken) { - Import-Module ('.\src\{0}.psm1' -f $CALLSIGN) -Verbose -Force - $FileMap = New-PesterFileMap -SourceRoot '.\src' -PesterRoot '.\tests' - $CoverageReport = New-CoverageReport -PesterFileMap $FileMap -RepoToken $RepoToken - Write-Host "CoverageReport JSON:" -ForegroundColor Yellow - $CoverageReport | Out-String | Write-Host - Publish-CoverageReport -CoverageReport $CoverageReport - } - else { - Write-Warning 'CoverallsToken var given but empty. This run is triggered by a PR. Skipping coverage report...' - } + + Import-Module ('.\src\{0}.psm1' -f $CALLSIGN) -Verbose -Force + $FileMap = New-PesterFileMap -SourceRoot '.\src' -PesterRoot '.\tests' + $CoverageReport = New-CoverageReport -PesterFileMap $FileMap -RepoToken $RepoToken + Write-Host "CoverageReport JSON:" -ForegroundColor Yellow + $CoverageReport | Out-String | Write-Host + Publish-CoverageReport -CoverageReport $CoverageReport } Function Invoke-AppVeyorPSGallery() { -- 2.40.1 From 8ed1f99e950258645ecdc486c81a6aa166a9142c Mon Sep 17 00:00:00 2001 From: OCram85 Date: Mon, 5 Mar 2018 09:00:53 +0100 Subject: [PATCH 03/32] skipp coverage report creation for PRs --- appveyor.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 19b96e0..1fa7b84 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -33,7 +33,13 @@ build_script: test_script: - ps: Invoke-AppVeyorTests - - ps: Invoke-CoverageReport + - ps: >- + if ($null -ne $Env:CoverallsToken) { + Invoke-CoverageReport + } + else { + Write-Warning "No CoverallsToken found. This build seems to be triggered by a PR. Skipping this step..." + } deploy: #- provider: GitHub -- 2.40.1 From 99b3c85124c129769020da53e37f62cfe25d3a29 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Mon, 5 Mar 2018 09:04:22 +0100 Subject: [PATCH 04/32] fix YAML syntax --- appveyor.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 1fa7b84..30511a4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -33,13 +33,13 @@ build_script: test_script: - ps: Invoke-AppVeyorTests - - ps: >- - if ($null -ne $Env:CoverallsToken) { - Invoke-CoverageReport - } - else { - Write-Warning "No CoverallsToken found. This build seems to be triggered by a PR. Skipping this step..." - } + - ps: | + if ($null -ne $Env:CoverallsToken) { + Invoke-CoverageReport + } + else { + Write-Warning "No CoverallsToken found. This build seems to be triggered by a PR. Skipping this step..." + } deploy: #- provider: GitHub -- 2.40.1 From d938fa9f13e3b585802f494b17b802391a36272a Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 6 Mar 2018 14:36:43 +0100 Subject: [PATCH 05/32] adds WinScp dependency --- src/Dependency.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Dependency.json b/src/Dependency.json index 865f246..4d12c8a 100644 --- a/src/Dependency.json +++ b/src/Dependency.json @@ -32,6 +32,12 @@ "Modules": [ "VMware.VimAutomation.Cis.Core" ] + }, + { + "Name": "SCP", + "Modules": [ + "WinSCP" + ] } ] } -- 2.40.1 From c35f6477768ad911f15cd469d9097b51529ed2d0 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 6 Mar 2018 14:36:59 +0100 Subject: [PATCH 06/32] adds scp connection type --- src/Connection/Connect-To.ps1 | 46 ++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/Connection/Connect-To.ps1 b/src/Connection/Connect-To.ps1 index 5fb97b1..2e8c443 100644 --- a/src/Connection/Connect-To.ps1 +++ b/src/Connection/Connect-To.ps1 @@ -20,8 +20,9 @@ function Connect-To { - NetAppFAS Establish a connection to a NetApp Clustered ONTAP filer. - VMware Establish a connection to a VMware vCenter or ESXi host. - CisServer Establish a connection to a Vmware CisServer. - - ExchangeHTTP Start a new remote session to the given Exchange server via unsecure http. + - ExchangeHTTP Start a new remote session to the given Exchange server via insecure http. - Exchange HTTPS Start a new remote session to the given exchange server with the secure https endpoint. + - SCP Establish a SCP connection. .PARAMETER Credentials Use this parameter to bypass the stored credentials. Without this parameter Connect-To tries to read the @@ -89,7 +90,16 @@ function Connect-To { [Parameter(Mandatory = $true, ParameterSetName = "Shared")] [Parameter(Mandatory = $true, ParameterSetName = "Private")] - [ValidateSet('CiscoUcs', 'FTP', 'NetAppFAS', 'VMware', 'CisServer', 'ExchangeHTTP', 'ExchangeHTTPS')] + [ValidateSet( + 'CiscoUcs', + 'FTP', + 'NetAppFAS', + 'VMware', + 'CisServer', + 'ExchangeHTTP', + 'ExchangeHTTPS', + 'SCP' + )] [string]$Type, [Parameter(Mandatory = $False, ParameterSetName = "Shared")] @@ -251,7 +261,6 @@ function Connect-To { ErrorAction = 'Stop' } $Global:PSExchangeRemote = New-PSSession @ConnectionParams - $Global:PSExchangeRemote } catch { # Write a error message to the log. @@ -271,7 +280,6 @@ function Connect-To { ErrorAction = 'Stop' } $Global:PSExchangeRemote = New-PSSession @ConnectionParams - $Global:PSExchangeRemote } catch { # Write a error message to the log. @@ -282,6 +290,36 @@ function Connect-To { Write-Error @MessageParams } } + "SCP" { + $WinSCPSessionParams = @{ + Credential = $creds + Hostname = $RemoteHost + Protocol = 'Scp' + GiveUpSecurityAndAcceptAnySshHostKey = $True + } + try { + $SessionOption = New-WinSCPSessionOption @WinSCPSessionParams + $Global:WinSCPSession = New-WinSCPSession -SessionOption $SessionOption + Write-Verbose -Message ("SCP Connection established with {0}" -f $Global:WinSCPSession.Hostname) + } + catch { + # Write a error message to the log. + $MessageParams = @{ + Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type + ErrorAction = "Stop" + } + Write-Error @MessageParams + } + # Check the Connection State + if (!($WinSCPSession.Opened)) { + # Check the connection state and find out if the session is still open. + $MessageParams = @{ + Message = "Connection to {0} using Type {1} was established. But now it seems to be lost!" -f $RemoteHost, $Type + ErrorAction = "Stop" + } + Write-Error @MessageParams + } + } default { # Write a error message to the log. $MessageParams = @{ -- 2.40.1 From 98a50d76302741a74fb9d4ec159f107b5b4f4d79 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 6 Mar 2018 14:40:06 +0100 Subject: [PATCH 07/32] adds scp disconnect --- src/Connection/Disconnect-From.ps1 | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Connection/Disconnect-From.ps1 b/src/Connection/Disconnect-From.ps1 index abc864b..3da3fe4 100644 --- a/src/Connection/Disconnect-From.ps1 +++ b/src/Connection/Disconnect-From.ps1 @@ -22,6 +22,8 @@ function Disconnect-From { - CisServer Terminates the connection from a Vmware CisServer. - ExchangeHTTP Remove the existing remote session to the given Exchange server - ExchangeHTTPS Remove the existing remote session to the given Exchange server + - SCP Terminates the existing SCP session. + .PARAMETER Force Force the disconnect, even if the disconnect would fail. @@ -70,7 +72,16 @@ function Disconnect-From { [string]$RemoteHost, [Parameter(Mandatory = $true)] - [ValidateSet('CiscoUcs', 'FTP', 'NetAppFAS', 'VMware', 'CisServer', 'ExchangeHTTP', 'ExchangeHTTPS')] + [ValidateSet( + 'CiscoUcs', + 'FTP', + 'NetAppFAS', + 'VMware', + 'CisServer', + 'ExchangeHTTP', + 'ExchangeHTTPS', + 'SCP' + )] [string]$Type, [Parameter(Mandatory = $false)] @@ -178,6 +189,18 @@ function Disconnect-From { Write-Error @MessageParams } } + "SCP" { + if ($Global:WinSCPSession.Opened) { + Remove-WinSCPSession -WinSCPSession $Global:WinSCPSession + } + else { + $MessageParams = @{ + Message = "There is no open WinSCP Session" + ErrorAction = "Stop" + } + Write-Error @MessageParams + } + } default { # Write a error message to the log. $MessageParams = @{ -- 2.40.1 From 0235aa5c917d77cd31daa09c3fbf385a6ef519a0 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 6 Mar 2018 14:42:01 +0100 Subject: [PATCH 08/32] bump version --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 30511a4..400c196 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 0.2.0.{build} +version: 0.2.1.{build} branches: only: -- 2.40.1 From b6cfa5e580cffe55314c699ccd4af5ae2d2b3839 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 6 Mar 2018 15:08:08 +0100 Subject: [PATCH 09/32] update docs --- docs/Connect-To.md | 39 +++++++++----- docs/Disconnect-From.md | 33 ++++++++---- docs/Get-CredentialStore.md | 6 +-- docs/Get-CredentialStoreItem.md | 10 ++-- docs/New-CredentialStore.md | 10 ++-- docs/New-CredentialStoreItem.md | 12 ++--- docs/PSCredentialStore.md | 5 +- docs/Remove-CredentialStoreItem.md | 10 ++-- docs/Set-CredentialStoreItem.md | 10 ++-- docs/Test-CSConnection.md | 82 ++++++++++++++++++++++++++++++ docs/Test-CredentialStore.md | 6 +-- docs/Test-CredentialStoreItem.md | 10 ++-- 12 files changed, 170 insertions(+), 63 deletions(-) create mode 100644 docs/Test-CSConnection.md diff --git a/docs/Connect-To.md b/docs/Connect-To.md index 01277b5..8e80352 100644 --- a/docs/Connect-To.md +++ b/docs/Connect-To.md @@ -29,32 +29,42 @@ Establish a connection to the selected host using a stored CredentialStoreItem. ## EXAMPLES -### -------------------------- EXAMPLE 1 -------------------------- +### EXAMPLE 1 ``` Connect-To -RemoteHost "ucs.myside.local" -Type CiscoUcs ``` -### -------------------------- EXAMPLE 2 -------------------------- +### EXAMPLE 2 ``` Connect-To -RemoteHost "ftp.myside.local" -Type FTP ``` -### -------------------------- EXAMPLE 3 -------------------------- +### EXAMPLE 3 ``` Connect-To -RemoteHost "fas.myside.local" -Type NetAppFAS ``` -### -------------------------- EXAMPLE 4 -------------------------- +### EXAMPLE 4 ``` Connect-To -RemoteHost "esx01.myside.local" -Type VMware ``` -### -------------------------- EXAMPLE 5 -------------------------- +### EXAMPLE 5 ``` Connect-To -RemoteHost "vCenter.myside.local" -Type CisServer ``` -### -------------------------- EXAMPLE 6 -------------------------- +### EXAMPLE 6 +``` +Connect-To -RemoteHost "exchange01.myside.local" -Type ExchangeHTTP +``` + +### EXAMPLE 7 +``` +Connect-To -RemoteHost "exchange01.myside.local" -Type ExchangeHTTPS +``` + +### EXAMPLE 8 ``` $MyCreds = Get-Credential ``` @@ -71,7 +81,7 @@ Specify the host, for which you would like to change the credentials. ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: True Position: Named @@ -88,7 +98,7 @@ same hostname. ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: False Position: Named @@ -105,11 +115,14 @@ Currently implemented targets are: - NetAppFAS Establish a connection to a NetApp Clustered ONTAP filer. - VMware Establish a connection to a VMware vCenter or ESXi host. - CisServer Establish a connection to a Vmware CisServer. + - ExchangeHTTP Start a new remote session to the given Exchange server via insecure http. + - Exchange HTTPS Start a new remote session to the given exchange server with the secure https endpoint. + - SCP Establish a SCP connection. ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: True Position: Named @@ -128,7 +141,7 @@ So you can use it to enable credentials without preparing any user interaction. ```yaml Type: PSCredential Parameter Sets: (All) -Aliases: +Aliases: Required: False Position: Named @@ -143,7 +156,7 @@ Define a custom path to a shared CredentialStore. ```yaml Type: String Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named @@ -160,7 +173,7 @@ can be decrypted across systems. ```yaml Type: SwitchParameter Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named @@ -181,11 +194,9 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ### [None] ## NOTES -\`\`\` File Name : Connect-To.ps1 Author : Marco Blessing - marco.blessing@googlemail.com Requires : -\`\`\` ## RELATED LINKS diff --git a/docs/Disconnect-From.md b/docs/Disconnect-From.md index dda7e88..bcafe08 100644 --- a/docs/Disconnect-From.md +++ b/docs/Disconnect-From.md @@ -21,36 +21,46 @@ Terminates a session established with Connect-To using a CredentialStoreItem. ## EXAMPLES -### -------------------------- EXAMPLE 1 -------------------------- +### EXAMPLE 1 ``` Disconnect-From -RemoteHost "ucs.myside.local" -Type CiscoUcs ``` -### -------------------------- EXAMPLE 2 -------------------------- +### EXAMPLE 2 ``` Disconnect-From -RemoteHost "ftp.myside.local" -Type FTP ``` -### -------------------------- EXAMPLE 3 -------------------------- +### EXAMPLE 3 ``` Disconnect-From -RemoteHost "fas.myside.local" -Type NetAppFAS ``` -### -------------------------- EXAMPLE 4 -------------------------- +### EXAMPLE 4 ``` Disconnect-From -RemoteHost "esx01.myside.local" -Type VMware ``` -### -------------------------- EXAMPLE 5 -------------------------- +### EXAMPLE 5 ``` Disconnect-From -RemoteHost "esx01.myside.local" -Type VMware -Force:$True ``` -### -------------------------- EXAMPLE 6 -------------------------- +### EXAMPLE 6 ``` Disconnect-From -RemoteHost "vcenter.myside.local" -Type CisServer ``` +### EXAMPLE 7 +``` +Disconnect-From -RemoteHost "exchange01.myside.local" -Type ExchangeHTTP +``` + +### EXAMPLE 8 +``` +Disconnect-From -RemoteHost "exchange01.myside.local" -Type ExchangeHTTPS +``` + ## PARAMETERS ### -RemoteHost @@ -59,7 +69,7 @@ Specify the remote endpoint, whose session you would like to terminate. ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: True Position: 1 @@ -76,11 +86,14 @@ Currently implemented targets are: - NetAppFAS Terminates the connection from a NetApp Clustered ONTAP filer. - VMware Terminates the connection from a VMware vCenter or ESXi host. - CisServer Terminates the connection from a Vmware CisServer. + - ExchangeHTTP Remove the existing remote session to the given Exchange server + - ExchangeHTTPS Remove the existing remote session to the given Exchange server + - SCP Terminates the existing SCP session. ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: True Position: 2 @@ -95,7 +108,7 @@ Force the disconnect, even if the disconnect would fail. ```yaml Type: SwitchParameter Parameter Sets: (All) -Aliases: +Aliases: Required: False Position: Named @@ -116,11 +129,9 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ### [None] ## NOTES -\`\`\` File Name : Disconnect-From.ps1 Author : Marco Blessing - marco.blessing@googlemail.com Requires : -\`\`\` ## RELATED LINKS diff --git a/docs/Get-CredentialStore.md b/docs/Get-CredentialStore.md index dc32b47..4a9b63c 100644 --- a/docs/Get-CredentialStore.md +++ b/docs/Get-CredentialStore.md @@ -31,7 +31,7 @@ Get-CredentialStoreItem. ## EXAMPLES -### -------------------------- EXAMPLE 1 -------------------------- +### EXAMPLE 1 ``` $CSContent = Get-CredentialStore -Path "C:\TMP\mystore.json" ``` @@ -44,7 +44,7 @@ Define a custom path to a shared CredentialStore. ```yaml Type: String Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named @@ -61,7 +61,7 @@ can be decrypted across systems. ```yaml Type: SwitchParameter Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named diff --git a/docs/Get-CredentialStoreItem.md b/docs/Get-CredentialStoreItem.md index bd1c5cf..0962eb5 100644 --- a/docs/Get-CredentialStoreItem.md +++ b/docs/Get-CredentialStoreItem.md @@ -28,7 +28,7 @@ Return the credential as PSCredential object. ## EXAMPLES -### -------------------------- EXAMPLE 1 -------------------------- +### EXAMPLE 1 ``` $myCreds = Get-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx01.myside.local" ``` @@ -41,7 +41,7 @@ Define a custom path to a shared CredentialStore. ```yaml Type: String Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named @@ -56,7 +56,7 @@ Specify the host, for which you would like to change the credentials. ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: True Position: Named @@ -74,7 +74,7 @@ For example ad/sys1, ftp/sys1, mssql/sys1 ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: False Position: Named @@ -91,7 +91,7 @@ can be decrypted across systems. ```yaml Type: SwitchParameter Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named diff --git a/docs/New-CredentialStore.md b/docs/New-CredentialStore.md index bd1c5cf..0962eb5 100644 --- a/docs/New-CredentialStore.md +++ b/docs/New-CredentialStore.md @@ -28,7 +28,7 @@ Return the credential as PSCredential object. ## EXAMPLES -### -------------------------- EXAMPLE 1 -------------------------- +### EXAMPLE 1 ``` $myCreds = Get-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx01.myside.local" ``` @@ -41,7 +41,7 @@ Define a custom path to a shared CredentialStore. ```yaml Type: String Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named @@ -56,7 +56,7 @@ Specify the host, for which you would like to change the credentials. ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: True Position: Named @@ -74,7 +74,7 @@ For example ad/sys1, ftp/sys1, mssql/sys1 ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: False Position: Named @@ -91,7 +91,7 @@ can be decrypted across systems. ```yaml Type: SwitchParameter Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named diff --git a/docs/New-CredentialStoreItem.md b/docs/New-CredentialStoreItem.md index eb5a7ff..1c373ea 100644 --- a/docs/New-CredentialStoreItem.md +++ b/docs/New-CredentialStoreItem.md @@ -33,7 +33,7 @@ a VIConnection, NetApp FAS or UCS Fabric Interconnect. ## EXAMPLES -### -------------------------- EXAMPLE 1 -------------------------- +### EXAMPLE 1 ``` New-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx01.myside.local" ``` @@ -46,7 +46,7 @@ Define the store in which you would like to add a new item. ```yaml Type: String Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named @@ -61,7 +61,7 @@ The identifier or rather name for the given credentials. ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: True Position: Named @@ -79,7 +79,7 @@ For example ad/sys1, ftp/sys1, mssql/sys1 ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: False Position: Named @@ -94,7 +94,7 @@ You can provide credentials optionally as pre existing pscredential object. ```yaml Type: PSCredential Parameter Sets: (All) -Aliases: +Aliases: Required: False Position: Named @@ -109,7 +109,7 @@ Accept wildcard characters: False ```yaml Type: SwitchParameter Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named diff --git a/docs/PSCredentialStore.md b/docs/PSCredentialStore.md index 69f3f3b..6b840c0 100644 --- a/docs/PSCredentialStore.md +++ b/docs/PSCredentialStore.md @@ -8,7 +8,7 @@ Locale: en-US # PSCredentialStore Module ## Description -PSCredentialStore enables managing multiple PSCredential objects. +{{Manually Enter Description Here}} ## PSCredentialStore Cmdlets ### [Connect-To](Connect-To.md) @@ -41,3 +41,6 @@ Returns the credential store state. ### [Test-CredentialStoreItem](Test-CredentialStoreItem.md) Checks if the given RemoteHost identifier combination exists in the credential store. +### [Test-CSConnection](Test-CSConnection.md) +Returns the connection state of a given type to the remote host. + diff --git a/docs/Remove-CredentialStoreItem.md b/docs/Remove-CredentialStoreItem.md index 7f0f540..ee5757d 100644 --- a/docs/Remove-CredentialStoreItem.md +++ b/docs/Remove-CredentialStoreItem.md @@ -28,7 +28,7 @@ Use this CMDLet to completely remove an credential store item. ## EXAMPLES -### -------------------------- EXAMPLE 1 -------------------------- +### EXAMPLE 1 ``` Remove-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx01.myside.local" ``` @@ -43,7 +43,7 @@ Define the store in which your given host entry already exists. ```yaml Type: String Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named @@ -58,7 +58,7 @@ Specify the host you for which you would like to change the credentials. ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: True Position: Named @@ -75,7 +75,7 @@ same hostname. ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: False Position: Named @@ -92,7 +92,7 @@ can be decrypted across systems. ```yaml Type: SwitchParameter Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named diff --git a/docs/Set-CredentialStoreItem.md b/docs/Set-CredentialStoreItem.md index 9f15422..34f119a 100644 --- a/docs/Set-CredentialStoreItem.md +++ b/docs/Set-CredentialStoreItem.md @@ -28,7 +28,7 @@ Set-CredentialStoreItem [-Path ] -RemoteHost [-Identifier [-Type] [] +``` + +## DESCRIPTION +Use this script to check a connection which was established with the \`Connect-To\` cmdlet. + +## EXAMPLES + +### EXAMPLE 1 +``` +.\Test-CMConnection -RemoteHost "r0-i01-vcr01.p0r.kivbf-cloud.net" -Type VMware +``` + +## PARAMETERS + +### -RemoteHost +Define the remote host you would like to check. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Type +Define the connection type you would like to check. +See the \`Connect-To\` documentation +for valid type values. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### [None] + +## OUTPUTS + +### [Boolean] + +## NOTES +File Name : Test-CSConnection.ps1 +Author : Marco Blessing - marco.blessing@googlemail.com +Requires : + +## RELATED LINKS + +[https://github.com/OCram85/PSCredentialStore](https://github.com/OCram85/PSCredentialStore) + diff --git a/docs/Test-CredentialStore.md b/docs/Test-CredentialStore.md index de4f824..465d450 100644 --- a/docs/Test-CredentialStore.md +++ b/docs/Test-CredentialStore.md @@ -30,7 +30,7 @@ the file exists. ## EXAMPLES ### Example 1 -``` +```powershell PS C:\> {{ Add example code here }} ``` @@ -44,7 +44,7 @@ Define a custom path to a shared CredentialStore. ```yaml Type: String Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named @@ -61,7 +61,7 @@ can be decrypted across systems. ```yaml Type: SwitchParameter Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named diff --git a/docs/Test-CredentialStoreItem.md b/docs/Test-CredentialStoreItem.md index bccadf3..e5f5126 100644 --- a/docs/Test-CredentialStoreItem.md +++ b/docs/Test-CredentialStoreItem.md @@ -30,7 +30,7 @@ you try to interact with it. ## EXAMPLES -### -------------------------- EXAMPLE 1 -------------------------- +### EXAMPLE 1 ``` If (Test-CredentialStoreItem -RemoteHost "Default") { ``` @@ -51,7 +51,7 @@ Without the \`-Path\` parameter ```yaml Type: String Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named @@ -66,7 +66,7 @@ Specify the host, for which you would like to change the credentials. ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: True Position: Named @@ -83,7 +83,7 @@ for a single host. ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Required: False Position: Named @@ -100,7 +100,7 @@ can be decrypted across systems. ```yaml Type: SwitchParameter Parameter Sets: Shared -Aliases: +Aliases: Required: False Position: Named -- 2.40.1 From ee2c509759ca5bc9ec19500cc021abd187c234a4 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 7 Mar 2018 09:44:04 +0100 Subject: [PATCH 10/32] remove gh-pages test files --- docs/_config.yml | 1 - 1 file changed, 1 deletion(-) delete mode 100644 docs/_config.yml diff --git a/docs/_config.yml b/docs/_config.yml deleted file mode 100644 index 1885487..0000000 --- a/docs/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-midnight \ No newline at end of file -- 2.40.1 From 77c97b5ccc20f931325c0df95a351a7a4067bb8d Mon Sep 17 00:00:00 2001 From: OCram85 Date: Wed, 7 Mar 2018 09:44:20 +0100 Subject: [PATCH 11/32] fix markdown list syntax error --- src/Connection/Connect-To.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Connection/Connect-To.ps1 b/src/Connection/Connect-To.ps1 index 2e8c443..0169d41 100644 --- a/src/Connection/Connect-To.ps1 +++ b/src/Connection/Connect-To.ps1 @@ -15,6 +15,7 @@ function Connect-To { .PARAMETER Type Specify the host type of the target. Currently implemented targets are: + - CiscoUcs Establish a connection to a Cisco UCS fabric interconnect. - FTP Establish a connection to a FTP host. - NetAppFAS Establish a connection to a NetApp Clustered ONTAP filer. -- 2.40.1 From d58496416f10a13168580d07b9c440d7fb0e07e6 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 8 Mar 2018 10:17:10 +0100 Subject: [PATCH 12/32] fix syntax in cmbh to work with platyPS --- src/Connection/Connect-To.ps1 | 18 ++---------------- src/Connection/Disconnect-From.ps1 | 11 ++--------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/src/Connection/Connect-To.ps1 b/src/Connection/Connect-To.ps1 index 0169d41..31f405d 100644 --- a/src/Connection/Connect-To.ps1 +++ b/src/Connection/Connect-To.ps1 @@ -14,16 +14,8 @@ function Connect-To { same hostname. .PARAMETER Type - Specify the host type of the target. Currently implemented targets are: - - - CiscoUcs Establish a connection to a Cisco UCS fabric interconnect. - - FTP Establish a connection to a FTP host. - - NetAppFAS Establish a connection to a NetApp Clustered ONTAP filer. - - VMware Establish a connection to a VMware vCenter or ESXi host. - - CisServer Establish a connection to a Vmware CisServer. - - ExchangeHTTP Start a new remote session to the given Exchange server via insecure http. - - Exchange HTTPS Start a new remote session to the given exchange server with the secure https endpoint. - - SCP Establish a SCP connection. + Specify the host type of the target. Currently implemented targets are: Possible connection values are: + CiscoUcs, FTP, NetAppFAS, VMware, CisServer, ExchangeHTTP, ExchangeHTTPS, SCP. .PARAMETER Credentials Use this parameter to bypass the stored credentials. Without this parameter Connect-To tries to read the @@ -64,12 +56,6 @@ function Connect-To { .EXAMPLE Connect-To -RemoteHost "exchange01.myside.local" -Type ExchangeHTTPS - .EXAMPLE - $MyCreds = Get-Credential - Connect-To -RemoteHost "vcr01.myside.local" -Type VMware -Credentials $MyCreds - Get-VM -Name "*vlm*" | Select-Object -Property Name - Disconnect-From -RemoteHost "vcr01.myside.local" -Type VMware - .NOTES File Name : Connect-To.ps1 Author : Marco Blessing - marco.blessing@googlemail.com diff --git a/src/Connection/Disconnect-From.ps1 b/src/Connection/Disconnect-From.ps1 index 3da3fe4..1ccaa70 100644 --- a/src/Connection/Disconnect-From.ps1 +++ b/src/Connection/Disconnect-From.ps1 @@ -14,15 +14,8 @@ function Disconnect-From { same hostname. .PARAMETER Type - Specify the host type of the target. Currently implemented targets are: - - CiscoUcs Terminates the connection from a Cisco UCS Fabric Interconnect. - - FTP Terminates the connection from a FTP host. - - NetAppFAS Terminates the connection from a NetApp Clustered ONTAP filer. - - VMware Terminates the connection from a VMware vCenter or ESXi host. - - CisServer Terminates the connection from a Vmware CisServer. - - ExchangeHTTP Remove the existing remote session to the given Exchange server - - ExchangeHTTPS Remove the existing remote session to the given Exchange server - - SCP Terminates the existing SCP session. + Specify the host type of the target. Currently implemented targets are: CiscoUcs, FTP, NetAppFAS, VMware, + CisServer, ExchangeHTTP, ExchangeHTTPS, SCP. .PARAMETER Force Force the disconnect, even if the disconnect would fail. -- 2.40.1 From 649bcfdeaf83d3013cac88cd4f426d99d132816b Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 8 Mar 2018 10:19:25 +0100 Subject: [PATCH 13/32] Update docs (platyPS) --- docs/Connect-To.md | 99 ++++++++++++--------------- docs/Disconnect-From.md | 44 ++++++------ docs/Get-CredentialStore.md | 3 +- docs/Get-CredentialStoreItem.md | 39 +++++------ docs/New-CredentialStore.md | 104 ++++++++++++++++------------- docs/New-CredentialStoreItem.md | 69 +++++++++---------- docs/PSCredentialStore.md | 24 +++---- docs/Remove-CredentialStoreItem.md | 37 +++++----- docs/Set-CredentialStoreItem.md | 37 +++++----- docs/Test-CSConnection.md | 3 +- docs/Test-CredentialStore.md | 3 +- docs/Test-CredentialStoreItem.md | 37 +++++----- 12 files changed, 248 insertions(+), 251 deletions(-) diff --git a/docs/Connect-To.md b/docs/Connect-To.md index 8e80352..4287e02 100644 --- a/docs/Connect-To.md +++ b/docs/Connect-To.md @@ -64,26 +64,21 @@ Connect-To -RemoteHost "exchange01.myside.local" -Type ExchangeHTTP Connect-To -RemoteHost "exchange01.myside.local" -Type ExchangeHTTPS ``` -### EXAMPLE 8 -``` -$MyCreds = Get-Credential -``` - -Connect-To -RemoteHost "vcr01.myside.local" -Type VMware -Credentials $MyCreds -Get-VM -Name "*vlm*" | Select-Object -Property Name -Disconnect-From -RemoteHost "vcr01.myside.local" -Type VMware - ## PARAMETERS -### -RemoteHost -Specify the host, for which you would like to change the credentials. +### -Credentials +Use this parameter to bypass the stored credentials. +Without this parameter Connect-To tries to read the +needed credentials from the CredentialStore. +If you provide this parameter you skip this lookup behavior. +So you can use it to enable credentials without preparing any user interaction. ```yaml -Type: String +Type: PSCredential Parameter Sets: (All) Aliases: -Required: True +Required: False Position: Named Default value: None Accept pipeline input: False @@ -107,49 +102,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Type -Specify the host type of the target. -Currently implemented targets are: - - CiscoUcs Establish a connection to a Cisco UCS fabric interconnect. - - FTP Establish a connection to a FTP host. - - NetAppFAS Establish a connection to a NetApp Clustered ONTAP filer. - - VMware Establish a connection to a VMware vCenter or ESXi host. - - CisServer Establish a connection to a Vmware CisServer. - - ExchangeHTTP Start a new remote session to the given Exchange server via insecure http. - - Exchange HTTPS Start a new remote session to the given exchange server with the secure https endpoint. - - SCP Establish a SCP connection. - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Credentials -Use this parameter to bypass the stored credentials. -Without this parameter Connect-To tries to read the -needed credentials from the CredentialStore. -If you provide this parameter you skip this lookup behavior. -So you can use it to enable credentials without preparing any user interaction. - -```yaml -Type: PSCredential -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -Path Define a custom path to a shared CredentialStore. @@ -165,6 +117,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -RemoteHost +Specify the host, for which you would like to change the credentials. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Shared Switch to shared mode with this param. This enforces the command to work with a shared CredentialStore which @@ -182,8 +149,26 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Type +Specify the host type of the target. +Currently implemented targets are: Possible connection values are: +CiscoUcs, FTP, NetAppFAS, VMware, CisServer, ExchangeHTTP, ExchangeHTTPS, SCP. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. +For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/docs/Disconnect-From.md b/docs/Disconnect-From.md index bcafe08..85e7950 100644 --- a/docs/Disconnect-From.md +++ b/docs/Disconnect-From.md @@ -63,6 +63,21 @@ Disconnect-From -RemoteHost "exchange01.myside.local" -Type ExchangeHTTPS ## PARAMETERS +### -Force +Force the disconnect, even if the disconnect would fail. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -RemoteHost Specify the remote endpoint, whose session you would like to terminate. @@ -80,15 +95,8 @@ Accept wildcard characters: False ### -Type Specify the host type of the target. -Currently implemented targets are: - - CiscoUcs Terminates the connection from a Cisco UCS Fabric Interconnect. - - FTP Terminates the connection from a FTP host. - - NetAppFAS Terminates the connection from a NetApp Clustered ONTAP filer. - - VMware Terminates the connection from a VMware vCenter or ESXi host. - - CisServer Terminates the connection from a Vmware CisServer. - - ExchangeHTTP Remove the existing remote session to the given Exchange server - - ExchangeHTTPS Remove the existing remote session to the given Exchange server - - SCP Terminates the existing SCP session. +Currently implemented targets are: CiscoUcs, FTP, NetAppFAS, VMware, +CisServer, ExchangeHTTP, ExchangeHTTPS, SCP. ```yaml Type: String @@ -102,23 +110,9 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Force -Force the disconnect, even if the disconnect would fail. - -```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: False -Accept pipeline input: False -Accept wildcard characters: False -``` - ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. +For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/docs/Get-CredentialStore.md b/docs/Get-CredentialStore.md index 4a9b63c..d22cd2d 100644 --- a/docs/Get-CredentialStore.md +++ b/docs/Get-CredentialStore.md @@ -71,7 +71,8 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. +For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/docs/Get-CredentialStoreItem.md b/docs/Get-CredentialStoreItem.md index 0962eb5..2491019 100644 --- a/docs/Get-CredentialStoreItem.md +++ b/docs/Get-CredentialStoreItem.md @@ -35,6 +35,24 @@ $myCreds = Get-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx0 ## PARAMETERS +### -Identifier +Provide a custom identifier to the given remote host key. +This enables you to store multiple credentials +for a single remote host entry. +For example ad/sys1, ftp/sys1, mssql/sys1 + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Path Define a custom path to a shared CredentialStore. @@ -65,24 +83,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Identifier -Provide a custom identifier to the given remote host key. -This enables you to store multiple credentials -for a single remote host entry. -For example ad/sys1, ftp/sys1, mssql/sys1 - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -Shared Switch to shared mode with this param. This enforces the command to work with a shared CredentialStore which @@ -101,7 +101,8 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. +For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/docs/New-CredentialStore.md b/docs/New-CredentialStore.md index 0962eb5..2cce87c 100644 --- a/docs/New-CredentialStore.md +++ b/docs/New-CredentialStore.md @@ -5,38 +5,79 @@ online version: https://github.com/OCram85/PSCredentialStore schema: 2.0.0 --- -# Get-CredentialStoreItem +# New-CredentialStore ## SYNOPSIS -Returns the Credential from a given remote host item. +Creates a new credential store File ## SYNTAX ### Private (Default) ``` -Get-CredentialStoreItem -RemoteHost [-Identifier ] [] +New-CredentialStore [-Force] [] ``` ### Shared ``` -Get-CredentialStoreItem [-Path ] -RemoteHost [-Identifier ] [-Shared] - [] +New-CredentialStore [-Shared] [-Path ] [-Force] [] ``` ## DESCRIPTION -Return the credential as PSCredential object. +You need to run this script first to create a new credential store before you try to +save new credentials with New-CredentialStoreItem. ## EXAMPLES ### EXAMPLE 1 ``` -$myCreds = Get-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx01.myside.local" +New-CredentialStore ``` +# Creates a new private CredentialStore + +### EXAMPLE 2 +``` +New-CredentialStore -Force +``` + +# Resets an existing private CredentialStore + +### EXAMPLE 3 +``` +New-CredentialStore -Shared +``` + +# Creates a new shared CredentialStore + +### EXAMPLE 4 +``` +New-CredentialStore -Shared -Path "C:\TMP\CredentialStore.json" +``` + +# Creates a new shared CredentialStore in the given location. + ## PARAMETERS +### -Force +Use this switch to reset an existing store. +The complete content will be wiped. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Path -Define a custom path to a shared CredentialStore. +Define a location for the new shared CredentialStore. +The default store will be created in +$Env:ProgramData\PSCredentialStore dir. ```yaml Type: String @@ -50,43 +91,11 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -RemoteHost -Specify the host, for which you would like to change the credentials. - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Identifier -Provide a custom identifier to the given remote host key. -This enables you to store multiple credentials -for a single remote host entry. -For example ad/sys1, ftp/sys1, mssql/sys1 - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -Shared -Switch to shared mode with this param. -This enforces the command to work with a shared CredentialStore which -can be decrypted across systems. +Creates a CredentialStore in the Shared mode. +This enables you to read the CredentialStore Items on +different systems or profiles. +In addition you can optionally provide a custom path wit the -Path parameter. ```yaml Type: SwitchParameter @@ -101,7 +110,8 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. +For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS @@ -109,11 +119,11 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## OUTPUTS -### [System.Management.Automation.PSCredential] +### [None] ## NOTES \`\`\` -File Name : Get-CredentialStoreItem.ps1 +File Name : New-CredentialStore.ps1 Author : Marco Blessing - marco.blessing@googlemail.com Requires : \`\`\` diff --git a/docs/New-CredentialStoreItem.md b/docs/New-CredentialStoreItem.md index 1c373ea..9e6fc89 100644 --- a/docs/New-CredentialStoreItem.md +++ b/docs/New-CredentialStoreItem.md @@ -40,6 +40,39 @@ New-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx01.myside.lo ## PARAMETERS +### -Credential +You can provide credentials optionally as pre existing pscredential object. + +```yaml +Type: PSCredential +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Identifier +Provide a custom identifier to the given remote host key. +This enables you to store multiple credentials +for a single remote host entry. +For example ad/sys1, ftp/sys1, mssql/sys1 + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Path Define the store in which you would like to add a new item. @@ -70,39 +103,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Identifier -Provide a custom identifier to the given remote host key. -This enables you to store multiple credentials -for a single remote host entry. -For example ad/sys1, ftp/sys1, mssql/sys1 - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Credential -You can provide credentials optionally as pre existing pscredential object. - -```yaml -Type: PSCredential -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -Shared {{Fill Shared Description}} @@ -119,7 +119,8 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. +For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/docs/PSCredentialStore.md b/docs/PSCredentialStore.md index 6b840c0..da93bf4 100644 --- a/docs/PSCredentialStore.md +++ b/docs/PSCredentialStore.md @@ -12,35 +12,35 @@ Locale: en-US ## PSCredentialStore Cmdlets ### [Connect-To](Connect-To.md) -Connects to the given host using the stored CredentialStoreItem. +{{Manually Enter Connect-To Description Here}} ### [Disconnect-From](Disconnect-From.md) -Terminates a session established with Connect-To using a CredentialStoreItem. +{{Manually Enter Disconnect-From Description Here}} ### [Get-CredentialStore](Get-CredentialStore.md) -Reads the complete content of the credential store and returns it as a new object. +{{Manually Enter Get-CredentialStore Description Here}} ### [Get-CredentialStoreItem](Get-CredentialStoreItem.md) -Returns the Credential from a given remote host item. +{{Manually Enter Get-CredentialStoreItem Description Here}} -### [Get-CredentialStoreItem](Get-CredentialStoreItem.md) -Returns the Credential from a given remote host item. +### [New-CredentialStore](New-CredentialStore.md) +{{Manually Enter New-CredentialStore Description Here}} ### [New-CredentialStoreItem](New-CredentialStoreItem.md) -Adds a credential store item containing host, user and password to the given store. +{{Manually Enter New-CredentialStoreItem Description Here}} ### [Remove-CredentialStoreItem](Remove-CredentialStoreItem.md) -Remove the given credentials from the credential store. +{{Manually Enter Remove-CredentialStoreItem Description Here}} ### [Set-CredentialStoreItem](Set-CredentialStoreItem.md) -Changes the credentials for the given remote host in the store. +{{Manually Enter Set-CredentialStoreItem Description Here}} ### [Test-CredentialStore](Test-CredentialStore.md) -Returns the credential store state. +{{Manually Enter Test-CredentialStore Description Here}} ### [Test-CredentialStoreItem](Test-CredentialStoreItem.md) -Checks if the given RemoteHost identifier combination exists in the credential store. +{{Manually Enter Test-CredentialStoreItem Description Here}} ### [Test-CSConnection](Test-CSConnection.md) -Returns the connection state of a given type to the remote host. +{{Manually Enter Test-CSConnection Description Here}} diff --git a/docs/Remove-CredentialStoreItem.md b/docs/Remove-CredentialStoreItem.md index ee5757d..2fd8470 100644 --- a/docs/Remove-CredentialStoreItem.md +++ b/docs/Remove-CredentialStoreItem.md @@ -37,6 +37,23 @@ Remove-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx01.myside ## PARAMETERS +### -Identifier +Defaults to "". +Specify a string, which separates two CredentialStoreItems for the +same hostname. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Path Define the store in which your given host entry already exists. @@ -67,23 +84,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Identifier -Defaults to "". -Specify a string, which separates two CredentialStoreItems for the -same hostname. - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -Shared Switch to shared mode with this param. This enforces the command to work with a shared CredentialStore which @@ -102,7 +102,8 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. +For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/docs/Set-CredentialStoreItem.md b/docs/Set-CredentialStoreItem.md index 34f119a..29a4385 100644 --- a/docs/Set-CredentialStoreItem.md +++ b/docs/Set-CredentialStoreItem.md @@ -37,6 +37,23 @@ Set-CredentialStoreItem -Path "C:\TMP\mystore.json" -RemoteHost "esx01.myside.lo ## PARAMETERS +### -Identifier +Defaults to "". +Specify a string, which separates two CredentialStoreItems for the +same hostname. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Path Define the store in which your given host entry already exists. @@ -67,23 +84,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Identifier -Defaults to "". -Specify a string, which separates two CredentialStoreItems for the -same hostname. - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -Shared Switch to shared mode with this param. This enforces the command to work with a shared CredentialStore which @@ -102,7 +102,8 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. +For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/docs/Test-CSConnection.md b/docs/Test-CSConnection.md index da6e927..2e0a607 100644 --- a/docs/Test-CSConnection.md +++ b/docs/Test-CSConnection.md @@ -61,7 +61,8 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. +For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/docs/Test-CredentialStore.md b/docs/Test-CredentialStore.md index 465d450..d8eaf62 100644 --- a/docs/Test-CredentialStore.md +++ b/docs/Test-CredentialStore.md @@ -71,7 +71,8 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. +For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/docs/Test-CredentialStoreItem.md b/docs/Test-CredentialStoreItem.md index e5f5126..1635a9d 100644 --- a/docs/Test-CredentialStoreItem.md +++ b/docs/Test-CredentialStoreItem.md @@ -43,6 +43,23 @@ Else { ## PARAMETERS +### -Identifier +Adds an optional identifier to the given RemoteHost. +Makes it possible to store multiple credentials +for a single host. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Path Define a custom credential store you try to read from. Without the \`-Path\` parameter @@ -75,23 +92,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Identifier -Adds an optional identifier to the given RemoteHost. -Makes it possible to store multiple credentials -for a single host. - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - ### -Shared Switch to shared mode with this param. This enforces the command to work with a shared CredentialStore which @@ -110,7 +110,8 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. +For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS -- 2.40.1 From f538802da4fab7866ddd0fc188eaabb163eba487 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 8 Mar 2018 10:57:21 +0100 Subject: [PATCH 14/32] add helper function for pester --- src/Helper/Get-ModuleBase.ps1 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/Helper/Get-ModuleBase.ps1 diff --git a/src/Helper/Get-ModuleBase.ps1 b/src/Helper/Get-ModuleBase.ps1 new file mode 100644 index 0000000..118dfeb --- /dev/null +++ b/src/Helper/Get-ModuleBase.ps1 @@ -0,0 +1,29 @@ +function Get-ModuleBase { + <# + .SYNOPSIS + Returns the base path of the current module. + + .DESCRIPTION + This is just a wrapper for enabling pester tests. + + + .OUTPUTS + 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()] + [OutputType()] + param() + begin {} + process { + return $MyInvocation.MyCommand.Module.ModuleBase + } + end {} +} -- 2.40.1 From b325fea2bbb289a380adf4ee859c25ba9ddc46be Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 8 Mar 2018 10:57:37 +0100 Subject: [PATCH 15/32] add tests resources --- resources/Dependency.json | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 resources/Dependency.json diff --git a/resources/Dependency.json b/resources/Dependency.json new file mode 100644 index 0000000..4658395 --- /dev/null +++ b/resources/Dependency.json @@ -0,0 +1,25 @@ +{ + "Version": 0.1, + "Mandatory": {}, + "Optional": [ + { + "Name": "foobar2000", + "Modules": [ + "foobar2000" + ] + }, + { + "Name": "foo", + "Modules": [ + "foo", + "bar" + ] + }, + { + "Name": "bar", + "Modules": [ + "bar" + ] + } + ] +} -- 2.40.1 From 0dae01d141e5fd2444dc1d07f3a600f03c8f6c56 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 8 Mar 2018 10:57:51 +0100 Subject: [PATCH 16/32] add pester tests for Resolve-Dependency --- src/Helper/Resolve-Dependency.ps1 | 3 +- tests/Helper/01_Resolve-Dependendy.Tests.ps1 | 31 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/Helper/01_Resolve-Dependendy.Tests.ps1 diff --git a/src/Helper/Resolve-Dependency.ps1 b/src/Helper/Resolve-Dependency.ps1 index 1687275..59cfc5f 100644 --- a/src/Helper/Resolve-Dependency.ps1 +++ b/src/Helper/Resolve-Dependency.ps1 @@ -53,11 +53,12 @@ function Resolve-Dependency { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] + [ValidateNotNullOrEmpty()] [string]$Name ) begin { - $ModuleRootDir = $MyInvocation.MyCommand.Module.ModuleBase + $ModuleRootDir = Get-ModuleBase $DepFilePath = Join-Path -Path $ModuleRootDir -ChildPath "Dependency.json" if (Test-Path -Path $DepFilePath) { $Dependency = Get-Content -Path $DepFilePath -Raw -Encoding UTF8 | ConvertFrom-Json diff --git a/tests/Helper/01_Resolve-Dependendy.Tests.ps1 b/tests/Helper/01_Resolve-Dependendy.Tests.ps1 new file mode 100644 index 0000000..013c65b --- /dev/null +++ b/tests/Helper/01_Resolve-Dependendy.Tests.ps1 @@ -0,0 +1,31 @@ +#region HEADER +$here = Split-Path -Parent $MyInvocation.MyCommand.Path +# $RepoRoot = (Get-Item -Path $here).Parent.Parent.FullName +$RepoRoot = (Get-GitDirectory).replace('\.git', '') +$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' +$sut = $sut -replace "\d{2}`_", '' +$suthome = (Get-ChildItem -Path $RepoRoot -Exclude ".\tests\" -Filter $sut -Recurse).FullName +# Skip try loading the source file if it doesn't exists. +If ($suthome.Length -gt 0) { + . $suthome +} +Else { + Write-Warning ("Could not find source file {0}" -f $sut) +} + +# load additional functions defined in the repository. Replace the expression . +#. (Get-ChildItem -Path $RepoRoot -Filter ".ps1" -Recurse).FullName +#endregion HEADER + +Describe "Resolve-Dependency" { + Context "Basic syntax check" { + Mock Get-ModuleBase {return "{0}\resources" -f $PWD} + Mock Test-Module {return $true} + It "Test1: Should not throw" { + { Resolve-Dependency -Name 'foobar2000' } | Should -Not -Throw + } + It "Test2: Output type should be bool" { + Resolve-Dependency -Name 'foobar2000' | Should -BeOfType system.bool + } + } +} -- 2.40.1 From 64a242c1d3fcd89dbdcd36593110f2492f7bc3b5 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 8 Mar 2018 11:04:58 +0100 Subject: [PATCH 17/32] add refs for pester test --- tests/00_BasicModule.Tests.ps1 | 15 +++++++++++++++ ....Tests.ps1 => 01_Resolve-Dependency.Tests.ps1} | 5 +++-- ...s.ps1 => 02_New-CredentialStoreItem.Tests.ps1} | 0 ...Tests.ps1 => 01_Get-CredentialStore.Tests.ps1} | 0 ...Tests.ps1 => 01_New-CredentialStore.Tests.ps1} | 0 ...ests.ps1 => 01_Test-CredentialStore.Tests.ps1} | 0 6 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/00_BasicModule.Tests.ps1 rename tests/Helper/{01_Resolve-Dependendy.Tests.ps1 => 01_Resolve-Dependency.Tests.ps1} (84%) rename tests/Item/{01_New-CredentialStoreItem.Tests.ps1 => 02_New-CredentialStoreItem.Tests.ps1} (100%) rename tests/Store/{00_Get-CredentialStore.Tests.ps1 => 01_Get-CredentialStore.Tests.ps1} (100%) rename tests/Store/{00_New-CredentialStore.Tests.ps1 => 01_New-CredentialStore.Tests.ps1} (100%) rename tests/Store/{00_Test-CredentialStore.Tests.ps1 => 01_Test-CredentialStore.Tests.ps1} (100%) diff --git a/tests/00_BasicModule.Tests.ps1 b/tests/00_BasicModule.Tests.ps1 new file mode 100644 index 0000000..7e8dfe9 --- /dev/null +++ b/tests/00_BasicModule.Tests.ps1 @@ -0,0 +1,15 @@ +$RepoRoot = (Get-GitDirectory).replace('\.git', '') + +Describe "Pre-Flight module tests" { + $ManifestFilePath = "{0}\src\PSCredentialstore.psd1" -f $RepoRoot + Context "Manifest file related" { + It "Test the parsed file itsef" { + { Test-ModuleManifest -Path $ManifestFilePath } | Should -Not -Throw + } + } + Context "Module consistency tests" { + IT "Importing should work" { + { Import-Module -Name $ManifestFilePath -Global } | Should -Not -Throw + } + } +} diff --git a/tests/Helper/01_Resolve-Dependendy.Tests.ps1 b/tests/Helper/01_Resolve-Dependency.Tests.ps1 similarity index 84% rename from tests/Helper/01_Resolve-Dependendy.Tests.ps1 rename to tests/Helper/01_Resolve-Dependency.Tests.ps1 index 013c65b..9c6e54d 100644 --- a/tests/Helper/01_Resolve-Dependendy.Tests.ps1 +++ b/tests/Helper/01_Resolve-Dependency.Tests.ps1 @@ -14,7 +14,8 @@ Else { } # load additional functions defined in the repository. Replace the expression . -#. (Get-ChildItem -Path $RepoRoot -Filter ".ps1" -Recurse).FullName +. (Get-ChildItem -Path $RepoRoot -Filter "Get-ModuleBase.ps1" -Recurse).FullName +. (Get-ChildItem -Path $RepoRoot -Filter "Test-Module.ps1" -Recurse).FullName #endregion HEADER Describe "Resolve-Dependency" { @@ -25,7 +26,7 @@ Describe "Resolve-Dependency" { { Resolve-Dependency -Name 'foobar2000' } | Should -Not -Throw } It "Test2: Output type should be bool" { - Resolve-Dependency -Name 'foobar2000' | Should -BeOfType system.bool + Resolve-Dependency -Name 'foobar2000' | Should -BeOfType bool } } } diff --git a/tests/Item/01_New-CredentialStoreItem.Tests.ps1 b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 similarity index 100% rename from tests/Item/01_New-CredentialStoreItem.Tests.ps1 rename to tests/Item/02_New-CredentialStoreItem.Tests.ps1 diff --git a/tests/Store/00_Get-CredentialStore.Tests.ps1 b/tests/Store/01_Get-CredentialStore.Tests.ps1 similarity index 100% rename from tests/Store/00_Get-CredentialStore.Tests.ps1 rename to tests/Store/01_Get-CredentialStore.Tests.ps1 diff --git a/tests/Store/00_New-CredentialStore.Tests.ps1 b/tests/Store/01_New-CredentialStore.Tests.ps1 similarity index 100% rename from tests/Store/00_New-CredentialStore.Tests.ps1 rename to tests/Store/01_New-CredentialStore.Tests.ps1 diff --git a/tests/Store/00_Test-CredentialStore.Tests.ps1 b/tests/Store/01_Test-CredentialStore.Tests.ps1 similarity index 100% rename from tests/Store/00_Test-CredentialStore.Tests.ps1 rename to tests/Store/01_Test-CredentialStore.Tests.ps1 -- 2.40.1 From afcfae5130628fd29ccbcd0c1bb70f3e1d651a70 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 8 Mar 2018 11:31:56 +0100 Subject: [PATCH 18/32] test new poject intetnal pester dependency workflow --- tests/00_BasicModule.Tests.ps1 | 2 +- tests/Helper/01_Resolve-Dependency.Tests.ps1 | 1 + tests/Store/01_Get-CredentialStore.Tests.ps1 | 2 +- tools/AppVeyor.psm1 | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/00_BasicModule.Tests.ps1 b/tests/00_BasicModule.Tests.ps1 index 7e8dfe9..b605a56 100644 --- a/tests/00_BasicModule.Tests.ps1 +++ b/tests/00_BasicModule.Tests.ps1 @@ -9,7 +9,7 @@ Describe "Pre-Flight module tests" { } Context "Module consistency tests" { IT "Importing should work" { - { Import-Module -Name $ManifestFilePath -Global } | Should -Not -Throw + { Import-Module -Name $ManifestFilePath -Global -Force }| Should -Not -Throw } } } diff --git a/tests/Helper/01_Resolve-Dependency.Tests.ps1 b/tests/Helper/01_Resolve-Dependency.Tests.ps1 index 9c6e54d..ff44eb7 100644 --- a/tests/Helper/01_Resolve-Dependency.Tests.ps1 +++ b/tests/Helper/01_Resolve-Dependency.Tests.ps1 @@ -16,6 +16,7 @@ Else { # load additional functions defined in the repository. Replace the expression . . (Get-ChildItem -Path $RepoRoot -Filter "Get-ModuleBase.ps1" -Recurse).FullName . (Get-ChildItem -Path $RepoRoot -Filter "Test-Module.ps1" -Recurse).FullName + #endregion HEADER Describe "Resolve-Dependency" { diff --git a/tests/Store/01_Get-CredentialStore.Tests.ps1 b/tests/Store/01_Get-CredentialStore.Tests.ps1 index 5fbe500..a0cab26 100644 --- a/tests/Store/01_Get-CredentialStore.Tests.ps1 +++ b/tests/Store/01_Get-CredentialStore.Tests.ps1 @@ -14,7 +14,7 @@ Else { } # load additional functions defined in the repository. Replace the expression . -. (Get-ChildItem -Path $RepoRoot -Filter "Test-CredentialStore.ps1" -Recurse).FullName +#. (Get-ChildItem -Path $RepoRoot -Filter "Test-CredentialStore.ps1" -Recurse).FullName #endregion HEADER diff --git a/tools/AppVeyor.psm1 b/tools/AppVeyor.psm1 index de78763..71e1e85 100644 --- a/tools/AppVeyor.psm1 +++ b/tools/AppVeyor.psm1 @@ -95,7 +95,7 @@ Function Invoke-AppVeyorTests() { Details = 'Now running all test found in .\tests\ dir.' } Add-AppveyorMessage @MsgParams - $testresults = Invoke-Pester -Path ".\tests\*" -ExcludeTag 'Disabled' -PassThru + $testresults = Invoke-Pester -Path ( Get-ChildItem -Path ".\tests\*.Tests.ps1" -Recurse | Sort-Object -Property Name ) -ExcludeTag 'Disabled' -PassThru ForEach ($Item in $testresults.TestResult) { Switch ($Item.Result) { "Passed" { -- 2.40.1 From c851fef3a6e11b8545dbd262bcc4b1795c19b1a6 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 8 Mar 2018 12:13:54 +0100 Subject: [PATCH 19/32] fix #17 --- tests/Item/02_New-CredentialStoreItem.Tests.ps1 | 8 ++++---- tests/Store/01_New-CredentialStore.Tests.ps1 | 2 +- tools/AppVeyor.psm1 | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 index 9624c2b..f1914bb 100644 --- a/tests/Item/02_New-CredentialStoreItem.Tests.ps1 +++ b/tests/Item/02_New-CredentialStoreItem.Tests.ps1 @@ -14,10 +14,10 @@ Else { } # load additional functions defined in the repository. Replace the expression . -. (Get-ChildItem -Path $RepoRoot -Filter "Test-CredentialStore.ps1" -Recurse).FullName -. (Get-ChildItem -Path $RepoRoot -Filter "New-CredentialStore.ps1" -Recurse).FullName -. (Get-ChildItem -Path $RepoRoot -Filter "Get-CredentialStore.ps1" -Recurse).FullName -. (Get-ChildItem -Path $RepoRoot -Filter "Get-CredentialStoreItem.ps1" -Recurse).FullName +#. (Get-ChildItem -Path $RepoRoot -Filter "Test-CredentialStore.ps1" -Recurse).FullName +#. (Get-ChildItem -Path $RepoRoot -Filter "New-CredentialStore.ps1" -Recurse).FullName +#. (Get-ChildItem -Path $RepoRoot -Filter "Get-CredentialStore.ps1" -Recurse).FullName +#. (Get-ChildItem -Path $RepoRoot -Filter "Get-CredentialStoreItem.ps1" -Recurse).FullName . (Get-ChildItem -Path $RepoRoot -Filter "Test-ChallengeFile.ps1" -Recurse).FullName . (Get-ChildItem -Path $RepoRoot -Filter "Get-ChallengeFile.ps1" -Recurse).FullName . (Get-ChildItem -Path $RepoRoot -Filter "Set-ChallengeFile.ps1" -Recurse).FullName diff --git a/tests/Store/01_New-CredentialStore.Tests.ps1 b/tests/Store/01_New-CredentialStore.Tests.ps1 index e633374..3c7e2a8 100644 --- a/tests/Store/01_New-CredentialStore.Tests.ps1 +++ b/tests/Store/01_New-CredentialStore.Tests.ps1 @@ -14,7 +14,7 @@ Else { } # load additional functions defined in the repository. Replace the expression . -. (Get-ChildItem -Path $RepoRoot -Filter "Test-CredentialStore.ps1" -Recurse).FullName +#. (Get-ChildItem -Path $RepoRoot -Filter "Test-CredentialStore.ps1" -Recurse).FullName . (Get-ChildItem -Path $RepoRoot -Filter "Test-ChallengeFile.ps1" -Recurse).FullName . (Get-ChildItem -Path $RepoRoot -Filter "Set-ChallengeFile.ps1" -Recurse).FullName . (Get-ChildItem -Path $RepoRoot -Filter "Get-RandomKey.ps1" -Recurse).FullName diff --git a/tools/AppVeyor.psm1 b/tools/AppVeyor.psm1 index 71e1e85..dc1bb7d 100644 --- a/tools/AppVeyor.psm1 +++ b/tools/AppVeyor.psm1 @@ -156,6 +156,7 @@ Function Invoke-CoverageReport() { Import-Module ('.\src\{0}.psm1' -f $CALLSIGN) -Verbose -Force $FileMap = New-PesterFileMap -SourceRoot '.\src' -PesterRoot '.\tests' + $FileMap | Format-List $CoverageReport = New-CoverageReport -PesterFileMap $FileMap -RepoToken $RepoToken Write-Host "CoverageReport JSON:" -ForegroundColor Yellow $CoverageReport | Out-String | Write-Host -- 2.40.1 From 4ac85f9c6822a49e5f3744466fd8f181498753b4 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 8 Mar 2018 14:42:03 +0100 Subject: [PATCH 20/32] fix test task definition --- .vscode/tasks.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 27bf957..d8fd688 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -28,7 +28,7 @@ "taskName": "Test", "suppressTaskName": true, "args": [ - "Write-Host 'Invoking Pester...'; $ProgressPreference = 'SilentlyContinue'; Invoke-Pester -Script '.\\tests\\*' -EnableExit $flase -PesterOption @{IncludeVSCodeMarker=$true};", + "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};", "Invoke-Command { Write-Host 'Completed Test task in task runner.' }" ], "problemMatcher": "$pester", -- 2.40.1 From 492031e34e465289ec89933cba9487e8ceeb2203 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 8 Mar 2018 14:43:43 +0100 Subject: [PATCH 21/32] fix coveralls.io badge link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b2a5873..f17dea3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![AppVeyor branch](https://img.shields.io/appveyor/ci/OCram85/PSCredentialStore/master.svg?style=plastic "Master Banch Build Status")](https://ci.appveyor.com/project/OCram85/pscredentialstore/branch/master) [![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) -[![Coveralls github](https://img.shields.io/coveralls/github/OCram85/PSCredentialStore.svg?style=plastic "Coveralls.io Coverage Report")](https://coveralls.io/github/OCram85/PSCredentialStorebranch=master) +[![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) [![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/dt/PSCredentialStore.svg?style=plastic "PowershellGallery Downloads")](https://www.powershellgallery.com/packages/PSCredentialStore) -- 2.40.1 From 55260af89424de38c466499002d13f5b2a8017c2 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 8 Mar 2018 14:51:51 +0100 Subject: [PATCH 22/32] adds deug output --- tests/Store/01_New-CredentialStore.Tests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Store/01_New-CredentialStore.Tests.ps1 b/tests/Store/01_New-CredentialStore.Tests.ps1 index 3c7e2a8..934dc4f 100644 --- a/tests/Store/01_New-CredentialStore.Tests.ps1 +++ b/tests/Store/01_New-CredentialStore.Tests.ps1 @@ -46,6 +46,7 @@ $VerbosePreference = "SilentlyContinue" Describe "New-CredentialStore" { Context "Private CS tests" { $pCS = Join-Path -Path $env:APPDATA -ChildPath "CredentialStore.json" + Write-Debug -Message ("Parsed private CS:" -f $pCS) It "Test1: Create new private CredentialStore" { New-CredentialStore $result = Test-Path -Path $pCS -- 2.40.1 From 3d3497c58e430b2803c173027c8bff4034aa1fb0 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 8 Mar 2018 14:52:49 +0100 Subject: [PATCH 23/32] adds verbose output --- tests/Store/01_New-CredentialStore.Tests.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Store/01_New-CredentialStore.Tests.ps1 b/tests/Store/01_New-CredentialStore.Tests.ps1 index 934dc4f..dfc47b0 100644 --- a/tests/Store/01_New-CredentialStore.Tests.ps1 +++ b/tests/Store/01_New-CredentialStore.Tests.ps1 @@ -46,11 +46,10 @@ $VerbosePreference = "SilentlyContinue" Describe "New-CredentialStore" { Context "Private CS tests" { $pCS = Join-Path -Path $env:APPDATA -ChildPath "CredentialStore.json" - Write-Debug -Message ("Parsed private CS:" -f $pCS) It "Test1: Create new private CredentialStore" { New-CredentialStore $result = Test-Path -Path $pCS - $CS = Get-Content -Path $pCS -Raw | ConvertFrom-Json -ErrorAction SilentlyContinue + $CS = Get-Content -Path $pCS -Raw | ConvertFrom-Json ($result -eq $True) -and ($CS.Type -eq "Private") | Should Be $True } It "Test2: Try to override private Store" { -- 2.40.1 From c439611b8c84cb57feca744c0c1c7fe5ed22ca64 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 9 Mar 2018 08:27:27 +0100 Subject: [PATCH 24/32] enable debug rdp connection --- appveyor.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 400c196..c745716 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,6 +13,11 @@ skip_tags: true image: Visual Studio 2017 # 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 -Verbose @@ -61,3 +66,7 @@ deploy: 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')) -- 2.40.1 From 97a9238f87542adb594d8e57a03458a1c3cd4a10 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 9 Mar 2018 08:41:23 +0100 Subject: [PATCH 25/32] disable debug rdp connecition --- appveyor.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index c745716..d1f3a05 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -15,8 +15,8 @@ image: Visual Studio 2017 # 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')) +#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 @@ -68,5 +68,5 @@ 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')) +#on_finish: +# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) -- 2.40.1 From 1adde5cec010e9397bae72d230ad515700094b98 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 9 Mar 2018 08:43:53 +0100 Subject: [PATCH 26/32] remove debug output in appveyor build --- tools/AppVeyor.psm1 | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/AppVeyor.psm1 b/tools/AppVeyor.psm1 index dc1bb7d..71e1e85 100644 --- a/tools/AppVeyor.psm1 +++ b/tools/AppVeyor.psm1 @@ -156,7 +156,6 @@ Function Invoke-CoverageReport() { Import-Module ('.\src\{0}.psm1' -f $CALLSIGN) -Verbose -Force $FileMap = New-PesterFileMap -SourceRoot '.\src' -PesterRoot '.\tests' - $FileMap | Format-List $CoverageReport = New-CoverageReport -PesterFileMap $FileMap -RepoToken $RepoToken Write-Host "CoverageReport JSON:" -ForegroundColor Yellow $CoverageReport | Out-String | Write-Host -- 2.40.1 From 4e0e8c79949dc28b7bea2faf257828c1a08a1006 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 9 Mar 2018 09:00:55 +0100 Subject: [PATCH 27/32] update Readme file --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f17dea3..650d148 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ scripts without exposing them as plain text. PSCredentialStore was developed to simplify the delegation of complex powershell scripts. In this case you often need to store credentials for non interactive usage like in scheduled tasks. -For more details read the [about_PSCredentialStore](/src/en-US/about_PSCredential.help.txt) page. +For more details read the [about_PSCredentialStore](/docs/about_PSCredentialStore.md) page on github or via CLI with +`Get-Help about_PSCredentialStore`. Installation ============ @@ -80,6 +81,12 @@ If you have already installed the underlying framework / modules, you can connec * Required Modules: [`VMware.VimAutomation.Core`](https://www.powershellgallery.com/packages/VMware.PowerCLI) * **CisServer** - Establish a connection to the CisServer Service on vCenter Host. * Required Modules: [`VMware.VimAutomation.Cis.Core`](https://www.powershellgallery.com/packages/VMware.PowerCLI) +* **ExchangeHTTP** - Establish a remote connection with an Exchange endpoint via http. + * Requires PowerShell remoting +* **ExchangeHTTPS** - Establish a remote connection with an Exchange endpoint via https. + * Requires PowerShell remoting +* **SCP** - Establish a SCP connection. + * Required Modules: [`WinSCP`](https://www.powershellgallery.com/packages/WinSCP) Here are some basic examples: -- 2.40.1 From e05b853bf41a34c99e7a6372cdc5cffd65d2f0da Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 9 Mar 2018 09:02:09 +0100 Subject: [PATCH 28/32] update about page --- docs/about_PSCredentialStore.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/about_PSCredentialStore.md b/docs/about_PSCredentialStore.md index 6b1b11f..a4694ae 100644 --- a/docs/about_PSCredentialStore.md +++ b/docs/about_PSCredentialStore.md @@ -72,7 +72,12 @@ If you have already installed the underlying framework your can connect to: * Required Modules: [`VMware.VimAutomation.Core`](https://www.powershellgallery.com/packages/VMware.PowerCLI) * **CisServer** - Establish a connection to the CisServer Service on vCenter Host. * Required Modules: [`VMware.VimAutomation.Cis.Core`](https://www.powershellgallery.com/packages/VMware.PowerCLI)) - +* **ExchangeHTTP** - Establish a remote connection with an Exchange endpoint via http. + * Requires PowerShell remoting +* **ExchangeHTTPS** - Establish a remote connection with an Exchange endpoint via https. + * Requires PowerShell remoting +* **SCP** - Establish a SCP connection. + * Required Modules: [`WinSCP`](https://www.powershellgallery.com/packages/WinSCP) # EXAMPLES ```powershell -- 2.40.1 From 9062bd1d4ff5bb915660368b3893af68ca2a1346 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 9 Mar 2018 09:11:14 +0100 Subject: [PATCH 29/32] adds extra tests for Resolve-Dependency --- tests/Helper/01_Resolve-Dependency.Tests.ps1 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/Helper/01_Resolve-Dependency.Tests.ps1 b/tests/Helper/01_Resolve-Dependency.Tests.ps1 index ff44eb7..8ab62ce 100644 --- a/tests/Helper/01_Resolve-Dependency.Tests.ps1 +++ b/tests/Helper/01_Resolve-Dependency.Tests.ps1 @@ -30,4 +30,15 @@ Describe "Resolve-Dependency" { Resolve-Dependency -Name 'foobar2000' | Should -BeOfType bool } } + Context "Enforce Error" { + # Return incorrect module base to enforce there is no config file. + Mock Get-ModuleBase {return "C:\"} + It "Missing dependency file should not cause an error" { + { Resolve-Dependency -Name 'awesome'} | Should -Not -Throw + } + + It "Missing dependency file should return false" { + Resolve-Dependency -Name 'awesome' | Should -Be $false + } + } } -- 2.40.1 From 6991487a3c9803da9f4d894458331970b9faa63b Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 9 Mar 2018 09:31:43 +0100 Subject: [PATCH 30/32] fix Resolve-Dependency error for missing module --- src/Helper/Resolve-Dependency.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Helper/Resolve-Dependency.ps1 b/src/Helper/Resolve-Dependency.ps1 index 59cfc5f..5152623 100644 --- a/src/Helper/Resolve-Dependency.ps1 +++ b/src/Helper/Resolve-Dependency.ps1 @@ -75,7 +75,10 @@ function Resolve-Dependency { foreach ($Module in $SelectedDependency.Modules) { $res += Test-Module -Name $Module } - if ($res -contains $false) { + if ($res.count -eq 0) { + return $false + } + elseif ($res.count -contains $false) { return $false } else { -- 2.40.1 From 9d2e048a4c938c74e7d95ba67d046868b1d75e79 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 9 Mar 2018 11:02:27 +0100 Subject: [PATCH 31/32] adds additional test scenario for Resolve-Dependency --- resources/Dependency.json | 13 +++++++++++++ src/Helper/Resolve-Dependency.ps1 | 2 +- tests/Helper/01_Resolve-Dependency.Tests.ps1 | 9 +++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/resources/Dependency.json b/resources/Dependency.json index 4658395..232341f 100644 --- a/resources/Dependency.json +++ b/resources/Dependency.json @@ -20,6 +20,19 @@ "Modules": [ "bar" ] + }, + { + "Name": "PSGet", + "Modules": [ + "PowerShellGet" + ] + }, + { + "Name": "PSGetMixed", + "Modules": [ + "PowerShellGet", + "foobar2000" + ] } ] } diff --git a/src/Helper/Resolve-Dependency.ps1 b/src/Helper/Resolve-Dependency.ps1 index 5152623..3893502 100644 --- a/src/Helper/Resolve-Dependency.ps1 +++ b/src/Helper/Resolve-Dependency.ps1 @@ -78,7 +78,7 @@ function Resolve-Dependency { if ($res.count -eq 0) { return $false } - elseif ($res.count -contains $false) { + elseif ($res -contains $false) { return $false } else { diff --git a/tests/Helper/01_Resolve-Dependency.Tests.ps1 b/tests/Helper/01_Resolve-Dependency.Tests.ps1 index 8ab62ce..2c2e1f4 100644 --- a/tests/Helper/01_Resolve-Dependency.Tests.ps1 +++ b/tests/Helper/01_Resolve-Dependency.Tests.ps1 @@ -41,4 +41,13 @@ Describe "Resolve-Dependency" { Resolve-Dependency -Name 'awesome' | Should -Be $false } } + Context "Testing input variations" { + Mock Get-ModuleBase {return "{0}\resources" -f $PWD} + It "Should return true if all given dependencies exist" { + Resolve-Dependency -Name 'PSGet' | Should -Be $true + } + It "Mixed results should return false" { + Resolve-Dependency -Name 'PSGetMixed' | Should -Be $false + } + } } -- 2.40.1 From 697b268a920981e2efbd99419a06f16ee9d1adc5 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 9 Mar 2018 13:58:22 +0100 Subject: [PATCH 32/32] fix logic test --- resources/Dependency.json | 2 +- src/Helper/Resolve-Dependency.ps1 | 9 +++------ tests/Helper/01_Resolve-Dependency.Tests.ps1 | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/resources/Dependency.json b/resources/Dependency.json index 232341f..d6558a1 100644 --- a/resources/Dependency.json +++ b/resources/Dependency.json @@ -22,7 +22,7 @@ ] }, { - "Name": "PSGet", + "Name": "Existing", "Modules": [ "PowerShellGet" ] diff --git a/src/Helper/Resolve-Dependency.ps1 b/src/Helper/Resolve-Dependency.ps1 index 3893502..23f026c 100644 --- a/src/Helper/Resolve-Dependency.ps1 +++ b/src/Helper/Resolve-Dependency.ps1 @@ -66,19 +66,16 @@ function Resolve-Dependency { else { Write-Warning ("Could not find the dependency file: {0}" -f $DepFilePath) } - $res = @() } process { $SelectedDependency = $Dependency.Optional | Where-Object {$_.Name -match $Name} - + $res = @() foreach ($Module in $SelectedDependency.Modules) { $res += Test-Module -Name $Module } - if ($res.count -eq 0) { - return $false - } - elseif ($res -contains $false) { + # return false if there was not module at all + if (($res -contains $false) -or ($res.Count -eq 0)) { return $false } else { diff --git a/tests/Helper/01_Resolve-Dependency.Tests.ps1 b/tests/Helper/01_Resolve-Dependency.Tests.ps1 index 2c2e1f4..4d8f30e 100644 --- a/tests/Helper/01_Resolve-Dependency.Tests.ps1 +++ b/tests/Helper/01_Resolve-Dependency.Tests.ps1 @@ -44,7 +44,7 @@ Describe "Resolve-Dependency" { Context "Testing input variations" { Mock Get-ModuleBase {return "{0}\resources" -f $PWD} It "Should return true if all given dependencies exist" { - Resolve-Dependency -Name 'PSGet' | Should -Be $true + Resolve-Dependency -Name 'Existing' | Should -Be $true } It "Mixed results should return false" { Resolve-Dependency -Name 'PSGetMixed' | Should -Be $false -- 2.40.1