AdminToolbox PowerShell Framework

repository·main·Indexed 42 days ago

https://github.com/thetaylorlee/admintoolbox

A modular PowerShell framework providing a suite of administrative tools for Active Directory, Networking, Cloud (M365/Azure), Endpoint Management, Exchange, and more. It includes specialized modules such as AdminToolbox.Networking for network discovery and iperf3 support, and AdminToolbox.FortiWizard for generating Fortinet configuration scripts and managing SSH sessions.

Tokens
5.5K
Snippets
8
Records
12
Agent score
49%

What's inside AdminToolbox

  1. Overview of AdminToolbox dependency modules

    main

    AdminToolbox is a collection of specialized modules designed for various administrative tasks. You can use the main module to get everything, or install specific modules based on your needs:

    • ActiveDirectory: Account and Group management and discovery.
    • EndpointManagement: Endpoint and server setup and common management tasks.
    • Exchange: Mailbox management, connecting to Exchange PowerShell, and Exchange Virtual Directories.
    • FFTools: Opinionated media transcoding and batch processing using ffmpeg.
    • FileManagement: Share and file management, including free space cleanup.
    • FortiWizard: Generating Fortinet config scripts, pushing configs to FortiGate via SSH, and generating VPN configs from forms.
    • Fun: Miscellaneous functions (music, creed, funny excuses).
    • Networking: Network discovery, troubleshooting, and resolution.
    • Office365: Microsoft 365 and Azure related functions. Note: Functions using deprecated AzureAD/MSOnline modules have been updated to use MSGraph and are located in the AdminToolbox.MSGraph module.
    • Remoting: Remote access and management tasks.
    • SecOps: Security operations and investigations.
    • VmwareAutomate: Automation of bulk VMware tasks.
  2. Iperf3 files in AdminToolbox.Networking

    main

    The AdminToolbox.Networking module includes the necessary binaries to run iperf3 within a PowerShell environment. The following files are provided to support Iperf3 functionality:

    • iperf3.exe (The main executable)
    • cyggcc_s-1.dll (Dependency)
    • cygwin1.dll (Dependency)

    These files allow for network bandwidth testing and performance analysis using the Iperf3 tool directly through the module's capabilities.

  3. Install the AdminToolbox PowerShell Module

    main

    To install the complete AdminToolbox suite, which includes all dependency modules, use the Install-Module command from the PowerShell Gallery. Using -AllowClobber and -Force ensures that existing commands are overwritten and the installation proceeds without interactive prompts.

    Note that while installing AdminToolbox installs all dependencies, you can also install individual modules separately if you do not require the full suite.

    Install-Module AdminToolbox -Allowclobber -Force
  4. Push a command to multiple SSH sessions

    main

    You can automate command execution across multiple active SSH sessions by retrieving all current sessions with Get-SSHSession and iterating through them using Invoke-SSHCommand. This is useful for bulk configuration changes across multiple devices simultaneously.

    $command = Enable-Management -AdminUsername test -WANInterfaceName wan
    $sessions = Get-SSHSession
    foreach ($session in $sessions) {
        Invoke-SSHCommand -Command $command -SessionId $session.sessionid
    }
  5. Generate a Dial-Up VPN tunnel configuration from an Excel form

    main

    You can automate the creation of VPN tunnel configuration scripts by importing parameters from an Excel file (VPN form). This approach allows you to fill out a structured form and use the New-DialUPTunnelBehindNAT function to generate the configuration, reducing manual entry errors.

    While this example uses the Import-Excel module to extract data from specific worksheet cells, you can use any method to populate the parameter splatting object ($params) required by the function.

    $VPNFormPath = "$env:userprofile\downloads\VPN Buildout Form.xlsx"
    
    $params = @{
        dhgroups           = ((import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 13 -EndRow 13 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        LANInterface       = (import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 3 -EndRow 3 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        LocalAddressCIDRs  = ((import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 4 -EndRow 4 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        PeerAddress        = (import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 5 -EndRow 5 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        PeerID             = (import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 15 -EndRow 15 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        Proposal           = (import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 10 -EndRow 10 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        PSK                = (import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 11 -EndRow 11 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        RemoteAddressCIDRs = ((import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 8 -EndRow 8 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        Services           = ((import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 14 -EndRow 14 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        TTL                = (import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 12 -EndRow 12 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        TunnelName         = (import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 6 -EndRow 6 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        WANInterface       = (import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 2 -EndRow 2 -StartColumn 2 -EndColumn 2 -NoHeader).p1
    }
    New-DialUPTunnelBehindNAT @params
  6. Generate Dial-Up Tunnel Remote NAT configuration from Excel

    main

    You can automate the creation of VPN tunnel configuration scripts by importing parameters from an Excel file. This pattern uses an Excel form (e.g., created with Import-Excel) to map specific worksheet cells to the parameters required by New-DialUPTunnelRemoteNAT.

    This approach allows you to perform the manual data entry in a structured spreadsheet and then use PowerShell to generate the full configuration script automatically. While this example uses Import-Excel, you can substitute it with any method for importing data from your preferred form format.

    $VPNFormPath = "$env:userprofile\downloads\VPN Buildout Form.xlsx"
    
    $params = @{
        dhgroups           = ((import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 13 -EndRow 13 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        LANInterface       = (import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 3 -EndRow 3 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        LocalAddressCIDRs  = ((import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 4 -EndRow 4 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        PeerID             = (import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 15 -EndRow 15 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        Proposal           = (import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 10 -EndRow 10 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        PSK                = (import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 11 -EndRow 11 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        RemoteAddressCIDRs = ((import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 8 -EndRow 8 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        Services           = ((import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 14 -EndRow 14 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        TTL                = (import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 12 -EndRow 12 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        TunnelName         = (import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 6 -EndRow 6 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        WANInterface       = (import-excel -Path $VPNFormPath -WorksheetName DialUpNat -StartRow 2 -EndRow 2 -StartColumn 2 -EndColumn 2 -NoHeader).p1
    }
    New-DialUPTunnelRemoteNAT @params
  7. Generate a P2P Tunnel configuration from an Excel VPN form

    main

    You can automate the creation of VPN tunnel configuration scripts by importing parameters from an Excel-based VPN form. This approach allows you to perform the manual data entry in a spreadsheet and then use PowerShell to parse that data into the New-P2PTunnel command.

    While this example uses the Import-Excel module to read the spreadsheet, you can substitute this with any method of importing data as long as you map the spreadsheet cells to the required parameters for New-P2PTunnel.

    $VPNFormPath = "$env:userprofile\downloads\VPN Buildout Form.xlsx"
    
    $params = @{
        dhgroups           = ((import-excel -Path $VPNFormPath -WorksheetName vpn -StartRow 14 -EndRow 14 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        LANInterface       = (import-excel -Path $VPNFormPath -WorksheetName vpn -StartRow 3 -EndRow 3 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        LocalAddressCIDRs  = ((import-excel -Path $VPNFormPath -WorksheetName vpn -StartRow 4 -EndRow 4 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        PeerAddress        = (import-excel -Path $VPNFormPath -WorksheetName vpn -StartRow 9 -EndRow 9 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        Proposal           = (import-excel -Path $VPNFormPath -WorksheetName vpn -StartRow 11 -EndRow 11 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        PSK                = (import-excel -Path $VPNFormPath -WorksheetName vpn -StartRow 12 -EndRow 12 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        RemoteAddressCIDRs = ((import-excel -Path $VPNFormPath -WorksheetName vpn -StartRow 8 -EndRow 8 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        Services           = ((import-excel -Path $VPNFormPath -WorksheetName vpn -StartRow 15 -EndRow 15 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        TTL                = (import-excel -Path $VPNFormPath -WorksheetName vpn -StartRow 13 -EndRow 13 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        TunnelName         = (import-excel -Path $VPNFormPath -WorksheetName vpn -StartRow 6 -EndRow 6 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        WANInterface       = (import-excel -Path $VPNFormPath -WorksheetName vpn -StartRow 2 -EndRow 2 -StartColumn 2 -EndColumn 2 -NoHeader).p1
    }
    New-P2PTunnel @params
  8. Generate P2P Tunnel NAT configuration from an Excel VPN form

    main

    You can automate the creation of VPN tunnel configuration scripts by importing parameters from an Excel-based VPN form. This approach allows you to perform the manual data entry in a spreadsheet and then use PowerShell to parse that data into the New-P2PTunnelNAT command.

    While this example uses the Import-Excel module to read the worksheet, you can use any method to import your VPN parameters. The key is to map the specific cells from your Excel form to the parameter names required by New-P2PTunnelNAT.

    $VPNFormPath = "$env:userprofile\downloads\VPN Buildout Form.xlsx"
    
    $params = @{
        dhgroups           = ((import-excel -Path $VPNFormPath -WorksheetName natvpn -StartRow 15 -EndRow 15 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        LANInterface       = (import-excel -Path $VPNFormPath -WorksheetName natvpn -StartRow 3 -EndRow 3 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        LocalAddressCIDRs  = ((import-excel -Path $VPNFormPath -WorksheetName natvpn -StartRow 4 -EndRow 4 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        NATAddressCIDRs    = ((import-excel -Path $VPNFormPath -WorksheetName natvpn -StartRow 5 -EndRow 5 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        PeerAddress        = (import-excel -Path $VPNFormPath -WorksheetName natvpn -StartRow 10 -EndRow 10 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        Proposal           = (import-excel -Path $VPNFormPath -WorksheetName natvpn -StartRow 12 -EndRow 12 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        PSK                = (import-excel -Path $VPNFormPath -WorksheetName natvpn -StartRow 13 -EndRow 13 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        RemoteAddressCIDRs = ((import-excel -Path $VPNFormPath -WorksheetName natvpn -StartRow 9 -EndRow 9 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        Services           = ((import-excel -Path $VPNFormPath -WorksheetName natvpn -StartRow 16 -EndRow 16 -StartColumn 2 -EndColumn 2 -NoHeader).p1).split(", ")
        TTL                = (import-excel -Path $VPNFormPath -WorksheetName natvpn -StartRow 14 -EndRow 14 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        TunnelName         = (import-excel -Path $VPNFormPath -WorksheetName natvpn -StartRow 7 -EndRow 7 -StartColumn 2 -EndColumn 2 -NoHeader).p1
        WANInterface       = (import-excel -Path $VPNFormPath -WorksheetName natvpn -StartRow 2 -EndRow 2 -StartColumn 2 -EndColumn 2 -NoHeader).p1
    }
    New-P2PTunnelNAT @params
  9. Execute an SSH command in a single session

    main

    To run a command on a remote device using a single SSH session, follow these steps:

    1. Initialize a new session using New-SSHSession.
    2. Prepare your command (e.g., using Enable-Management).
    3. Execute the command using Invoke-SSHCommand, passing the command string and the SessionId returned by the session initialization (typically 0 for the first session).
    4. Access the command output via the .output property of the result object.
    New-SSHSession
    $command = Enable-Management -AdminUsername test -WANInterfaceName wan
    $result = Invoke-SSHCommand -Command $command -SessionId 0
    $result.output
  10. Parameters for New-DialUPTunnelBehindNAT

    main

    The New-DialUPTunnelBehindNAT function accepts several parameters to define the VPN tunnel. When using an Excel-based automation, ensure your data mapping covers the following keys:

    • dhgroups: Diffie-Hellman groups (typically a comma-separated list).
    • LANInterface: The local LAN interface.
    • LocalAddressCIDRs: Local network address ranges (comma-separated).
    • PeerAddress: The remote peer's address.
    • PeerID: The identifier for the peer.
    • Proposal: The encryption/hashing proposals.
    • PSK: The Pre-Shared Key.
    • RemoteAddressCIDRs: Remote network address ranges (comma-separated).
    • Services: The services associated with the tunnel.
    • TTL: Time To Live value.
    • TunnelName: The name of the tunnel.
    • WANInterface: The local WAN interface.