Need a msol command like set-mailbox -emailaddresspolicyenabled for hybrid server - powershell

We have office 365 and a hybrid server. It is set to sync 1 way from hybrid to o365.
We are wanting to run
Set-mailbox "$usertodisable#domain.com" -EmailAddressPolicyEnabled $true
on the hybrid server.
The problem is the hybrid server doesn't support/have the -mailbox commands. It has the -msol commands. I can not find an msol command that changes the emailaddresspolicyenabled. I also don't see a module to load for -mailbox.
We are running this command directly off the server itself. Any help would be great. Thank you and have a great day.

Use the Set-RemoteMailbox cmdlet to modify remote mailboxes. A remote mailbox is a mail user in Active Directory that's associated with a mailbox in the cloud-based service.
So what you are searching for seamed to be:
Set-RemoteMailbox -Identity "$usertodisable#domain.com" -EmailAddressPolicyEnabled $True

Related

PowerShell scripts that acts on both local AD and Azure objects

I have a PowerShell scripts that opens sessions to both our on-prem Exchange server and online Exchange server to manage distribution lists specific to each environment. Problem is, when running
Add-DistributionGroupMember -Identity "TestAzureGroup#domain.com" -Member "TestUser"
Which is a distribution list defined in online Exchange, it throws an error saying it can't find the list on our local AD.
Is it possible to specify which session to work on within the command? Or another way?
Thanks
To answer my own question, if you add '-Prefix' to the Import-PSSession command, you remove name collision when you have multiple commands imported with the same name. For example,
Import-PSSession $LocalSession -AllowClobber -Prefix "Local"
Import-PSSession $AzureSession -AllowClobber -Prefix "Remote"
Creates two different Add-DistributionGroupMember commands, one called Add-LocalDistributionGroupMember and the other called Add-RemoteDistributionGroupMember so you can then work on both sessions at the same time using the two different command names.

i'am trying to remove a user from a local group throught AD (powershell)

i'm trying to develop a script that remove a domain user from local administrators group (i can use computer management from ad but its a graphical interface i need to do it with commands) for now i'm using invoke command to remotely connect to machines and remove their users from local admins group .
im using this command : Invoke-Command -ComputerName $line2.split(";")[0] -ScriptBlock { net localgroup "administrators" $using:notadmin /DELETE } -Credential $Cred
the problem here if a the machine is not online i need to wait until it will be online , i'm searching how to remove users from local group (administrators for example ) through ad
is there a command to do that ?
I see two approaches:
If you would like to use Group Policy, you may check for: Restricted groups.
https://www.petri.com/manage-local-active-directory-groups-using-group-policy-restricted-groups
Another option would be to incoroporate Test-Connection in your script, validating if computer is online. If it is - execute the script, if it is not, store it in another list with offline machines.
Then later run the script against the offline machine list ... and so on until all the computers are being covered.
P.S. And yes, as suggested in the commments, consider using remove-localgroupmember, if your powershell version support it.
Again, depends of the case.
Hope it helps!
$RemoteComputer = "yourComputer"
$Computer = [ADSI]("WinNT://$RemoteComputer,computer")
$Group = $Computer.PSBase.Children.Find("Administrators")
ForEach ($User in (Get-Content
"c:\users\administrator.domain\desktop\localadmin.txt"))
{ $Group.Remove("WinNT://$User")
}
i tired this code and it really helped me thnx for help

Setting a mail forward in Exchange Powershell

I want to be able to set an email forward in Exchange Powershell O365
I'm trying
Set-Mailbox -Identity emailaddress -DeliverToMailboxAndForward $true -ForwardingSMTPAddress forwardingaddress
but getting
A parameter cannot be found that matches parameter name
'DeliverToMailboxAndForward'.
Do I need to load a snap-in? I can't find any help about this.
You forgot your $'s my friend
Set-Mailbox -Identity $emailaddress -DeliverToMailboxAndForward $true -ForwardingSMTPAddress $forwardingaddress
Also something to look out for when using Exchange Online PSSession (and maybe regular Exchange PSSession) is that it uses the JEA functionality of PowerShell. JEA is Just Enough Administration it actually looks at what roles the account used to connect to the PowerShell Session has and it ONLY gives you the commands that account has the roles to do. I'm not sure if it goes to the level of removing parameters from functions you only have partial access to do. For the missing Cmdlet part though I ran into this while beating my head against the wall writing a batch migration utility come to find out SysAdmin never gave me the permission to do batch migration. As soon as They gave me the permission and I imported the PSSession again BAM Cmdlet was there.
Hope that helps.

Enter Office 365 Shell Multi-Factor Authentication credentials inside Powershell

I've been trying to find a way to enter the username, password and token code for the Office 365 shell directly into the terminal and not have the normal secondary GUI window pop-up. Currently I have a basic script that logs in with:
Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA + "\Apps\2.0\") -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse).FullName | Where-Object {$_ -notmatch "_none_"} | Select-Object -First 1)
Connect-MSOLService
Import-PSSession (New-ExoPSSession -UserPrincipalName USER#domain.tld) -AllowClobber -DisableNameChecking
Is it even possible to use strictly the TUI over the GUI for entering credentials?
Don't guess at how to do X or Y. It will just lead you down a very frustrated path. Always look to the help files and online docs.
What you are trying to do is a common practice, these days, and fully documented from Microsoft and many other web resources. There are specific module to assist with this use case.
Connect to Exchange Online PowerShell using multi-factor authentication
Connect to Exchange Online PowerShell by using MFA
1.On your local computer, open the Exchange Online Remote PowerShell Module ( Microsoft Corporation > Microsoft Exchange Online Remote
PowerShell Module).
2.The command that you need to run uses the following syntax:
Connect-EXOPSSession -UserPrincipalName <UPN> [-ConnectionUri <ConnectionUri> -AzureADAuthorizationEndPointUri <AzureADUri>]
Connect to Office 365 PowerShell
Step 2: Connect to Azure AD for your Office 365 subscription
> To connect to Azure AD for your Office 365 subscription with an
account name and password or with multi-factor authentication (MFA),
run one of these commands from a Windows PowerShell command prompt (it
does not have to be elevated).
Exchange Online PowerShell Module has been around since circa 2016 from the MFA PowerShell team
There is even a script from the gallery, that specifically for EXO using MFA.
Connect to Exchange Online PowerShell using multi-factor authentication (MFA)
If you want to use multi-factor authentication (MFA) to connect to
Exchange Online PowerShell, you can't use the instructions at regular
Connect to Exchange Online PowerShell to use remote PowerShell to
connect to Exchange Online.
Download : MFA.ps1

PowerShell - how to set mailbox to a user in Exchange 2003 remotely from a Win2008 server

in my company we still have Exchange 2003 with a MS domain 2003. I also have some member servers 2008 and I would like to run some powershell scripts from this last server.
I need to create a user which have 3 different email addreses SMTP.
I run this code to create the user
New-ADUser -SamAccountName $adpsID -Name $fmbName -Description
$fmbName -DisplayName $fmbName -UserPrincipalName $adpsID
-EmailAddress $fmbNameEmail -AccountPassword (ConvertTo-SecureString -AsPlainText "!$%&DF45DFG_" -Force) -Enabled $true -PasswordNeverExpires $false -Path $pathFMB
and I tried this to add an extra email...
Set-Mailbox -identity $fmbName -EmailAddresses -Description
"SMTP:$($fmbNameEmail)#$($domainFQDN)"
I get the following error:
Set-Mailbox : The term 'Set-Mailbox' 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.
searching in google I found how to query the exchange 2003 usin WMI object but I couldnt find how to add mailboxes with WMI.
is it possible? is there any way to do so?
thanks a lot in advance.
Jose
The Exchange Management Shell was first introduced in Exchange 2007 so all the scripts you have for 2007,2010,2013 will not work on 2013 you will need to start from scratch.
On Exchange 2003 the Exchange API to use for Management is CDOEXM (important if you want to Mail-Enable objects) this is Com library you get when you install the exchange 2003 system management tools .Or you can modify the Directory objects directly using LDAP via ADSI. WMI on 2003 is useful if you want to access management information like Mailbox sizes or MessageTracking logs or you need to reconnect a disconnected Mailbox.
Cheers
Glen