psRemoting - System.Management.Automation.PSCredential

I’m trying to create a dashboard for all domain controllers with a button to allow me to jump into a pssession. I’m pulling a bunch of different creds for the many different environments. I’m almost there but I’m stuck at passing the PScredentials as an object. Is there another way to call -credentials and not pass it as a string like I’m doing below?

New-UDGrid -Title "Domain Controllers" -Headers $params -Properties $params -PageSize 200 -Endpoint {
    $ListofDomainControllers | ForEach-Object {
        $selectcredential = if ($_.domain -eq "xxxxxxxxx") {
            $xxxxxxxxx
        }
        elseif ($_.domain -eq "xxxxxxxxx") {
            $xxxxxxxxx
        }

        [PSCustomObject]@{
            Icon            = New-UDIcon -Icon check_circle
            Name            = $_.name
            IPv4Address     = $_.Ipv4Address
            Domain          = $_.Domain
            OperatingSystem = $_.OperatingSystem
            Connect         = New-UDButton -Text "Connect" -BackgroundColor "#4CAF50"  -OnClick { 
                Show-UDToast -Message ("Trying to connect to: $($_.hostname) ")
                Start-Process powershell -arg "-noexit -command ""Enter-PsSession $($_.hostname) -credential $($xxxxxxxxx) """
            }
        }


image

Hi Dennis,

have a look at the PowerShell module CredentialManager.
This one allow you to use the Windows Credential Store to keep your credentials in a safe place.
But what is more important for you, the module allows you to store them using a ‘Target’ which is just a plain simple name you give to the stored credential.
Since this is just plain text you can simply pass around in your forms and fetch the credential on the server once you push your Connect button.

Success,

Rudy

1 Like

+1 for Credential Manager, i use it in my dashboards.

To install:

Install-Module CredentialManager

To store a credential:

Get-Credential -Message "Optional explanation goes here" | New-StoredCredential -Target MyAwesomeCreds -Persist Enterprise

To get them back to a PSCredential Object:

My-Function -Credential (Get-StoredCredential -Target MyAwesomeCreds)

NOTE: Credential Manager interacts with the windows credential store, meaning you must store credentials as the same user the dashboard runs as. In IIS, this can be configured in the application pool to run as the same user, and you’ll need the advanced option ’ enable profile load = TRUE