IT Guy
asked on
Shortcut that will launch & run Office 365 PowerShell command line commands
I am looking for a way where I can click on a single file icon that will launch the Windows Power Shell and run the following commands:
$UserCredential = Get-Credential
Connect-MsolService -Credential $UserCredential
Connect-MsolService
So I will be prompted to and will be able to logon to Office 365 with my administrator account.
What is the best way to do this?
$UserCredential = Get-Credential
Connect-MsolService -Credential $UserCredential
Connect-MsolService
So I will be prompted to and will be able to logon to Office 365 with my administrator account.
What is the best way to do this?
You can do this by creating a file like Office 365.ps1 (create a .txt file and rename it) and put in the script, then to run it you right click the file and chose "Run with Powershell".
Save this is Office365.cmd or Whatever.cmd
It's PowerShell at heart, but wrapped in batch for easier execution.
You can add more Powershell commands that you want to automatically run below the first two lines.
It's PowerShell at heart, but wrapped in batch for easier execution.
You can add more Powershell commands that you want to automatically run below the first two lines.
@PowerShell.exe -NoExit -Command "Invoke-Expression -Command ((Get-Content -Path '%~f0' | Select-Object -Skip 2) -join [environment]::NewLine)"
@exit /b %Errorlevel%
$UserCredential = Get-Credential -Message "Please enter the Office 365 credentials"
"Hello, $($UserCredential.UserName)" | Write-Host -ForegroundColor Yellow
Connect-MsolService -Credential $UserCredential
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.