Jump to content

Start Powershell to connect to Office 365


Recommended Posts

Hello All

I'm new to this forum, so go easy on me :)

I have a current issue when attempting to run a powershell window and use the 'Connect-MsolService' command that comes with 'Windows Azure Active Directory Module for Windows Powershell'.

After further investigation I found out that running the powershell.exe from an AutoIT script does not include the Azure Active Directory for Powershell Module once I run 'get-command' within the same window.

But, when I run a powershell.exe instance from 'C:\Windows\System32\WindowsPowershell\v1.0' I then run the get-command and the command appears that I need.

Here is my code that I have:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=AssignLicenseE1Test.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 
 Script Function:
    Install Connect and Assign E1 License on Office365

#ce ----------------------------------------------------------------------------

; Script Start

; Runs Script to begin connection
Run ( "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -noexit C:\Scripts\Office365\ConnectMSOL_Service.ps1" )

; Waits for Powershell Credential Prompt
WinWait ( "Windows PowerShell credential request ", "" )

; Waits for the first setup window to run
ControlSetText( "", "OK", "[CLASS:Edit; INSTANCE:2]", "***@***.onmicrosoft.com" )
ControlSetText( "", "OK", "[CLASS:Edit; INSTANCE:3]", "********" )

ControlClick ( "", "OK", 1 )

It's pretty basic at the moment, I have not included the assign E1 License at the moment as I am just trying to get the connection side of things sorted first.

This may not be the best method of completing the task but I'm not great at coding, any other methods of completing the task are more than welcome.

Below is the Powershell script I am calling:

#Assigning Licenses in Office 365

#This first command will import the Azure Active Directory module into your PowerShell session.
Import-Module MSOnline

#Capture administrative credential for future connections.
$credential = get-credential

#Establishes Online Services connection to Azure Active Directory  
Connect-MsolService -Credential $credential

Any help would be greatly appreciated, if a part of this post does not make sense I apologise.

Thanks in Advance

Dan

Link to comment
Share on other sites

you can use the semicolon to run subsequent commands (without using -noexit which is generally an undesirable behavior for a script).  see post #1 where i import a module and then use it:

edit:  post #5 might be more apt since you are importing a .ps1

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...