Functions/Add-HetznerCloudSshKey.ps1
function Add-HetznerCloudSshKey { [CmdletBinding(SupportsShouldProcess, ConfirmImpact='Low')] param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $Name , [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $PublicKey ) begin { if (-not $PSBoundParameters.ContainsKey('Confirm')) { $ConfirmPreference = $PSCmdlet.SessionState.PSVariable.GetValue('ConfirmPreference') } if (-not $PSBoundParameters.ContainsKey('WhatIf')) { $WhatIfPreference = $PSCmdlet.SessionState.PSVariable.GetValue('WhatIfPreference') } } process { if ($Force -or $PSCmdlet.ShouldProcess("Add SSH public key with name '$Name'?")) { Invoke-HetznerCloudApi -Api 'ssh_keys' -Method 'Post' -Payload @{ name = $Name public_key = $PublicKey } } } } |