Dump DHCP Leases with PowerShell

This PowerShell script will dump all of the leases from a Windows DHCP server. From there you can output them to a file if you need to.

$Scopes = netsh dhcp server show scope
$LeaseReport = @()
foreach ($Scope in $Scopes)
    $Leases = (netsh dhcp server scope $Scope.split("-")[0].trim() show clients 1) | Select-String "-D-" 
    foreach ($Lease in $Leases) 
        If ($Lease -notmatch "NEVER EXPIRES")
            $Info = New-Object -type System.Object
            $Hostname = $Lease.tostring().replace("-D-",";").Split(";").Trim()
            $Info | Add-Member -MemberType NoteProperty -name Hostname -Value $Hostname[1]
            $IP = $Hostname[0].replace(" - ",";").Split(";") 
            $Info | Add-Member -MemberType NoteProperty -name IPAddress -Value $IP[0]
            $Info | Add-Member -MemberType NoteProperty -name SubnetMask -Value $IP[1]
            $Info | Add-Member -MemberType NoteProperty -name MACAddress -Value $IP[2].replace(" -",";").Split(";")[0].Trim()
            $LeaseReport += $Info
            $Info | ft -AutoSize

$LeaseReport | ft -AutoSize

Check SHA1 Hash of a File with PowerShell

A short PowerShell script for checking the hash on a file downloaded from the Internet

$FilePath = "C:\users\user\downloads\gpg4win-2.2.4.exe"

$Sha1 = New-Object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider

$hashSha1 = [System.BitConverter]::ToString($sha1.ComputeHash([System.IO.File]::ReadAllBytes($FilePath)))

If ($hashSha1.Replace("-","") -eq $SourceSha1) {"Match"}Else{"Doesn not Match"}