<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Getting Credentials From The Command Line</title><link>http://blogs.msdn.com/powershell/archive/2008/06/20/getting-credentials-from-the-command-line.aspx</link><description>When you use the Get-Credential cmdlet, you get a GUI dialog box to enter the credentials. This is the "Common Criteria Certified" way of handling credentials. It is also a pain in the butt at times. If you are an admin, you can alter this and request</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Getting Credentials From The Command Line</title><link>http://blogs.msdn.com/powershell/archive/2008/06/20/getting-credentials-from-the-command-line.aspx#8628227</link><pubDate>Sat, 21 Jun 2008 03:30:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8628227</guid><dc:creator>Carter Shanklin</dc:creator><description>&lt;p&gt;I ended up using this approach for a different reason: because I couldn't find a way to customize what the pop-up dialog says when you use get-credential.&lt;/p&gt;</description></item><item><title>re: Getting Credentials From The Command Line</title><link>http://blogs.msdn.com/powershell/archive/2008/06/20/getting-credentials-from-the-command-line.aspx#8628306</link><pubDate>Sat, 21 Jun 2008 03:50:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8628306</guid><dc:creator>Carter Shanklin</dc:creator><description>&lt;p&gt;On second thought I used something slightly different:&lt;/p&gt;
&lt;p&gt;echo 'Enter the password to log in: '&lt;/p&gt;
&lt;p&gt;$password = read-host -assecurestring&lt;/p&gt;
&lt;p&gt;$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $user, $password&lt;/p&gt;
&lt;p&gt;One advantage here is that it's a little less disruptive to the environment (no registry change).&lt;/p&gt;</description></item><item><title>re: Getting Credentials From The Command Line</title><link>http://blogs.msdn.com/powershell/archive/2008/06/20/getting-credentials-from-the-command-line.aspx#8628422</link><pubDate>Sat, 21 Jun 2008 04:31:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8628422</guid><dc:creator>Sean</dc:creator><description>&lt;p&gt;I've been looking for a way to create a credential for the transporter suite using a notes id. &amp;nbsp;There are no examples that I've been able to find, but the object type that's expected is a PSCredential using a Notes ID. &amp;nbsp;How would you do this?&lt;/p&gt;</description></item><item><title>re: Getting Credentials From The Command Line</title><link>http://blogs.msdn.com/powershell/archive/2008/06/20/getting-credentials-from-the-command-line.aspx#8629014</link><pubDate>Sat, 21 Jun 2008 07:04:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8629014</guid><dc:creator>Brian Reiter</dc:creator><description>&lt;p&gt;Interesting. Some time ago, I created a function Get-ConsoleCredential for just this purpose. It is useful for creating a &amp;quot;su&amp;quot; analog among other things. Here's the relevant bit from my profile.&lt;/p&gt;
&lt;p&gt;#starts a new powershell console with specified credentials, similar to su(1) on UNIX&lt;/p&gt;
&lt;p&gt;function Substitute-User( [String] $username=&amp;quot;root&amp;quot; )&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;	if( $username -eq $null )&lt;/p&gt;
&lt;p&gt;	{&lt;/p&gt;
&lt;p&gt;		#look up the built-in Administrator account using WMI. &lt;/p&gt;
&lt;p&gt;		#the built-in administrator has a SID that starts with S-1-5 and ends with -500.&lt;/p&gt;
&lt;p&gt;		$accts = get-wmiobject win32_useraccount&lt;/p&gt;
&lt;p&gt;		foreach( $acct in $accts )&lt;/p&gt;
&lt;p&gt;		{	&lt;/p&gt;
&lt;p&gt;			if( $acct.SID -match '^S-1-5-.+-500$' )&lt;/p&gt;
&lt;p&gt;			{ &lt;/p&gt;
&lt;p&gt;				$username = $acct.Caption&lt;/p&gt;
&lt;p&gt;				break&lt;/p&gt;
&lt;p&gt;			} &lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;	$credential = Get-ConsoleCredential( $username )&lt;/p&gt;
&lt;p&gt;	$startinfo = new-object Diagnostics.ProcessStartInfo&lt;/p&gt;
&lt;p&gt;	$startinfo.UseShellExecute = $false&lt;/p&gt;
&lt;p&gt;	$startinfo.FileName = &amp;quot;$pshome\powershell.exe&amp;quot;&lt;/p&gt;
&lt;p&gt;	$startinfo.UserName = $credential.UserName&lt;/p&gt;
&lt;p&gt;	$startinfo.Password = $credential.Password&lt;/p&gt;
&lt;p&gt;	$startinfo.WorkingDirectory = $pwd&lt;/p&gt;
&lt;p&gt;	trap [ComponentModel.Win32Exception]&lt;/p&gt;
&lt;p&gt;	{&lt;/p&gt;
&lt;p&gt;		if( $_.Exception.NativeErrorCode -eq 267 )&lt;/p&gt;
&lt;p&gt;		{&lt;/p&gt;
&lt;p&gt;			write-host &amp;quot;$pwd is an invalid directory for $username.&amp;quot;&lt;/p&gt;
&lt;p&gt;			write-host &amp;quot;Starting PowerShell in ${env:SystemRoot}\system32.&amp;quot;&lt;/p&gt;
&lt;p&gt;			$startinfo.WorkingDirectory = &amp;quot;${env:SystemRoot}\system32&amp;quot;&lt;/p&gt;
&lt;p&gt;			$null = [Diagnostics.Process]::Start( $startinfo )&lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;		else &lt;/p&gt;
&lt;p&gt;		{	&lt;/p&gt;
&lt;p&gt;			$_.Exception.Message&lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;		continue&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;	$null = [Diagnostics.Process]::Start( $startinfo )&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;#Generate a PSCredential object without creating a pop-up security dialog like &lt;/p&gt;
&lt;p&gt;#the built-in get-credential cmdlet.&lt;/p&gt;
&lt;p&gt;function Get-ConsoleCredential( [String] $username=$( read-host 'Username' ) )&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;	while( !($username) )	&lt;/p&gt;
&lt;p&gt;	{&lt;/p&gt;
&lt;p&gt;		$username = read-host 'Username'&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;	$passwd = read-host -asSecureString 'Password'&lt;/p&gt;
&lt;p&gt;	new-object Management.Automation.PSCredential $username, $passwd&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;# alias functions&lt;/p&gt;
&lt;p&gt;new-alias cred Get-ConsoleCredential&lt;/p&gt;
&lt;p&gt;new-alias su Substitute-User&lt;/p&gt;</description></item><item><title>re: Getting Credentials From The Command Line</title><link>http://blogs.msdn.com/powershell/archive/2008/06/20/getting-credentials-from-the-command-line.aspx#8629092</link><pubDate>Sat, 21 Jun 2008 07:23:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8629092</guid><dc:creator>Bran Reiter</dc:creator><description>&lt;p&gt;Whoops. I just realized that the Substitute-User function was hard-coded to default to a specific user account and didn't look up the local administrator account correctly. Here's the correction: &lt;/p&gt;
&lt;p&gt;#starts a new powershell console with specified credentials, similar to su(1) on UNIX&lt;/p&gt;
&lt;p&gt;function Substitute-User( [String] $username )&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;	if( !$username )&lt;/p&gt;
&lt;p&gt;	{&lt;/p&gt;
&lt;p&gt;		#look up the built-in Administrator account using WMI. &lt;/p&gt;
&lt;p&gt;		#the built-in administrator has a SID that starts with S-1-5 and ends with -500.&lt;/p&gt;
&lt;p&gt;		$accts = get-wmiobject win32_useraccount&lt;/p&gt;
&lt;p&gt;		foreach( $acct in $accts )&lt;/p&gt;
&lt;p&gt;		{	&lt;/p&gt;
&lt;p&gt;			if( $acct.SID -match '^S-1-5-.+-500$' )&lt;/p&gt;
&lt;p&gt;			{ &lt;/p&gt;
&lt;p&gt;				$username = $acct.Caption&lt;/p&gt;
&lt;p&gt;				if( $username -match &amp;quot;[^\\]+$&amp;quot; )&lt;/p&gt;
&lt;p&gt;				{	&lt;/p&gt;
&lt;p&gt;					$username = $matches[0] &lt;/p&gt;
&lt;p&gt;				}&lt;/p&gt;
&lt;p&gt;				break&lt;/p&gt;
&lt;p&gt;			} &lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;	$credential = Get-ConsoleCredential( $username )&lt;/p&gt;
&lt;p&gt;	$startinfo = new-object Diagnostics.ProcessStartInfo&lt;/p&gt;
&lt;p&gt;	$startinfo.UseShellExecute = $false&lt;/p&gt;
&lt;p&gt;	$startinfo.FileName = &amp;quot;$pshome\powershell.exe&amp;quot;&lt;/p&gt;
&lt;p&gt;	$startinfo.UserName = $credential.UserName&lt;/p&gt;
&lt;p&gt;	$startinfo.Password = $credential.Password&lt;/p&gt;
&lt;p&gt;	$startinfo.WorkingDirectory = $pwd&lt;/p&gt;
&lt;p&gt;	trap [ComponentModel.Win32Exception]&lt;/p&gt;
&lt;p&gt;	{&lt;/p&gt;
&lt;p&gt;		if( $_.Exception.NativeErrorCode -eq 267 )&lt;/p&gt;
&lt;p&gt;		{&lt;/p&gt;
&lt;p&gt;			write-host &amp;quot;$pwd is an invalid directory for $username.&amp;quot;&lt;/p&gt;
&lt;p&gt;			write-host &amp;quot;Starting PowerShell in ${env:SystemRoot}\system32.&amp;quot;&lt;/p&gt;
&lt;p&gt;			$startinfo.WorkingDirectory = &amp;quot;${env:SystemRoot}\system32&amp;quot;&lt;/p&gt;
&lt;p&gt;			$null = [Diagnostics.Process]::Start( $startinfo )&lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;		else &lt;/p&gt;
&lt;p&gt;		{	&lt;/p&gt;
&lt;p&gt;			$_.Exception.Message&lt;/p&gt;
&lt;p&gt;		}&lt;/p&gt;
&lt;p&gt;		continue&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;	$null = [Diagnostics.Process]::Start( $startinfo )&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;#Generate a PSCredential object without creating a pop-up security dialog like &lt;/p&gt;
&lt;p&gt;#the built-in get-credential cmdlet.&lt;/p&gt;
&lt;p&gt;function Get-ConsoleCredential( [String] $username=$( read-host 'Username' ) )&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;	while( !($username) )	&lt;/p&gt;
&lt;p&gt;	{&lt;/p&gt;
&lt;p&gt;		$username = read-host 'Username'&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;	$passwd = read-host -asSecureString 'Password'&lt;/p&gt;
&lt;p&gt;	new-object Management.Automation.PSCredential $username, $passwd&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;</description></item><item><title>re: Getting Credentials From The Command Line</title><link>http://blogs.msdn.com/powershell/archive/2008/06/20/getting-credentials-from-the-command-line.aspx#8636706</link><pubDate>Sun, 22 Jun 2008 08:53:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8636706</guid><dc:creator>Karl Prosser</dc:creator><description>&lt;p&gt;why don't no add a parameter to get-credential in V2 so you can do this without a registry hack. Additional i presume this is the default behaviour in PS remoting?&lt;/p&gt;</description></item><item><title>re: Getting Credentials From The Command Line</title><link>http://blogs.msdn.com/powershell/archive/2008/06/20/getting-credentials-from-the-command-line.aspx#8642095</link><pubDate>Mon, 23 Jun 2008 16:53:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8642095</guid><dc:creator>Dave Saxon</dc:creator><description>&lt;p&gt;Can I still do the following to expose the password in clear text?&lt;/p&gt;
&lt;p&gt;$cred = get-credential Admin&lt;/p&gt;
&lt;p&gt;$cred.GetNetworkCredential()&lt;/p&gt;
&lt;p&gt;We bugged this ages ago, but haven't seen a response - it'd be nice to know it's fixed in v2...&lt;/p&gt;</description></item><item><title>re: Getting Credentials From The Command Line</title><link>http://blogs.msdn.com/powershell/archive/2008/06/20/getting-credentials-from-the-command-line.aspx#8642958</link><pubDate>Mon, 23 Jun 2008 20:24:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8642958</guid><dc:creator>Jim Foster</dc:creator><description>&lt;p&gt;By the way, this DOES NOT seem to work in Graphical Windows PowerShell V2 (CTP2). It always brings up the GUI dialog.&lt;/p&gt;
&lt;p&gt;Jim&lt;/p&gt;</description></item><item><title>Interesting Links – 6/24/2008</title><link>http://blogs.msdn.com/powershell/archive/2008/06/20/getting-credentials-from-the-command-line.aspx#8647348</link><pubDate>Tue, 24 Jun 2008 17:17:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8647348</guid><dc:creator>Matt Johnson's Technical Adventures</dc:creator><description>&lt;p&gt;Ask the Directory Services Team : Custom Certificate Request in Windows Vista Microsoft Security Development&lt;/p&gt;
</description></item><item><title>re: Getting Credentials From The Command Line</title><link>http://blogs.msdn.com/powershell/archive/2008/06/20/getting-credentials-from-the-command-line.aspx#8648395</link><pubDate>Tue, 24 Jun 2008 21:50:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8648395</guid><dc:creator>PowerShellTeam</dc:creator><description>&lt;p&gt;@Sean - There are examples in the comments of instantiating a PSCredential from scratch. See if they help.&lt;/p&gt;
&lt;p&gt;@Karl - This is not meant to be a configuration option that the script decides. If it were, then the administrator is no longer in control of their Common Criteria compliance.&lt;/p&gt;
&lt;p&gt;@Dave - We're considering changing the default _formatting_ to not display the password by default, so that you don't accidentally display the password. Having access to the password is not a problem, as the GetNetworkCredential() method is designed explicitly to support the many .NET APIs that require a NetworkCredential object.&lt;/p&gt;
&lt;p&gt;--&lt;/p&gt;
&lt;p&gt;Lee Holmes [MSFT]&lt;/p&gt;
&lt;p&gt;Windows PowerShell Development&lt;/p&gt;
&lt;p&gt;Microsoft Corporation&lt;/p&gt;
</description></item><item><title>re: Getting Credentials From The Command Line</title><link>http://blogs.msdn.com/powershell/archive/2008/06/20/getting-credentials-from-the-command-line.aspx#8752152</link><pubDate>Sat, 19 Jul 2008 02:16:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8752152</guid><dc:creator>Kris</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Is it possible to execute a block (of commandlets) with a different user context. I have the user id and pwd of the privileged user but need to run just a particular block with those credentials. The script is launched with the NETWORK SERVICE.&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;</description></item><item><title>Notes Credential</title><link>http://blogs.msdn.com/powershell/archive/2008/06/20/getting-credentials-from-the-command-line.aspx#8978853</link><pubDate>Tue, 07 Oct 2008 00:49:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8978853</guid><dc:creator>Sean</dc:creator><description>&lt;p&gt;Forgot about posting the question here about getting a Notes ID. &amp;nbsp;After some trial and error I eventually had figured this out. &amp;nbsp;The following example will successfully allow the passing of a notes credential to the various Transporter Suite cmdlets without being prompted for the notes credentials:&lt;/p&gt;
&lt;p&gt;To get and store the credential for the current user:&lt;/p&gt;
&lt;p&gt;$notespw = Read-Host &amp;quot;Enter the password for the Notes ID file&amp;quot; -AsSecureString&lt;/p&gt;
&lt;p&gt;$notespw | ConvertFrom-SecureString | Set-Content $pwfile -force&lt;/p&gt;
&lt;p&gt;To retrieve the password and create the PSCredential object:&lt;/p&gt;
&lt;p&gt;$notespw = get-content $pwfile | ConvertTo-SecureString&lt;/p&gt;
&lt;p&gt;$notesid = new-object -typename system.management.automation.pscredential -argumentlist &amp;quot;-default-&amp;quot;,$notespw&lt;/p&gt;
&lt;p&gt;Example of use:&lt;/p&gt;
&lt;p&gt;Get-DominoMailbox mary@contoso.com -SourceCredential $notesid&lt;/p&gt;</description></item></channel></rss>