When running Exchange Powershell "Get-EXOMailboxFolderStatistics" command on large mailbox (10's of thousands of folders) a timeout occurs and I have found no way of getting the results i need. My next step is to create a full command line application or UWP to achieve the administrative results needed.
Does anyone know of a way to retreive list of empty folders in this situation?
This works in normal mailboxes but returns timeout error in large mailbox:
Get-MailboxFolderStatistics $mailboxidentity |
Where {$_.identity -like "*Inbox*" -and $_.ItemsInFolder -eq 0} |
Select Identity |
Export-Csv -Path "c:\temp\emptyfolders.csv" -NoTypeInformation
Thanks!
Related
I am creating hundreds of local accounts for testing purposes. The problem is cleanup, when I run the command to delete all the temp accounts, it only deletes half of them. "bca" is the account prefix, short for "bulk created account"
I run the count (everything done as admin)
Get-LocalUser | ? {$_.Name -like "bca*"} | Measure-Object
And I get count of 20
So I run the delete
Get-LocalUser | ? {$_.Name -like "bca*"} | Remove-LocalUser
Then I do the count again. Expecting 0. I get 10
I repeat the deletion, do the count, get 5, then 2, then 1 then finally 0.
UPDATE:
I was able to delete them all using the following command, from a comment below
foreach($user in Get-LocalUser -Name "bca*") { Remove-LocalUser $user}
BUT I am still curious why the original didn't work
I'm having the hardest time getting the following output from powershell. The console just stops at the blinking cursor like the command is running, but I wait 20 min or so, and I still have no output, both in the powershell console, as well as when I try to export as a csv. I'm using the following command:
Search-ADAccount -AccountExpiring -DateTime "01/29/2017" | where {$_.ObjectClass -eq 'user'} | FT Name,ObjectClass -A | Export-Csv C:\temp
Could someone help? I've scoured the internet to no avail.
You are using format-table inappropriately. Don't use any Format-* cmdlets if you need to process the data after that point - formatting makes that impossible. Always save formatting for the very end, and only for user presentation.
Also, you're going to end up with a file in your C:\ root directory named temp that's not entirely usable as a CSV file, at least from Excel and other readers, because additional information is going to be inserted by Export-CSV. This will be eliminated by the -notypeinformation switch.
Additionally, you can speed this up by specifying the -UsersOnly switch for Search-ADAccount and skipping the where-object loop - the pipeline is really useful, but constructs like this can slow it down. Filter your data as far to the left as possible, and if you can do it inside a cmdlet that offers a filter, do it there.
Corrected script which should work as you expect:
Search-ADAccount -AccountExpiring -DateTime "01/29/2017" -UsersOnly | select-object -Property Name,ObjectClass | Export-Csv C:\temp\expiring.csv -NoTypeInformation;
Forgive me if this isn't perfect code, but this script will get you accounts expiring within the next 7 days. You can change the $DaysAhead variable to alter the time frame.
$maxPwdAge=(Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge.Days;
$daysAhead = 7;
$dateMin=(get-date).AddDays(-$maxPwdAge);
$dateMax=$DateMin.AddDays($daysAhead);
Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False -and PasswordLastSet -gt 0} –Properties * | where {($_.PasswordLastSet) -ge $dateMin} |where {($_.PasswordLastSet) -le $dateMax} | select CN,EmailAddress,passwordLastSet | Format-Table;
I'm using the following script to get all the active users in AD.
Import-Module ActiveDirectory
Get-ADGroupMember -Identity "Domain Users" |
Where {$_.Enabled -eq $true} | select * |
Export-Csv AD.csv -NoTypeInformation -Force
I'm getting a timeout:
Error: Get-ADGroupMember : The operation returned because the timeout limit was exceeded
There are only 3000 users in AD, I was able to get the report from one server but from another one I get this error.
This might be of help to you. I was starting to get time-out errors on large security groups when using Get-ADGroupMember so I had to revert to using an LDAP query:
$Group = [ADSI]"LDAP://$($G.DistinguishedName)"
$Members = $Group.PSBase.Invoke('Members') | ForEach-Object {
$_.GetType().InvokeMember('samaccountname','GetProperty',$null,$_,$null)
}
I am running this powershell script in order to pull Send-As permissions.
Get-Mailbox -Resultsize Unlimited | Get-ADPermission | ? {($.ExtendedRights -like "*send-as*") -and -not ($.User -like "nt authorityself")} | ft Identity, User -auto
I get the error "Deserialized objects exceed the memory quota". Can someone help me get passed this error? I don't want to change the maximum output and preferably would like to have it return multiple .csv files if I can work around this error.
We are getting ready to merge our AD with another. We have about 300 computers that I'm trying to match up with who uses them so the accounts and home folders migrate correctly, and I'm trying to think of the most efficient way to get this information.
We have everyone in an inventory system (Filemaker) (and will be implementing SCCM once we migrate (thank god) ) but we had a few errors when we did our first test batch. Im looking for something I can push out through group policy (possibly?) that will give me the computer name, logged in account, and them email it to me.
So far this is what I have.
[System.Environment]::UserName
[System.Environment]::UserDomainName
[System.Environment]::MachineName
Out-File T:\TEST.txt
But the output is blank. Any idea what I'm doing wrong here? Also is there a way to have this run on multiple computers but write to the same file?
"$env:USERNAME,$env:USERDOMAIN,$env:COMPUTERNAME" | Out-File 'T:\test.txt'
will write the name and domain of the currently logged-in user as well as the hostname of the local computer to the file T:\test.txt.
Using a single file may cause conflicts due to concurrent write attempts, though. It's better to use one file per computer, like this:
"$env:USERDOMAIN\$env:USERNAME" | Out-File "T:\$env:COMPUTERNAME.txt"
Run it as a logon script (or from a logon script), e.g. like this:
powershell -ExecutionPolicy Bypass -File "\\%USERDNSDOMAIN\netlogon\your.ps1"
Get-ADComputer -Filter * -Property * | Select-Object Name | Out-File C:\outdir\machinelist.txt -NoTypeInformation -Encoding UTF8
will get you all machine names, unless you have them already. Either way, use your list of machines in
$MachineList = Get-Content -Path c:\outdir\machinelist.txt;
foreach ($Machine in $MachineList){
($Machine + ": " + #(Get-WmiObject -ComputerName $Machine -Namespace root\cimv2 -Class Win32_ComputerSystem)[0].UserName) | Out-File "C:\outdir\result.txt" -Append
}
If you change the destination directory to somewhere that all computers have access to, it can run on multiple computers. It won't email it to you but you can just grab it.
You'll need to pipe those properties into the file like..
[System.Environment]::UserName, [System.Environment]::UserDomainName, [System.Environment]::MachineName | Out-File T:\Test.txt