Solved

Problem with exporting credentials in Powershell to a .xml file.

Posted on 2015-02-05
2
246 Views
Last Modified: 2015-02-16
First question:
I am having problems with getting powershell to export my credentials to a file. I am running this:
Get-Credential "admin@ScriptingGuy.OnMicrosoft.Com" |
Export-Clixml c:\fso\ScriptingGuyCredential.xml
I have used Azure active directory module for windows powershell and Azure powershell and both wont export my creds to a file to refer to.

Second question.
I am trying to write a ps1 file to run from powershell to make things easier. When we add a new user to active directory it syncs to 365. Nobody can see the busy/free details of this user even though every one is set to Reviewer. The only way I have been able to show the details is by running a ps1 file after logging in with creds every time a new user comes on board. This is what I run.

$Creds = Get-Credential
(user@domain.onmicrosoft.com
Password)

get-executionpolicy

set-executionpolicy unrestricted      (answer yes)

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Creds -Authentication Basic –AllowRedirection

Import-PSSession $Session
      
Import-Module MSOnline

Connect-MsolService –Credential $Creds
      
$onPrem = get-credential
(Differentdomain\differentuser
Password)

Then I run this PS1 file called outlookfix.ps1 This is the file.

foreach($mbx in Get-Mailbox -ResultSize Unlimited | where-object {$_.displayname -notmatch "discovery"}) {
    $mbox = $mbx.alias+":\calendar"
    $test = Get-MailboxFolderPermission -Identity $mbox -erroraction silentlycontinue
    if($test -ne $null){
        Set-MailboxFolderPermission -Identity $mbox -User Default -AccessRights Reviewer | out-null
        [string]$user=$mbx.name
        [string]$folder="Calendar"
        [string]$AccessRight="Applied"
        $obj = New-Object PSObject
        $obj | Add-Member NoteProperty User ($user)
        $obj | Add-Member NoteProperty Folder ($folder)
        $obj | Add-Member NoteProperty AccessRight ($AccessRight)
        Write-Output $obj

I want to combine the stuff into one ps1 file that I can call upon in powershell to automate the process.
Is it possible to get the first creds and the second creds put into 2 diff files so that I can minimize the amount of scripts I have to put in.

Thanks in advance.
0
Comment
Question by:bobgraf
2 Comments
 
LVL 78

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 40592406
it will never be an .xml file
if(!(test-path "c:\test\username.txt"))
    {
    $username = read-host "Username"
    $username | out-file -FilePath c:\test\username.txt
    }
if(!(test-path "c:\test\cred.txt"))
    {
    read-host "Password" -assecurestring | convertfrom-securestring | out-file C:\test\cred.txt
    }
$password = get-content c:\test\cred.txt | convertto-securestring
$username = get-content -Path C:\test\username.txt
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$password
$O365Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Authentication Basic -AllowRedirection -Credential $credentials
#Import-PSSession $O365Session
Connect-MsolService -Credential $credentials

foreach($mbx in Get-Mailbox -ResultSize Unlimited | where-object {$_.displayname -notmatch "discovery"}) {
    $mbox = $mbx.alias+":\calendar"
    $test = Get-MailboxFolderPermission -Identity $mbox -erroraction silentlycontinue
    if($test -ne $null){
        Set-MailboxFolderPermission -Identity $mbox -User Default -AccessRights Reviewer | out-null
        [string]$user=$mbx.name
        [string]$folder="Calendar"
        [string]$AccessRight="Applied"
        $obj = New-Object PSObject
        $obj | Add-Member NoteProperty User ($user)
        $obj | Add-Member NoteProperty Folder ($folder)
        $obj | Add-Member NoteProperty AccessRight ($AccessRight)
        Write-Output $obj
        }
}

Open in new window

0
 

Author Comment

by:bobgraf
ID: 40612819
Thanks for the assistance. The import creds didn't work and its possible that I might not be doing it right. I was able to write a script regardless and it's working. Thanks for your help.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
A procedure for exporting installed hotfix details of remote computers using powershell
In this video we show how to create a Shared Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Sha…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now