mirror of
https://github.com/js0ny/dotfiles.git
synced 2025-12-21 08:43:00 +00:00
🪟: Add pathlib, PowerShell Password Script
This commit is contained in:
parent
684f694d23
commit
1a0f4a01a4
3 changed files with 81 additions and 29 deletions
33
powershell/bw.ps1
Normal file
33
powershell/bw.ps1
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
function Get-Password {
|
||||
param (
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Name,
|
||||
[Boolean]$Hidden = $true
|
||||
)
|
||||
$result = (bw list items --search $Name | ConvertFrom-Json).login | Select-Object -Property username, password
|
||||
if ($result.Length -eq 0) {
|
||||
Write-Host -ForegroundColor Red "No password found"
|
||||
return
|
||||
}
|
||||
elseif ($result.Length -gt 1) {
|
||||
Write-Host -ForegroundColor Red "More than one password found, please specify"
|
||||
$counter = 0
|
||||
foreach ($username in $result.username) {
|
||||
Write-Host "["$counter "]" $username
|
||||
$counter++
|
||||
}
|
||||
$selector = Read-Host -MaskInput "Select the username"
|
||||
if ($result[$selector] -eq "") {
|
||||
Write-Host -ForegroundColor Red "Invalid selection"
|
||||
return
|
||||
}
|
||||
$result = $result[$selector]
|
||||
}
|
||||
if ($Hidden) {
|
||||
Write-Host -ForegroundColor Green "Password copied to clipboard"
|
||||
Set-Clipboard -Value $result.password
|
||||
} else {
|
||||
Write-Host $result
|
||||
}
|
||||
return $result
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue