1
# Copyright 2016 Cloudbase Solutions Srl
3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
# not use this file except in compliance with the License. You may obtain
5
# a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
# License for the specific language governing permissions and limitations
15
function Invoke-DHCPRenew {
18
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
19
[Microsoft.Management.Infrastructure.CimInstance]$NetAdapter
22
if($NetAdapter.CreationClassName -ne "MSFT_NetAdapter"){
23
Throw ("Invalid object class: {0}" -f $NetAdapter.CreationClassName)
25
$ifIndex = $NetAdapter.ifIndex
27
$interface = Get-CimInstance -Class Win32_NetworkAdapterConfiguration | Where-Object {$_.InterfaceIndex -eq $ifIndex}
28
if($interface.IPEnabled -eq $false) {
29
Throw "IP subsystem not enabled on this interface"
31
if ($interface.DHCPEnabled -eq $false) {
32
Throw "Interface not configured for DHCP"
34
$code = Invoke-CimMethod -CimInstance $interface -MethodName "RenewDHCPLease"
35
return $code.ReturnValue
39
function Invoke-DHCPRelease {
42
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
43
[Microsoft.Management.Infrastructure.CimInstance]$NetAdapter
46
if($NetAdapter.CreationClassName -ne "MSFT_NetAdapter"){
47
Throw ("Invalid object class: {0}" -f $NetAdapter.CreationClassName)
49
$ifIndex = $NetAdapter.ifIndex
51
$interface = Get-CimInstance -Class Win32_NetworkAdapterConfiguration | Where-Object {$_.InterfaceIndex -eq $ifIndex}
52
if($interface.IPEnabled -eq $false) {
55
if ($interface.DHCPEnabled -eq $false) {
56
Throw "Interface not configured for DHCP"
58
$code = Invoke-CimMethod -CimInstance $interface -MethodName "ReleaseDHCPLease"
59
return $code.ReturnValue
63
Export-ModuleMember -Function * -Alias *
b'\\ No newline at end of file'