locked
Have anyone know how to fix the get-mailbox credential issue? RRS feed

  • Question

  • Hi, everyone.

    Recently I am trying to write some script to automate some task.

    I want to generate a command text and then run it on the powershell. And finally export the output result.

    Here is some script that I use.

    powershell -command $string |Out-File $outputFilePath -Encoding default

    $string is the command text that I generate, everything is fine, but this command require Get-Credential before the running.

    It seem like the powershell -command is running in another powershell instance? I guess?

    But I don't want to put those authorization stuff into the command text.

    Have anyone got any solution?

    Thanks you so much

    Thursday, April 19, 2018 1:25 AM

All replies

  • by the way, this is the exchange online command...
    Thursday, April 19, 2018 1:26 AM
  • No.  You cannot avoid that.  You will need to find some other method.

    You can store credentials as an object using:

    $creds | Export-CliXml mycreds.clixml

    The credentials will be unusable outside of your account.


    \_(ツ)_/

    Thursday, April 19, 2018 1:33 AM
  • Thanks for you reply.

    I think you are right. Maybe there is no way to avoid it.

    So you adding the credential stuff into my command text....

    lol

    Thursday, April 19, 2018 5:29 AM
  • Another method how to store creds ..

    $Username = "domain\myusername"
    $enc = "01000000d08c9ddf0115d1118c7a00c04fc297eb01000000a021d5b345e98a4f871e6af67b61a2b70000000002000000000003660000c00000001000000008a2b3a9bac5cc4133f33df6d2536e6d0000000004800000a0000000100000008df173ae6b1783fc6a987350a785f01518000000aaab3ba968892197d7084f83a24f7c2fd77ac22301944316140000004ef41484ad4a7ec400b48c39ba01fcb6af98a2xc"
    $pw = $enc |Convertto-SecureString
    $creds = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $pw 
    

    To generate the secure string

    $plaintext = "MyPassword"
    $encryptedpassword = $($plaintext |ConvertTo-SecureString -AsPlainText -Force) | ConvertFrom-SecureString
    write-host "String is: $encryptedpassword"
    

    Thursday, April 19, 2018 7:37 AM