Tuesday, July 16, 2019

Find a list of SAMAccountNames from a list of DisplayNames

Find a list of SAMAccountNames from a list of DisplayNames

Tried a bunch and this is the only one that worked for me.

$names = get-content C:\Users\jsmith\Documents\App_Users.csv
foreach ($name in $names) {Get-ADUser -filter { DisplayName -eq $name } | Select name,samAccountName | Export-Csv C:\Users\jsmith\Documents\App_Users_results.csv -NoTypeInformation -Append }

Friday, October 26, 2018

Get a list of VMs set to upgrade tools at power cycle


I needed to know what was set to upgrade at power cycle to verify a change request so with a little googling I got a good foundation and modified it to this.


Get-View -ViewType VirtualMachine -SearchRoot (Get-Cluster "Your_Cluster").id -Filter @{'Config.Tools.ToolsUpgradePolicy' = 'UpgradeAtPowerCycle' } | Select-Object name, @{N='ToolsUpgradePolicy';E={$_.Config.Tools.ToolsUpgradePolicy } }

Thursday, July 12, 2018

Move a List of PCs to a new OU


I needed to move 400 machine to a different OU and was provided a list.  So I spent 5 min and put this together.  Hope it helps someone.


Import-Csv "C:\temp\DistinguishedNames.csv" | ForEach-Object { Move-ADObject -Identity $_.DistinguishedName -TargetPath "OU=Computers,DC=YourDomain,DC=com" -Confirm:$false }

Monday, September 12, 2016

Get last boot time from a list

I was asked to reboot 60 some servers just because someone thought they hadn't rebooted in forever.  Being a skeptic I had to verify so I put this thing together from some googleing I did.

First line pulls in a list of machine names.  Second line makes the WMI call then the select.  Last line exports to a CSV.

$ComputerName = Get-Content -Path C:\temp\computers.txt

foreach ($Computer in $ComputerName) { Get-WmiObject win32_operatingsystem -ComputerName $Computer |

       select CSName, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime) } } |
   
              export-csv "C:\temp\Computers_LastBoot_Results.csv" -NoClobber -NoTypeInformation -Append

}

Monday, August 22, 2016

Mail DB seed status

The team decided to build a new mail server and added it to the DAG.  As they were seeding the existing mail DBs to the new server I asked about the status.  One of the team members said you have to do this here and this there then subtract these two numbers.  I told him there has to be a better way.  Fifteen minutes later he came back with this:

$SERVER = "Your Mail Server"
$DB = "Your Mail DB"
(Get-MailboxDatabaseCopyStatus -Identity "$DB\$SERVER") | fl DatabaseSeedStatus, ContentIndexState, CopyQueueLength, StatusRetrievedTime

Output example:
DatabaseSeedStatus  : Percentage:90; Read:387.7 GB; Written:387.7 GB; ReadPerSec:4.727 MB; WrittenPerSec:4.726 MB
ContentIndexState   : FailedAndSuspended
CopyQueueLength     : 1295605

StatusRetrievedTime : 7/4/2016 1:45:04 PM

Monday, August 15, 2016

Re-balance mail DBs in a DAG

I ran into an issue where my mail DBs all ended up on one host in my DAG.  Being the DAG system was still new to me coming from Exchange 2007 SCC I had to get on google.  I found the script below that would inform me which MBX the activation preference was set to for each DB among other things.

Get-MailboxDatabaseCopyStatus * -Active | Select Name,Status,MailboxServer,ActivationPreference,ContentIndexState | Format-Table -AutoSize

Once I knew everything wasn’t set to all activate on the same host I looked for a way to rebalance my mail DBs across the hosts in my DAG.  That’s when I called a former employee and asked if knew a way and to make sure I was going down the right path.  He gave me this:

From Exchange Management Shell on one of your exchange servers:
cd '.\Program Files\Microsoft\Exchange Server\V15\Scripts'

Then run this:

.\RedistributeActiveDatabases.ps1 -DagName “Your DAG Name” -BalanceDbsByActivationPreference -confirm:$false –ShowFinalDatabaseDistribution


This process only takes 5 minutes or so but when it’s done your Mail DBs will be online living on its preferred host.

Monday, August 8, 2016

Exchange health scripts

When I got promoted into a leadership role years ago one of the first things I knew I need to give up was Exchange Administration.  There was no way I could effectively complete my new responsibilities and manage the health of Exchange long term.  So I hire a guy, he ended up being the most talented “mail guy” I have worked with.  This enabled me to walk away from exchange and sleep through the night.  Fast forward 4 years and I start a new job.  Not sure what type of talent I had, I knew I needed to monitor things from a distance and my confidence build for my new team.  I started with Exchange, things changed a lot from 2007 to 2013.  So I hit the inter-webbles and in doing so I found some Exchange commands that helped me out.  I thought I would share.

The first one I use was:

Get-MailboxDatabaseCopyStatus -Server “Your Mail Server” | Sort-Object name | Format-Table –AutoSize

This allowed me to see all of my mail DBs on one page and their health status.

The second one was:

Get-Queue -Server “Your Mail Server”

This script allows you to see the queues and their associated message counts.  I also figured out if you run this command for each of your mail servers you will see all of your queues across all of you servers in the same table.

Example:
Get-Queue -Server "Your Mail Server 1"; Get-Queue -Server “Your Mail Server 2”; Get-Queue -Server “Your Mail Server 3”

The third was:

Test-ReplicationHealth -Identity “Your Mail Server”

It checks for all necessary services, listeners, and processes needed to successfully replicate you mail DBs to other DAG members.
The last script is:

Test-ServiceHealth -Server “Your Mail Server”

This just verifies all the required services are running.


All 4 of these helped me understand how healthy my new mail setup was and how responsive my new staff was also.