Office 365 PS script question.

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Mark Hammonds Mark Hammonds 1 year, 5 months ago.

  • Author
    Posts
  • #32798
    Profile photo of Mr. Skript
    Mr. Skript
    Participant

    Hey guys,

    I work for a company in which we resell Office365 products. That being said, we have access to many domains that are our clients.

    That being said, sometimes, we have to connect to the PS Module of O365 to get certain info about mailboxes, users etc...

    Here's a little script we made:

    Connect-MsolService

    Get Tenant ID
    Get-MsolPartnerContract -DomainName domain.onmicrosoft.com

    Connect to an MSOL tenant
    $tenID=(get-msolpartnercontract -domain domain.onmicrosoft.com).tenantId.guid

    Get Commands for a tenant (add -tenantID $tenID to the command after running the one above)
    Get-MsolUser user@domain.com -tenantID $tenID

    Connect to Exchange Powershell for a client

    $Creds = Get-Credential

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/PowerShell-LiveID?DelegatedOrg=domain.onmicrosoft.com -Credential $Creds -Authentication Basic –AllowRedirection

    Import-PSSession $Session

    ______________________________________________________________

    My question is the following:

    Is there a way to build a script, so that we create variables so that it asks us for the domain and the TenantID is a more user friendly way ?

    The end goal would be to build a script that would have ask for the domain and tenant ID only and once we enter that, we easily get in the PowerShell session to get commands such as get-mailbox and so on...

    Any help would be appreciated.

    Thanks

    MS

  • #32801
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    Yes, you need to look into using parameters in your scripts. Check out help on "about_Functions_Advanced_Parameters"

    Additionally, there is a really good book being talked about all over the place. It's called "Learn Windows PowerShell in a Month of Lunches". It would probably be a good read for you to get some good foundational skill in PowerShell.

  • #32803
    Profile photo of Mr. Skript
    Mr. Skript
    Participant

    Hi Curtis,

    Can you help me with the script itself. I look at the Functions_Advanced_Parameters but have not been able to find what I am looking for.

    Thanks

  • #32804
    Profile photo of Mark Hammonds
    Mark Hammonds
    Participant

    This guy here has an excellent article

    https://technet.microsoft.com/en-us/magazine/jj554301.aspx

You must be logged in to reply to this topic.