update
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A short one-line action-based description, e.g. 'Tests if a function is valid'
|
||||
.DESCRIPTION
|
||||
A longer description of the function, its purpose, common use cases, etc.
|
||||
.NOTES
|
||||
Information or caveats about the function e.g. 'This function is not supported in Linux'
|
||||
.LINK
|
||||
Specify a URI to a help page, this will show when Get-Help -Online is used.
|
||||
.EXAMPLE
|
||||
Test-MyTestFunction -Verbose
|
||||
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
|
||||
#>
|
||||
|
||||
function Export-ITDPasswordList {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[string]
|
||||
$PasswordList,
|
||||
|
||||
[string]
|
||||
$Destination,
|
||||
|
||||
[PSCredential]
|
||||
$Credential
|
||||
)
|
||||
|
||||
begin {
|
||||
$PasswordListSearch = Get-ITDPasswordList -PasswordList $PasswordList -Credential $Credential
|
||||
switch (@($PasswordListSearch).count) {
|
||||
{ $_ -gt 1 } {
|
||||
Write-Error -Message "More than one password list found, adjust search" -ErrorAction Stop
|
||||
}
|
||||
{ $_ -le 0} {
|
||||
Write-Error -Message "Zero password lists found, adjust search" -ErrorAction Stop
|
||||
}
|
||||
{ 1 }{
|
||||
$PasswordListId = $PasswordListSearch.PasswordListId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
$PasswordstateUrl = ("https://itdpv.nd.gov/winapi/passwords/" + $PasswordListId + "?QueryAll&PreventAuditing=true")
|
||||
$Passwords = Invoke-RestMethod -Method GET -Uri $PasswordstateUrl -Credential $Credential
|
||||
$Passwords | Export-Csv -Path $Destination
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A short one-line action-based description, e.g. 'Tests if a function is valid'
|
||||
.DESCRIPTION
|
||||
A longer description of the function, its purpose, common use cases, etc.
|
||||
.NOTES
|
||||
Information or caveats about the function e.g. 'This function is not supported in Linux'
|
||||
.LINK
|
||||
Specify a URI to a help page, this will show when Get-Help -Online is used.
|
||||
.EXAMPLE
|
||||
Test-MyTestFunction -Verbose
|
||||
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
|
||||
#>
|
||||
|
||||
|
||||
|
||||
function Find-ITDPassword {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[string]
|
||||
$Title,
|
||||
|
||||
[string]
|
||||
$UserName,
|
||||
|
||||
[PSCredential]
|
||||
$Credential
|
||||
)
|
||||
|
||||
begin {
|
||||
|
||||
}
|
||||
|
||||
process {
|
||||
$Uri = 'https://itdpv.nd.gov/winapi/searchpasswords/?'
|
||||
|
||||
If ($Title) { $Uri += 'title=' + $Title + '&' }
|
||||
If ($UserName) { $Uri += 'username=' + "$UserName" + '&' }
|
||||
$Uri = $Uri.TrimEnd('&')
|
||||
|
||||
$InvokeResult = Invoke-RestMethod -Method Get -Uri $Uri -Credential $Credential -ErrorAction SilentlyContinue
|
||||
|
||||
Write-Output $InvokeResult
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Retrive password from ITD Passwordstate
|
||||
.DESCRIPTION
|
||||
A longer description of the function, its purpose, common use cases, etc.
|
||||
.NOTES
|
||||
Information or caveats about the function e.g. 'This function is not supported in Linux'
|
||||
.LINK
|
||||
Specify a URI to a help page, this will show when Get-Help -Online is used.
|
||||
.EXAMPLE
|
||||
Test-MyTestFunction -VerboseZM
|
||||
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
|
||||
#>
|
||||
|
||||
function Get-ITDPassword {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[string]
|
||||
$Title,
|
||||
|
||||
[string]
|
||||
$UserName,
|
||||
|
||||
[PSCredential]
|
||||
$Credential,
|
||||
|
||||
[Parameter(ParameterSetName = "ToClipboard")]
|
||||
[switch]
|
||||
$ToClipboard,
|
||||
|
||||
[switch]
|
||||
$FullRecord
|
||||
)
|
||||
|
||||
begin {
|
||||
|
||||
}
|
||||
|
||||
process {
|
||||
$Uri = 'https://itdpv.nd.gov/winapi/searchpasswords/?'
|
||||
|
||||
If ($PSBoundParameters.ContainsKey('Title')) {
|
||||
$Uri += 'title=' + $Title + '&'
|
||||
}
|
||||
If ($PSBoundParameters.ContainsKey('Username')) {
|
||||
$Uri += 'username=' + "$UserName" + '&'
|
||||
}
|
||||
|
||||
$Uri = $Uri.TrimEnd('&')
|
||||
|
||||
$InvokeRestMethodParams = @{
|
||||
Method = 'Get';
|
||||
Uri = $Uri;
|
||||
SkipHttpErrorCheck = $true;
|
||||
}
|
||||
If ($PSBoundParameters.ContainsKey('Credential')) {
|
||||
$InvokeRestMethodParams += @{Credential = $Credential }
|
||||
}
|
||||
Else {
|
||||
$InvokeRestMethodParams += @{UseDefaultCredentials = $true }
|
||||
}
|
||||
$InvokeResult = Invoke-RestMethod @InvokeRestMethodParams
|
||||
|
||||
switch ($InvokeResult) {
|
||||
{ $_ -eq $null } {
|
||||
Write-Error -Message "No password found"
|
||||
Break
|
||||
}
|
||||
{ $_ | Get-Member -MemberType Properties | Where-Object { $_.Name -eq 'errors' } } {
|
||||
If ($InvokeResult.errors.message -eq 'Not found') {
|
||||
Write-Warning -Message "Search for Password records return zero results"
|
||||
}
|
||||
}
|
||||
Default {
|
||||
$OutResult = $InvokeResult | Select-Object PasswordListID, PasswordList, PasswordID, Title, Description, UserName, @{n = 'SecurePassword'; e = { $_.Password | ConvertTo-SecureString -AsPlainText -Force } }, AccountTypeId, AccountType
|
||||
|
||||
If (@($OutResult).count -eq 1) {
|
||||
If ($PSCmdlet.ParameterSetName -eq "ToClipboard") {
|
||||
$InvokeResult.Password | Set-Clipboard
|
||||
}
|
||||
If ($FullRecord) {
|
||||
Write-Output $OutResult
|
||||
}
|
||||
Else {
|
||||
$OutCred = New-Object System.Management.Automation.PSCredential($OutResult.UserName, $OutResult.SecurePassword)
|
||||
Write-Output $OutCred
|
||||
}
|
||||
}
|
||||
Else {
|
||||
Write-Output $OutResult
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A short one-line action-based description, e.g. 'Tests if a function is valid'
|
||||
.DESCRIPTION
|
||||
A longer description of the function, its purpose, common use cases, etc.
|
||||
.NOTES
|
||||
Information or caveats about the function e.g. 'This function is not supported in Linux'
|
||||
.LINK
|
||||
Specify a URI to a help page, this will show when Get-Help -Online is used.
|
||||
.EXAMPLE
|
||||
Test-MyTestFunction -Verbose
|
||||
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
|
||||
#>
|
||||
|
||||
function Get-ITDPasswordAccountTypeId {
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[ValidateSet('VMware ESXi','Active Directory','HP iLO')]
|
||||
[string]
|
||||
$AccountType
|
||||
)
|
||||
Begin {
|
||||
|
||||
}
|
||||
Process {
|
||||
switch ($AccountType) {
|
||||
'VMware ESXi' { $AccountTypeId = 34 }
|
||||
'Active Directory' { $AccountTypeId = 70 }
|
||||
'HP iLO' { $AccountTypeId = 1084 }
|
||||
}
|
||||
}
|
||||
End {
|
||||
return $AccountTypeId
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A short one-line action-based description, e.g. 'Tests if a function is valid'
|
||||
.DESCRIPTION
|
||||
A longer description of the function, its purpose, common use cases, etc.
|
||||
.NOTES
|
||||
Information or caveats about the function e.g. 'This function is not supported in Linux'
|
||||
.LINK
|
||||
Specify a URI to a help page, this will show when Get-Help -Online is used.
|
||||
.EXAMPLE
|
||||
Test-MyTestFunction -Verbose
|
||||
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
|
||||
#>
|
||||
|
||||
function Get-ITDPasswordList {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]
|
||||
$PasswordList,
|
||||
|
||||
[PSCredential]
|
||||
$Credential
|
||||
)
|
||||
|
||||
begin {
|
||||
|
||||
}
|
||||
|
||||
process {
|
||||
$Uri = "https://itdpv.nd.gov/winapi/searchpasswordlists/?"
|
||||
|
||||
If ($PasswordList) { $Uri += "PasswordList=$PasswordList" }
|
||||
$Uri = $Uri.TrimEnd('&')
|
||||
|
||||
$InvokeRestMethodParams = @{
|
||||
Method = 'Get';
|
||||
Uri = $Uri;
|
||||
}
|
||||
If ($PSBoundParameters.ContainsKey('Credential')){
|
||||
$InvokeRestMethodParams += @{Credential = $Credential}
|
||||
} Else {
|
||||
$InvokeRestMethodParams += @{UseDefaultCredentials = $true}
|
||||
}
|
||||
|
||||
$reply = Invoke-RestMethod -Method Get -Uri $Uri -Credential $Credential
|
||||
If ($PasswordList) {
|
||||
$result = $reply | Where-Object PasswordList -EQ $PasswordList
|
||||
}
|
||||
Else {
|
||||
$result = $reply
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
Write-Output $result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A short one-line action-based description, e.g. 'Tests if a function is valid'
|
||||
.DESCRIPTION
|
||||
A longer description of the function, its purpose, common use cases, etc.
|
||||
.NOTES
|
||||
Information or caveats about the function e.g. 'This function is not supported in Linux'
|
||||
.LINK
|
||||
Specify a URI to a help page, this will show when Get-Help -Online is used.
|
||||
.EXAMPLE
|
||||
Test-MyTestFunction -Verbose
|
||||
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
|
||||
#>
|
||||
|
||||
function New-ITDPassword {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory = $true)]
|
||||
#[ValidateSet('Office365', 'VMware_Systems', 'CSRC', 'Shared Linux Password List', 'Peoplesoft Share PW', 'Cohesity', 'VDI')]
|
||||
[string]
|
||||
$PasswordList,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]
|
||||
$Title,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]
|
||||
$Description,
|
||||
|
||||
[string]
|
||||
$AccountType,
|
||||
|
||||
[Parameter(ParameterSetName = 'GeneratePassword', Mandatory)]
|
||||
[string]
|
||||
$UserName,
|
||||
|
||||
[string]
|
||||
$Notes,
|
||||
|
||||
[Parameter(ParameterSetName = 'EnterCredential')]
|
||||
[PSCredential]
|
||||
$CredentialToSave,
|
||||
|
||||
[PSCredential]
|
||||
$Credential
|
||||
)
|
||||
|
||||
begin {
|
||||
$PSList = Get-ITDPasswordList -PasswordList $PasswordList -Credential $Credential
|
||||
If (@($PSList).count -gt 1) { Write-Error "More than one PasswordList match." -ErrorAction Stop }
|
||||
}
|
||||
|
||||
process {
|
||||
switch ($PSCmdlet.ParameterSetName) {
|
||||
'EnterCredential' {
|
||||
Write-Verbose -Message "EnterCredential"
|
||||
$Username = $CredentialToSave.UserName
|
||||
$Password = $CredentialToSave.GetNetworkCredential().Password
|
||||
}
|
||||
'GeneratePassword' {
|
||||
Write-Verbose -Message "GeneratePassword"
|
||||
$Password = New-ITDRandomPassword -Credential $Credential
|
||||
}
|
||||
}
|
||||
|
||||
Write-Verbose -Message "Create password object"
|
||||
$PasswordObj = [PSCustomObject]@{
|
||||
'PasswordListID' = $PSList.PasswordListID;
|
||||
'Title' = $Title;
|
||||
'Description' = $Description;
|
||||
'UserName' = $Username;
|
||||
'Password' = $Password;
|
||||
'Notes' = ("Auto-generated by " + $Credential.UserName + " @ " + (Get-Date -UFormat "%Y/%m/%d %H:%M:%S"));
|
||||
}
|
||||
|
||||
switch ($PSBoundParameters.Keys) {
|
||||
Notes {
|
||||
$PasswordObj.Notes += ("`n" + $Notes)
|
||||
}
|
||||
}
|
||||
|
||||
If ($AccountType) {
|
||||
$AccountTypeId = Get-ITDPasswordAccountTypeId -AccountType $AccountType
|
||||
$PasswordObj | Add-Member -Name AccountTypeId -MemberType NoteProperty -Value $AccountTypeId
|
||||
}
|
||||
else {
|
||||
$PasswordObj | Add-Member -Name AccountTypeId -MemberType NoteProperty -Value 0
|
||||
}
|
||||
|
||||
$InvokeRestMethodParams = @{
|
||||
Method = 'Post';
|
||||
Uri = 'https://itdpv.nd.gov/winapi/passwords';
|
||||
ContentType = 'application/json';
|
||||
Body = ($PasswordObj | ConvertTo-Json);
|
||||
}
|
||||
|
||||
If ($PSBoundParameters.ContainsKey('Credential')){
|
||||
$InvokeRestMethodParams += @{Credential = $Credential}
|
||||
} Else {
|
||||
$InvokeRestMethodParams += @{UseDefaultCredentials = $true}
|
||||
}
|
||||
|
||||
Write-Verbose -Message "Invoke Passwordstate record creation"
|
||||
$InvokeResult = Invoke-RestMethod @InvokeRestMethodParams
|
||||
|
||||
#Write-Verbose -Message "Store Invoke result in variable"
|
||||
#$OutResult = $InvokeResult | Select-Object PasswordList, Title, Description, UserName, @{n = 'SecurePassword'; e = { $_.Password | ConvertTo-SecureString -AsPlainText -Force } }, AccountTypeId, AccountType
|
||||
<# storing the returned PSCredential object (see code above) sometimes causes the following error:
|
||||
[error] Exception calling ".ctor" with "2" argument(s): "Cannot process argument because the value of argument "password" is null. Change the value of argument "password" to a non-null value."
|
||||
Running Get-ITDPassword does not cause the error, unsure of cause. Unsure of the reason why, not looking into it further
|
||||
#>
|
||||
|
||||
|
||||
Write-Verbose -Message "Retrieve new password"
|
||||
$GetITDPasswordParams = @{
|
||||
Title = $Title;
|
||||
UserName = $UserName;
|
||||
}
|
||||
If ($PSBoundParameters.ContainsKey('Credential')){
|
||||
$GetITDPasswordParams += @{Credential = $Credential}
|
||||
} Else {
|
||||
$GetITDPasswordParams += @{UseDefaultCredentials = $true}
|
||||
}
|
||||
$OutResult = Get-ITDPassword @GetITDPasswordParams
|
||||
|
||||
#Write-Verbose -Message "put OutResult in credential variable and return"
|
||||
#$OutCred = New-Object System.Management.Automation.PSCredential($OutResult.UserName, $OutResult.SecurePassword)
|
||||
}
|
||||
|
||||
end {
|
||||
Write-Output $OutResult
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A short one-line action-based description, e.g. 'Tests if a function is valid'
|
||||
.DESCRIPTION
|
||||
A longer description of the function, its purpose, common use cases, etc.
|
||||
.NOTES
|
||||
Information or caveats about the function e.g. 'This function is not supported in Linux'
|
||||
.LINK
|
||||
Specify a URI to a help page, this will show when Get-Help -Online is used.
|
||||
.EXAMPLE
|
||||
Test-MyTestFunction -Verbose
|
||||
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
|
||||
#>
|
||||
|
||||
|
||||
|
||||
function New-ITDRandomPassword {
|
||||
[CmdletBinding()]
|
||||
Param
|
||||
(
|
||||
[PSCredential]
|
||||
$Credential
|
||||
)
|
||||
|
||||
Begin {
|
||||
}
|
||||
Process {
|
||||
$InvokeRestMethodParams = @{
|
||||
Method = 'Get';
|
||||
Uri = 'https://itdpv.nd.gov/winapi/generatepassword/?PasswordGeneratorID=2';
|
||||
ErrorAction = 'Stop';
|
||||
}
|
||||
|
||||
If ($PSBoundParameters.ContainsKey('Credential')){
|
||||
$InvokeRestMethodParams += @{Credential = $Credential}
|
||||
} Else {
|
||||
$InvokeRestMethodParams += @{UseDefaultCredentials = $true}
|
||||
}
|
||||
|
||||
$NewPassword = (Invoke-RestMethod @InvokeRestMethodParams).Password
|
||||
$Length = $NewPassword.Length
|
||||
While ($null -ne $NewPassword -and $Length -lt 20) {
|
||||
$NewPassword2 = (Invoke-RestMethod @InvokeRestMethodParams).Password
|
||||
$NewPassword += $NewPassword2.split('-')[1]
|
||||
$Length = $NewPassword.Length
|
||||
}
|
||||
If (!($NewPassword -match '\d')) { $NewPassword += (Get-Random -Minimum 0 -Maximum 9) }
|
||||
}
|
||||
End {
|
||||
return $NewPassword
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A short one-line action-based description, e.g. 'Tests if a function is valid'
|
||||
.DESCRIPTION
|
||||
A longer description of the function, its purpose, common use cases, etc.
|
||||
.NOTES
|
||||
Information or caveats about the function e.g. 'This function is not supported in Linux'
|
||||
.LINK
|
||||
Specify a URI to a help page, this will show when Get-Help -Online is used.
|
||||
.EXAMPLE
|
||||
Test-MyTestFunction -Verbose
|
||||
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
|
||||
#>
|
||||
|
||||
function Remove-ITDPassword {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0, ParameterSetName = "Title")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$Title,
|
||||
|
||||
[switch]
|
||||
$Force,
|
||||
|
||||
[PSCredential]
|
||||
$Credential
|
||||
)
|
||||
|
||||
begin {
|
||||
|
||||
}
|
||||
|
||||
process {
|
||||
# Find the passwords
|
||||
$GetITDPasswordParams = @{
|
||||
Title = $Title;
|
||||
}
|
||||
If ($PSBoundParameters.ContainsKey('Credential')) {
|
||||
$InvokeRestMethodParams += @{Credential = $Credential }
|
||||
}
|
||||
Else {
|
||||
$InvokeRestMethodParams += @{UseDefaultCredentials = $true }
|
||||
}
|
||||
|
||||
$ExistingRecords = Get-ITDPassword @GetITDPasswordParams
|
||||
|
||||
switch ($ExistingRecords.count) {
|
||||
{ [int]0 } {
|
||||
Write-Warning -Message "Title $Title not found."
|
||||
}
|
||||
{ $_ -ge 1 } {
|
||||
If (-not $Force) {
|
||||
$VerifyString = ( ([string]@($ExistingRecords).Count) + " record(s) have been found, all will be removed.")
|
||||
$question = 'Are you sure you want to proceed?'
|
||||
|
||||
$choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription]
|
||||
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&Yes'))
|
||||
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&No'))
|
||||
|
||||
$decision = $Host.UI.PromptForChoice($VerifyString, $question, $choices, 1)
|
||||
}
|
||||
if ($decision -eq 0 -or $Force -eq $true) {
|
||||
ForEach ($ExistingRecord in $ExistingRecords) {
|
||||
$Uri = ("https://itdpv.nd.gov/winapi/passwords/" + $ExistingRecord.PasswordID + "?MoveToRecycleBin=True")
|
||||
|
||||
$InvokeRestMethodParams = @{
|
||||
Method = 'Delete';
|
||||
Uri = $Uri;
|
||||
ContentType = 'application/json';
|
||||
}
|
||||
If ($PSBoundParameters.ContainsKey('Credential')) {
|
||||
$InvokeRestMethodParams += @{Credential = $Credential }
|
||||
}
|
||||
Else {
|
||||
$InvokeRestMethodParams += @{UseDefaultCredentials = $true }
|
||||
}
|
||||
|
||||
Invoke-RestMethod @InvokeRestMethodParams
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
A short one-line action-based description, e.g. 'Tests if a function is valid'
|
||||
.DESCRIPTION
|
||||
A longer description of the function, its purpose, common use cases, etc.
|
||||
.NOTES
|
||||
Information or caveats about the function e.g. 'This function is not supported in Linux'
|
||||
.LINK
|
||||
Specify a URI to a help page, this will show when Get-Help -Online is used.
|
||||
.EXAMPLE
|
||||
Test-MyTestFunction -Verbose
|
||||
Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
|
||||
#>
|
||||
|
||||
|
||||
|
||||
function Update-ITDPassword {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0, ParameterSetName = "Id")]
|
||||
[ValidateRange(1, [UInt32]::MaxValue)]
|
||||
[Int]$Id,
|
||||
|
||||
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0, ParameterSetName = "Title")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$Title,
|
||||
|
||||
[String]
|
||||
$Notes,
|
||||
|
||||
[switch]
|
||||
$AppendNotes,
|
||||
|
||||
[PSCredential]
|
||||
$Credential,
|
||||
|
||||
[switch]
|
||||
$Force,
|
||||
|
||||
[switch]
|
||||
$All
|
||||
)
|
||||
|
||||
begin {
|
||||
|
||||
}
|
||||
|
||||
process {
|
||||
$GetITDPasswordParams = @{
|
||||
Title = $Title;
|
||||
}
|
||||
If ($PSBoundParameters.ContainsKey('Credential')) {
|
||||
$InvokeRestMethodParams += @{Credential = $Credential }
|
||||
}
|
||||
Else {
|
||||
$InvokeRestMethodParams += @{UseDefaultCredentials = $true }
|
||||
}
|
||||
|
||||
$ExistingRecords = Get-ITDPassword @GetITDPasswordParams
|
||||
|
||||
If (-not $Force) {
|
||||
$title = ( ([string]@($ExistingRecords).Count) + " record(s) have been found, all will be modified.")
|
||||
$question = 'Are you sure you want to proceed?'
|
||||
|
||||
$choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription]
|
||||
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&Yes'))
|
||||
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&No'))
|
||||
|
||||
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
|
||||
}
|
||||
|
||||
if ($Force -eq $true -or $decision -eq 0) {
|
||||
ForEach ($ExistingRecord in $ExistingRecords) {
|
||||
|
||||
$PasswordObj = @{
|
||||
'PasswordID' = $ExistingRecord.PasswordID
|
||||
}
|
||||
|
||||
switch ($PSBoundParameters.Keys) {
|
||||
'Notes' {
|
||||
if ($PSBoundParameters.AppendNotes) {
|
||||
$PasswordObj.Notes = $ExistingRecord.Notes + "<div> </div>$($PSBoundParameters.Notes)"
|
||||
}
|
||||
else {
|
||||
$PasswordObj.Notes = $PSBoundParameters.Notes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$InvokeRestMethodParams = @{
|
||||
Method = 'Put';
|
||||
Uri = 'https://itdpv.nd.gov/winapi/passwords';
|
||||
ContentType = 'application/json';
|
||||
Body = ($PasswordObj | ConvertTo-Json);
|
||||
}
|
||||
If ($PSBoundParameters.ContainsKey('Credential')) {
|
||||
$InvokeRestMethodParams += @{Credential = $Credential }
|
||||
}
|
||||
Else {
|
||||
$InvokeRestMethodParams += @{UseDefaultCredentials = $true }
|
||||
}
|
||||
|
||||
$InvokeRestMethodParams.Body
|
||||
|
||||
Invoke-RestMethod @InvokeRestMethodParams
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user