With PowerShell, I want to make an export of all the mailboxes in an Exchange environment of users in a specific OU where the level of AccessRights of the user "Default" on the folder level does not equal "None". For this I am using the following command:
$AllMailbox = Get-Mailbox -OrganizationalUnit "DNofOU" -ResultSize Unlimited
$ResultData = foreach ($Mailbox in $AllMailbox)
{
Get-MailboxFolderPermission $Mailbox | Where-Object {$_.User -Match "Default" -AND $_.AccessRights -NotMatch "None"} | Select-Object Identity,AccessRights,#{Name="Name"; Expression={$Mailbox.Name}}
}
$ResultData | Export-CSV -Path C:\temp\MailboxFolderPermissions.csv
However, when running this command I get the following error:
Cannot process argument transformation on parameter 'Identity'. Cannot convert the "DisplayNameOfMailbox" value of type "Deserialized.Microsoft.Exc
hange.Data.Directory.Management.Mailbox" to type "Microsoft.Exchange.Configuration.Tasks.MailboxFolderIdParameter".
+ CategoryInfo : InvalidData: (:) [Get-MailboxFolderPermission], ParameterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-MailboxFolderPermission
+ PSComputerName : FQDNofExchangeServer
The environment is based on Exchange 2010 on a Windows Server 2008 R2 server with PowerShell version 2.0. It is also possible to execute this from a Windows Server 2012 R2 server with PowerShell version 4.0 when remote connecting to the Exchange server.
For me, it worked better to use the full Canonical name of the object.
Like so:
$mailboxArray = Get-Mailbox -OrganizationalUnit "example.com/Accounts" -ResultSize Unlimited
I Wasn't sure if this for have found the answer or not yet, but wanted to provide my input on how you could possibly get all the mailboxes in an organizational Unit.
Related
I am running the below script on Windows 10 without problems. So i am attempting to run it on Windows 7. However I get this weird error. The piece before the pipe to Remove-CimInstance works fine. Just something wrong when it hits the pipe
Get-CimInstance -Class Win32_UserProfile | Where-Object { $_.LocalPath.split('\')[-1] -eq $pullUser } | Remove-CimInstance
However, i am getting the error below
Remove-CimInstance : The parameter is incorrect.
At line:1 char:104
+ ... LocalPath.split('\')[-1] -eq "useridhere" } | Remove-CimInstance
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Win32_UserProfi...6-100815088...):CimInstance) [Remove-CimInstance], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070057,Microsoft.Management.Infrastructure.CimCmdlets.RemoveCimInstanceCommand
EDIT
So as it turns out, there was an issue with a WMI on the device i was testing on. I originally created this script for Win10 and have been moving backwards to make it work on Windows 7. The premise of the entire script is to create a TASK JOB to delete a user profile on Startup.
For whatever reason, the script in its entirety works fine when running from a Powershell ISE Window with Admin rights, the TASK JOB is set to run as system, however it is failing the most basic of commands (almost as if the cmdlets are not loaded). I will be posting a new question on this if I cannot figure out what the problem is.
Tyr this to see all details of this action.
# Get the stack information and the full error message if any
Trace-Command -Name metadata,parameterbinding,cmdlet -Expression {
Get-CimInstance -Class Win32_UserProfile |
Where-Object {
$_.LocalPath.split('\')[-1] -eq 'TestUser'} |
Remove-CimInstance -Verbose -WhatIf
} -PSHost
$Error[0] |
Select-Object -'*' |
Format-List -Force
We have swapped over to a new virus protection and I'm trying to track down all the machines with our old McAfee software on it. We are in a domain group, and all the PC's are listed in active directory.
$list = Get-ADComputer -Filter *
foreach($PC in $list){
$data = Get-WmiObject -ComputerName $PC -Class Win32_Product | sort-object Name |
Select-Object Name | Where-Object { $_.Name -like "*McAfee*"}
if($data){
Write-Output "$PC has $($data.name) installed" |
out-file C:\Users\username\Desktop -Append
}
}
I'm a bit amateur when it comes to powershell.
Im getting this error over and over again
Get-WmiObject : The RPC server is unavailable.
At line:4 char:13
+ $data = Get-WmiObject -ComputerName $PC -Class Win32_Product | so ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
I've read it's likely a firewall setting in the group policy. Before I try and get that changed is this the most effective way to do this? I'm avoiding using a list of computer names for simplicity, but I can do if necessary.
You are right, there is a firewall setting blocking the Powershell remote access. It seems like a very common security setting in a lot of places since it's easier to turn it all off than to try to tune it to just allow specific people to use.
If you don't have access to SCCM or any other inventory/configuration management software like AdminOfThings commented, then this is a reasonable way to get the information you're looking for. I used a similar method to track RAM and CPU usages on some of our computers, but I had to modify each computer with the code at the link codaamok posted. It was an opt-in program so that method worked for me.
It's probably going to depend on how your Group Policy Admins want to handle it, if they want to allow this sort of remote access or not.
I need the LastLogonTime from all our cloud hosted mailboxes. Google tells me to
Get-Mailbox | Get-MailboxStatistics
Get-Mailbox currently returns 2172 mailboxes but when returning the entire object to Get-MailboxStatistics, it's giving an error on 59 mailboxes: The specified mailbox "Firstname Lastname" isn't unique.
For some of these mailboxes I can indeed find a Mailbox with a duplicate DisplayName but not for all.
So there are some Mailboxes without a valid Get-MailboxStatistics result. But when I ask the Get-MailboxStatistics from the ExchangeGuid, the record IS returned. I.e.
Get-MailboxStatistics -Identity 7045326a-5c0f-4a84-aa0c-ceb$$$$c67fe
When I modify my script to loop the mailbox results and query the statistics for each mailbox, I get the (obvious) response: The request is not serviced on the server. Your request is too frequent. Please wait for few minutes and retry again.
So.. my question is..
How do I pipe the ExchangeGuid of every Get-Mailbox record to the Get-MailboxStatistics?
Get-Mailbox -ResultSize 5 | Select-Object ExchangeGuid | Get-MailboxStatistics
returns:
The input object cannot be bound to any parameters for the command either because the command does not take pipeline in put or the input and its properties do not match any of the parameters that take pipeline input.
+ CategoryInfo : InvalidArgument: (#{ExchangeGuid=...5-684390d4a758}:PSObject) [Get-MailboxStatistics], P arameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Get-MailboxStatistics
+ PSComputerName : outlook.office365.com
You can try to use the UPN (User Principal Name) which is unique :
get-mailbox -ResultSize 5 |select -expand userprincipalname |Get-MailboxStatistics
I have one problem with two questions. I have following powercli cmd:
$snapLst = Get-VM vmindev |Get-Snapshot |Select VM, Name, Description, `
#{Name='Created'; Expression={{$_.Created.ToString("yyMMdd")}}, `
#{Name='SizeMB'; Expression={[int] $_.SizeMB}}
$resultLst=$snapLst| where SizeMB -gt 1000 |Sort-Object SizeMB |`
Select #{Name='Type'; Expression={'BIG'}},*
When run in my DEV env (powercli session on my desktop connecting to the vSphere sever), everything is fine. When run in PRODUCTION (ie. powercli session on the vSphere server), I get the following error:
Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert the "SizeMB" value of type "System.String" to type System.Management.Automation.ScriptBlock".
At C:\Users\kness\Scripts\sn2.ps1:32 char:27
+ $resultLst=$snapLst| where <<<< SizeMB -gt 1000 |Sort-Object SizeMB |Select
#{Name='Type'; Expression={'BIG'}},
+ CategoryInfo : InvalidArgument: (:) [Where-Object], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WhereObjectCommand
Q1: What - in the environment setup - would make the script behaves differently? I checked the versions of the powercli ... they're exactly the same.
Q2: Because the above error, I look into the property of the list by running this cmd:
$snapLst = Get-VM vmindev |Get-Snapshot |Get-Member |Findstr Size
SizeGB Property System.Nullable`1[[System.Decimal, mscorlib, Ve...
SizeMB Property System.Decimal SizeMB {get;}
SizeMB is a "decimal" type; why the error complains that it is a "string"?
Thx in advance!
I got it resolved with helps fr TessellatingHeckler.
A1. Although my PowerCLI package is the same, it operates on two different Powershell installation. On my desktop, PSVersion is 4.0 and on the production server, it is 2.0
A2. This is related to A1. In PS 4.0, the cmdlet where is translated properly to Where-Object {...}. Whereas in PS 2.0, it is a syntax error. The complain about SizeMB being System.String is just a red herring following the "where" syntax error.
By changing where SizeMB -gt 1000 to Where-Object {$_.SizeMB -gt 1000} the script is now working. I guess, the alternative would be to upgrade the PS on the vSphere server ... but I dont want to go there. Thanks for your helps everyone.
I am trying to writing a script to move a user to a new database and then export their mailbox to pst, but I need to verify if the user is in the correct database to begin with from a user input.
I am trying a command like:Get-Mailbox -Database "Archive Mailbox Database" -Identity Fbloggs
Then I would error trap if the user is not found. This line does not work however with error:
Parameter set cannot be resolved using the specified named parameters.
+ CategoryInfo : InvalidArgument: (:) [Get-Mailbox], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Get-Mailbox
Many thanks for any help.
NA
Try with the Filter parameter (you can also use Name instead of Alias):
Get-Mailbox -Database "Archive Mailbox Database" -Filter {Alias -eq 'Fbloggs'}
Or the other way around:
(Get-Mailbox -Identity Fbloggs).Database.Name
Or
Get-Mailbox -Database "Archive Mailbox Database" | Where-Object {$_.Name -eq 'Fbloggs'}