ramz_g
 New Member Posts:9

 |
| 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 Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 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_g
 New Member Posts:9

 |
| 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 Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 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_g
 New Member Posts:9

 |
| 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 Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
|
ramz_g
 New Member Posts:9

 |
| 23 Nov 2009 07:05 AM |
|
Oh okay.. Thanks for your help anyways... :-) |
|
|
|
|