Import contacts from GAL to users accounts in Office 365 - powershell

my organization move to Office 365 and users should have all GAL contacts on their folder contacts and phones. I try to use a Steve!
But I've got:
Exception calling "AutodiscoverUrl" with "1" argument(s): "Autodiscover blocked a potentially insecure redirection to h
ttps://autodiscover-s.outlook.com/autodiscover/autodiscover.xml. To allow Autodiscover to follow the redirection, use t
he AutodiscoverUrl(string, AutodiscoverRedirectionUrlValidationCallback) overload."
At C:\PS\Import-MailboxContacts.ps1:159 char:9
+ $service.AutodiscoverUrl($EmailAddress);
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : AutodiscoverLocalException
Any ideas how I can add contacts?

In that script you reference you need to change the line
$service.AutodiscoverUrl($EmailAddress);
to
$service.AutodiscoverUrl($MailboxName,{$true})
This will essentially allow redirection of Autodiscover you need for Office365

Related

PowerShell error: Exception calling "FindOne" with "0" argument(s): "The user name or password is incorrect. "

There is a Windows Server VM in my department that hosts some of our Web Applications. We want one of this Web Applications to get, automatically, the user department based on his NT-USER. To do so, we imagine the following path:
User enters in the Website. His NT-User is automatically taken
by IIS Whindows Authentication;
We Powershell (using an Active
Directory API) using the NT-User as a parameter;
We finally get
the user name and department.
This API works fine in my personal computer, but not in the Server. I am executing a Powershell script like this:
$helpstring = find-user 'fie7ca' | select displayname, name, st, l, distinguishedname
$helpstring;
In my personal computer:
It works fine.
But then (in the Server), I receive the following error:
Exception calling "FindOne" with "0" argument(s): "The user name or password is incorrect.
"
At C:\Users\RBAdmin_App2\Documents\WindowsPowerShell\Modules\BC-Tools\User-Functions.psm1:496 char:11
+ $user = $searcher.FindOne()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DirectoryServicesCOMException
I am imagine that I need a Active Directory feature, use LDAP or something that I do not know.
This problem was regarding the company proxy.

Can't set an user mailbox to a shared mailbox (Exchange)

I want to set an user mailbox to a shared mailbox with the command below:
Set-Mailbox user#domain.com -Type shared
I'm getting this error message back (Sorry for bad format):
The operation couldn't be performed because object 'user#domain.com' couldn't be found on
'server-vm-02.domain.com'.
+ CategoryInfo : NotSpecified: (:) [Set-Mailbox], ManagementObjectNotFoundException
+ FullyQualifiedErrorId : [Server=SERVER-VM-37,RequestId=1f445bc7-6d4c-4443-a0b3-8a0617d8e83a,TimeStamp=22.05.201
12:11:51] [FailureCategory=Cmdlet-ManagementObjectNotFoundException] 96F1E1EA,Microsoft.Exchange.Management.Recip
ientTasks.SetMailbox
+ PSComputerName : server-vm-37.domain.com
I've tried it when the user is enabled and disabled in AD.
In the Portal Admin Center the Account is blocked, but in my oppinion it doesn't matter.
And yes I typed the address correctly, I typed instead of the address the name as well as the username, nothing worked.
Before doing a Set-Mailbox try a Get-Mailbox. Are you sure there is a mailbox under this UPN ? Are you on the Exchange Server or on your computer when you run this cmdlet ?

Getting error while exporting azure db using powershell

Followed Export SQL database example using link :
https://learn.microsoft.com/en-us/azure/sql-database/sql-database-export-powershell#export-sql-database-example
Getting below error:
New-AzureRmSqlDatabaseExport : ResourceNotFound: The Resource 'Microsoft.Sql/servers/XXX.database.windows.net/databases/[DBNAME]' under resource group 'Default-SQL-SoutheastAsia' was
not found.
At [FilePath]\sample.ps1:24 char:18
+ $exportRequest = New-AzureRmSqlDatabaseExport –ResourceGroupName $ResourceGroupN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureRmSqlDatabaseExport], CloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Sql.ImportExport.Cmdlet.NewAzureSqlDatabaseExport
Get-AzureRmSqlDatabaseImportExportStatus : Cannot bind argument to parameter 'OperationStatusLink' because it is null.
At [FilePath]\sample.ps1:30 char:63
+ Get-AzureRmSqlDatabaseImportExportStatus -OperationStatusLink $exportRequest.Ope ...
+ CategoryInfo : InvalidData: (:) [Get-AzureRmSqlDatabaseImportExportStatus], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Azure.Commands.Sql.ImportExport.Cmdlet.GetAzureSqlDatabaseImportExportStatus
Any help?
I had this same issue today, actually. I think if you change your server name to not use the fully-qualified name, that might do it. So, just use "xxxxx."
At least that's what worked for me.
You need to verify that your Automation account has latest modules imported and are up to date (AzureRM.Automation – AzureRM.Profile – AzureRM.Sql) atleast to Version: 2.5.0. If modules show a different version, i.e. 1.0.3 then:
navigate to assets in the automation account, select modules and click on
Update Azure Modules
.
Wait for the modules to get updated it normally takes a few minutes

Access denied adding domain user to local administrators group

When adding a domain user to the local administrators group I receive an access denied, this worked before and now sadly and strangely it no longer does.
$user = "mydomain/user"
$group = [ADSI]"WinNT://./Administrators,group"
$group.Add("WinNT://$user,user")
Exception calling "Add" with "1" argument(s): "Access is denied.
"
At C:\test\Untitled5.ps1:3 char:1
+ $group.Add("WinNT://$user,user")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI
Logged on as a domain administrator
Same error using the PowerShell ISE or the console
Yet, I am able to add the user through the Computer Management MMC snap-in, no problem.
This is most likely User Account Control (UAC) related. Make sure you run PowerShell "As Administrator." Otherwise, if you're not running "as admin," you're running PowerShell under your user's account's standard user token, which doesn't have access to make this change.

Powershell Error when run on a different machine

I wrote a script to take an AD user, disable the user, remove the user from group memberships and move the user to an OU. I originally wrote this on our Windows 2008 R2 DC (I know, bad idea) and I wanted to run the script locally on my Win 7 SP1 machine. It has the AD role installed as stated in this article (http://blogs.msdn.com/b/rkramesh/archive/2012/01/17/how-to-add-active-directory-module-in-powershell-in-windows-7.aspx)
I ran on both the DC and my Win7 machine $PSVersionTable and they are exactly the same. I can run ADSIEDIT.msc on the Win 7 machine. The error is occurring when doing an AD user lookup. See error output below:
Here is my script: https://github.com/nocode99/powershell/blob/master/UserDisableGroupRemoval.ps1
Property 'filter' cannot be found on this object; make sure it exists and is settable.
At C:\Admin\test.ps1:23 char:12
+ $ADsearch. <<<< filter = "(&(objectClass=user)(sAMAccountName=$user))"
+ CategoryInfo : InvalidOperation: (filter:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\Admin\test.ps1:24 char:32
+ $ADfind = $ADsearch.findOne <<<< ()
+ CategoryInfo : InvalidOperation: (findOne:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Any ideas? The ActiveDirectory module imports with no issues and I want my users to run this locally on their machine rather than the DC.
Looks like I needed to include a filter before the lookup and added:
$adsearch = [adsisearcher]""
though I'm not sure why this works without the filter on AD server itself.