New Python script published: Excel to Markdown

I just published a new Python script that I’ve dubbed Excel to Markdown to Github and wanted to share the details of the what and the why.

Using some of the PowerShell scripts I published on nexxai.dev last week, I found that I had a need to dump the results of some of these spreadsheets into a more accessible documentation repo. We use Confluence here and so the easy choice was to convert those worksheets to Markdown. However, when I looked around, I couldn’t find anything that would do what I needed without costing several thousand(!!!) dollars.

This script takes a single input (the path to your spreadsheet), will prompt you for the heading level to use for the title of the table, and will dump to the screen every worksheet in the workbook. You can then copy/paste this text into the documentation management system of your choice, and presto, you have an editable document that you and your teams can use.

I hope this help you if you ever have to convert Excel to Markdown!

Get all of the scopes and reservations from all activated DHCP servers in an Active Directory domain

Today I had to get all of the scopes and reservations from all activated DHCP servers in our Active Directory domain. I whipped up this PowerShell script and figured someone else out there might need it. Please note that the Import-Excel package is required if you plan on using this script verbatim. It can be easily modified to not use it, however this is left as an exercise for the reader to implement.

Get-DhcpServerInDC | ForEach-Object {
    $DHCPServer = $_
    $hostName = $DHCPServer.DnsName
    Write-Host $hostName

    $scopes = Get-DhcpServerv4Scope -ComputerName $DHCPServer.DnsName | Where-Object { $_.State -eq "Active" } | Select-Object -Property Name, ScopeId, SubnetMask, StartRange, EndRange
    $scopes | Export-Excel ".\DHCPScopes.xlsx" -WorkSheetname "$($hostName)-Scopes" -AutoSize -AutoFilter

    ForEach ($scope in $scopes) {
        $reservations = Get-DhcpServerv4Reservation -ComputerName $DHCPServer.DnsName -ScopeId $scope.ScopeId | Select-Object -Property ClientId, Description, IPAddress, Name
        $reservations | Export-Excel ".\DHCPScopes.xlsx" -WorkSheetname "$($hostName)-Reservations" -AutoSize -AutoFilter 
    }
}

Get all of the conditional forwarders setup in an Active Directory domain

Just a quick post here as I found myself needing to find out what conditional forwarders each domain controller in an Active Directory domain had configured. We have nearly a hundred domain controllers and so going manually one-by-one was simply not an option.

I whipped up this PowerShell script and figured that someone else out there might need something similar. It is parallelized (the number of $instances can be changed to do more/less parallel work) and then just dumps it to a CSV-ish file.

$instances = 10

Get-AdDomainController -Filter * | ForEach-Object -ThrottleLimit $instances -Parallel {
    $dc = $_
    Write-Host $dc.Name
    $zones = Get-DnsServerZone -ComputerName $dc.Name | Where-Object {$_.ZoneType -eq "Forwarder" }
    $string = $dc.Name + ","
     ForEach ($zone in $zones) {
         $string = $string + $zone.ZoneName + ","
     }
    Write-Host $string
    $string | Out-File -FilePath ".\zones.txt" -Append 
}

There’s a lot of room for improvement here obviously, but it should at least get you going.

Posts navigation