Category: server

Report of DNS settings on all Windows Servers via powershell

$AllServers=Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*" -and Enabled -eq 'True'}
$Servers = ForEach ($Server in $AllServers){

$Result=Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled = 'True'" -Property DNSServerSearchOrder -ComputerName $Server.Name

New-Object -TypeName PSObject -Property @{
ComputerName = $Server.Name -join ','
DNSServerSearchOrder = $Result.DNSServerSearchOrder -join ','

} | Select-Object ComputerName,DNSServerSearchOrder | Export-Csv -Path C:\Temp\ServerDNSSettings.csv -NoTypeInformation -Append
}

Run this from a domain controller and it will report the DNS servers set on the NIC card.

Search group policies for specific setting

Sometimes you need to search in a domain environment for a specific setting in GPO’s. This script will search through all the GPO’s in the domain and list the results at the end!

# Get the string you want to search for
$string = Read-Host -Prompt "What string do you want to search for?"

# Set the domain to search for GPOs
$DomainName = $env:USERDNSDOMAIN

# Find all GPO's in the current domain of logged on user
write-host "Finding all the GPO's in $DomainName"
Import-Module grouppolicy
$allGposInDomain = Get-GPO -All -Domain $DomainName
[string[]] $MatchedGPOList = @()

# Look through each GPO's XML for the string
Write-Host "Starting search...."
foreach ($gpo in $allGposInDomain) {
    $report = Get-GPOReport -Guid $gpo.Id -ReportType Xml
    if ($report -match $string) {
        write-host "********** Match found in: $($gpo.DisplayName) **********" -foregroundcolor "Green"
        $MatchedGPOList += "$($gpo.DisplayName)";
    } # end if
    else {
        Write-Host "No match in: $($gpo.DisplayName)"
    } # end else
} # end foreach
write-host "`r`n"
write-host "Results: **************" -foregroundcolor "Yellow"
foreach ($match in $MatchedGPOList) {
    write-host "Match found in: $($match)" -foregroundcolor "Green"
}

Extending an XFS partition on Centos

I came across the need to extend a partition on a Centos VM deployed in Azure which was not running LVM, but XFS. This seems to be a common way of how the templates are deployed in Azure.

I won’t go into detail on how you increase the disk space on the virtualization layer, I’ll leave that to you since it’s different for every platform and a fairly basic task.

This example is for increasing /dev/sda2. Let’s say you’ve increased your disk from 32GB to 64GB, however when issuing the below command to list your disks, you still see it at 32GB!

df -h

Resulting Output - 

Filesystem Size Used Avail Use% Mounted on
udev 1.5G 0 1.5G 0% /dev
tmpfs 291M 33M 259M 12% /run
/dev/sda2 32G 3.9G 32G 11% /
tmpfs 1.5G 4.0K 1.5G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup
/dev/vda1 472M 171M 277M 39% /boot
tmpfs 291M 0 291M 0% /run/user/0

From here, you’ll want to run the below command to see that the OS is recognizing the increase space and just hasn’t allocated it –

fdisk -l

Resulting Output - 

Disk /dev/vda: 64 GiB, 42949672960 bytes, 83886080 sectors

Now that we have confirmed the OS is seeing the extra space, lets assign it to the partition we need –

1) fdisk -l /dev/sda
2) p (This will print the existing partition table)
3) d (This will enter delete mode to remove the partition)
4) 2 (This is the partition number we want to delete)
5) p (This will print the partition table again to confirm)
6) n (Wizard to create new partition)
7) p (This selects type of partition, in our case P for primary)
8) 2 (Re use the partition number we had previously)
9) First sector - just press enter to accept the default
10) Last sector - same as above, this will ensure its assigned all available free space on that disk 
11) w - this will write the partition 

After completing the above steps, you will be given a warning about the device or resource being busy, don’t worry this is completely fine. One more command before we reboot –

partprobe

This will synchronize the partition to the kernel however fail due to requiring a reboot to take effect. Reboot now and execute the final step once back up –

xfs_growfs /

This will now assign all the free space available and we should be fine!

SNMP V3 on Ubuntu

We will be installing 3 packages to get SNMP up and running on Linux.

apt install snmpd snmp libsnmp-dev

OR

yum -y install net-snmp net-snmp-utils (if you are running yum)

Copy the default snmpd config file for backup purposes ( if you want to )

cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak

Empty the file out by doing the below

cat /dev/null > /etc/snmp/snmpd.conf

Stop the running service of snmpd by issuing the command

systemctl stop snmpd

Create your read only user account for SNMP V3. Replace “SUPERPASSWORD” and “USERNAME” with your required information

net-snmp-create-v3-user -ro -A SUPERPASSWORD -a SHA -X SUPERPASSWORD -x AES USERNAME

Now make the service start on bootup

systemctl enable snmpd

Start the service!

systemctl start snmpd

Find the DNS being used on linux

This is useful when troubleshooting some network related issues and you need to find which DNS servers are being used. Since resolv.conf is not really used much anymore, it’s most likely that your DNS settings are set in the NIC configuration file, which is located at /etc/network/interfaces. 

You can also print which DNS is being used on a per interface basis by doing the below – 

Identify the NIC you want to use by using 

ifconfig

Once the names of the NIC’s have been printed, find the one you want and issue this command 

nmcli device show <INTERFACE NAME> | grep IP4.DNS

Obviously replace the “<INTERFACE NAME>” with you know what.

Remove “Network” from Windows Server Explorer sidebar

This is a registry edit that will remove the “network” icon from the file explorer window on Server 2012 R2 and most likely even Windows 7/8/10.

This is done by creating a registry key via GPO under User Configuration.

User Configuration, Preferences, Registry

Right click and choose New, Registry Item


Hive: HKEY_LOCAL_MACHINE
Key Path: SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\NonEnum
Value name: {F02C1A0D-BE21-4350-88B0-7367FC96EF3C}
Value type: REG_DWORD
Value Data (hex): 00000001

Windows Server 2012 RDP Logon Timeout

When using the interactive logon via RDP, you will find that you will be disconnected  if you do not login after the initial 30 seconds of the connection being established. This will cause the RDP window to close.

In my case, since this was a kiosk image being deployed across offices with only RDP running, it would look un-pleasent with the RDP session constantly restarting every 30 seconds. The below registry addition fixes/extends the timeout period.


HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp

Create a DWORD key “LogonTimeout” in the above location and input the amount of time you want the initial logon screen to be displayed in seconds. I used 1800 seconds which is 30 minutes. Make sure to use decimal when inputting this value.

Once this is applied, reboot your machine and test!