Link to home
Start Free TrialLog in
Avatar of Sybux
SybuxFlag for Switzerland

asked on

How to use Encrypted password with Exchange Web Service

Hi,

I'm trying to connect to Exchange Web Service Like this :

$Password = ConvertTo-SecureString -string $Encrypted
$exchService = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($exchVersion) #connects to the Exchange service
$Credentials = new-object Microsoft.Exchange.WebServices.Data.WebCredentials("username", $Password,"domain")
$exchService.Credentials = $Credentials

Open in new window


The problem is that Exchange Web Service failed to connect as I soon I try to read email I got a 401 Unauthorizied error.
If I type my password in place of "$Password" it's working fine.

Does any1 got an idea or a different approch for using encrypted password in this cmd-let ?

Thx in advance
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

$Password = ConvertTo-SecureString -string $Encrypted
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Don't you mean?

$Encrypted = ConvertTo-SecureString -string $Password

$exchService = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($exchVersion) #connects to the Exchange service
$Credentials = new-object Microsoft.Exchange.WebServices.Data.WebCredentials("username", $Encrypted,"domain")
$exchService.Credentials = $Credentials

Open in new window

Avatar of Sybux

ASKER

Oops yes you're right, I've just copy/past the wrong line. Sorry. My code is like you said
ASKER CERTIFIED SOLUTION
Avatar of Sybux
Sybux
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sybux

ASKER

New way to resolve the problem