header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Password as CommandLine parameter
Last Post 23 Nov 2009 07:05 AM by ramz_g. 6 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
ramz_gUser is Offline
New Member
New Member
Posts:9
Avatar

--
06 Nov 2009 10:21 PM
    Hi,
    I'm trying to write a cmdlet that takes the user name and password as input and authenticates a user. Is there a way in which I can show only *'s or #'s instead of showing the characters in the password? I tried using SecureString object but that does not work when the password is specified as a command line parameter. Pls suggest other ways..

    Thanks,
    ramz_g
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    07 Nov 2009 01:54 PM
    You can prompt the user for his credentials using Get-Credential and get access to username+password (in plain text) so you can pass it along:


    $creds = Get-Credential

    # get the user name
    $creds.GetNetworkCredential().UserName

    # get the user password
    $creds.GetNetworkCredential().Password

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    ramz_gUser is Offline
    New Member
    New Member
    Posts:9
    Avatar

    --
    11 Nov 2009 09:37 PM
    Hi Shay,
    Thanks a lot for your reply.. I am a beginner to powershell and I was just wondering if the user can be prompted for his credentials only when a specific condition occurs... Consider a cmdlet "copy-myfile" that copies a file from one location to another... I would want to prompt the user for the credentials only when he tries to copy a file into another computer on the network. Could you pls tell me how this can be achieved?

    Thanks,
    ramz_g
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    12 Nov 2009 01:53 AM
    You can create a condition where the destination is name starts with "\\", for example:

    function copy-myfile{
    param($path,$destination)

    if($destination.startsWith("\\")){
    "user is trying to copy to remote location, prompt for credentials..."
    } else{
    ...
    }
    }

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    ramz_gUser is Offline
    New Member
    New Member
    Posts:9
    Avatar

    --
    15 Nov 2009 10:26 PM
    Hi Shay,

    Thanks for the reply... So every thing can be done only using powershell scripts? I was wondering if this can be achieved using C# code. I'm using C# to create custom cmdlets and I'm hunting for the way in which I can prompt for parameters only when required. Is this possible in C# code?

    Thanks,
    ramz_g
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    16 Nov 2009 02:20 AM
    Sorry, I'm not a dev guy.

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    ramz_gUser is Offline
    New Member
    New Member
    Posts:9
    Avatar

    --
    23 Nov 2009 07:05 AM
    Oh okay.. Thanks for your help anyways... :-)
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer