update pwsh style in item files

This commit is contained in:
OCram85 2022-06-13 10:06:54 +02:00
parent b302cd0b0c
commit 739d56648f
5 changed files with 70 additions and 114 deletions

View File

@ -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
} }

View File

@ -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 {}
}
} }

View File

@ -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
} }

View File

@ -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
} }

View File

@ -35,19 +35,11 @@ function Test-CredentialStoreItem {
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")] [CmdletBinding(DefaultParameterSetName = 'Private')]
[OutputType([Boolean])] [OutputType([boolean])]
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 +50,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 +78,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 +87,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 {}
}
} }