Category: Microsoft Windows PowerShell

Microsoft Active Directory – Get Computer Object Organizational Unit

You may use the following Windows PowerShell cmdlet to query Microsoft Active Directory (AD) for the hostname and organizational unit (OU) of a computer object.

Get-ADComputer -Filter ‘Name -EQ “HOSTNAME“‘ | Format-List -Property Name, DistinguishedName


Hardware – View Architecture of Host

You may use the following command from the command prompt or Windows PowerShell to view the architecture, physical or virtual, of the local or remote host on a network. In the second command substitute the %computername% variable with the hostname of the host to be queried.

systeminfo | findstr /c:”Model:” /c:”Host Name”
systeminfo /s %computername% | findstr /c:”Model:” /c:”Host Name”


Microsoft Active Directory – View a List of Servers

You may use the following Windows PowerShell cmdlet to get a list of all of the Windows Servers in your Microsoft Active Directory (AD) domain. In particular, it will provide the hostname of the server, operating system, and service pack then output the results to a CSV file.

Get-ADComputer -Filter ‘OperatingSystem -like “Windows Server*”‘ -Properties Name, OperatingSystem, OperatingSystemServicePack | Sort-Object -Property Name | Format-List -Property Name, OperatingSystem, OperatingSystemServicePack | Out-File -FilePath “<<>>.csv”


Microsoft Windows PowerShell – DHCP Logs

You may use the following Microsoft Windows PowerShell cmdlet to view the last one hundred lines of a Microsoft Windows Server DHCP server log for a particular Internet Protocol (IP) address. This may be useful when you are troubleshooting DHCP errors in Microsoft Windows Server.

Get-Content DhcpSrvLog-Mon.log | Select -Last 100 | Select-String -Pattern “X.X.X.X” -encoding ASCII


Microsoft Windows PowerShell – Resolve-DnsName

You may use the Resolve-DnsName Microsoft Windows PowerShell cmdlet to perform Domain Name System (DNS) query resolution for the domain name(s) you specify. Below you will find a few examples of this cmdlet.

To perform a standard query enter Resolve-DnsName domain.com.

To perform a query without the use of a local hosts file or DNS cache enter Resolve-DnsName domain.com -NoHostsFile.

To perform a query only using the DNS client cache enter Resolve-DnsName domain.com -CacheOnly. NOTE: In this example, the DNS client cache is cleared, first. Therefore, the error is expected.

To perform a query while specifying a particular DNS server enter Resolve-DnsName domain.com -Server X.X.X.X.

To perform a query for a specific DNS record enter Resolve-DnsName domain.com -Type XX.

To perform a query of multiple domains enter domain.com“,”domain.com“,”domain.com” | Resolve-DnsName

To perform a query of domain names using a file enter Get-Content file | Resolve-DnsName. NOTE: I do not recommend placing the file in the C:\Windows\System32 directory. However, I used that directory in this example for simplicity.


Microsoft Windows PowerShell – Remote Server Service Status

The Microsoft Windows PowerShell script below will request the hostname of a server as well as the service to be queried then provide the status of the service.

<#
.SYNOPSIS
This script will request the hostname of a server, the name of the service, then provide it’s status.
.DESCRIPTION
This script will request the hostname of a server, the name of the service, then provide it’s status.
.EXAMPLE
N/A.
.AUTHOR
Written by Noel Enrique Alvarez on Thursday, November 11, 2018.
#>

#Request the hostname of the server
$HOSTNAME = Read-Host “What is the hostname of the server?”

#Request the name of the service
$SERVICE = Read-Host “What is the name of the service?”

#Provide the status of the service
Get-Service -Name $SERVICE -ComputerName $HOSTNAME

#End of script


Microsoft Windows PowerShell – Remote Server Uptime

The Microsoft Windows PowerShell script below will request the hostname of a server then provide it’s uptime using Event ID 6005.

<#
.SYNOPSIS
This script will request the hostname of a server then provide it’s uptime.
.DESCRIPTION
This script will request the hostname of a server then provide it’s uptime.
.EXAMPLE
N/A.
.AUTHOR
Written by Noel Enrique Alvarez on Thursday, November 11, 2018.
#>

#Request the hostname of the server
$HOSTNAME = Read-Host “What is the hostname of the server?”

#Provide the uptime of the server
Get-EventLog -Logname System -ComputerName $HOSTNAME | Where-Object {$_.EventID -EQ 6005} | Select-Object -First 1

#End of script


VMware PowerCLI – View Snapshots

You may use the following VMware PowerCLI cmdlets to view all of the snapshots managed by vCenter Server or more specifically a cluster. These are sample commands and further information and documentation may be found here.

Get-VM | Get-Snapshot | Format-List
Get-VM | Get-Snapshot | Format-List VM, Name, SizeGB, Created, Description
Get-VM -Location “CLUSTER01” | Get-Snapshot | Format-List
Get-VM -Location “CLUSTER01”| Get-Snapshot | Format-List VM, Name, SizeGB, Created, Description


Microsoft Exchange Server 2016 – View and Configure the Whitelist

You may use the Microsoft Exchange Management Shell cmdlets below to view and configure the whitelist for Microsoft Exchange Server 2016 for an entire domain or an individual email address. The whitelist contains a list of trusted domains and/or email addresses as part of the Anti-Spam feature. The domains and/or email addresses configured using these cmdlets have all email delivered irrespective of their contents. Therefore, be sure to plan and test appropriately prior to implementing it’s use in a production environment.

Get-ContentFilterConfig
Set-ContentFilterConfig -BypassedSenderDomains domain.com
Set-ContentFilterConfig -BypassedSenders [email protected]
Set-ContentFilterConfig -BypassedSenderDomains @{Remove=”gmail.com”}
Set-ContentFilterConfig -BypassedSenders @{Remove=”[email protected]”}


Microsoft Exchange Server 2016 – Mailbox Server Services

In many environments monitoring solutions are used to help facilitate availability and expected performance levels. Below is a representative list of Microsoft Exchange Server 2016 Mailbox server services that are good candidates for monitoring your Microsoft Exchange environment.

Microsoft Exchange Active Directory Topology
Microsoft Exchange DAG Management
Microsoft Exchange Diagnostics
Microsoft Exchange EdgeSync
Microsoft Exchange Frontend Transport
Microsoft Exchange Health Manager
Microsoft Exchange Information Store
Microsoft Exchange Mailbox Transport Delivery
Microsoft Exchange Mailbox Transport Submission
Microsoft Exchange Replication
Microsoft Exchange Transport
Microsoft Exchange Unified Messaging