Skip to content

Commit

Permalink
Add composite to rename NICs (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyanhp authored Apr 18, 2023
1 parent 37e2841 commit 0824282
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- HyperVReplica
- new resource to configure replication of Hyper-V virtual machines
- HyperVState
- new resource to control state parameters of Hyper-V virtual machines
- new resource to control state parameters of Hyper-V virtual machines
- RenameNetworkAdapters
- Add composite to rename network adapters

### Changed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@{
RootModule = 'RenameNetworkAdapters.schema.psm1'

ModuleVersion = '0.0.1'

GUID = '4f8e12dc-4437-42cc-9844-035af67576f4'

Author = 'NA'

CompanyName = 'NA'

Copyright = 'NA'

DscResourcesToExport = @('RenameNetworkAdapters')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
configuration RenameNetworkAdapters
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')]

param (
[Parameter(Mandatory = $true)]
[hashtable[]]
$Adapters
)

Import-DscResource -ModuleName PSDesiredStateConfiguration
Import-DscResource -ModuleName NetworkingDsc

foreach ($adapter in $Adapters)
{
$adapter = @{} + $adapter

$executionName = "NetAdapterName_$($adapter.NewName)" -replace '[\s(){}/\\:-]', '_'
(Get-DscSplattedResource -ResourceName NetAdapterName -ExecutionName $executionName -Properties $adapter -NoInvoke).Invoke($adapter)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Adapters:
- Name: OldDeviceName
NewName: en-0
- Name: MacAddress
NewName: en-1
- Name: InterfaceIndex
NewName: en-2

0 comments on commit 0824282

Please sign in to comment.