0

I am developing a windows 8.1 store app and in that i want to get the GAL and add the GAL by using power shell script. When i tried to add the referance to System.Security.SecurityString it is giving an errors like follows.. I am trying to authenticate to with my office365 admin details but it is giving an error while building the app.

'System.Management.Automation.PSCredential' does not contain a constructor that takes 2 arguments

But it contains a constructor with two arguments , The same code works well when i build a windows forms application. What will be the wrong with windows 8.1 app?

 System.Uri psURL = new Uri("https://ps.outlook.com/powershell/");
  System.Security.SecureString securePassword1 = safeString("test");
  System.Management.Automation.PSCredential creds1 = new System.Management.Automation.PSCredential("test", securePassword1);

Questions

1) Is System.Security.SecurityString is compatible with windows 8.1 app or this error coming from PSCredential why because when i removed the securestring referance the PSCredential error not happening but getting securestring error missing like that?

2) Is there any alternative method to connect to powershell without secure string by c# code?

1 Answers1

0

System.Security.SecureString is part of the .NET Framework.

It is not visible in your example code how you convert your string to secure string:

$secure_string_pwd = convertto-securestring "P@ssW0rD!" -asplaintext -force
$username = "username@yourdomain.com"
$cred = New-Object System.Management.Automation.PSCredential $username, $secure_string_pwd

Try to connect to O365 with following code:

Import-Module MSOnline
$O365Cred = Get-Credential
$O365Session = New-PSSession –ConfigurationName Microsoft.Exchange 
     -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred 
     -Authentication Basic -AllowRedirection
Import-PSSession $O365Session
Connect-MsolService –Credential $O365Cred

You might also find this article interesting - the example code is taken from there...

Peter Schneider
  • 2,879
  • 1
  • 14
  • 17
  • I checked your example and it works well as powershell script. But i need this in C# code. Any help on this? – user5224152 Aug 28 '15 at 16:49
  • You should be more specific - Web or Desktop application? In the meantime you might find a solution [here](https://github.com/OfficeDev/O365API-PopulateSampleData) – Peter Schneider Aug 28 '15 at 21:15
  • Desktop application i am developing. I saw you link but it is only have contacts , mail and events but i need GAL ( Global Address List ) as well thats why i am trying to connect using powershell. – user5224152 Aug 29 '15 at 14:33