Skip to content

swys/Get-O365Session

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Get-O365Session

The purpose of this module is to make it easier to obtain a Powershell Session with Office365 for Administative tasks. It does REQUIRE an administrative account to Office365 in order to work properly.

Once session is aquired you will have access to all of the Office365 remote management cmdlets, such as Get-Mailbox Get-DistributionList Get-MailboxPermissions etc. There are over 500 cmdlets that will be downloaded into your PSSESSION that will be available.

motivation

If you are tired of writing the below lines over and over again (or if you just can't remember and don't care to remember them just like me) :

# create the PSCredential Object
$cred = Get-Credential # <-- here you will be prompted for username and password and you have to type manually

# setup session
$Session = New-PSSession `
  -ConfigurationName Microsoft.Exchange `
  -ConnectionUri https://ps.outlook.com/powershell/ `
  -Credential $cred `
  -Authentication Basic `
  -AllowRedirection

# actualy import the session  
Import-PSSession $Session

then use this module and you can eliminate all of the above in an easy to remember command. Also if you use the Non-Interactive version of this module then you can easily automate session creation.

install

Clone the repo into a directory contained in your PSMODULES path.

Note : After adding to path you may need to restart your powershell session for the module to become available.

usage

There are 2 ways to use this module. You can either pass in samaccountname and domain argument and be prompted for your password. Or you can supply an already crafted PSCredential Object. If you pass in a credential object you will NOT be prompted. This will enable to ability to automate the session creation.

###Option 1 - Interactive (will prompt you for Password)

Get-O365Session -samAccountName testing.tester -domain example.com

OR (shorthand with unnamed arguments)

Get-O365Session testing.tester example.com

samAccountName refers to your logon name (the left side of the @ in your email address) domain refers to the domain after the @ in your email address

###Option 2 - Non-Interactive (will NOT prompt for anything)

$password = Get-Content -Path .\password.txt | ConvertTo-SecureString
$cred = New-Object -TypeName PSCredential -ArgumentList 'testing.tester@example.com', $password

Get-O365Session -credObject $cred

Note : Don't worry about storing passwords in plain text. You can follow below code to create a txt file that encrypts your password and stores on disk.

#####Create Encrypted file to use in Non-interactive mode

$credential = Get-Credential
# you will be prompted for username and password...please type in the correct info

$credential.Password | ConvertFrom-SecureString | Out-File -FilePath "c:\password.txt"

Now you can use c:\password.txt in the above example section. Just supply the correct path in the $password variable declaration section

tests

Test Require Pester. See https://github.com/pester/Pester for details.

To run the test just run below command from anywhere inside the repo :

Invoke-Pester

Pester will find the tests directory and run all of the tests.

license

MIT

About

Open an Office365 Powershell session

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published