Multiple logins for a single credential.

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of ravilobo ravilobo 7 months, 1 week ago.

  • Author
    Posts
  • #55302
    Profile photo of ravilobo
    ravilobo
    Participant

    I have a need for storing multiple logins/passwords in a single credential object. Some time ago, I received a PowerShell Tip, which said it is possible. But I have lost that mail.

    Here's the crude way, I'm using:

    $senduser1 = "User1"
    $password1 = "Pwd1"

    $senduser2 = "User2"
    $password2 = "Pwd2"

    $PWord11 = ConvertTo-SecureString –String $password1 –AsPlainText -Force
    $PWord22 = ConvertTo-SecureString –String $password2 –AsPlainText -Force

    $Credz = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $senduser1, $PWord11
    $Credz| where {$_.UserName -like 'User1'}

    $Credz = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $senduser2, $PWord22
    $Credz| where {$_.UserName -like 'User2'}

    Is there a better way to do this?

    • This topic was modified 7 months, 1 week ago by Profile photo of ravilobo ravilobo.
  • #55304
    Profile photo of Sam Boutros
    Sam Boutros
    Participant

    Yes, see this post and PS function. And as an added benefit, you don't have to put clear text passwords in script..

    You can have an array of PS Credential objects like:

    $Creds = @() # Declare an array
    
    $Creds += Get-SBCredential 'domain1\MyADAdmin1'
    $Creds += Get-SBCredential 'domain2\MyADAdmin1'
    $Creds += Get-SBCredential 'domain1\MyADAdmin2'
    
    $Creds # Show credentials
    
    # Example using the credentials:
    Disable-ADAccount -Identity 'Someone' -Server 'MyDomainController1' -Credential ( $Creds | where { $_.UserName -eq 'domain2\MyADAdmin1' } )
    
    • This reply was modified 7 months, 1 week ago by Profile photo of Sam Boutros Sam Boutros.
    • This reply was modified 7 months, 1 week ago by Profile photo of Sam Boutros Sam Boutros.
  • #55308
    Profile photo of ravilobo
    ravilobo
    Participant

    Thank you Sam.

You must be logged in to reply to this topic.