Is it possible to query mailbox statistics for mailbox that has been put on litigation hold then the associated user account deleted in office 365 PS - powershell

I'm trying to retrieve mailbox statistics for a mailbox that I put on litigation hold, then deleted its associated account in office 365. I know the mailbox is inactive state.
Is it possible to query mailbox statistics for mailbox that has been put on litigation hold then the associated user account deleted in office 365, I need to achieve this using powershell.
My PowerShell script and the error that is getting.
PS C:\Windows\system32> $inactive = Get-Mailbox -InactiveMailboxOnly
PS C:\Windows\system32> $user = $inactive.SamAccountName
PS C:\Windows\system32> $mailstat = Get-MailboxStatistics $user
The specified mailbox Identity:"$VLHCB0-O2T8NUTCI12G" doesn't exist.
+ CategoryInfo : NotSpecified: (:) [Get-MailboxStatistics], ManagementObjectNotFoundException
+ FullyQualifiedErrorId : [Server=AM9PR09MB4882,RequestId=97a79e6b-77a1-48f8-9a1a-32ada94a0f5a,TimeStamp=4/14/2022 6:49:24 PM] [FailureCategory=Cmdlet-ManagementObjectNotFoundExceptio
n] FE6CA880,Microsoft.Exchange.Management.MapiTasks.GetMailboxStatistics
+ PSComputerName : outlook.office365.com
I get the same errors above, when i pass each accepted identity parameter value for get-mailboxstatistics cmdlet
According to microsoft, this are the accepted values for identity parameter, when using get-mailboxstatistics:
Name
Alias
Distinguished name (DN)
Canonical DN
Domain\Username
Email address
GUID
LegacyExchangeDN
SamAccountName
User ID or user principal name (UPN)

Related

Find groups in which the user is a member in another trusted domain

My Case is the following, I have a user in domain A who is members of groups in domain b, this domain is not a member in the florest A but have a trusted relacion with domain A and i need obtain a list of groups this user is member on this domain
Try to do the search with the following command
Get-ADPrincipalGroupMembership -Identity 'user -ResourceContextServer 'domain2.com.br' and the command works fine in the domain controller but when i try on my machine returns error
Get-ADPrincipalGroupMembership : Erro de operações
No linha:1 caractere:1
Get-ADPrincipalGroupMembership -Identity 'XXX' -Resourc ...
+ CategoryInfo : NotSpecified: (XX:ADPrincipal) [Get-ADPrincipalGroupMembership], ADExcept
ion
+ FullyQualifiedErrorId : ActiveDirectoryServer:8224,Microsoft.ActiveDirectory.Management.Commands.GetADPrincipalG
roupMembership
I need to create a script to automate the creation of users and to my access control team an them cannot have access to the Domain Controller anyone know why this happen and what i can do?

Powershell - MailboxFolderPermissions problem with multiple Exchange Servers

I've been trying to solve this problem for days and at least narrowed it down. I'm writing a script for my company with a user interface that allows my colleagues to easily create a new Active Directory user based on a template user, create a new mailbox and add Calendar permissions to their Manager.
Everything is working except for adding the Calendar permissions.
We are running two Exchange Servers, let's call them Exchange1 and Exchange2. Enabling the mailbox based on the AD user works fine but when I get to the step of adding calendar permissions I get this error:
The mailbox /o=COMPANY/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Configuration/cn=Servers/cn=EXCHANGE2/cn=Microsoft System
Attendant kann nicht geöffnet werden.
+ CategoryInfo : NotSpecified: (:) [Add-MailboxFolderPermission], MailboxUnavailableException
+ FullyQualifiedErrorId : [Server=EXCHANGE1,RequestId=4f818454-7ffc-4fd9-b57d-594bedd7fab6,TimeStamp=15.10.2020 14:11:32] [FailureCategory=Cmd
let-MailboxUnavailableException] 676ABDB0,Microsoft.Exchange.Management.StoreTasks.AddMailboxFolderPermission
+ PSComputerName : EXCHANGE1
The command I'm trying to run:
Enable-Mailbox -Identity $ADUser
$EmailCalendar = $Email + ":\Calendar"
Add-MailboxFolderPermission -Identity $EmailCalendar -User $Manager -AccessRights Editor
I'm really new to using Powershell administrating Exchange servers, so I'm kind of at my troubleshooting end. It doesn't matter if I connect to EXCHANGE1 or EXCHANGE2, the error message stays the same and I'm having trouble understand why the mailbox is unavailable.
Any help is appreciate:)

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 ?

Powershell Script for adding users to AD

Hi I've just resently started to use powershell on my server. Though when I run the script I get the error:
New-ADUser : Unable to find a default server with Active Directory Web Services running.
At C:\Users\Administrator\Desktop\Powerwhell Script, H1 case.ps1:6 char:1
+ New-ADUser -name $_."fornavn"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [New-ADUser], ADServerDownException
+ FullyQualifiedErrorId : ActiveDirectoryServer:1355,Microsoft.ActiveDirectory.Management.Commands.NewADUser
I have attached the script and my .csv file. Hope any of you can help me figuring it out.
(Don't worry about the information, it's for a school assignment)
Script
.csv file
It looks like your script can not find the domain control on your domain. Simply use the -Server parameter and give it the Full Qualified Domain Name or IP of the domain control.
New-ADUser -Server "ServerName.Domain.com"
If this doesn't work you might not have Active Directory Management Gateway Service installed on your domain control (Download Here). With Windows server 2012 R2 make sure you have the following feature installed.
The headers warning you are seeing is because Import-Csv is unable to get the headings from your CSV file for some reason, and replaces the header name with H1,H2 ... Hx. For example:
fornavn efternavn H1 beskrivelse, ...
------- --------- ----- -----------
Keld Bruun KB Adm.Ledergruppe, ...
You can get round this you can giving Import-Csv the names of your columns via the -Header parameter. Note that these do not have to be the same as the ones in the CSV, as the new column headers will overwrite the CSV.
Import-Csv "C:\H1, Powershell.csv" -Header 'fornavn','efternavn','forkortelse','beskrivelse','email','brugernavn','kode','kontor','fuldnavn'

Get mailbox folder permissions for "remote" mailboxes

I'm using PowerShell commandlets to extract MailboxFolderPermissions.
I'm using Get-MailboxfolderStatistics to get list of folders for particular mailbox and then Get-MailboxfolderPermission to get permissions for all available folders.
All is working fine for mailboxes hosted locally on Exchange server I'm connected to.
But in the same domain there is another Exchange server and mailboxes hosted on it are also listed when invoking Get-Mailbox on the first one.
When I try to run Get-MailboxfolderStatistics or Get-MailboxfolderPermission for such "remote" mailbox I'm getting en error:
For Get-MailboxFolderStatistics cmdlet:
Unable to retrieve mailbox folder statistics for mailbox xxxxxxx#xxxxxx.local. Failure: Error code -2146233088 occurred with message Cannot open mailbox /o=xxxxxxxx/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Configuration/cn=Servers/cn=EXCH2013/cn=Microsoft System Attendant..
+ CategoryInfo: ReadError: (:) [Get-MailboxFolderStatistics],MailboxFolderStatisticsException
+ FullyQualifiedErrorId : BE037E6,Microsoft.Exchange.Management.Tasks.GetMailboxFolderStatistics
+ PSComputerName: xxxxxxxxxxx
For Get-MailboxFolderPermission cmdlet:
Cannot open mailbox /o=xxxxxxxx/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Configuration/cn=Servers/cn=EXCH2013/cn=Microsoft System Attendant.
+ CategoryInfo: NotSpecified: (0:Int32) [Get-MailboxFolderPermission], ConnectionFailedTransientException
+ FullyQualifiedErrorId : A44BD817,Microsoft.Exchange.Management.StoreTasks.GetMailboxFolderPermission
+ PSComputerName: xxxxxxxxxxx
Does anyone know what could the cause of above errors?
Is it possible to list permissions for remote mailbox folders?
Any help is really appreciated.
connect remote exchange server via ps session https://technet.microsoft.com/en-us/library/dd335083(v=exchg.160).aspx