143 lines
4.9 KiB
PowerShell
143 lines
4.9 KiB
PowerShell
|
function Get-IFConfig {
|
||
|
<#
|
||
|
.SYNOPSIS
|
||
|
Because sometimes I forget what OS I'm on, so I type ifconfig when I meant ipconfig
|
||
|
So this is just a passthrough in PowerShell style to ipconfig instead
|
||
|
TODO: Make it actually do an ifconfig style input/output instead of ipconfig
|
||
|
|
||
|
.NOTES
|
||
|
Adapter name doesn't allow wildcards. Sorry for the inconvenience.
|
||
|
|
||
|
.PARAMETER All
|
||
|
Display full configuration information.
|
||
|
|
||
|
.PARAMETER Release
|
||
|
Release the IPv4 address for the specified adapter.
|
||
|
|
||
|
.PARAMETER Release6
|
||
|
Release the IPv6 address for the specified adapter.
|
||
|
|
||
|
.PARAMETER Renew
|
||
|
Renew the IPv4 address for the specified adapter.
|
||
|
|
||
|
.PARAMETER Renew6
|
||
|
Renew the IPv6 address for the specified adapter.
|
||
|
|
||
|
.PARAMETER FlushDNS
|
||
|
Purges the DNS Resolver cache.
|
||
|
|
||
|
.PARAMETER RegisterDNS
|
||
|
Refreshes all DHCP leases and re-registers DNS names
|
||
|
|
||
|
.PARAMETER DisplayDNS
|
||
|
Display the contents of the DNS Resolver Cache.
|
||
|
|
||
|
.PARAMETER ShowClassID
|
||
|
Displays all the dhcp class IDs allowed for adapter.
|
||
|
|
||
|
.PARAMETER SetClassID
|
||
|
Modifies the dhcp class id.
|
||
|
|
||
|
.PARAMETER ShowClassID6
|
||
|
Displays all the IPv6 DHCP class IDs allowed for adapter.
|
||
|
|
||
|
.PARAMETER SetClassID6
|
||
|
Modifies the IPv6 DHCP class id.
|
||
|
#>
|
||
|
[CmdletBinding(DefaultParameterSetName = 'All')]
|
||
|
param (
|
||
|
# This can be used by all commands, the rest can't
|
||
|
[switch]$AllCompartments,
|
||
|
[Parameter(ParameterSetName = 'All')]
|
||
|
[switch]$All,
|
||
|
[Parameter(ParameterSetName = 'FlushDNS')]
|
||
|
[switch]$FlushDNS,
|
||
|
[Parameter(ParameterSetName = 'RegisterDNS')]
|
||
|
[switch]$RegisterDNS,
|
||
|
[Parameter(ParameterSetName = 'DisplayDNS')]
|
||
|
[switch]$DisplayDNS,
|
||
|
|
||
|
[Parameter(ParameterSetName = 'Release')]
|
||
|
[string]$Release,
|
||
|
[Parameter(ParameterSetName = 'Release6')]
|
||
|
[string]$Release6,
|
||
|
[Parameter(ParameterSetName = 'Renew')]
|
||
|
[string]$Renew,
|
||
|
[Parameter(ParameterSetName = 'Renew6')]
|
||
|
[string]$Renew6,
|
||
|
[Parameter(ParameterSetName = 'ShowClassID')]
|
||
|
[string]$ShowClassID,
|
||
|
[Parameter(ParameterSetName = 'ShowClassID6')]
|
||
|
[string]$ShowClassID6,
|
||
|
|
||
|
[Parameter(ParameterSetName = 'SetClassID')]
|
||
|
[string]$SetClassID,
|
||
|
[Parameter(ParameterSetName = 'SetClassID6')]
|
||
|
[string]$SetClassID6,
|
||
|
|
||
|
[Parameter(ParameterSetName = 'SetClassID', ValueFromRemainingArguments = $true)]
|
||
|
[Parameter(ParameterSetName = 'SetClassID6', ValueFromRemainingArguments = $true)]
|
||
|
[string[]]$ClassID
|
||
|
)
|
||
|
|
||
|
$logLead = Get-LogLeadName
|
||
|
|
||
|
$splat = @{
|
||
|
Path = "C:\WINDOWS\system32\ipconfig.exe"
|
||
|
Arguments = @()
|
||
|
}
|
||
|
|
||
|
if ($null -ne $ClassID) {
|
||
|
$ClassID = @($ClassID)[0]
|
||
|
}
|
||
|
|
||
|
$lines = ipconfig
|
||
|
|
||
|
$adapters = @()
|
||
|
foreach ($line in $lines) {
|
||
|
if ($line.StartsWith("Ethernet adapter")) {
|
||
|
$adapters += $line.Substring(16).Trim().TrimEnd(':')
|
||
|
}
|
||
|
}
|
||
|
|
||
|
# Only one of these values can be supplied in the first place, so it is a lot of empty strings concat together
|
||
|
$adapterString = "$Release$Release6$Renew$Renew6$ShowClassID$ShowClassID6$SetClassID$SetClassID6"
|
||
|
if (![string]::IsNullOrWhiteSpace($adapterString)) { if ($adapters -notcontains $adapterString) {
|
||
|
Write-Warning "$logLead : Adapter string given was not a present adapter. Choose from: `n`t$($adapters -join "`n`t")"
|
||
|
throw "$logLead : Adapter string given was not a present adapter."
|
||
|
}}
|
||
|
|
||
|
switch ($PSCmdlet.ParameterSetName) {
|
||
|
# Switches
|
||
|
'All' { $splat.Arguments += "/all"}
|
||
|
'FlushDNS' { $splat.Arguments += "/flushdns"}
|
||
|
'RegisterDNS' { $splat.Arguments += "/registerdns"}
|
||
|
'DisplayDNS' { $splat.Arguments += "/displaydns"}
|
||
|
|
||
|
# Valid variables required
|
||
|
'Release' { $splat.Arguments += "/release $Release"}
|
||
|
'Release6' { $splat.Arguments += "/release6 $Release6"}
|
||
|
'Renew' { $splat.Arguments += "/renew $Renew"}
|
||
|
'Renew6' { $splat.Arguments += "/renew6 $Renew6"}
|
||
|
'ShowClassID' {
|
||
|
if ([string]::IsNullOrWhiteSpace($ShowClassID)) { throw "$logLead : adapter name must be specified" }
|
||
|
$splat.Arguments += "/showclassid $ShowClassID"
|
||
|
}
|
||
|
'ShowClassID6' {
|
||
|
if ([string]::IsNullOrWhiteSpace($ShowClassID6)) { throw "$logLead : adapter name must be specified" }
|
||
|
$splat.Arguments += "/showclassid6 $ShowClassID6"
|
||
|
}
|
||
|
|
||
|
# Multiple variables set
|
||
|
'SetClassID' {
|
||
|
if ([string]::IsNullOrWhiteSpace($SetClassID)) { throw "$logLead : adapter name must be specified" }
|
||
|
$splat.Arguments += "/setclassid $SetClassID $ClassID"
|
||
|
}
|
||
|
'SetClassID6' {
|
||
|
if ([string]::IsNullOrWhiteSpace($SetClassID6)) { throw "$logLead : adapter name must be specified" }
|
||
|
$splat.Arguments += "/setclassid6 $SetClassID6 $ClassID"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Invoke-CallOperatorWithPathAndParameters @splat
|
||
|
}
|