Click here to Skip to main content
15,881,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Where I can find Microsoft.PowerShell.Security.Activities. please check the following URL.
http://msdn.microsoft.com/en-us/library/microsoft.powershell.security.activities.converttosecurestring(v=vs.85).aspx[^]

I wish to use ConvertToSecureString method, But I am unable to add above namespace.

Any help would be appreciated.

Thanks
Sebastian
Posted
Updated 15-May-12 19:36pm
v7
Comments
Jim Jos 15-May-12 3:16am    
Please tell me how are you trying to use it? You are trying to write a cmdlet or a host application?
Sebastian T Xavier 15-May-12 5:22am    
I am trying to use below code...
------------------------------------------------------------------
String username = "xxx";
String password = "xxx";
SecureString ss = ConvertToSecureString(password);
PSCredential creds = new PSCredential(username, ss);
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri(liveIdconnectionUri), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", creds);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
----------------------------------------------------------------------
But I get the following error

----------------------------------------------------------------------
The name 'ConvertToSecureString' does not exist in the current context
----------------------------------------------------------------------

I thought I need to refer corresponding namespace, that's why.

Regards
Sebastian

1 solution

Itz because ConvertToSecureString is not .NET class library, but itz PowerShell script. Just to give the background, Microsoft Windows PowerShell is a command-line shell and scripting tool based on the Microsoft .NET Framework. It is designed for system administrators, engineers and developers to control and automate the administration of Windows and applications

Refer Microsoft page at http://technet.microsoft.com/en-us/library/dd315356.aspx[^]
 
Share this answer
 
Comments
Sebastian T Xavier 19-Jun-12 4:03am    
Hi,

Thanks for reply. I have tried the following code...

private SecureString ConvertToSecureString(string value)
{
SecureString ret = new SecureString();
foreach (char c in value)
{
ret.AppendChar(c);
}
ret.MakeReadOnly();
return ret;
}

It worked without any build errors But threw an exception.

Connecting to remote server failed with the following error message : The WinRM client cannot process the request. The authentication mechanism requested by the client is not supported by the server or unencrypted traffic is disabled in the service configuration. Verify the unencrypted traffic setting in the service configuration or specify one of the authentication mechanisms supported by the server. To use Kerberos, specify the computer name as the remote destination. Also verify that the client computer and the destination computer are joined to a domain. To use Basic, specify the computer name as the remote destination, specify Basic authentication and provide user name and password. Possible authentication mechanisms reported by server: Basic For more information, see the about_Remote_Troubleshooting Help topic.

If you can further help me on this, that would be great.

Regards
Sebastian

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900