Import Contacts to a Public Folder in Office 365 - powershell

I would like to batch import contacts from a CSV file to a public folder located on an Office 365 / Exchange Online server.
There is a wonderful PowerShell script from Microsoft that does the same in an on premises environment using EWS (Exchange Web Services): http://gallery.technet.microsoft.com/office/Import-Contacts-to-a-08e6ffd7
Is there a way to get this to work with Office 365?
What I tried
This is how I tried to connect to the Webservice, resulting in an error:
$cred = get-credential
Connect-MsolService -Credential $cred
Import-Module .\ImportOSCEXPFContact.psm1
Connect-OSCEXWebService -Credential $cred -Force
Error returned (translated from German):
Connect-OSCEXWebService : Error calling "AutodiscoverUrl" with 2 arguments: "The Autodiscover service couldn't be located."
On Line:1 Character:24
+ Connect-OSCEXWebService <<<< -Credential $cred -Force
+ CategoryInfo : NotSpecified: (:) [Connect-OSCEXWebService], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException,Connect-OSCEXWebService
Anyone might help out or knows if that could work at all?
Thanks for help!
Aaron

Made it!
I modified a Script by Steve Goodman to do so.
Here is the code if you need to do the same:
https://web.archive.org/web/20160730070630/http://pastie.org/8489637

Related

Powershell : Connect-partnercenter Error: ClientId is not a Guid

Here is my problem, I want to get the list of people with administrator role on O365 partner center while going through Azure Automation for scheduled task.
One of the first problems, is that access to the partner center is that you have to have the MFA activated on the account that does it. So I created an Azure application by following the information here: https://www.cyberdrain.com/connect-to-exchange-online-automated-when-mfa-is-enabled-using-the-secureapp-model/
The application has been created successfully, so I run the command given on the Microsoft site at the bottom (https://learn.microsoft.com/en-us/powershell/partnercenter/multi-factor-auth?view= partnercenterps-3.0):
$credential = Get-Credential
$refreshToken = '<refreshToken>'
Connect-PartnerCenter -ApplicationId 'xxxx-xxxx-xxxx-xxxx' -Credential $credential -RefreshToken $refreshToken
The problem is that when I run this command, this is the message I get:
Connect-PartnerCenter : Error: ClientId is not a Guid.
At line:8 char:1
+ Connect-PartnerCenter -ApplicationId $ApplicationId -Credential $cred ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Connect-PartnerCenter], MsalClientException
+ FullyQualifiedErrorId : Microsoft.Store.PartnerCenter.PowerShell.Commands.ConnectPartnerCenter
I have searched everywhere, I do not understand where this problem comes from.
Have some of you already encountered this problem or have another solution to get the list of admin people on the partner center?
Thank you

Connecting MFA account to multiple CMDlets

I am trying to connect to three different CMDlets with one login:
$credential = Get-Credential
Connect-MsolService -Credential $credential
Connect-ExchangeOnline -Credential $credential
Connect-AzureAD -Credential $credential
it prompts for login, it prompts for old credentials then prompts for MFA, seems to connect to exchange online but returns the following error:
New-ExoPSSession : One or more errors occurred.
At C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\netFramework\ExchangeOnlineManagement.psm1:475 char:30
+ ... PSSession = New-ExoPSSession -ExchangeEnvironmentName $ExchangeEnviro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-ExoPSSession], AggregateException
+ FullyQualifiedErrorId : System.AggregateException,Microsoft.Exchange.Management.ExoPowershellSnapin.NewExoPSSession
Could I please have assistance to connect these three cmdlets at one please?
Using $credential = Get-Credential, then pass $credential to the commands to login, this way will not work both for Connect-ExchangeOnline and Connect-AzureAD, you just got the error from Connect-ExchangeOnline as the error interrupted the script. For Connect-MsolService, when passing $credential, it will promote you to login interactively again.
In your case, you may need to login for all of them with an MFA-enabled account. If you want to avoid interactively login, you could use Azure AD App to login the commands.
Reference:
App-only authentication for unattended scripts in the EXO V2 module
Using a Service Principal to connect to a directory in PowerShell

Issue with executing Powershell commands

I'm trying to execute the following commands in Microsoft Powershell console (with Administrator right):
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Import-Module MicrosoftTeams
$userCredential = Get-Credential
$sfbSession = New-CsOnlineSession -Credential $userCredential
Import-PSSession $sfbSession
The first three commands are executed without any issue but when I try to execute $sfbSession = New-CsOnlineSession -Credential $userCredential I'm getting the following error:
New-CsOnlineSession : The term 'New-CsOnlineSession' is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
At line:1 char:15
+ $sfbSession = New-CsOnlineSession -Credential $userCredential
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (New-CsOnlineSession:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I have tried to look on various online forums but it's not solving my issue. On Microsoft's website they say that we have to use MicrosoftTeams module instead of SkypeOnlineConnector module but it's not working in my case. I tried various steps but all in vain. I hope someone got an idea how to solve this issue.
Thanks.
Regards,
Seeya

Use Connect-SPOService with Powershell 6 (core version)

I'm trying to connect to a sharepoint environment and I want to do that with Powershell version 6. Why? Eventually, I want to put the PS commands in a .net core 3 application. And as far as I know I cannot use PS5.1 in .net core.
It is about this powershell script:
Import-Module -Force -name Microsoft.Online.SharePoint.PowerShell;
Import-Module -Force -name Microsoft.Online.SharePoint.PowerShell -DisableNameChecking;
$username = 'admin#shootme.com';
$password = 'right now';
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force);
Connect-SPOService -Url https://shootme.sharepoint.com -Credential $cred;
When I try this in the default PS 5.1 it just works fine. When I try this with PS 6.2.3, I get an error:
Connect-SPOService : The remote server returned an error: (400) Bad Request.
At line:1 char:1
+ Connect-SPOService -Url https://shootme.sharepoint.com -Credent ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-SPOService], WebException
+ FullyQualifiedErrorId : System.Net.WebException,Microsoft.Online.SharePoint.PowerShell.ConnectSPOService
Does the newer Powershell have different syntax orso, of what am I doing wrong?
Also, maybe there is a way to run scripts in ps 5.1 when running them in .net core?
Have you tried connecting manually by removing the credentials portion and letting it prompt you for a login and test if that resolves successfully?
Edit: I do know you can also call powershell from a .bat like so:
powershell -version 2 .\xyz.ps1
But not knowing what you're going for exactly makes it tough to suggest if that's even a viable option.

Connect-MsolService : Unable to find an entry point named 'GetPerAdapterInfo' in DLL 'iphlpapi.dll'

I am running the code in my azure AD runbook with the MSOnline module installed:
Import-Module MSOnline
$credential = get-automationpscredential -name 'CoreyA'
Connect-MsolService -Credential $credential
But get the following error:
Connect-MsolService : Unable to find an entry point named 'GetPerAdapterInfo' in DLL 'iphlpapi.dll'.
At line:3 char:1
+ Connect-MsolService -Credential $credential
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Connect-MsolService], EntryPointNotFoundException
+ FullyQualifiedErrorId :
System.EntryPointNotFoundException,Microsoft.Online.Administration.Automation.ConnectMsolService
I have tried multiple variations of the code and just cannot seem to find a solution ANYWHERE. The code works on my local machine with powershell ISE when I connect to my run as account, but not in AAD.
I met this exception too and seems the root reason is the account I used for connecting to tenant enabled MFA. Using an account isn't enabled MFA will solve this issue.
There is something wrong with reporting exception message in the latest MSOnline module, this issue directed me a wrong way and wasted me a lot of time.
When you change the MSOnline version to 1.0, you will see the right exception message.
MSOnline 1.0: https://www.powershellgallery.com/packages/MSOnline/1.0
Btw, I found a good way to solve Azure and O365 issues : https://support.microsoft.com/en-us/help/3174960/dev-chat-for-office365-azure this team will answer some queries for common Azure users too .