From ce26d6623e10670ad4092a5bfdee72b45c528783 Mon Sep 17 00:00:00 2001 From: Lennart Date: Sun, 14 Jan 2024 16:02:57 +0100 Subject: [PATCH] adds language files for parent locale of en-US to tackle https://github.com/dsccommunity/DscResource.Common/issues/37 --- .../DSC_VHD/en/DSC_Vhd.strings.psd1} | 0 .../DSC_VHD/en/about_Vhd.help.txt | 343 +++ .../en/DSC_VMDvdDrive.strings.psd1} | 0 .../en/about_VMDvdDrive.help.txt} | 4 +- .../en/DSC_VMHardDiskDrive.strings.psd1} | 0 .../en/about_VMHardDiskDrive.help.txt | 227 ++ .../DSC_VMHost/en/DSC_VMHost.strings.psd1} | 0 .../DSC_VMHost/en/about_VMHost.help.txt} | 39 +- .../en/DSC_VMHyperV.strings.psd1} | 0 .../DSC_VMHyperV/en/about_VMHyperV.help.txt | 541 ++++ .../en/DSC_VMNetworkAdapter.strings.psd1} | 0 .../en/about_VMNetworkAdapter.help.txt | 201 ++ .../en/DSC_VMProcessor.strings.psd1} | 0 .../en/about_VMProcessor.help.txt} | 10 +- .../en/DSC_VMScsiController.strings.psd1} | 0 .../en/about_VMScsiController.help.txt | 100 + .../en/DSC_VMSwitch.strings.psd1} | 0 .../DSC_VMSwitch/en/about_VMSwitch.help.txt | 241 ++ .../en/DSC_VhdFileDirectory.strings.psd1} | 0 .../en/about_VhdFile.help.txt | 125 + .../DSCResources/MSFT_xVHD/MSFT_xVHD.psm1 | 387 --- .../MSFT_xVHD/MSFT_xVHD.schema.mof | 15 - .../xHyper-V/DSCResources/MSFT_xVHD/README.md | 8 - .../MSFT_xVHD/en-US/about_xVHD.help.txt | 54 - .../MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.psm1 | 425 --- .../MSFT_xVMDvdDrive.schema.mof | 9 - .../DSCResources/MSFT_xVMDvdDrive/README.md | 8 - .../MSFT_xVMHardDiskDrive.psm1 | 262 -- .../MSFT_xVMHardDiskDrive.schema.mof | 10 - .../MSFT_xVMHardDiskDrive/README.md | 11 - .../en-US/about_xVMHardDiskDrive.help.txt | 41 - .../MSFT_xVMHost/MSFT_xVMHost.psm1 | 450 --- .../MSFT_xVMHost/MSFT_xVMHost.schema.mof | 21 - .../DSCResources/MSFT_xVMHost/README.md | 8 - .../MSFT_xVMHyperV/MSFT_xVMHyperV.psm1 | 993 ------- .../MSFT_xVMHyperV/MSFT_xVMHyperV.schema.mof | 30 - .../DSCResources/MSFT_xVMHyperV/README.md | 14 - .../en-US/about_xVMHyperV.help.txt | 123 - .../MSFT_xVMNetworkAdapter.psm1 | 709 ----- .../MSFT_xVMNetworkAdapter.schema.mof | 23 - .../MSFT_xVMNetworkAdapter/README.md | 9 - .../en-US/about_xVMNetworkAdapter.help.txt | 49 - .../MSFT_xVMProcessor/MSFT_xVMProcessor.psm1 | 433 --- .../MSFT_xVMProcessor.schema.mof | 17 - .../DSCResources/MSFT_xVMProcessor/README.md | 8 - .../MSFT_xVMScsiController.psm1 | 222 -- .../MSFT_xVMScsiController.schema.mof | 8 - .../MSFT_xVMScsiController/README.md | 11 - .../en-US/about_xVMScsiController.help.txt | 32 - .../MSFT_xVMSwitch/MSFT_xVMSwitch.psm1 | 697 ----- .../MSFT_xVMSwitch/MSFT_xVMSwitch.schema.mof | 14 - .../DSCResources/MSFT_xVMSwitch/README.md | 8 - .../en-us/about_xVMSwitch.help.txt | 55 - .../MSFT_xVhdFileDirectory.psm1 | 551 ---- .../MSFT_xVhdFileDirectory.schema.mof | 24 - .../MSFT_xVhdFileDirectory/README.md | 13 - .../en-US/about_xVhdFile.help.txt | 29 - .../0.10.3/DscResource.Common.psd1 | 79 - .../0.10.3/DscResource.Common.psm1 | 2615 ----------------- .../en-US/DscResource.Common.strings.psd1 | 38 - .../en-US/about_DscResource.Common.help.txt | 26 - .../HyperVDsc.Common/HyperVDsc.Common.psd1 | 57 - .../HyperVDsc.Common/HyperVDsc.Common.psm1 | 341 --- .../en-US/HyperVDsc.Common.strings.psd1 | 13 - .../xHyper-V/en-US/about_xHyper-V.help.txt | 25 - DSCResources/xHyper-V/xHyper-V.psd1 | 107 - DSCResources/xHyper-V/xHyper-V.psm1 | 4 - 67 files changed, 1817 insertions(+), 9100 deletions(-) rename DSCResources/{xHyper-V/DSCResources/MSFT_xVHD/en-US/MSFT_xVHD.strings.psd1 => HyperVDsc/DSCResources/DSC_VHD/en/DSC_Vhd.strings.psd1} (100%) create mode 100644 DSCResources/HyperVDsc/DSCResources/DSC_VHD/en/about_Vhd.help.txt rename DSCResources/{xHyper-V/DSCResources/MSFT_xVMDvdDrive/en-us/MSFT_xVMDvdDrive.strings.psd1 => HyperVDsc/DSCResources/DSC_VMDvdDrive/en/DSC_VMDvdDrive.strings.psd1} (100%) rename DSCResources/{xHyper-V/DSCResources/MSFT_xVMDvdDrive/en-us/about_xVMDvdDrive.help.txt => HyperVDsc/DSCResources/DSC_VMDvdDrive/en/about_VMDvdDrive.help.txt} (89%) rename DSCResources/{xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/en-US/MSFT_xVMHardDiskDrive.strings.psd1 => HyperVDsc/DSCResources/DSC_VMHardDiskDrive/en/DSC_VMHardDiskDrive.strings.psd1} (100%) create mode 100644 DSCResources/HyperVDsc/DSCResources/DSC_VMHardDiskDrive/en/about_VMHardDiskDrive.help.txt rename DSCResources/{xHyper-V/DSCResources/MSFT_xVMHost/en-US/MSFT_xVMHost.strings.psd1 => HyperVDsc/DSCResources/DSC_VMHost/en/DSC_VMHost.strings.psd1} (100%) rename DSCResources/{xHyper-V/DSCResources/MSFT_xVMHost/en-US/about_xVMHost.help.txt => HyperVDsc/DSCResources/DSC_VMHost/en/about_VMHost.help.txt} (64%) rename DSCResources/{xHyper-V/DSCResources/MSFT_xVMHyperV/en-US/MSFT_xVMHyperV.strings.psd1 => HyperVDsc/DSCResources/DSC_VMHyperV/en/DSC_VMHyperV.strings.psd1} (100%) create mode 100644 DSCResources/HyperVDsc/DSCResources/DSC_VMHyperV/en/about_VMHyperV.help.txt rename DSCResources/{xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.strings.psd1 => HyperVDsc/DSCResources/DSC_VMNetworkAdapter/en/DSC_VMNetworkAdapter.strings.psd1} (100%) create mode 100644 DSCResources/HyperVDsc/DSCResources/DSC_VMNetworkAdapter/en/about_VMNetworkAdapter.help.txt rename DSCResources/{xHyper-V/DSCResources/MSFT_xVMProcessor/en-US/MSFT_xVMProcessor.strings.psd1 => HyperVDsc/DSCResources/DSC_VMProcessor/en/DSC_VMProcessor.strings.psd1} (100%) rename DSCResources/{xHyper-V/DSCResources/MSFT_xVMProcessor/en-US/about_xVMProcessor.help.txt => HyperVDsc/DSCResources/DSC_VMProcessor/en/about_VMProcessor.help.txt} (80%) rename DSCResources/{xHyper-V/DSCResources/MSFT_xVMScsiController/en-US/MSFT_xVMScsiController.strings.psd1 => HyperVDsc/DSCResources/DSC_VMScsiController/en/DSC_VMScsiController.strings.psd1} (100%) create mode 100644 DSCResources/HyperVDsc/DSCResources/DSC_VMScsiController/en/about_VMScsiController.help.txt rename DSCResources/{xHyper-V/DSCResources/MSFT_xVMSwitch/en-us/MSFT_xVMSwitch.strings.psd1 => HyperVDsc/DSCResources/DSC_VMSwitch/en/DSC_VMSwitch.strings.psd1} (100%) create mode 100644 DSCResources/HyperVDsc/DSCResources/DSC_VMSwitch/en/about_VMSwitch.help.txt rename DSCResources/{xHyper-V/DSCResources/MSFT_xVhdFileDirectory/en-US/MSFT_xVhdFileDirectory.strings.psd1 => HyperVDsc/DSCResources/DSC_VhdFileDirectory/en/DSC_VhdFileDirectory.strings.psd1} (100%) create mode 100644 DSCResources/HyperVDsc/DSCResources/DSC_VhdFileDirectory/en/about_VhdFile.help.txt delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVHD/MSFT_xVHD.psm1 delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVHD/MSFT_xVHD.schema.mof delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVHD/README.md delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVHD/en-US/about_xVHD.help.txt delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.psm1 delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.schema.mof delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/README.md delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.psm1 delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.schema.mof delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/README.md delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/en-US/about_xVMHardDiskDrive.help.txt delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/MSFT_xVMHost.psm1 delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/MSFT_xVMHost.schema.mof delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/README.md delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.psm1 delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.schema.mof delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/README.md delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/en-US/about_xVMHyperV.help.txt delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/README.md delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/en-US/about_xVMNetworkAdapter.help.txt delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.psm1 delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.schema.mof delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/README.md delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.psm1 delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.schema.mof delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/README.md delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/en-US/about_xVMScsiController.help.txt delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.psm1 delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.schema.mof delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/README.md delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/en-us/about_xVMSwitch.help.txt delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.psm1 delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.schema.mof delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/README.md delete mode 100644 DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/en-US/about_xVhdFile.help.txt delete mode 100644 DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/DscResource.Common.psd1 delete mode 100644 DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/DscResource.Common.psm1 delete mode 100644 DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/en-US/DscResource.Common.strings.psd1 delete mode 100644 DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/en-US/about_DscResource.Common.help.txt delete mode 100644 DSCResources/xHyper-V/Modules/HyperVDsc.Common/HyperVDsc.Common.psd1 delete mode 100644 DSCResources/xHyper-V/Modules/HyperVDsc.Common/HyperVDsc.Common.psm1 delete mode 100644 DSCResources/xHyper-V/Modules/HyperVDsc.Common/en-US/HyperVDsc.Common.strings.psd1 delete mode 100644 DSCResources/xHyper-V/en-US/about_xHyper-V.help.txt delete mode 100644 DSCResources/xHyper-V/xHyper-V.psd1 delete mode 100644 DSCResources/xHyper-V/xHyper-V.psm1 diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVHD/en-US/MSFT_xVHD.strings.psd1 b/DSCResources/HyperVDsc/DSCResources/DSC_VHD/en/DSC_Vhd.strings.psd1 similarity index 100% rename from DSCResources/xHyper-V/DSCResources/MSFT_xVHD/en-US/MSFT_xVHD.strings.psd1 rename to DSCResources/HyperVDsc/DSCResources/DSC_VHD/en/DSC_Vhd.strings.psd1 diff --git a/DSCResources/HyperVDsc/DSCResources/DSC_VHD/en/about_Vhd.help.txt b/DSCResources/HyperVDsc/DSCResources/DSC_VHD/en/about_Vhd.help.txt new file mode 100644 index 00000000..8a07bc8e --- /dev/null +++ b/DSCResources/HyperVDsc/DSCResources/DSC_VHD/en/about_Vhd.help.txt @@ -0,0 +1,343 @@ +.NAME + Vhd + +.DESCRIPTION + Manages VHDs in a Hyper-V host. + + ## Requirements + + * The Hyper-V Role has to be installed on the machine. + * The Hyper-V PowerShell module has to be installed on the machine. + +.PARAMETER Name + Key - String + The desired VHD file name. + +.PARAMETER Path + Key - String + The desired Path where the VHD will be created. + +.PARAMETER ParentPath + Write - String + Parent VHD file path, for differencing disk. + +.PARAMETER MaximumSizeBytes + Write - UInt64 + Maximum size of VHD to be created. + +.PARAMETER Generation + Write - String + Allowed values: Vhd, Vhdx + Virtual disk format. The default value is Vhd. + +.PARAMETER Ensure + Write - String + Allowed values: Present, Absent + Specifies if the virtual disk should be present (if not it will be created) or absent (if present it will be removed). Default value is Present. + +.PARAMETER ID + Read - String + Returns the virtual disk identifier. + +.PARAMETER Type + Write - String + Allowed values: Dynamic, Fixed, Differencing + The type of virtual disk. The default value is Dynamic. + +.PARAMETER FileSizeBytes + Read - UInt64 + Returns the current size of the virtual disk. + +.PARAMETER IsAttached + Read - Boolean + Returns if the virtual disk is attached to a VM. + +.EXAMPLE 1 + +Description not yet written. + +configuration Example +{ + param + ( + [Parameter()] + [System.String[]] + $NodeName = 'localhost', + + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter(Mandatory = $true)] + [System.String] + $Path, + + [Parameter(Mandatory = $true)] + [System.UInt64] + $MaximumSizeBytes, + + [Parameter()] + [ValidateSet('Vhd', 'Vhdx')] + [System.String]$Generation = 'Vhd', + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present' + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + Node $NodeName + { + # Install HyperV feature, if not installed - Server SKU only + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + + WindowsFeature HyperVPowerShell + { + Ensure = 'Present' + Name = 'Hyper-V-PowerShell' + } + + Vhd NewVhd + { + Ensure = $Ensure + Name = $Name + Path = $Path + Generation = $Generation + MaximumSizeBytes = $MaximumSizeBytes + DependsOn = '[WindowsFeature]HyperV', '[WindowsFeature]HyperVPowerShell' + } + } +} + +.EXAMPLE 2 + +Description not yet written. + +configuration Example +{ + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter(Mandatory = $true)] + [System.String] + $Path, + + [Parameter(Mandatory = $true)] + [System.String] + $ParentPath, + + [Parameter(Mandatory = $true)] + [System.String] + $MaximumSizeBytes, + + [Parameter()] + [ValidateSet('Vhd', 'Vhdx')] + [System.String] + $Generation = 'Vhd', + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present' + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + Node localhost + { + Vhd WrongVHD + { + Ensure = $Ensure + Name = $Name + Path = $Path + ParentPath = $ParentPath + MaximumSizeBytes = $MaximumSizeBytes + Generation = $Generation + } + } +} + +.EXAMPLE 3 + +Description not yet written. + +configuration Example +{ + param + ( + [Parameter()] + [System.String[]] + $NodeName = 'localhost', + + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter(Mandatory = $true)] + [System.String] + $Path, + + [Parameter(Mandatory = $true)] + [System.String] + $ParentPath, + + [Parameter()] + [ValidateSet('Vhd', 'Vhdx')] + [System.String] + $Generation = 'Vhd', + + [Parameter()] + [ValidateSet('Dynamic', 'Fixed', 'Differencing')] + [System.String]$Type = 'Differencing', + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present' + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + Node $NodeName + { + # Install HyperV feature, if not installed - Server SKU only + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + + WindowsFeature HyperVPowerShell + { + Ensure = 'Present' + Name = 'Hyper-V-PowerShell' + } + + Vhd DiffVhd + { + Ensure = $Ensure + Name = $Name + Path = $Path + ParentPath = $ParentPath + Generation = $Generation + Type = $Type + DependsOn = '[WindowsFeature]HyperV', '[WindowsFeature]HyperVPowerShell' + } + } +} + +.EXAMPLE 4 + +Description not yet written. + +configuration Example +{ + param + ( + [Parameter()] + [System.String[]] + $NodeName = 'localhost', + + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter(Mandatory = $true)] + [System.String] + $Path, + + [Parameter()] + [ValidateSet('Vhd', 'Vhdx')] + [System.String] + $Generation = 'Vhd', + + [Parameter()] + [ValidateSet('Dynamic', 'Fixed', 'Differencing')] + [System.String] + $Type = 'Fixed', + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present' + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + Node $NodeName + { + # Install HyperV feature, if not installed - Server SKU only + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + + WindowsFeature HyperVPowerShell + { + Ensure = 'Present' + Name = 'Hyper-V-PowerShell' + } + + Vhd DiffVhd + { + Ensure = $Ensure + Name = $Name + Path = $Path + Generation = $Generation + Type = $Type + DependsOn = '[WindowsFeature]HyperV', '[WindowsFeature]HyperVPowerShell' + } + } +} + +.EXAMPLE 5 + +Description not yet written. + +configuration Example +{ + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Name, + + [Parameter(Mandatory = $true)] + [System.String] + $Path, + + [Parameter()] + [ValidateSet('Vhd', 'Vhdx')] + [System.String] + $Generation = 'Vhd', + + [Parameter()] + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present' + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + Node localhost + { + Vhd WrongVHD + { + Ensure = $Ensure + Name = $Name + Path = $Path + Generation = $Generation + } + } +} + diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/en-us/MSFT_xVMDvdDrive.strings.psd1 b/DSCResources/HyperVDsc/DSCResources/DSC_VMDvdDrive/en/DSC_VMDvdDrive.strings.psd1 similarity index 100% rename from DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/en-us/MSFT_xVMDvdDrive.strings.psd1 rename to DSCResources/HyperVDsc/DSCResources/DSC_VMDvdDrive/en/DSC_VMDvdDrive.strings.psd1 diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/en-us/about_xVMDvdDrive.help.txt b/DSCResources/HyperVDsc/DSCResources/DSC_VMDvdDrive/en/about_VMDvdDrive.help.txt similarity index 89% rename from DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/en-us/about_xVMDvdDrive.help.txt rename to DSCResources/HyperVDsc/DSCResources/DSC_VMDvdDrive/en/about_VMDvdDrive.help.txt index a09cb73e..bbd74110 100644 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/en-us/about_xVMDvdDrive.help.txt +++ b/DSCResources/HyperVDsc/DSCResources/DSC_VMDvdDrive/en/about_VMDvdDrive.help.txt @@ -1,5 +1,5 @@ .NAME - xVMDvdDrive + VMDvdDrive .DESCRIPTION Manages DVD drives attached to a Hyper-V virtual machine. @@ -28,5 +28,5 @@ .PARAMETER Ensure Write - String Allowed values: Present, Absent - Specifies if the DVD Drive should exist or not. + Specifies if the DVD Drive should exist or not. The default value is Present. diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/en-US/MSFT_xVMHardDiskDrive.strings.psd1 b/DSCResources/HyperVDsc/DSCResources/DSC_VMHardDiskDrive/en/DSC_VMHardDiskDrive.strings.psd1 similarity index 100% rename from DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/en-US/MSFT_xVMHardDiskDrive.strings.psd1 rename to DSCResources/HyperVDsc/DSCResources/DSC_VMHardDiskDrive/en/DSC_VMHardDiskDrive.strings.psd1 diff --git a/DSCResources/HyperVDsc/DSCResources/DSC_VMHardDiskDrive/en/about_VMHardDiskDrive.help.txt b/DSCResources/HyperVDsc/DSCResources/DSC_VMHardDiskDrive/en/about_VMHardDiskDrive.help.txt new file mode 100644 index 00000000..9344ba3a --- /dev/null +++ b/DSCResources/HyperVDsc/DSCResources/DSC_VMHardDiskDrive/en/about_VMHardDiskDrive.help.txt @@ -0,0 +1,227 @@ +.NAME + VMHardDiskDrive + +.DESCRIPTION + Manages VHD(X)s attached to a Hyper-V virtual machine. + + When parameter ControllerNumber or ControllerLocation is not provided, + the same logic as Set-VMHardDiskDrive command is used. + + ## Requirements + + * The Hyper-V Role has to be installed on the machine. + * The Hyper-V PowerShell module has to be installed on the machine. + +.PARAMETER VMName + Key - String + Specifies the name of the virtual machine whose hard disk drive is to be manipulated. + +.PARAMETER Path + Key - String + Specifies the full path of the VHD file to be manipulated. + +.PARAMETER ControllerType + Write - String + Allowed values: IDE, SCSI + Specifies the type of controller (IDE/SCSI) to which the hard disk drive is to be set. If not specified, it defaults to SCSI. + +.PARAMETER ControllerNumber + Write - UInt32 + Allowed values: 0, 1, 2, 3 + Specifies the number of the controller to which the hard disk drive is to be set. For IDE the possible values are 0 or 1, for SCSI the possible values are 0, 1, 2, or 3. If not specified, it defaults to 0. + +.PARAMETER ControllerLocation + Write - UInt32 + Specifies the number of the location on the controller at which the hard disk drive is to be set. Possible values for IDE are 0 or 1, and for SCSI the possible values are between 0 to 63. If not specified, it defaults to 0. + +.PARAMETER Ensure + Write - String + Allowed values: Present, Absent + Specifies if the hard disk drive must be present (exist) or absent (not exist). If not specified, it defaults to Present. + +.EXAMPLE 1 + +VM with an extra disk. + +configuration Example +{ + param + ( + [Parameter()] + [System.String[]] + $NodeName = 'localhost', + + [Parameter(Mandatory = $true)] + [System.String] + $VMName, + + [Parameter(Mandatory = $true)] + [System.String] + $VhdPath + ) + + Import-DscResource -ModuleName 'HyperVDsc' + Import-DscResource -ModuleName 'PSDesiredStateConfiguration' + + Node $NodeName + { + # Install HyperV feature, if not installed - Server SKU only + $diskNameOS = "$VMName-DiskOS.vhdx" + $diskNameExtra1 = "$VMName-Disk1.vhdx" + + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + + WindowsFeature HyperVPowerShell + { + Ensure = 'Present' + Name = 'Hyper-V-PowerShell' + } + + VHD DiskOS + { + Name = $diskNameOS + Path = $VhdPath + Generation = 'vhdx' + MaximumSizeBytes = 20GB + Ensure = 'Present' + DependsOn = '[WindowsFeature]HyperV' + } + + VHD Disk1 + { + Name = $diskNameExtra1 + Path = $VhdPath + Generation = 'vhdx' + MaximumSizeBytes = 20GB + Ensure = 'Present' + DependsOn = '[WindowsFeature]HyperV' + } + + VMHyperV NewVM + { + Ensure = 'Present' + Name = $VMName + VhdPath = Join-Path $VhdPath -ChildPath $diskNameOS + Generation = 1 + DependsOn = '[VHD]DiskOS' + } + + VMHardDiskDrive ExtraDisk + { + VMName = $VMName + Path = Join-Path $VhdPath -ChildPath $diskNameExtra1 + ControllerType = 'IDE' + ControllerNumber = 0 + ControllerLocation = 1 + Ensure = 'Present' + DependsOn = '[VHD]Disk1' + } + } +} + +.EXAMPLE 2 + +VM with 4 additional disks. + +configuration Example +{ + param + ( + [Parameter()] + [System.String[]] + $NodeName = 'localhost', + + [Parameter(Mandatory = $true)] + [System.String] + $VMName, + + [Parameter(Mandatory = $true)] + [System.String] + $VhdPath + ) + + Import-DscResource -ModuleName 'HyperVDsc' + Import-DscResource -ModuleName 'PSDesiredStateConfiguration' + + Node $NodeName + { + $diskNameOS = "$VMName-OS.vhdx" + + # Install HyperV feature, if not installed - Server SKU only + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + + WindowsFeature HyperVPowerShell + { + Ensure = 'Present' + Name = 'Hyper-V-PowerShell' + } + + # Create the VHD for the OS + VHD DiskOS + { + + Name = $diskNameOS + Path = $VhdPath + Generation = 'vhdx' + MaximumSizeBytes = 20GB + Ensure = 'Present' + DependsOn = '[WindowsFeature]HyperV' + } + + # Create the VM + VMHyperV NewVM + { + Name = $VMName + VhdPath = Join-Path $VhdPath -ChildPath $diskNameOS + Generation = 1 + Ensure = 'Present' + DependsOn = '[VHD]DiskOS' + } + + # Ensures a SCSI controller exists on the VM + VMScsiController Controller + { + Ensure = 'Present' + VMName = $VMName + ControllerNumber = 0 + DependsOn = '[VMHyperV]NewVM' + } + + foreach ($i in 0 .. 3) + { + $diskName = "$VMName-Disk-$i.vhdx" + + # Create the VHD + VHD "Disk-$i" + { + + Name = $diskName + Path = $VhdPath + Generation = 'vhdx' + MaximumSizeBytes = 20GB + Ensure = 'Present' + DependsOn = '[WindowsFeature]HyperV' + } + + # Attach the VHD + VMHardDiskDrive "ExtraDisk-$i" + { + VMName = $VMName + Path = Join-Path $VhdPath -ChildPath $diskName + ControllerType = 'SCSI' + ControllerLocation = $i + Ensure = 'Present' + DependsOn = '[VMScsiController]Controller', "[VHD]Disk-$i" + } + } + } +} + diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/en-US/MSFT_xVMHost.strings.psd1 b/DSCResources/HyperVDsc/DSCResources/DSC_VMHost/en/DSC_VMHost.strings.psd1 similarity index 100% rename from DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/en-US/MSFT_xVMHost.strings.psd1 rename to DSCResources/HyperVDsc/DSCResources/DSC_VMHost/en/DSC_VMHost.strings.psd1 diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/en-US/about_xVMHost.help.txt b/DSCResources/HyperVDsc/DSCResources/DSC_VMHost/en/about_VMHost.help.txt similarity index 64% rename from DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/en-US/about_xVMHost.help.txt rename to DSCResources/HyperVDsc/DSCResources/DSC_VMHost/en/about_VMHost.help.txt index 383411a2..d0c70586 100644 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/en-US/about_xVMHost.help.txt +++ b/DSCResources/HyperVDsc/DSCResources/DSC_VMHost/en/about_VMHost.help.txt @@ -1,5 +1,5 @@ .NAME - xVMHost + VMHost .DESCRIPTION Manages Hyper-V host settings. @@ -24,19 +24,19 @@ .PARAMETER FibreChannelWwpnMaximum Write - String - Specifies the maximum value that can be used to generate World Wide Port Names on the Hyper-V host. + Specifies the maximum value that can be used to generate the World Wide Port Names on the Hyper-V host. Use with the FibreChannelWwpnMinimum parameter to establish a range of WWPNs that the specified Hyper-V host can assign to virtual Fibre Channel adapters. .PARAMETER FibreChannelWwpnMinimum Write - String - Specifies the minimum value that can be used to generate the World Wide Port Names on the Hyper-V host. + Specifies the minimum value that can be used to generate the World Wide Port Names on the Hyper-V host. Use with the FibreChannelWwpnMaximum parameter to establish a range of WWPNs that the specified Hyper-V host can assign to virtual Fibre Channel adapters. .PARAMETER MacAddressMaximum Write - String - Specifies the maximum MAC address using a valid hexadecimal value. + Specifies the maximum MAC address using a valid hexadecimal value. Use with the MacAddressMinimum parameter to establish a range of MAC addresses that the specified Hyper-V host can assign to virtual machines configured to receive dynamic MAC addresses. .PARAMETER MacAddressMinimum Write - String - Specifies the minimum MAC address using a valid hexadecimal value. + Specifies the minimum MAC address using a valid hexadecimal value. Use with the MacAddressMaximum parameter to establish a range of MAC addresses that the specified Hyper-V host can assign to virtual machines configured to receive dynamic MAC addresses. .PARAMETER MaximumStorageMigrations Write - UInt32 @@ -52,11 +52,11 @@ .PARAMETER ResourceMeteringSaveIntervalMinute Write - UInt32 - Specifies how often the Hyper-V host saves the data that tracks resource usage. The range is a minimum of 60 minutes to a maximum of 1440 (24 hours). + Specifies how often the Hyper-V host saves the data that tracks resource usage. The range is a minimum of 60 minutes to a maximum of 1440 minutes (24 hours). .PARAMETER UseAnyNetworkForMigration Write - Boolean - Specifies how networks are selected for incoming live migration traffic. + Specifies how networks are selected for incoming live migration traffic. If set to $true, any available network on the host can be used for this traffic. If set to $false, incoming live migration traffic is transmitted only on the networks specified in the MigrationNetworks property of the host. .PARAMETER VirtualHardDiskPath Write - String @@ -80,3 +80,28 @@ Write - Boolean Indicates whether Live Migration should be enabled or disabled on the Hyper-V host. +.EXAMPLE 1 + +Set paths f?r the Hyper-V host. + +Configuration Example +{ + param + ( + [Parameter()] + $VirtualHardDiskPath = 'C:\VMDisks', + + [Parameter()] + $VirtualMachinePath = 'C:\VMs' + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + VMHost HyperVHostPaths + { + IsSingleInstance = 'Yes' + VirtualHardDiskPath = $VirtualHardDiskPath + VirtualMachinePath = $VirtualMachinePath + } +} + diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/en-US/MSFT_xVMHyperV.strings.psd1 b/DSCResources/HyperVDsc/DSCResources/DSC_VMHyperV/en/DSC_VMHyperV.strings.psd1 similarity index 100% rename from DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/en-US/MSFT_xVMHyperV.strings.psd1 rename to DSCResources/HyperVDsc/DSCResources/DSC_VMHyperV/en/DSC_VMHyperV.strings.psd1 diff --git a/DSCResources/HyperVDsc/DSCResources/DSC_VMHyperV/en/about_VMHyperV.help.txt b/DSCResources/HyperVDsc/DSCResources/DSC_VMHyperV/en/about_VMHyperV.help.txt new file mode 100644 index 00000000..2e3bd03f --- /dev/null +++ b/DSCResources/HyperVDsc/DSCResources/DSC_VMHyperV/en/about_VMHyperV.help.txt @@ -0,0 +1,541 @@ +.NAME + VMHyperV + +.DESCRIPTION + Manages VMs in a Hyper-V host. + + The following properties cannot be changed after VM creation: + + * VhdPath + * Path + * Generation + + ## Requirements + + * The Hyper-V Role has to be installed on the machine. + * The Hyper-V PowerShell module has to be installed on the machine. + +.PARAMETER Name + Key - String + The desired name of the VM. + +.PARAMETER VhdPath + Required - String + The desired VHD associated with the VM. + +.PARAMETER SwitchName + Write - StringArray + Virtual switch(es) associated with the VM. Multiple NICs can now be assigned. + +.PARAMETER State + Write - String + Allowed values: Running, Paused, Off + State of the VM. + +.PARAMETER Path + Write - String + Folder where the VM data will be stored. + +.PARAMETER Generation + Write - UInt32 + Virtual machine's generation. Generation 2 virtual machines only support VHDX files. The default value is 1. + +.PARAMETER StartupMemory + Write - UInt64 + Startup RAM for the VM. If neither MinimumMemory nor MaximumMemory is specified, dynamic memory will be disabled. + +.PARAMETER MinimumMemory + Write - UInt64 + Minimum RAM for the VM. Setting this property enables dynamic memory, with the exception; If MinimumMemory, MaximumMemory and StartupMemory is equal, dynamic memory will be disabled. + +.PARAMETER MaximumMemory + Write - UInt64 + Maximum RAM for the VM. Setting this property enables dynamic memory, with the exception; If MinimumMemory, MaximumMemory and StartupMemory is equal, dynamic memory will be disabled. + +.PARAMETER MACAddress + Write - StringArray + MAC address(es) of the VM NICs. Multiple MAC addresses can now be assigned. + +.PARAMETER ProcessorCount + Write - UInt32 + Processor count for the VM. + +.PARAMETER WaitForIP + Write - Boolean + If specified, waits for the VM to get valid IP address. + +.PARAMETER RestartIfNeeded + Write - Boolean + If specified, will shutdown and restart the VM as needed for property changes. + +.PARAMETER Ensure + Write - String + Allowed values: Present, Absent + Specifies if the VM should be Present (created) or Absent (removed). The default value is Present. + +.PARAMETER Notes + Write - String + Notes about the VM. + +.PARAMETER SecureBoot + Write - Boolean + Specifies if Secure Boot should be enabled for Generation 2 virtual machines. Only supports generation 2 virtual machines. Default value is $true. + +.PARAMETER EnableGuestService + Write - Boolean + Enable Guest Service Interface for the VM. The default value is $false. + +.PARAMETER AutomaticCheckpointsEnabled + Write - Boolean + Enable AutomaticCheckpoints for the VM. + +.PARAMETER ID + Read - String + Returns the unique ID for the VM. + +.PARAMETER Status + Read - String + Returns the current status of the VM. + +.PARAMETER CPUUsage + Read - UInt32 + Returns the current CPU usage of the VM. + +.PARAMETER MemoryAssigned + Read - UInt64 + Returns the current memory assigned to the VM. + +.PARAMETER Uptime + Read - String + Returns the uptime of the VM. + +.PARAMETER CreationTime + Read - DateTime + Returns the creation time of the VM. + +.PARAMETER HasDynamicMemory + Read - Boolean + Returns $true if the VM has dynamic memory enabled. + +.PARAMETER NetworkAdapters + Read - StringArray + Returns the IP addresses of the virtual machine's network adapters. + +.EXAMPLE 1 + +Create a new VM. + +configuration Example +{ + param + ( + [System.String[]] + $NodeName = 'localhost', + + [Parameter(Mandatory = $true)] + [System.String] + $VMName, + + [Parameter(Mandatory = $true)] + [System.String] + $VhdPath + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + Node $NodeName + { + # Install HyperV feature, if not installed - Server SKU only + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + + # Ensures a VM with default settings + VMHyperV NewVM + { + Ensure = 'Present' + Name = $VMName + VhdPath = $VhdPath + Generation = 2 + DependsOn = '[WindowsFeature]HyperV' + } + } +} + +.EXAMPLE 2 + +Create a VM with DVD drive attached to it. + +configuration Example +{ + param + ( + [System.String[]] + $NodeName = 'localhost', + + [Parameter(Mandatory = $true)] + [System.String] + $VMName, + + [Parameter(Mandatory = $true)] + [System.String] + $VhdPath, + + [System.String] + $ISOPath + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + Node $NodeName + { + # Install HyperV feature, if not installed - Server SKU only + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + + # Ensures a VM with default settings + VMHyperV NewVM + { + Ensure = 'Present' + Name = $VMName + VhdPath = $VhdPath + Generation = $VhdPath.Split('.')[-1] + DependsOn = '[WindowsFeature]HyperV' + } + + # Adds DVD Drive with ISO + VMDvdDrive NewVMDvdDriveISO + { + Ensure = 'Present' + VMName = $VMName + ControllerNumber = 0 + ControllerLocation = 0 + Path = $ISOPath + DependsOn = '[VMHyperV]NewVM' + } + } +} + +.EXAMPLE 3 + +Create a VM with nested virtualization. + +configuration Example +{ + param + ( + [Parameter()] + [System.String[]] + $NodeName = 'localhost', + + [Parameter(Mandatory = $true)] + [System.String] + $VMName, + + [Parameter(Mandatory = $true)] + [System.String] + $VhdPath, + + [Parameter(Mandatory = $true)] + [System.UInt64] + $Memory + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + Node $NodeName + { + # Install HyperV feature, if not installed - Server SKU only + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + + # Ensures a VM with default settings + VMHyperV NewVM + { + Ensure = 'Present' + Name = $VMName + VhdPath = $VhdPath + Generation = 2 + StartupMemory = $Memory + MinimumMemory = $Memory + MaximumMemory = $Memory + DependsOn = '[WindowsFeature]HyperV' + } + + # Set the VM options + VMProcessor NestedVirtualization + { + VMName = $VMName + ExposeVirtualizationExtensions = $true + DependsOn = '[VMHyperV]NewVM' + } + } +} + +.EXAMPLE 4 + +Complete example. + +configuration Example +{ + param + ( + [System.String[]] + $NodeName = 'localhost', + + [Parameter(Mandatory = $true)] + [System.String] + $VMName, + + [Parameter(Mandatory = $true)] + [System.UInt64] + $VhdSizeBytes, + + [Parameter(Mandatory = $true)] + [System.UInt64] + $StartupMemory, + + [Parameter(Mandatory = $true)] + [System.UInt64] + $MinimumMemory, + + [Parameter(Mandatory = $true)] + [System.UInt64] + $MaximumMemory, + + [Parameter(Mandatory = $true)] + [System.String] + $SwitchName, + + [Parameter(Mandatory = $true)] + [System.String] + $Path, + + [Parameter(Mandatory = $true)] + [System.UInt32] + $ProcessorCount, + + [ValidateSet('Off','Paused','Running')] + [System.String] + $State = 'Off', + + [Switch] + $WaitForIP, + + [System.Boolean] + $AutomaticCheckpointsEnabled + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + Node $NodeName + { + # Logic to handle both Client and Server OS + # Configuration needs to be compiled on target server + $Operatingsystem = Get-CimInstance -ClassName Win32_OperatingSystem + if ($Operatingsystem.ProductType -eq 1) + { + # Client OS, install Hyper-V as OptionalFeature + $HyperVDependency = '[WindowsOptionalFeature]HyperV' + WindowsOptionalFeature HyperV + { + Ensure = 'Enable' + Name = 'Microsoft-Hyper-V-All' + } + } + else { + # Server OS, install HyperV as WindowsFeature + $HyperVDependency = '[WindowsFeature]HyperV','[WindowsFeature]HyperVPowerShell' + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + WindowsFeature HyperVPowerShell + { + Ensure = 'Present' + Name = 'Hyper-V-PowerShell' + } + } + + # Create new VHD + Vhd NewVhd + { + Ensure = 'Present' + Name = "$VMName-OSDisk.vhdx" + Path = $Path + Generation = 'vhdx' + MaximumSizeBytes = $VhdSizeBytes + DependsOn = $HyperVDependency + } + + # Ensures a VM with all the properties + VMHyperV NewVM + { + Ensure = 'Present' + Name = $VMName + VhdPath = (Join-Path -Path $Path -ChildPath "$VMName-OSDisk.vhdx") + SwitchName = $SwitchName + State = $State + Path = $Path + Generation = 2 + StartupMemory = $StartupMemory + MinimumMemory = $MinimumMemory + MaximumMemory = $MaximumMemory + ProcessorCount = $ProcessorCount + MACAddress = $MACAddress + RestartIfNeeded = $true + WaitForIP = $WaitForIP + AutomaticCheckpointsEnabled = $AutomaticCheckpointsEnabled + DependsOn = '[Vhd]NewVhd' + } + } +} + +.EXAMPLE 5 + +VM using dynamic memory. + +configuration Example +{ + param + ( + [System.String[]] + $NodeName = 'localhost', + + [Parameter(Mandatory = $true)] + [System.String] + $VMName, + + [Parameter(Mandatory = $true)] + [System.String] + $VhdPath, + + [Parameter(Mandatory = $true)] + [System.UInt64] + $StartupMemory, + + [Parameter(Mandatory = $true)] + [System.UInt64] + $MinimumMemory, + + [Parameter(Mandatory = $true)] + [System.UInt64] + $MaximumMemory + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + Node $NodeName + { + # Install HyperV feature, if not installed - Server SKU only + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + + # Ensures a VM with dynamic memory + VMHyperV NewVM + { + Ensure = 'Present' + Name = $VMName + VhdPath = $VhdPath + Generation = 2 + StartupMemory = $StartupMemory + MinimumMemory = $MinimumMemory + MaximumMemory = $MaximumMemory + DependsOn = '[WindowsFeature]HyperV' + } + } +} + +.EXAMPLE 6 + +Description not yet written. + +Configuration Example +{ + param + ( + [Parameter()] + [System.String[]] + $NodeName = 'localhost', + + [Parameter()] + [System.String] + $VMName = 'TestVM', + + [Parameter()] + [System.String] + $VhdPath = 'C:\temp\disk.vhdx', + + [Parameter()] + [System.String[]] + $SwitchName = @('MySwitch'), + + [Parameter()] + [System.String[]] + $MACAddress = '0000000' + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + Node $NodeName + { + # Install HyperV features, if not installed - Server SKU only + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + + WindowsFeature HyperVPowerShell + { + Ensure = 'Present' + Name = 'Hyper-V-PowerShell' + } + + # Dynamically build the 'DependsOn' array for the 'VMHyperV' feature + # based on the number of virtual switches specified + $VMHyperVDependsOn = @('[WindowsFeature]HyperV','[WindowsFeature]HyperVPowerShell') + + # Create each virtual switch + foreach ($vmSwitch in $SwitchName) + { + # Remove spaces and hyphens from the identifier + $vmSwitchName = $vmSwitch -replace ' ','' -replace '-','' + # Add the virtual switch dependency + $VMHyperVDependsOn += "[VMSwitch]$vmSwitchName" + + VMSwitch $vmSwitchName + { + Ensure = 'Present' + Name = $vmSwitch + Type = 'Internal' + DependsOn = '[WindowsFeature]HyperV','[WindowsFeature]HyperVPowerShell' + } + } + + # Ensures a VM with all the properties + VMHyperV $VMName + { + Ensure = 'Present' + Name = $VMName + VhdPath = $VhdPath + SwitchName = $SwitchName + MACAddress = $MACAddress + # Use the dynamically created dependency list/array + DependsOn = $VMHyperVDependsOn + } + } +} + diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.strings.psd1 b/DSCResources/HyperVDsc/DSCResources/DSC_VMNetworkAdapter/en/DSC_VMNetworkAdapter.strings.psd1 similarity index 100% rename from DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.strings.psd1 rename to DSCResources/HyperVDsc/DSCResources/DSC_VMNetworkAdapter/en/DSC_VMNetworkAdapter.strings.psd1 diff --git a/DSCResources/HyperVDsc/DSCResources/DSC_VMNetworkAdapter/en/about_VMNetworkAdapter.help.txt b/DSCResources/HyperVDsc/DSCResources/DSC_VMNetworkAdapter/en/about_VMNetworkAdapter.help.txt new file mode 100644 index 00000000..bcfbe1d4 --- /dev/null +++ b/DSCResources/HyperVDsc/DSCResources/DSC_VMNetworkAdapter/en/about_VMNetworkAdapter.help.txt @@ -0,0 +1,201 @@ +.NAME + VMNetworkAdapter + +.DESCRIPTION + Manages VM network adapters attached to a Hyper-V virtual machine or the + management OS. + + ## Requirements + + * The Hyper-V Role has to be installed on the machine. + * The Hyper-V PowerShell module has to be installed on the machine. + +.PARAMETER Id + Key - String + Unique string for identifying the resource instance. + +.PARAMETER Name + Required - String + Name of the network adapter as it appears either in the management OS or attached to a VM. + +.PARAMETER SwitchName + Required - String + Virtual Switch name to connect to. + +.PARAMETER VMName + Required - String + Name of the VM to attach to. If you want to attach new VM Network adapter to the management OS, set this property to 'ManagementOS'. + +.PARAMETER MacAddress + Write - String + Use this to specify a Static MAC Address. If this parameter is not specified, dynamic MAC Address will be set. + +.PARAMETER NetworkSetting + Write - Instance + Network Settings of the network adapter. If this parameter is not supplied, DHCP will be used. + +.PARAMETER VlanId + Write - String + Use this to specify a Vlan id on the Network Adapter. + +.PARAMETER Ensure + Write - String + Allowed values: Present, Absent + Ensures that the VM Network Adapter is Present or Absent. The default value is Present. + +.PARAMETER DynamicMacAddress + Read - Boolean + Returns $true if the network adapter uses a dynamic MAC address. + +.EXAMPLE 1 + +Description not yet written. + +Configuration Example +{ + Import-DscResource -ModuleName 'HyperVDsc' -Name VMNetworkAdapter + Import-DscResource -ModuleName PSDesiredStateConfiguration + + VMNetworkAdapter HostOSAdapter { + Id = 'Management-NIC' + Name = 'Management-NIC' + SwitchName = 'SETSwitch' + VMName = 'ManagementOS' + Ensure = 'Present' + } +} + +.EXAMPLE 2 + +Description not yet written. + +Configuration Example +{ + Import-DscResource -ModuleName 'HyperVDsc' -Name VMNetworkAdapter + Import-DscResource -ModuleName PSDesiredStateConfiguration + + VMNetworkAdapter ManagementAdapter { + Id = 'Management-NIC' + Name = 'Management-NIC' + SwitchName = 'SETSwitch' + VMName = 'ManagementOS' + Ensure = 'Present' + } + + VMNetworkAdapter ClusterAdapter { + Id = 'Cluster-NIC' + Name = 'Cluster-NIC' + SwitchName = 'SETSwitch' + VMName = 'ManagementOS' + Ensure = 'Present' + } +} + +.EXAMPLE 3 + +Add three network adapters to the same switch. + +Configuration Example +{ + Import-DscResource -ModuleName 'HyperVDsc' -Name VMNetworkAdapter + Import-DscResource -ModuleName PSDesiredStateConfiguration + + VMNetworkAdapter MyVM01NIC { + Id = 'MyVM01-NIC' + Name = 'MyVM01-NIC' + SwitchName = 'SETSwitch' + VMName = 'MyVM01' + Ensure = 'Present' + } + + VMNetworkAdapter MyVM02NIC { + Id = 'MyVM02-NIC' + Name = 'NetAdapter' + SwitchName = 'SETSwitch' + VMName = 'MyVM02' + Ensure = 'Present' + } + + VMNetworkAdapter MyVM03NIC { + Id = 'MyVM03-NIC' + Name = 'NetAdapter' + SwitchName = 'SETSwitch' + VMName = 'MyVM03' + Ensure = 'Present' + } +} + +.EXAMPLE 4 + +Description not yet written. + +Configuration Example +{ + Import-DscResource -ModuleName 'HyperVDsc' -Name VMNetworkAdapter + Import-DscResource -ModuleName PSDesiredStateConfiguration + + VMNetworkAdapter MyVM01NIC { + Id = 'MyVM01-NIC' + Name = 'MyVM01-NIC' + SwitchName = 'SETSwitch' + MacAddress = '001523be0c00' + VMName = 'MyVM01' + Ensure = 'Present' + } + + VMNetworkAdapter MyVM02NIC { + Id = 'MyVM02-NIC' + Name = 'MyVM02-NIC' + SwitchName = 'SETSwitch' + MacAddress = '001523be0c00' + VMName = 'MyVM02' + Ensure = 'Present' + } +} + +.EXAMPLE 5 + +Add a network adapter that is using static IP address. + +Configuration Example +{ + Import-DscResource -ModuleName 'HyperVDsc' + + VMNetworkAdapter MyVM01NIC + { + Ensure = 'Present' + Id = 'MyVM01-NIC' + Name = 'MyVM01-NIC' + SwitchName = 'SETSwitch' + MacAddress = '001523be0c00' + VMName = 'MyVM01' + NetworkSetting = VMNetworkAdapterNetworkSettings + { + IpAddress = '192.168.0.100' + Subnet = '255.255.255.255' + DefaultGateway = '192.168.0.1' + DnsServer = @( '192.168.0.1', '192.168.0.2' ) + } + } +} + +.EXAMPLE 6 + +Add a network adapter that is using a VLAN tag. + +Configuration Example +{ + Import-DscResource -ModuleName 'HyperVDsc' -Name VMNetworkAdapter + Import-DscResource -ModuleName PSDesiredStateConfiguration + + VMNetworkAdapter MyVM01NIC { + Id = 'MyVM01-NIC' + Name = 'MyVM01-NIC' + SwitchName = 'SETSwitch' + MacAddress = '001523be0c00' + VMName = 'MyVM01' + VlanId = '1' + Ensure = 'Present' + } +} + diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/en-US/MSFT_xVMProcessor.strings.psd1 b/DSCResources/HyperVDsc/DSCResources/DSC_VMProcessor/en/DSC_VMProcessor.strings.psd1 similarity index 100% rename from DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/en-US/MSFT_xVMProcessor.strings.psd1 rename to DSCResources/HyperVDsc/DSCResources/DSC_VMProcessor/en/DSC_VMProcessor.strings.psd1 diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/en-US/about_xVMProcessor.help.txt b/DSCResources/HyperVDsc/DSCResources/DSC_VMProcessor/en/about_VMProcessor.help.txt similarity index 80% rename from DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/en-US/about_xVMProcessor.help.txt rename to DSCResources/HyperVDsc/DSCResources/DSC_VMProcessor/en/about_VMProcessor.help.txt index 6635fcde..9a2a7919 100644 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/en-US/about_xVMProcessor.help.txt +++ b/DSCResources/HyperVDsc/DSCResources/DSC_VMProcessor/en/about_VMProcessor.help.txt @@ -1,5 +1,5 @@ .NAME - xVMProcessor + VMProcessor .DESCRIPTION Manages Hyper-V virtual machine processor options. @@ -15,15 +15,15 @@ .PARAMETER EnableHostResourceProtection Write - Boolean - Specifies whether to enable host resource protection. + Specifies whether to enable host resource protection. NOTE: Only supported on Windows 10 and Server 2016 or higher. .PARAMETER ExposeVirtualizationExtensions Write - Boolean - Specifies whether nested virtualization is enabled. + Specifies whether nested virtualization is enabled. NOTE: Only supported on Windows 10 and Server 2016 or higher. .PARAMETER HwThreadCountPerCore Write - UInt64 - Specifies the maximum thread core per processor core. + Specifies the maximum thread core per processor core. NOTE: Only supported on Windows 10 and Server 2016 or higher. .PARAMETER Maximum Write - UInt64 @@ -59,5 +59,5 @@ .PARAMETER RestartIfNeeded Write - Boolean - If specified, shutdowns and restarts the VM if needed for property changes. + If set to $true then shutdowns and restarts are allowed for the VM when needed for property changes. diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/en-US/MSFT_xVMScsiController.strings.psd1 b/DSCResources/HyperVDsc/DSCResources/DSC_VMScsiController/en/DSC_VMScsiController.strings.psd1 similarity index 100% rename from DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/en-US/MSFT_xVMScsiController.strings.psd1 rename to DSCResources/HyperVDsc/DSCResources/DSC_VMScsiController/en/DSC_VMScsiController.strings.psd1 diff --git a/DSCResources/HyperVDsc/DSCResources/DSC_VMScsiController/en/about_VMScsiController.help.txt b/DSCResources/HyperVDsc/DSCResources/DSC_VMScsiController/en/about_VMScsiController.help.txt new file mode 100644 index 00000000..8adc204c --- /dev/null +++ b/DSCResources/HyperVDsc/DSCResources/DSC_VMScsiController/en/about_VMScsiController.help.txt @@ -0,0 +1,100 @@ +.NAME + VMScsiController + +.DESCRIPTION + Manages the SCSI controllers attached to a Hyper-V virtual machine. + + When removing a controller, all the disks still connected to the controller + will be detached. + + ## Requirements + + * The Hyper-V Role has to be installed on the machine. + * The Hyper-V PowerShell module has to be installed on the machine. + +.PARAMETER VMName + Key - String + Specifies the name of the virtual machine whose SCSI controller is to be manipulated. + +.PARAMETER ControllerNumber + Key - UInt32 + Allowed values: 0, 1, 2, 3 + Specifies the number of the SCSI controller to be set. If not specified, it defaults to 0. + +.PARAMETER Ensure + Write - String + Allowed values: Present, Absent + Specifies if the SCSI controller should exist or not. If not specified, it defaults to Present. + +.PARAMETER RestartIfNeeded + Write - Boolean + If set to $true then shutdowns and restarts are allowed for the VM when needed for property changes. If not specified, it defaults to $false. + +.EXAMPLE 1 + +Add a SCSI controller to a VM. + +configuration Example +{ + param + ( + [Parameter()] + [System.String[]] + $NodeName = 'localhost', + + [Parameter(Mandatory = $true)] + [System.String] + $VMName, + + [Parameter(Mandatory = $true)] + [System.String] + $VhdPath + ) + + Import-DscResource -ModuleName 'HyperVDsc' + Import-DscResource -ModuleName 'PSDesiredStateConfiguration' + + Node $NodeName + { + $diskNameOS = "$VMName-OS.vhdx" + + # Install HyperV feature, if not installed - Server SKU only + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + + # Create the VHD for the OS + VHD DiskOS + { + Ensure = 'Present' + Name = $diskNameOS + Path = $VhdPath + Generation = 'vhdx' + MaximumSizeBytes = 20GB + DependsOn = '[WindowsFeature]HyperV' + } + + # Create the VM + VMHyperV NewVM + { + Ensure = 'Present' + Name = $VMName + VhdPath = Join-Path -Path $VhdPath -ChildPath $diskNameOS + Generation = 2 + DependsOn = '[VHD]DiskOS' + } + + # Add and additional SCSI controller + VMScsiController Controller + { + Ensure = 'Present' + VMName = $VMName + ControllerNumber = 1 + DependsOn = '[VMHyperV]NewVM' + } + + } +} + diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/en-us/MSFT_xVMSwitch.strings.psd1 b/DSCResources/HyperVDsc/DSCResources/DSC_VMSwitch/en/DSC_VMSwitch.strings.psd1 similarity index 100% rename from DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/en-us/MSFT_xVMSwitch.strings.psd1 rename to DSCResources/HyperVDsc/DSCResources/DSC_VMSwitch/en/DSC_VMSwitch.strings.psd1 diff --git a/DSCResources/HyperVDsc/DSCResources/DSC_VMSwitch/en/about_VMSwitch.help.txt b/DSCResources/HyperVDsc/DSCResources/DSC_VMSwitch/en/about_VMSwitch.help.txt new file mode 100644 index 00000000..00aec26d --- /dev/null +++ b/DSCResources/HyperVDsc/DSCResources/DSC_VMSwitch/en/about_VMSwitch.help.txt @@ -0,0 +1,241 @@ +.NAME + VMSwitch + +.DESCRIPTION + Manages virtual switches in a Hyper-V host. + + ## Requirements + + * The Hyper-V Role has to be installed on the machine. + * The Hyper-V PowerShell module has to be installed on the machine. + +.PARAMETER Name + Key - String + The desired VM Switch name. + +.PARAMETER Type + Key - String + Allowed values: External, Internal, Private + The desired type of switch. + +.PARAMETER NetAdapterName + Write - StringArray + Network adapter name(s) for external switch type. + +.PARAMETER AllowManagementOS + Write - Boolean + Specify if the VM host has access to the physical NIC. The default value is $false. + +.PARAMETER EnableEmbeddedTeaming + Write - Boolean + Should embedded NIC teaming be used (Windows Server 2016 or higher only). The default value is $false. + +.PARAMETER BandwidthReservationMode + Write - String + Allowed values: Default, Weight, Absolute, None, NA + Specify the QoS mode used (options other than NA are only supported on Hyper-V 2012 or higher). The default value is NA. + +.PARAMETER LoadBalancingAlgorithm + Write - String + Allowed values: Dynamic, HyperVPort + Specify the Load Balancing algorithm which should be used for the embedded NIC teaming. + +.PARAMETER Ensure + Write - String + Allowed values: Present, Absent + Ensures that the VM Switch is Present or Absent. The default value is Present. + +.PARAMETER Id + Write - String + Specify the desired Unique ID of the Hyper-V switch. If not specified the ID will be generated by the system every time the Hyper-V Switch is created. (Windows Server 2016 or higher only) + +.PARAMETER NetAdapterInterfaceDescription + Read - String + Returns the description of the network interface. + +.EXAMPLE 1 + +Creates a switch of the type External. + +configuration Example +{ + param + ( + [System.String[]] + $NodeName = 'localhost', + + [Parameter(Mandatory = $true)] + [System.String] + $SwitchName, + + [Parameter(Mandatory = $true)] + [System.String] + $NetAdapterName + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + Node $NodeName + { + # Install HyperV feature, if not installed - Server SKU only + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + + # Ensures a VM with default settings + VMSwitch ExternalSwitch + { + Ensure = 'Present' + Name = $SwitchName + Type = 'External' + NetAdapterName = $NetAdapterName + DependsOn = '[WindowsFeature]HyperV' + } + } +} + +.EXAMPLE 2 + +Creates a switch that is of type External and using load balancing. + +Configuration Example +{ + param + ( + [Parameter()] + [System.String[]] + $NodeName = 'localhost', + + [Parameter(Mandatory = $true)] + [System.String] + $SwitchName, + + [Parameter(Mandatory = $true)] + [System.String[]] + $NetAdapterNames + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + Node $NodeName + { + # Install HyperV feature, if not installed - Server SKU only + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + + WindowsFeature HyperVTools + { + Ensure = 'Present' + Name = 'RSAT-Hyper-V-Tools' + DependsOn = '[WindowsFeature]HyperV' + } + + # Ensures a VM with Load Balancing Algorithm 'Hyper-V Port" + VMSwitch ExternalSwitch + { + Ensure = 'Present' + Name = $SwitchName + Type = 'External' + NetAdapterName = $NetAdapterNames + EnableEmbeddedTeaming = $true + LoadBalancingAlgorithm = 'HyperVPort' + DependsOn = '[WindowsFeature]HyperVTools' + } + } +} + +.EXAMPLE 3 + +Creates a switch of the type External and uses embedded teaming. + +Configuration Example +{ + param + ( + [Parameter()] + [System.String[]] + $NodeName = 'localhost', + + [Parameter(Mandatory = $true)] + [System.String] + $SwitchName, + + [Parameter(Mandatory = $true)] + [System.String[]] + $NetAdapterNames + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + Node $NodeName + { + # Install HyperV feature, if not installed - Server SKU only + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + + WindowsFeature HyperVTools + { + Ensure = 'Present' + Name = 'RSAT-Hyper-V-Tools' + DependsOn = '[WindowsFeature]HyperV' + } + + # Ensures a VM with default settings + VMSwitch ExternalSwitch + { + Ensure = 'Present' + Name = $SwitchName + Type = 'External' + NetAdapterName = $NetAdapterNames + EnableEmbeddedTeaming = $true + DependsOn = '[WindowsFeature]HyperVTools' + } + } +} + +.EXAMPLE 4 + +Creates a switch of the type Internal. + +configuration Example +{ + param + ( + [System.String[]] + $NodeName = 'localhost', + + [Parameter(Mandatory = $true)] + [System.String] + $SwitchName + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + Node $NodeName + { + # Install HyperV feature, if not installed - Server SKU only + WindowsFeature HyperV + { + Ensure = 'Present' + Name = 'Hyper-V' + } + + # Ensures a VM with default settings + VMSwitch InternalSwitch + { + Ensure = 'Present' + Name = $SwitchName + Type = 'Internal' + DependsOn = '[WindowsFeature]HyperV' + } + } +} + diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/en-US/MSFT_xVhdFileDirectory.strings.psd1 b/DSCResources/HyperVDsc/DSCResources/DSC_VhdFileDirectory/en/DSC_VhdFileDirectory.strings.psd1 similarity index 100% rename from DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/en-US/MSFT_xVhdFileDirectory.strings.psd1 rename to DSCResources/HyperVDsc/DSCResources/DSC_VhdFileDirectory/en/DSC_VhdFileDirectory.strings.psd1 diff --git a/DSCResources/HyperVDsc/DSCResources/DSC_VhdFileDirectory/en/about_VhdFile.help.txt b/DSCResources/HyperVDsc/DSCResources/DSC_VhdFileDirectory/en/about_VhdFile.help.txt new file mode 100644 index 00000000..9589174d --- /dev/null +++ b/DSCResources/HyperVDsc/DSCResources/DSC_VhdFileDirectory/en/about_VhdFile.help.txt @@ -0,0 +1,125 @@ +.NAME + VhdFile + +.DESCRIPTION + Manages files or directories in a VHD. + + You can use it to copy files/folders to the VHD, remove files/folders + from a VHD, and change attributes of a file in a VHD (e.g. change a + file attribute to 'ReadOnly' or 'Hidden'). + + This resource is particularly useful when bootstrapping DSC Configurations + into a VM. + + ## Requirements + + * The Hyper-V Role has to be installed on the machine. + * The Hyper-V PowerShell module has to be installed on the machine. + +.PARAMETER VhdPath + Key - String + Path to the VHD. + +.PARAMETER FileDirectory + Required - InstanceArray + The FileDirectory objects to copy to the VHD (as used in the File resource). + +.PARAMETER CheckSum + Write - String + Allowed values: ModifiedDate, SHA-1, SHA-256, SHA-512 + Indicates the checksum type to use when determining whether two files are the same. The default value is ModifiedDate. + +.EXAMPLE 1 + +Not yet written. + +Configuration Example +{ + param + ( + [Parameter()] + $vhdPath = 'C:\temp\disk.vhdx', + + [Parameter()] + $relativeDestinationPath = 'Temp', + + [Parameter()] + [ValidateSet ('Archive', 'Hidden', 'ReadOnly', 'System' )] + $attribute = 'Archive' + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + VhdFile Change-Attribute + { + VhdPath = $vhdPath + FileDirectory = DSC_FileDirectory + { + DestinationPath = $relativeDestinationPath + Attributes = $attribute + } + } +} + +.EXAMPLE 2 + +Not yet written. + +Configuration Example +{ + param + ( + [Parameter()] + $vhdPath = 'C:\temp\disk.vhdx', + + [Parameter()] + $itemToCopy = 'C:\Temp', + + [Parameter()] + $relativeDestinationPath = 'Temp' + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + VhdFile FileCopy + { + VhdPath = $vhdPath + FileDirectory = DSC_FileDirectory + { + SourcePath = $itemToCopy + DestinationPath = $relativeDestinationPath + } + } +} + +.EXAMPLE 3 + +Not yet written. + +Configuration Example +{ + param + ( + [Parameter()] + $vhdPath = 'C:\temp\disk.vhdx', + + [Parameter()] + $relativeDestinationPath = 'Temp', + + [Parameter()] + $Ensure = 'Absent' + ) + + Import-DscResource -ModuleName 'HyperVDsc' + + VhdFile RemoveFile + { + VhdPath = $vhdPath + FileDirectory = DSC_FileDirectory + { + DestinationPath = $relativeDestinationPath + Ensure = $Ensure + } + } +} + diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVHD/MSFT_xVHD.psm1 b/DSCResources/xHyper-V/DSCResources/MSFT_xVHD/MSFT_xVHD.psm1 deleted file mode 100644 index eb7243e4..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVHD/MSFT_xVHD.psm1 +++ /dev/null @@ -1,387 +0,0 @@ -$script:dscResourceCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/DscResource.Common' - -Import-Module -Name $script:dscResourceCommonModulePath - -$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' - -<# -.SYNOPSIS - Gets MSFT_xVHD resource current state. - -.PARAMETER Name - The desired VHD file name. - -.PARAMETER Path - The desired Path where the VHD will be created. - -.PARAMETER Generation - Virtual disk format. -#> -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - [Parameter(Mandatory = $true)] - [System.String] - $Path, - - [Parameter()] - [ValidateSet('Vhd', 'Vhdx')] - [System.String] - $Generation = 'Vhd' - ) - - # Check if Hyper-V module is present for Hyper-V cmdlets - if (!(Get-Module -ListAvailable -Name Hyper-V)) - { - throw 'Please ensure that Hyper-V role is installed with its PowerShell module' - } - - # Construct the full path for the vhdFile - $vhdName = GetNameWithExtension -Name $Name -Generation $Generation - $vhdFilePath = Join-Path -Path $Path -ChildPath $vhdName - Write-Verbose -Message "Vhd full path is $vhdFilePath" - - $vhd = Get-VHD -Path $vhdFilePath -ErrorAction SilentlyContinue - - $ensure = 'Absent' - if ($vhd) - { - $ensure = 'Present' - } - - @{ - Name = $Name - Path = $Path - ParentPath = $vhd.ParentPath - Generation = $vhd.VhdFormat - Ensure = $ensure - ID = $vhd.DiskIdentifier - Type = $vhd.VhdType - FileSizeBytes = $vhd.FileSize - MaximumSizeBytes = $vhd.Size - IsAttached = $vhd.Attached - } -} - -<# -.SYNOPSIS - Configures MSFT_xVHD resource state. - -.PARAMETER Name - The desired VHD file name. - -.PARAMETER Path - The desired Path where the VHD will be created. - -.PARAMETER ParentPath - Parent VHD file path, for differencing disk. - -.PARAMETER MaximumSizeBytes - Maximum size of VHD to be created. - -.PARAMETER Type - Virtual disk type. - -.PARAMETER Generation - Virtual disk format. - -.PARAMETER Ensure - Ensures that the VHD is Present or Absent. -#> -function Set-TargetResource -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - [Parameter(Mandatory = $true)] - [System.String] - $Path, - - [Parameter()] - [System.String] - $ParentPath, - - [Parameter()] - [System.UInt64] - $MaximumSizeBytes, - - [Parameter()] - [ValidateSet('Dynamic', 'Fixed', 'Differencing')] - [System.String] - $Type = 'Dynamic', - - [Parameter()] - [ValidateSet('Vhd', 'Vhdx')] - [System.String] - $Generation = 'Vhd', - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present' - ) - - # Construct the full path for the vhdFile - $vhdName = GetNameWithExtension -Name $Name -Generation $Generation - $vhdFilePath = Join-Path -Path $Path -ChildPath $vhdName - Write-Verbose -Message "Vhd full path is $vhdFilePath" - - Write-Verbose -Message "Checking if $vhdFilePath is $Ensure ..." - - # If vhd should be absent, delete it - if ($Ensure -eq 'Absent') - { - if (Test-Path -Path $vhdFilePath) - { - Write-Verbose -Message "$vhdFilePath is not $Ensure" - Remove-Item -Path $vhdFilePath -Force -ErrorAction Stop - } - Write-Verbose -Message "$vhdFilePath is $Ensure" - } - - else - { - # Check if the Vhd is present - try - { - $vhd = Get-VHD -Path $vhdFilePath -ErrorAction Stop - - # If this is a differencing disk, check the parent path - if ($ParentPath) - { - Write-Verbose -Message "Checking if $vhdFilePath parent path is $ParentPath ..." - - # If the parent path is not set correct, fix it - if ($vhd.ParentPath -ne $ParentPath) - { - Write-Verbose -Message "$vhdFilePath parent path is not $ParentPath." - Set-VHD -Path $vhdFilePath -ParentPath $ParentPath - Write-Verbose -Message "$vhdFilePath parent path is now $ParentPath." - } - else - { - Write-Verbose -Message "$vhdFilePath is $Ensure and parent path is set to $ParentPath." - } - } - - # This is a fixed disk, check the size - elseif ($PSBoundParameters.ContainsKey('MaximumSizeBytes')) - { - Write-Verbose -Message "Checking if $vhdFilePath size is $MaximumSizeBytes ..." - - # If the size is not correct, fix it - if ($vhd.Size -ne $MaximumSizeBytes) - { - Write-Verbose -Message "$vhdFilePath size is not $MaximumSizeBytes." - Resize-VHD -Path $vhdFilePath -SizeBytes $MaximumSizeBytes - Write-Verbose -Message "$vhdFilePath size is now $MaximumSizeBytes." - } - else - { - Write-Verbose -Message "$vhdFilePath is $Ensure and size is $MaximumSizeBytes." - } - } - - if ($vhd.Type -ne $Type) - { - Write-Verbose -Message 'This module can''t convert disk types' - } - } - - # Vhd file is not present - catch - { - Write-Verbose -Message "$vhdFilePath is not $Ensure" - if ($ParentPath) - { - $null = New-VHD -Path $vhdFilePath -ParentPath $ParentPath - } - else - { - $params = @{ - Path = $vhdFilePath - SizeBytes = $MaximumSizeBytes - $Type = $True - } - $null = New-VHD @params - } - - Write-Verbose -Message "$vhdFilePath is now $Ensure" - } - } -} - -<# -.SYNOPSIS - Tests if MSFT_xVHD resource state is in the desired state or not. - -.PARAMETER Name - The desired VHD file name. - -.PARAMETER Path - The desired Path where the VHD will be created. - -.PARAMETER ParentPath - Parent VHD file path, for differencing disk. - -.PARAMETER MaximumSizeBytes - Maximum size of VHD to be created. - -.PARAMETER Type - Virtual disk type. - -.PARAMETER Generation - Virtual disk format. - -.PARAMETER Ensure - Ensures that the VHD is Present or Absent. -#> -function Test-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - [Parameter(Mandatory = $true)] - [System.String] - $Path, - - [Parameter()] - [System.String] - $ParentPath, - - [Parameter()] - [System.UInt64] - $MaximumSizeBytes, - - [Parameter()] - [ValidateSet('Vhd', 'Vhdx')] - [System.String] - $Generation = 'Vhd', - - [Parameter()] - [ValidateSet('Dynamic', 'Fixed', 'Differencing')] - [System.String] - $Type = 'Dynamic', - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present' - ) - - # Check if Hyper-V module is present for Hyper-V cmdlets - if (!(Get-Module -ListAvailable -Name Hyper-V)) - { - throw 'Please ensure that Hyper-V role is installed with its PowerShell module' - } - - # input validation - if ($Type -ne 'Differencing' -and -not $MaximumSizeBytes) - { - throw 'Specify MaximumSizeBytes property for Fixed and Dynamic VHDs.' - } - - if ($ParentPath -and $Type -ne 'Differencing') - { - throw 'Parent path is only supported for Differencing disks' - } - - if (-not $ParentPath -and $Type -eq 'Differencing') - { - throw 'Differencing requires a parent path' - } - - if ($ParentPath) - { - if (!(Test-Path -Path $ParentPath)) - { - throw "$ParentPath does not exists" - } - - # Check if the generation matches parenting disk - if ($Generation -and ($ParentPath.Split('.')[-1] -ne $Generation)) - { - throw "Generation $Generation should match ParentPath extension $($ParentPath.Split('.')[-1])" - } - } - - if (!(Test-Path -Path $Path)) - { - throw "$Path does not exists" - } - - # Construct the full path for the vhdFile - $vhdName = GetNameWithExtension -Name $Name -Generation $Generation - $vhdFilePath = Join-Path -Path $Path -ChildPath $vhdName - Write-Verbose -Message "Vhd full path is $vhdFilePath" - - # Add the logic here and at the end return either $true or $false. - $result = Test-VHD -Path $vhdFilePath -ErrorAction SilentlyContinue - Write-Verbose -Message "Vhd $vhdFilePath is present:$result and Ensure is $Ensure" - return ($result -and ($Ensure -eq 'Present')) -} - -<# -.SYNOPSIS - Appends generation appropriate file extension if not already specified. - -.PARAMETER Name - The desired VHD file name. - -.PARAMETER Generation - Virtual disk format. -#> -function GetNameWithExtension -{ - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - [Parameter(Mandatory = $true)] - [System.String] - $Generation = 'Vhd' - ) - - # If the name ends with vhd or vhdx don't append the generation to the vhdname. - if ($Name -like '*.vhd' -or $Name -like '*.vhdx') - { - $extension = $Name.Split('.')[-1] - if ($Generation -ne $extension) - { - throw "the extension $extension on the name does not match the generation $Generation" - } - else - { - Write-Verbose -Message "Vhd full name is $vhdName" - $vhdName = $Name - } - } - else - { - # Append generation to the name - $vhdName = "$Name.$Generation" - Write-Verbose -Message "Vhd full name is $vhdName" - } - - $vhdName -} - -Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVHD/MSFT_xVHD.schema.mof b/DSCResources/xHyper-V/DSCResources/MSFT_xVHD/MSFT_xVHD.schema.mof deleted file mode 100644 index f41e9d2a..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVHD/MSFT_xVHD.schema.mof +++ /dev/null @@ -1,15 +0,0 @@ -[ClassVersion("1.0.0"), FriendlyName("xVHD")] -class MSFT_xVHD : OMI_BaseResource -{ - [Key, Description("Name of the VHD File")] String Name; - [Key, Description("Folder where the VHD will be created")] String Path; - [Write, Description("Parent VHD file path, for differencing disk")] String ParentPath; - [Write, Description("Maximum size of Vhd to be created")] Uint64 MaximumSizeBytes; - [Write, Description("Virtual disk format - Vhd or Vhdx"), ValueMap{"Vhd","Vhdx"}, Values{"Vhd","Vhdx"}] String Generation; - [Write, Description("Should the VHD be created or deleted"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; - [Read, Description("Virtual Disk Identifier")] String ID; - [Write, Description("Type of Vhd - Dynamic, Fixed, Differencing"), ValueMap{"Dynamic","Fixed","Differencing"}, Values{"Dynamic","Fixed","Differencing"}] String Type; - [Read, Description("Current size of the VHD")] Uint64 FileSizeBytes; - [Read, Description("Is the VHD attached to a VM or not")] Boolean IsAttached; -}; - diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVHD/README.md b/DSCResources/xHyper-V/DSCResources/MSFT_xVHD/README.md deleted file mode 100644 index b0f90d1b..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVHD/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Description - -Manages VHDs in a Hyper-V host. - -## Requirements - -* The Hyper-V Role has to be installed on the machine. -* The Hyper-V PowerShell module has to be installed on the machine. diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVHD/en-US/about_xVHD.help.txt b/DSCResources/xHyper-V/DSCResources/MSFT_xVHD/en-US/about_xVHD.help.txt deleted file mode 100644 index 4183b5da..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVHD/en-US/about_xVHD.help.txt +++ /dev/null @@ -1,54 +0,0 @@ -.NAME - xVHD - -.DESCRIPTION - Manages VHDs in a Hyper-V host. - - ## Requirements - - * The Hyper-V Role has to be installed on the machine. - * The Hyper-V PowerShell module has to be installed on the machine. - -.PARAMETER Name - Key - String - Name of the VHD File - -.PARAMETER Path - Key - String - Folder where the VHD will be created - -.PARAMETER ParentPath - Write - String - Parent VHD file path, for differencing disk - -.PARAMETER MaximumSizeBytes - Write - UInt64 - Maximum size of Vhd to be created - -.PARAMETER Generation - Write - String - Allowed values: Vhd, Vhdx - Virtual disk format - Vhd or Vhdx - -.PARAMETER Ensure - Write - String - Allowed values: Present, Absent - Should the VHD be created or deleted - -.PARAMETER ID - Read - String - Virtual Disk Identifier - -.PARAMETER Type - Write - String - Allowed values: Dynamic, Fixed, Differencing - Type of Vhd - Dynamic, Fixed, Differencing - -.PARAMETER FileSizeBytes - Read - UInt64 - Current size of the VHD - -.PARAMETER IsAttached - Read - Boolean - Is the VHD attached to a VM or not - diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.psm1 b/DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.psm1 deleted file mode 100644 index 8eea5317..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.psm1 +++ /dev/null @@ -1,425 +0,0 @@ -$script:dscResourceCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/DscResource.Common' -$script:hyperVDscCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/HyperVDsc.Common' - -Import-Module -Name $script:dscResourceCommonModulePath -Import-Module -Name $script:hyperVDscCommonModulePath - -$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' - -<# - .SYNOPSIS - Returns the current status of the VM DVD Drive. - - .PARAMETER VMName - Specifies the name of the virtual machine to which the DVD drive is to be added. - - .PARAMETER ControllerNumber - Specifies the number of the controller to which the DVD drive is to be added. - - .PARAMETER ControllerLocation - Specifies the number of the location on the controller at which the DVD drive is to be added. -#> -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter(Mandatory = $true)] - [System.UInt32] - $ControllerNumber, - - [Parameter(Mandatory = $true)] - [System.UInt32] - $ControllerLocation - ) - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($script:localizedData.GettingVMDVDDriveMessage ` - -f $VMName, $ControllerNumber, $ControllerLocation) - ) -join '' ) - - Test-ParameterValid @PSBoundParameters - - $dvdDrive = Get-VMDvdDrive @PSBoundParameters - - if ($dvdDrive) - { - $returnValue = @{ - VMName = $VMName - ControllerLocation = $ControllerLocation - ControllerNumber = $ControllerNumber - Path = $dvdDrive.Path - Ensure = 'Present' - } - } - else - { - $returnValue = @{ - VMName = $VMName - ControllerLocation = $ControllerLocation - ControllerNumber = $ControllerNumber - Path = '' - Ensure = 'Absent' - } - } # if - - $returnValue -} # Get-TargetResource - -<# - .SYNOPSIS - Adds, removes or changes the mounted ISO on a VM DVD Drive. - - .PARAMETER VMName - Specifies the name of the virtual machine to which the DVD drive is to be added. - - .PARAMETER ControllerNumber - Specifies the number of the controller to which the DVD drive is to be added. - - .PARAMETER ControllerLocation - Specifies the number of the location on the controller at which the DVD drive is to be added. - - .PARAMETER Path - Specifies the full path to the virtual hard disk file or physical hard disk volume for the - added DVD drive. - - .PARAMETER Ensure - Specifies if the DVD Drive should exist or not. -#> -function Set-TargetResource -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter(Mandatory = $true)] - [System.UInt32] - $ControllerLocation, - - [Parameter(Mandatory = $true)] - [System.UInt32] - $ControllerNumber, - - [Parameter()] - [System.String] - $Path, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present' - ) - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($script:localizedData.SettingVMDVDDriveMessage ` - -f $VMName, $ControllerNumber, $ControllerLocation) - ) -join '' ) - - $null = $PSBoundParameters.Remove('Path') - $null = $PSBoundParameters.Remove('Ensure') - - # Get the current status of the VM DVD Drive - $dvdDrive = Get-TargetResource @PSBoundParameters - - if ($Ensure -eq 'Present') - { - # The DVD Drive should exist - if ($dvdDrive.Ensure -eq 'Present') - { - # The DVD Drive already exists - if (-not [System.String]::IsNullOrWhiteSpace($Path) ` - -and ($Path -ne $dvdDrive.Path)) - { - # The current path assigned to the DVD Drive needs to be changed. - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($script:localizedData.VMDVDDriveChangePathMessage) ` - -f $VMName, $ControllerNumber, $ControllerLocation, $Path ` - ) -join '' ) - - Set-VMDvdDrive @PSBoundParameters -Path $Path - } - } - else - { - # The DVD Drive does not exist but should. Change required. - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($script:localizedData.VMDVDDriveAddMessage) ` - -f $VMName, $ControllerNumber, $ControllerLocation, $Path ` - ) -join '' ) - - if (-not [System.String]::IsNullOrWhiteSpace($Path)) - { - $PSBoundParameters.Add('Path', $Path) - } # if - - Add-VMDvdDrive @PSBoundParameters - } # if - } - else - { - # The DVD Drive should not exist - if ($dvdDrive.Ensure -eq 'Present') - { - # The DVD Drive does exist, but should not. Change required. - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($script:localizedData.VMDVDDriveRemoveMessage) ` - -f $VMName, $ControllerNumber, $ControllerLocation ` - ) -join '' ) - - Remove-VMDvdDrive @PSBoundParameters - } # if - } # if -} # Set-TargetResource - -<# - .SYNOPSIS - Tests the state of a VM DVD Drive and the mounted ISO. - - .PARAMETER VMName - Specifies the name of the virtual machine to which the DVD drive is to be added. - - .PARAMETER ControllerNumber - Specifies the number of the controller to which the DVD drive is to be added. - - .PARAMETER ControllerLocation - Specifies the number of the location on the controller at which the DVD drive is to be added. - - .PARAMETER Path - Specifies the full path to the virtual hard disk file or physical hard disk volume for the - added DVD drive. - - .PARAMETER Ensure - Specifies if the DVD Drive should exist or not. -#> -function Test-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter(Mandatory = $true)] - [System.UInt32] - $ControllerLocation, - - [Parameter(Mandatory = $true)] - [System.UInt32] - $ControllerNumber, - - [Parameter()] - [System.String] - $Path, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present' - ) - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($script:localizedData.TestingVMDVDDriveMessage ` - -f $VMName, $ControllerNumber, $ControllerLocation) - ) -join '' ) - - $null = $PSBoundParameters.Remove('Path') - $null = $PSBoundParameters.Remove('Ensure') - - # Get the current status of the VM DVD Drive - $dvdDrive = Get-TargetResource @PSBoundParameters - - # Flag to signal whether settings are correct - [System.Boolean] $desiredConfigurationMatch = $true - - if ($Ensure -eq 'Present') - { - # The DVD Drive should exist - if ($dvdDrive.Ensure -eq 'Present') - { - # The DVD Drive already exists - if (-not [System.String]::IsNullOrWhiteSpace($Path) ` - -and ($Path -ne $dvdDrive.Path)) - { - # The current path assigned to the DVD drive is wrong. Change required. - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($script:localizedData.VMDVDDriveExistsAndShouldPathMismatchMessage) ` - -f $VMName, $ControllerNumber, $ControllerLocation, $Path, $dvdDrive.Path ` - ) -join '' ) - - $desiredConfigurationMatch = $false - } - else - { - # The DVD drive exists and should. Change not required. - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($script:localizedData.VMDVDDriveExistsAndShouldMessage) ` - -f $VMName, $ControllerNumber, $ControllerLocation, $Path ` - ) -join '' ) - } # if - } - else - { - # The DVD Drive does not exist but should. Change required. - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($script:localizedData.VMDVDDriveDoesNotExistButShouldMessage) ` - -f $VMName, $ControllerNumber, $ControllerLocation ` - ) -join '' ) - - $desiredConfigurationMatch = $false - } # if - } - else - { - # The DVD Drive should not exist - if ($dvdDrive.Ensure -eq 'Present') - { - # The DVD Drive does exist, but should not. Change required. - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($script:localizedData.VMDVDDriveDoesExistButShouldNotMessage) ` - -f $VMName, $ControllerNumber, $ControllerLocation ` - ) -join '' ) - - $desiredConfigurationMatch = $false - } - else - { - # The DVD Drive does not exist and should not. Change not required. - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($script:localizedData.VMDVDDriveDoesNotExistAndShouldNotMessage) ` - -f $VMName, $ControllerNumber, $ControllerLocation ` - ) -join '' ) - } # if - } # if - - return $desiredConfigurationMatch -} # Test-TargetResource - -<# - .SYNOPSIS - Validates that the parameters passed are valid. If the parameter combination - is invalid then an exception will be thrown. The following items are validated: - - The VM exists. - - A disk mount point at the controller number/location exists. - - A hard disk is not already mounted at the controller number/location. - - The Path if required is valid. - - .PARAMETER VMName - Specifies the name of the virtual machine to which the DVD drive is to be added. - - .PARAMETER ControllerNumber - Specifies the number of the controller to which the DVD drive is to be added. - - .PARAMETER ControllerLocation - Specifies the number of the location on the controller at which the DVD drive is to be added. - - .PARAMETER Path - Specifies the full path to the virtual hard disk file or physical hard disk volume for the - added DVD drive. - - .PARAMETER Ensure - Specifies if the DVD Drive should exist or not. - - .OUTPUTS - Returns true if the parameters are valid, but will throw a specific error if not. -#> -function Test-ParameterValid -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter(Mandatory = $true)] - [System.UInt32] - $ControllerLocation, - - [Parameter(Mandatory = $true)] - [System.UInt32] - $ControllerNumber, - - [Parameter()] - [System.String] - $Path, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present' - ) - - # Check if Hyper-V module is present for Hyper-V cmdlets - if (-not (Get-Module -ListAvailable -Name Hyper-V)) - { - $errorMessage = $script:localizedData.RoleMissingError -f 'Hyper-V' - - New-ObjectNotFoundException -Message $errorMessage - } # if - - # Does the VM exist? - $null = Get-VM -Name $VMName - - # Does the controller exist? - if (-not (Get-VMScsiController -VMName $VMName -ControllerNumber $ControllerNumber) ` - -and -not (Get-VMIdeController -VMName $VMName -ControllerNumber $ControllerNumber)) - { - # No it does not - $errorMessage = $script:localizedData.VMControllerDoesNotExistError -f $VMName, $ControllerNumber - - New-ObjectNotFoundException -Message $errorMessage - } # if - - # Is a Hard Drive assigned to this controller location/number? - if (Get-VMHardDiskDrive ` - -VMName $VMName ` - -ControllerLocation $ControllerLocation ` - -ControllerNumber $ControllerNumber) - { - # Yes, so don't even try and touch this - $errorMessage = $script:localizedData.ControllerConflictError -f $VMName, $ControllerNumber, $ControllerLocation - - New-ObjectNotFoundException -Message $errorMessage - } # if - - if ($Ensure -eq 'Present') - { - # If the path is not blank does it exist? - if (-not ([System.String]::IsNullOrWhiteSpace($Path))) - { - if (-not (Test-Path -Path $Path)) - { - # Path does not exist - $errorMessage = $script:localizedData.PathDoesNotExistError -f $Path - - New-ObjectNotFoundException -Message $errorMessage - } # if - } # if - } # if - - return $true -} # Test-ParameterValid - -Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.schema.mof b/DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.schema.mof deleted file mode 100644 index 04e3c4ad..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.schema.mof +++ /dev/null @@ -1,9 +0,0 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xVMDvdDrive")] -class MSFT_xVMDvdDrive : OMI_BaseResource -{ - [Key, Description("Specifies the name of the virtual machine to which the DVD drive is to be added.")] String VMName; - [Key, Description("Specifies the number of the controller to which the DVD drive is to be added.")] Uint32 ControllerNumber; - [Key, Description("Specifies the number of the location on the controller at which the DVD drive is to be added.")] Uint32 ControllerLocation; - [Write, Description("Specifies the full path to the virtual hard disk file or physical hard disk volume for the added DVD drive.")] String Path; - [Write, Description("Specifies if the DVD Drive should exist or not."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; -}; diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/README.md b/DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/README.md deleted file mode 100644 index 8eded356..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMDvdDrive/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Description - -Manages DVD drives attached to a Hyper-V virtual machine. - -## Requirements - -* The Hyper-V Role has to be installed on the machine. -* The Hyper-V PowerShell module has to be installed on the machine. diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.psm1 b/DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.psm1 deleted file mode 100644 index 85f4322c..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.psm1 +++ /dev/null @@ -1,262 +0,0 @@ -$script:dscResourceCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/DscResource.Common' -$script:hyperVDscCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/HyperVDsc.Common' - -Import-Module -Name $script:dscResourceCommonModulePath -Import-Module -Name $script:hyperVDscCommonModulePath - -$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' - -<# - .SYNOPSIS - Returns the current status of the VM hard disk drive. - .PARAMETER VMName - Specifies the name of the virtual machine whose hard disk drive status is to be fetched. - .PARAMETER Path - Specifies the full path of the VHD file linked to the hard disk drive. -#> -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter(Mandatory = $true)] - [System.String] - $Path - ) - - Assert-Module -ModuleName 'Hyper-V' - - $hardDiskDrive = Get-VMHardDiskDrive -VMName $VMName -ErrorAction Stop | - Where-Object -FilterScript { $_.Path -eq $Path } - - if ($null -eq $hardDiskDrive) - { - Write-Verbose -Message ($script:localizedData.DiskNotFound -f $Path, $VMName) - $ensure = 'Absent' - } - else - { - Write-Verbose -Message ($script:localizedData.DiskFound -f $Path, $VMName) - $ensure = 'Present' - } - - return @{ - VMName = $VMName - Path = $hardDiskDrive.Path - ControllerType = $hardDiskDrive.ControllerType - ControllerNumber = $hardDiskDrive.ControllerNumber - ControllerLocation = $hardDiskDrive.ControllerLocation - Ensure = $ensure - } -} - -<# - .SYNOPSIS - Tests the state of a VM hard disk drive. - .PARAMETER VMName - Specifies the name of the virtual machine whose hard disk drive is to be tested. - .PARAMETER Path - Specifies the full path of the VHD file to be tested. - .PARAMETER ControllerType - Specifies the type of controller to which the the hard disk drive is to be set (IDE/SCSI). - Default to SCSI. - .PARAMETER ControllerNumber - Specifies the number of the controller to which the hard disk drive is to be set. - If not specified, the controller number defaults to 0. - .PARAMETER ControllerLocation - Specifies the number of the location on the controller at which the hard disk drive is to be - set. If not specified, the controller location defaults to 0. - .PARAMETER Ensure - Specifies if the hard disk drive should exist or not. Defaults to Present. -#> -function Test-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter(Mandatory = $true)] - [System.String] - $Path, - - [Parameter()] - [ValidateSet('IDE', 'SCSI')] - [System.String] - $ControllerType = 'SCSI', - - [Parameter()] - [ValidateSet(0, 1, 2, 3)] - [System.UInt32] - $ControllerNumber, - - [Parameter()] - [ValidateRange(0, 63)] - [System.UInt32] - $ControllerLocation, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present' - ) - - $resource = Get-TargetResource -VMName $VMName -Path $Path - - # throw exception when the ControllerNumber or ControllerLocation are out of bounds for IDE - if ($ControllerType -eq 'IDE' -and ($ControllerNumber -gt 1 -or $ControllerLocation -gt 1)) - { - $errorMessage = $script:localizedData.IdeLocationError -f $ControllerNumber, $ControllerLocation - - New-InvalidArgumentException -ArgumentName 'ControllerType' -Message $errorMessage - } - - $isCompliant = $true - foreach ($key in $PSBoundParameters.Keys) - { - # Only check passed parameter values - if ($resource.ContainsKey($key)) - { - Write-Verbose -Message ($script:localizedData.ComparingParameter -f $key, - $PSBoundParameters[$key], - $resource[$key]) - $isCompliant = $isCompliant -and ($PSBoundParameters[$key] -eq $resource[$key]) - } - } - return $isCompliant -} - -<# - .SYNOPSIS - Tests the state of a VM hard disk drive. - .PARAMETER VMName - Specifies the name of the virtual machine whose hard disk drive is to be tested. - .PARAMETER Path - Specifies the full path of the VHD file to be tested. - .PARAMETER ControllerType - Specifies the type of controller to which the the hard disk drive is to be set (IDE/SCSI). - Default to SCSI. - .PARAMETER ControllerNumber - Specifies the number of the controller to which the hard disk drive is to be set. - If not specified, the controller number defaults to 0. - .PARAMETER ControllerLocation - Specifies the number of the location on the controller at which the hard disk drive is to be - set. If not specified, the controller location defaults to 0. - .PARAMETER Ensure - Specifies if the hard disk drive should exist or not. Defaults to Present. -#> -function Set-TargetResource -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter(Mandatory = $true)] - [System.String] - $Path, - - [Parameter()] - [ValidateSet('IDE', 'SCSI')] - [System.String] - $ControllerType = 'SCSI', - - [Parameter()] - [ValidateSet(0, 1, 2, 3)] - [System.UInt32] - $ControllerNumber, - - [Parameter()] - [ValidateRange(0, 63)] - [System.UInt32] - $ControllerLocation, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present' - ) - - Assert-Module -ModuleName 'Hyper-V' - - $hardDiskDrive = Get-VMHardDiskDrive -VMName $VMName | - Where-Object -FilterScript { $_.Path -eq $Path } - - if ($Ensure -eq 'Present') - { - $null = $PSBoundParameters.Remove('Ensure') - - Write-Verbose -Message ($script:localizedData.CheckingDiskIsAttached) - if ($hardDiskDrive) - { - Write-Verbose -Message ($script:localizedData.DiskFound -f $Path, $VMName) - $null = $PSBoundParameters.Remove('VMName') - $null = $PSBoundParameters.Remove('Path') - # As the operation is a move, we must use ToController instead of Controller - if ($PSBoundParameters.ContainsKey('ControllerType')) - { - $null = $PSBoundParameters.Remove('ControllerType') - $null = $PSBoundParameters.Add('ToControllerType', $ControllerType) - } - if ($PSBoundParameters.ContainsKey('ControllerNumber')) - { - $null = $PSBoundParameters.Remove('ControllerNumber') - $null = $PSBoundParameters.Add('ToControllerNumber', $ControllerNumber) - } - if ($PSBoundParameters.ContainsKey('ControllerLocation')) - { - $null = $PSBoundParameters.Remove('ControllerLocation') - $null = $PSBoundParameters.Add('ToControllerLocation', $ControllerLocation) - } - $null = $hardDiskDrive | Set-VMHardDiskDrive @PSBoundParameters - } - else - { - Write-Verbose -Message ($script:localizedData.CheckingExistingDiskLocation) - - $getVMHardDiskDriveParams = @{ - VMName = $VMName - ControllerType = $ControllerType - ControllerNumber = $ControllerNumber - ControllerLocation = $ControllerLocation - } - - $existingHardDiskDrive = Get-VMHardDiskDrive @getVMHardDiskDriveParams - - if ($null -ne $existingHardDiskDrive) - { - $errorMessage = $script:localizedData.DiskPresentError -f $ControllerNumber, $ControllerLocation - - New-InvalidResultException -Message $errorMessage - } - - Write-Verbose -Message ($script:localizedData.AddingDisk -f $Path, $VMName) - $null = Add-VMHardDiskDrive @PSBoundParameters - } - } - else - { - # We must ensure that the disk is absent - if ($hardDiskDrive) - { - Write-Verbose -Message ($script:localizedData.RemovingDisk -f $Path, $VMName) - $null = $hardDiskDrive | Remove-VMHardDiskDrive - } - else - { - Write-Warning -Message ($script:localizedData.DiskNotFound -f $Path, $VMName) - } - } -} - -Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.schema.mof b/DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.schema.mof deleted file mode 100644 index 3375c15c..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.schema.mof +++ /dev/null @@ -1,10 +0,0 @@ -[ClassVersion("1.0.0"), FriendlyName("xVMHardDiskDrive")] -class MSFT_xVMHardDiskDrive : OMI_BaseResource -{ - [Key, Description("Specifies the name of the virtual machine whose hard disk drive is to be manipulated.")] String VMName; - [Key, Description("Specifies the full path to the location of the VHD that represents the hard disk drive.")] String Path; - [Write, Description("Specifies the controller type - IDE/SCSI where the disk is attached. If not specified, it defaults to SCSI."), ValueMap{"IDE","SCSI"}, Values{"IDE","SCSI"}] String ControllerType; - [Write, Description("Specifies the number of the controller where the disk is attached. If not specified, it defaults to 0."), ValueMap{"0","1","2","3"}, Values{"0","1","2","3"}] Uint32 ControllerNumber; - [Write, Description("Specifies the number of the location on the controller where the disk is attached. If not specified, it defaults to 0.")] Uint32 ControllerLocation; - [Write, Description("Specifies if the hard disk drive must be present or absent. If not specified, it defaults to Present."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; -}; diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/README.md b/DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/README.md deleted file mode 100644 index 9ca45a72..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Description - -Manages VHD(X)s attached to a Hyper-V virtual machine. - -When ControllerNumber or ControllerLocation is not provided, the same logic -as Set-VMHardDiskDrive cmdlet is used. - -## Requirements - -* The Hyper-V Role has to be installed on the machine. -* The Hyper-V PowerShell module has to be installed on the machine. diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/en-US/about_xVMHardDiskDrive.help.txt b/DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/en-US/about_xVMHardDiskDrive.help.txt deleted file mode 100644 index c840efeb..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHardDiskDrive/en-US/about_xVMHardDiskDrive.help.txt +++ /dev/null @@ -1,41 +0,0 @@ -.NAME - xVMHardDiskDrive - -.DESCRIPTION - Manages VHD(X)s attached to a Hyper-V virtual machine. - - When ControllerNumber or ControllerLocation is not provided, the same logic - as Set-VMHardDiskDrive cmdlet is used. - - ## Requirements - - * The Hyper-V Role has to be installed on the machine. - * The Hyper-V PowerShell module has to be installed on the machine. - -.PARAMETER VMName - Key - String - Specifies the name of the virtual machine whose hard disk drive is to be manipulated. - -.PARAMETER Path - Key - String - Specifies the full path to the location of the VHD that represents the hard disk drive. - -.PARAMETER ControllerType - Write - String - Allowed values: IDE, SCSI - Specifies the controller type - IDE/SCSI where the disk is attached. If not specified, it defaults to SCSI. - -.PARAMETER ControllerNumber - Write - UInt32 - Allowed values: 0, 1, 2, 3 - Specifies the number of the controller where the disk is attached. If not specified, it defaults to 0. - -.PARAMETER ControllerLocation - Write - UInt32 - Specifies the number of the location on the controller where the disk is attached. If not specified, it defaults to 0. - -.PARAMETER Ensure - Write - String - Allowed values: Present, Absent - Specifies if the hard disk drive must be present or absent. If not specified, it defaults to Present. - diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/MSFT_xVMHost.psm1 b/DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/MSFT_xVMHost.psm1 deleted file mode 100644 index 476f935d..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/MSFT_xVMHost.psm1 +++ /dev/null @@ -1,450 +0,0 @@ -$script:dscResourceCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/DscResource.Common' -$script:hyperVDscCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/HyperVDsc.Common' - -Import-Module -Name $script:dscResourceCommonModulePath -Import-Module -Name $script:hyperVDscCommonModulePath - -$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' - -<# -.SYNOPSIS - Gets MSFT_xVMHost resource current state. - -.PARAMETER IsSingleInstance - Specifies the resource is a single instance, the value must be 'Yes'. -#> -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [ValidateSet('Yes')] - [System.String] - $IsSingleInstance - ) - - Assert-Module -ModuleName 'Hyper-V' - - Write-Verbose -Message $script:localizedData.QueryingVMHost - $vmHost = Get-VMHost - - # Convert the current TimeSpan into minutes - $convertFromTimeSpanParams = @{ - TimeSpan = $vmHost.ResourceMeteringSaveInterval - TimeSpanType = 'Minutes' - } - $resourceMeteringSaveInterval = ConvertFrom-TimeSpan @convertFromTimeSpanParams - - $configuration = @{ - IsSingleInstance = $IsSingleInstance - EnableEnhancedSessionMode = $vmHost.EnableEnhancedSessionMode - FibreChannelWwnn = $vmHost.FibreChannelWwnn - FibreChannelWwpnMaximum = $vmHost.FibreChannelWwpnMaximum - FibreChannelWwpnMinimum = $vmHost.FibreChannelWwpnMinimum - MacAddressMaximum = $vmHost.MacAddressMaximum - MacAddressMinimum = $vmHost.MacAddressMinimum - MaximumStorageMigrations = $vmHost.MaximumStorageMigrations - MaximumVirtualMachineMigrations = $vmHost.MaximumVirtualMachineMigrations - NumaSpanningEnabled = $vmHost.NumaSpanningEnabled - ResourceMeteringSaveIntervalMinute = $resourceMeteringSaveInterval - UseAnyNetworkForMigration = $vmHost.UseAnyNetworkForMigration - VirtualHardDiskPath = $vmHost.VirtualHardDiskPath - VirtualMachineMigrationAuthenticationType = $vmHost.VirtualMachineMigrationAuthenticationType - VirtualMachineMigrationPerformanceOption = $vmHost.VirtualMachineMigrationPerformanceOption - VirtualMachinePath = $vmHost.VirtualMachinePath - VirtualMachineMigrationEnabled = $vmHost.VirtualMachineMigrationEnabled - } - - return $configuration -} - -<# -.SYNOPSIS - Tests if MSFT_xVMHost resource state is in the desired state or not. - -.PARAMETER IsSingleInstance - Specifies the resource is a single instance, the value must be 'Yes'. - -.PARAMETER EnableEnhancedSessionMode - Indicates whether users can use enhanced mode when they connect to virtual machines on this - server by using Virtual Machine Connection. - -.PARAMETER FibreChannelWwnn - Specifies the default value of the World Wide Node Name on the Hyper-V host. - -.PARAMETER FibreChannelWwpnMaximum - Specifies the maximum value that can be used to generate World Wide Port Names on the Hyper-V - host. Use with the FibreChannelWwpnMinimum parameter to establish a range of WWPNs that the - specified Hyper-V host can assign to virtual Fibre Channel adapters. - -.PARAMETER FibreChannelWwpnMinimum - Specifies the minimum value that can be used to generate the World Wide Port Names on the - Hyper-V host. Use with the FibreChannelWwpnMaximum parameter to establish a range of WWPNs that - the specified Hyper-V host can assign to virtual Fibre Channel adapters. - -.PARAMETER MacAddressMaximum - Specifies the maximum MAC address using a valid hexadecimal value. Use with the - MacAddressMinimum parameter to establish a range of MAC addresses that the specified Hyper-V - host can assign to virtual machines configured to receive dynamic MAC addresses. - -.PARAMETER MacAddressMinimum - Specifies the minimum MAC address using a valid hexadecimal value. Use with the - MacAddressMaximum parameter to establish a range of MAC addresses that the specified Hyper-V - host can assign to virtual machines configured to receive dynamic MAC addresses. - -.PARAMETER MaximumStorageMigrations - Specifies the maximum number of storage migrations that can be performed at the same time on - the Hyper-V host. - -.PARAMETER MaximumVirtualMachineMigrations - Specifies the maximum number of live migrations that can be performed at the same time on the - Hyper-V host. - -.PARAMETER NumaSpanningEnabled - Specifies whether virtual machines on the Hyper-V host can use resources from more than one - NUMA node. - -.PARAMETER ResourceMeteringSaveIntervalMinute - Specifies how often the Hyper-V host saves the data that tracks resource usage. The range is a - minimum of 60 minutes to a maximum 1440 minutes (24 hours). - -.PARAMETER UseAnyNetworkForMigration - Specifies how networks are selected for incoming live migration traffic. If set to $True, any - available network on the host can be used for this traffic. If set to $False, incoming live - migration traffic is transmitted only on the networks specified in the MigrationNetworks - property of the host. - -.PARAMETER VirtualHardDiskPath - Specifies the default folder to store virtual hard disks on the Hyper-V host. - -.PARAMETER VirtualMachineMigrationAuthenticationType - Specifies the type of authentication to be used for live migrations. The acceptable values for - this parameter are 'Kerberos' and 'CredSSP'. - -.PARAMETER VirtualMachineMigrationPerformanceOption - Specifies the performance option to use for live migration. The acceptable values for this - parameter are 'TCPIP', 'Compression' and 'SMB'. - -.PARAMETER VirtualMachinePath - Specifies the default folder to store virtual machine configuration files on the Hyper-V host. - -.PARAMETER VirtualMachineMigrationEnabled - Indicates whether Live Migration should be enabled or disabled on the Hyper-V host. -#> -function Test-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [Parameter(Mandatory = $true)] - [ValidateSet('Yes')] - [System.String] - $IsSingleInstance, - - [Parameter()] - [System.Boolean] - $EnableEnhancedSessionMode, - - [Parameter()] - [System.String] - $FibreChannelWwnn, - - [Parameter()] - [System.String] - $FibreChannelWwpnMaximum, - - [Parameter()] - [System.String] - $FibreChannelWwpnMinimum, - - [Parameter()] - [System.String] - $MacAddressMaximum, - - [Parameter()] - [System.String] - $MacAddressMinimum, - - [Parameter()] - [System.UInt32] - $MaximumStorageMigrations, - - [Parameter()] - [System.UInt32] - $MaximumVirtualMachineMigrations, - - [Parameter()] - [System.Boolean] - $NumaSpanningEnabled, - - [Parameter()] - [System.UInt32] - $ResourceMeteringSaveIntervalMinute, - - [Parameter()] - [System.Boolean] - $UseAnyNetworkForMigration, - - [Parameter()] - [System.String] - $VirtualHardDiskPath, - - [Parameter()] - [ValidateSet('Kerberos', 'CredSSP')] - [System.String] - $VirtualMachineMigrationAuthenticationType, - - [Parameter()] - [ValidateSet('TCPIP', 'Compression', 'SMB')] - [System.String] - $VirtualMachineMigrationPerformanceOption, - - [Parameter()] - [System.String] - $VirtualMachinePath, - - [Parameter()] - [System.Boolean] - $VirtualMachineMigrationEnabled - ) - - Assert-Module -ModuleName 'Hyper-V' - - $targetResource = Get-TargetResource -IsSingleInstance $IsSingleInstance - $isTargetResourceCompliant = $true - - foreach ($parameter in $PSBoundParameters.GetEnumerator()) - { - if (($targetResource.ContainsKey($parameter.Key)) -and - ($parameter.Value -ne $targetResource[$parameter.Key])) - { - $isTargetResourceCompliant = $false - Write-Verbose -Message ($script:localizedData.PropertyMismatch -f $parameter.Key, - $parameter.Value, $targetResource[$parameter.Key]) - } - } - - if ($isTargetResourceCompliant) - { - Write-Verbose -Message $script:localizedData.VMHostInDesiredState - } - else - { - Write-Verbose -Message $script:localizedData.VMHostNotInDesiredState - } - - return $isTargetResourceCompliant -} #end function - -<# -.SYNOPSIS - Configures MSFT_xVMHost resource state. - -.PARAMETER IsSingleInstance - Specifies the resource is a single instance, the value must be 'Yes'. - -.PARAMETER EnableEnhancedSessionMode - Indicates whether users can use enhanced mode when they connect to virtual machines on this - server by using Virtual Machine Connection. - -.PARAMETER FibreChannelWwnn - Specifies the default value of the World Wide Node Name on the Hyper-V host. - -.PARAMETER FibreChannelWwpnMaximum - Specifies the maximum value that can be used to generate World Wide Port Names on the Hyper-V - host. Use with the FibreChannelWwpnMinimum parameter to establish a range of WWPNs that the - specified Hyper-V host can assign to virtual Fibre Channel adapters. - -.PARAMETER FibreChannelWwpnMinimum - Specifies the minimum value that can be used to generate the World Wide Port Names on the - Hyper-V host. Use with the FibreChannelWwpnMaximum parameter to establish a range of WWPNs that - the specified Hyper-V host can assign to virtual Fibre Channel adapters. - -.PARAMETER MacAddressMaximum - Specifies the maximum MAC address using a valid hexadecimal value. Use with the - MacAddressMinimum parameter to establish a range of MAC addresses that the specified Hyper-V - host can assign to virtual machines configured to receive dynamic MAC addresses. - -.PARAMETER MacAddressMinimum - Specifies the minimum MAC address using a valid hexadecimal value. Use with the - MacAddressMaximum parameter to establish a range of MAC addresses that the specified Hyper-V - host can assign to virtual machines configured to receive dynamic MAC addresses. - -.PARAMETER MaximumStorageMigrations - Specifies the maximum number of storage migrations that can be performed at the same time on - the Hyper-V host. - -.PARAMETER MaximumVirtualMachineMigrations - Specifies the maximum number of live migrations that can be performed at the same time on the - Hyper-V host. - -.PARAMETER NumaSpanningEnabled - Specifies whether virtual machines on the Hyper-V host can use resources from more than one - NUMA node. - -.PARAMETER ResourceMeteringSaveIntervalMinute - Specifies how often the Hyper-V host saves the data that tracks resource usage. The range is a - minimum of 60 minutes to a maximum 1440 minutes (24 hours). - -.PARAMETER UseAnyNetworkForMigration - Specifies how networks are selected for incoming live migration traffic. If set to $True, any - available network on the host can be used for this traffic. If set to $False, incoming live - migration traffic is transmitted only on the networks specified in the MigrationNetworks - property of the host. - -.PARAMETER VirtualHardDiskPath - Specifies the default folder to store virtual hard disks on the Hyper-V host. - -.PARAMETER VirtualMachineMigrationAuthenticationType - Specifies the type of authentication to be used for live migrations. The acceptable values for - this parameter are 'Kerberos' and 'CredSSP'. - -.PARAMETER VirtualMachineMigrationPerformanceOption - Specifies the performance option to use for live migration. The acceptable values for this - parameter are 'TCPIP', 'Compression' and 'SMB'. - -.PARAMETER VirtualMachinePath - Specifies the default folder to store virtual machine configuration files on the Hyper-V host. - -.PARAMETER VirtualMachineMigrationEnabled - Indicates whether Live Migration should be enabled or disabled on the Hyper-V host. -#> -function Set-TargetResource -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateSet('Yes')] - [System.String] - $IsSingleInstance, - - [Parameter()] - [System.Boolean] - $EnableEnhancedSessionMode, - - [Parameter()] - [System.String] - $FibreChannelWwnn, - - [Parameter()] - [System.String] - $FibreChannelWwpnMaximum, - - [Parameter()] - [System.String] - $FibreChannelWwpnMinimum, - - [Parameter()] - [System.String] - $MacAddressMaximum, - - [Parameter()] - [System.String] - $MacAddressMinimum, - - [Parameter()] - [System.UInt32] - $MaximumStorageMigrations, - - [Parameter()] - [System.UInt32] - $MaximumVirtualMachineMigrations, - - [Parameter()] - [System.Boolean] - $NumaSpanningEnabled, - - [Parameter()] - [System.UInt32] - $ResourceMeteringSaveIntervalMinute, - - [Parameter()] - [System.Boolean] - $UseAnyNetworkForMigration, - - [Parameter()] - [System.String] - $VirtualHardDiskPath, - - [Parameter()] - [ValidateSet('Kerberos', 'CredSSP')] - [System.String] - $VirtualMachineMigrationAuthenticationType, - - [Parameter()] - [ValidateSet('TCPIP', 'Compression', 'SMB')] - [System.String] - $VirtualMachineMigrationPerformanceOption, - - [Parameter()] - [System.String] - $VirtualMachinePath, - - [Parameter()] - [System.Boolean] - $VirtualMachineMigrationEnabled - ) - - Assert-Module -ModuleName 'Hyper-V' - - $null = $PSBoundParameters.Remove('IsSingleInstance') - - if ($PSBoundParameters.ContainsKey('ResourceMeteringSaveIntervalMinute')) - { - # Need to convert the specified minutes into a TimeSpan object first - $convertToTimeSpanParams = @{ - TimeInterval = $PSBoundParameters['ResourceMeteringSaveIntervalMinute'] - TimeIntervalType = 'Minutes' - } - $resourceMeteringSaveInterval = ConvertTo-TimeSpan @convertToTimeSpanParams - - # Remove the existing UInt32 explicit type and add the TimeSpan type parameter - $null = $PSBoundParameters.Remove('ResourceMeteringSaveIntervalMinute') - $PSBoundParameters['ResourceMeteringSaveInterval'] = $resourceMeteringSaveInterval - } - - if ($PSBoundParameters.ContainsKey('VirtualMachineMigrationEnabled')) - { - $null = $PSBoundParameters.Remove('VirtualMachineMigrationEnabled') - - if ($VirtualMachineMigrationEnabled) - { - if ((Get-CimInstance -ClassName Win32_ComputerSystem).PartOfDomain) - { - Write-Verbose -Message $script:localizedData.EnableLiveMigration - - Enable-VMMigration - } - else - { - $errorMessage = $script:localizedData.LiveMigrationDomainOnly - - New-InvalidOperationException -Message $errorMessage - } - } - else - { - Write-Verbose -Message $script:localizedData.DisableLiveMigration - - Disable-VMMigration - } - } - - $vmHostParams = $PSBoundParameters.GetEnumerator() | Where-Object -FilterScript { - $_.Key -notin ( - [System.Management.Automation.PSCmdlet]::CommonParameters + - [System.Management.Automation.PSCmdlet]::OptionalCommonParameters - ) - } - - if ($vmHostParams.Count -ne 0) - { - Write-Verbose -Message $script:localizedData.UpdatingVMHostProperties - Set-VMHost @PSBoundParameters - Write-Verbose -Message $script:localizedData.VMHostPropertiesUpdated - } -} #end function diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/MSFT_xVMHost.schema.mof b/DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/MSFT_xVMHost.schema.mof deleted file mode 100644 index 12be0e89..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/MSFT_xVMHost.schema.mof +++ /dev/null @@ -1,21 +0,0 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xVMHost")] -class MSFT_xVMHost : OMI_BaseResource -{ - [Key, Description("Specifies the resource is a single instance, the value must be 'Yes'."), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance; - [Write, Description("Indicates whether users can use enhanced mode when they connect to virtual machines on this server by using Virtual Machine Connection.")] Boolean EnableEnhancedSessionMode; - [Write, Description("Specifies the default value of the World Wide Node Name on the Hyper-V host.")] String FibreChannelWwnn; - [Write, Description("Specifies the maximum value that can be used to generate World Wide Port Names on the Hyper-V host.")] String FibreChannelWwpnMaximum; - [Write, Description("Specifies the minimum value that can be used to generate the World Wide Port Names on the Hyper-V host.")] String FibreChannelWwpnMinimum; - [Write, Description("Specifies the maximum MAC address using a valid hexadecimal value.")] String MacAddressMaximum; - [Write, Description("Specifies the minimum MAC address using a valid hexadecimal value.")] String MacAddressMinimum; - [Write, Description("Specifies the maximum number of storage migrations that can be performed at the same time on the Hyper-V host.")] Uint32 MaximumStorageMigrations; - [Write, Description("Specifies the maximum number of live migrations that can be performed at the same time on the Hyper-V host.")] Uint32 MaximumVirtualMachineMigrations; - [Write, Description("Specifies whether virtual machines on the Hyper-V host can use resources from more than one NUMA node.")] Boolean NumaSpanningEnabled; - [Write, Description("Specifies how often the Hyper-V host saves the data that tracks resource usage. The range is a minimum of 60 minutes to a maximum of 1440 (24 hours).")] Uint32 ResourceMeteringSaveIntervalMinute; - [Write, Description("Specifies how networks are selected for incoming live migration traffic.")] Boolean UseAnyNetworkForMigration; - [Write, Description("Specifies the default folder to store virtual hard disks on the Hyper-V host.")] String VirtualHardDiskPath; - [Write, Description("Specifies the type of authentication to be used for live migrations. The acceptable values for this parameter are 'Kerberos' and 'CredSSP'."), ValueMap{"CredSSP","Kerberos"}, Values{"CredSSP","Kerberos"}] String VirtualMachineMigrationAuthenticationType; - [Write, Description("Specifies the performance option to use for live migration. The acceptable values for this parameter are 'TCPIP', 'Compression' and 'SMB'."), ValueMap{"TCPIP","Compression","SMB"}, Values{"TCPIP","Compression","SMB"}] String VirtualMachineMigrationPerformanceOption; - [Write, Description("Specifies the default folder to store virtual machine configuration files on the Hyper-V host.")] String VirtualMachinePath; - [Write, Description("Indicates whether Live Migration should be enabled or disabled on the Hyper-V host.")] Boolean VirtualMachineMigrationEnabled; -}; diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/README.md b/DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/README.md deleted file mode 100644 index 56ab5819..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHost/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Description - -Manages Hyper-V host settings. - -## Requirements - -* The Hyper-V Role has to be installed on the machine. -* The Hyper-V PowerShell module has to be installed on the machine. diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.psm1 b/DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.psm1 deleted file mode 100644 index 112942fd..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.psm1 +++ /dev/null @@ -1,993 +0,0 @@ -$script:dscResourceCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/DscResource.Common' -$script:hyperVDscCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/HyperVDsc.Common' - -Import-Module -Name $script:dscResourceCommonModulePath -Import-Module -Name $script:hyperVDscCommonModulePath - -$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' - -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - [Parameter(Mandatory = $true)] - [System.String] - $VhdPath - ) - - Write-Verbose -Message ($script:localizedData.QueryingVM -f $Name) - - # Check if Hyper-V module is present for Hyper-V cmdlets - if (!(Get-Module -ListAvailable -Name Hyper-V)) - { - throw ($script:localizedData.RoleMissingError -f 'Hyper-V') - } - - $vmobj = Get-VM -Name $Name -ErrorAction SilentlyContinue - - # Check if 1 or 0 VM with name = $name exist - if ($vmobj.count -gt 1) - { - throw ($script:localizedData.MoreThanOneVMExistsError -f $Name) - } - - <# - Retrieve the Vhd hierarchy to ensure we enumerate snapshots/differencing disks - Fixes #28 - #> - if ($null -ne $vmobj) - { - $vhdChain = @(Get-VhdHierarchy -VhdPath ($vmObj.HardDrives[0].Path)) - } - - $vmSecureBootState = $false - if ($vmobj.Generation -eq 2) - { - # Retrieve secure boot status (can only be enabled on Generation 2 VMs) and convert to a boolean. - $vmSecureBootState = ($vmobj | Get-VMFirmware).SecureBoot -eq 'On' - } - - $guestServiceId = 'Microsoft:{0}\6C09BB55-D683-4DA0-8931-C9BF705F6480' -f $vmObj.Id - - $macAddress = @() - $switchName = @() - $ipAddress = @() - - foreach ($networkAdapter in $vmobj.NetworkAdapters) - { - $macAddress += $networkAdapter.MacAddress - - if (-Not ([System.String]::IsNullOrEmpty($networkAdapter.SwitchName))) - { - $switchName += $networkAdapter.SwitchName - } - - if ($networkAdapter.IPAddresses.Count -ge 1) - { - $ipAddress += $networkAdapter.IPAddresses - } - } - - @{ - Name = $Name - # Return the Vhd specified if it exists in the Vhd chain - VhdPath = if ($vhdChain -contains $VhdPath) - { - $VhdPath - } - else - { - $null - } - SwitchName = $switchName - State = $vmobj.State - Path = $vmobj.Path - Generation = $vmobj.Generation - SecureBoot = $vmSecureBootState - StartupMemory = $vmobj.MemoryStartup - MinimumMemory = $vmobj.MemoryMinimum - MaximumMemory = $vmobj.MemoryMaximum - MACAddress = $macAddress - ProcessorCount = $vmobj.ProcessorCount - Ensure = if ($vmobj) - { - 'Present' - } - else - { - 'Absent' - } - ID = $vmobj.Id - Status = $vmobj.Status - CPUUsage = $vmobj.CPUUsage - MemoryAssigned = $vmobj.MemoryAssigned - Uptime = $vmobj.Uptime - CreationTime = $vmobj.CreationTime - HasDynamicMemory = $vmobj.DynamicMemoryEnabled - NetworkAdapters = $ipAddress - EnableGuestService = ($vmobj | Get-VMIntegrationService | Where-Object -FilterScript { $_.Id -eq $guestServiceId }).Enabled - AutomaticCheckpointsEnabled = $vmobj.AutomaticCheckpointsEnabled - } -} - -function Set-TargetResource -{ - [CmdletBinding()] - param - ( - # Name of the VM - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - # VHD associated with the VM - [Parameter(Mandatory = $true)] - [System.String] - $VhdPath, - - # Virtual switch associated with the VM - [Parameter()] - [System.String[]] - $SwitchName, - - # State of the VM - [Parameter()] - [ValidateSet('Running', 'Paused', 'Off')] - [System.String] - $State, - - # Folder where the VM data will be stored - [Parameter()] - [System.String] - $Path, - - # Virtual machine generation - [Parameter()] - [ValidateRange(1, 2)] - [System.UInt32] - $Generation = 1, - - # Startup RAM for the VM - [Parameter()] - [ValidateRange(32MB, 65536MB)] - [System.UInt64] - $StartupMemory, - - # Minimum RAM for the VM. This enables dynamic memory - [Parameter()] - [ValidateRange(32MB, 65536MB)] - [System.UInt64] - $MinimumMemory, - - # Maximum RAM for the VM. This enables dynamic memory - [Parameter()] - [ValidateRange(32MB, 1048576MB)] - [System.UInt64] - $MaximumMemory, - - # MAC address of the VM - [Parameter()] - [System.String[]] - $MACAddress, - - # Processor count for the VM - [Parameter()] - [System.UInt32] - $ProcessorCount, - - # Waits for VM to get valid IP address - [Parameter()] - [System.Boolean] - $WaitForIP, - - # If specified, shutdowns and restarts the VM as needed for property changes - [Parameter()] - [System.Boolean] - $RestartIfNeeded, - - # Should the VM be created or deleted - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present', - - [Parameter()] - [System.String] - $Notes, - - # Enable secure boot for Generation 2 VMs - [Parameter()] - [System.Boolean] - $SecureBoot = $true, - - # Enable Guest Services - [Parameter()] - [System.Boolean] - $EnableGuestService = $false, - - # Enable AutomaticCheckpoints - [Parameter()] - [System.Boolean] - $AutomaticCheckpointsEnabled - ) - - # Check if Hyper-V module is present for Hyper-V cmdlets - if (!(Get-Module -ListAvailable -Name Hyper-V)) - { - throw ($script:localizedData.RoleMissingError -f 'Hyper-V') - } - - # Check if AutomaticCheckpointsEnabled is set in configuration - if ($PSBoundParameters.ContainsKey('AutomaticCheckpointsEnabled')) - { - <# - Check if AutomaticCheckpoints are supported - If AutomaticCheckpoints are supported, parameter exists on Set-VM - #> - if (-Not (Get-Command -Name Set-VM -Module Hyper-V).Parameters.ContainsKey('AutomaticCheckpointsEnabled')) - { - throw ($script:localizedData.AutomaticCheckpointsUnsupported) - } - } - - Write-Verbose -Message ($script:localizedData.CheckingVMExists -f $Name) - $vmObj = Get-VM -Name $Name -ErrorAction SilentlyContinue - - # VM already exists - if ($vmObj) - { - Write-Verbose -Message ($script:localizedData.VMExists -f $Name) - - # If VM shouldn't be there, stop it and remove it - if ($Ensure -eq 'Absent') - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'Ensure', $Ensure, 'Present') - Get-VM $Name | Stop-VM -Force -Passthru -WarningAction SilentlyContinue | Remove-VM -Force - Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'Ensure', $Ensure) - } - - <# - If VM is present, check its state, startup memory, minimum memory, maximum memory,processor count, automatic checkpoint and mac address - One cannot set the VM's vhdpath, path, generation and switchName after creation - #> - else - { - # If state has been specified and the VM is not in right state, set it to right state - if ($State -and ($vmObj.State -ne $State)) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'State', $State, $vmObj.State) - Set-VMState -Name $Name -State $State -WaitForIP $WaitForIP - Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'State', $State) - } - - $changeProperty = @{ } - # If the VM does not have the right startup memory - if ($PSBoundParameters.ContainsKey('StartupMemory') -and ($vmObj.MemoryStartup -ne $StartupMemory)) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'MemoryStartup', $StartupMemory, $vmObj.MemoryStartup) - $changeProperty['MemoryStartup'] = $StartupMemory - } - elseif ($PSBoundParameters.ContainsKey('MinimumMemory') -and ($vmObj.MemoryStartup -lt $MinimumMemory)) - { - Write-Verbose -Message ($script:localizedData.AdjustingLessThanMemoryWarning -f 'StartupMemory', $vmObj.MemoryStartup, 'MinimumMemory', $MinimumMemory) - $changeProperty['MemoryStartup'] = $MinimumMemory - } - elseif ($PSBoundParameters.ContainsKey('MaximumMemory') -and ($vmObj.MemoryStartup -gt $MaximumMemory)) - { - Write-Verbose -Message ($script:localizedData.AdjustingGreaterThanMemoryWarning -f 'StartupMemory', $vmObj.MemoryStartup, 'MaximumMemory', $MaximumMemory) - $changeProperty['MemoryStartup'] = $MaximumMemory - } - - # If the VM does not have the right minimum or maximum memory, stop the VM, set the right memory, start the VM - if ($PSBoundParameters.ContainsKey('MinimumMemory') -or $PSBoundParameters.ContainsKey('MaximumMemory')) - { - $changeProperty['DynamicMemory'] = $true - $changeProperty['StaticMemory'] = $false - - if ($PSBoundParameters.ContainsKey('MinimumMemory') -and ($vmObj.Memoryminimum -ne $MinimumMemory)) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'MinimumMemory', $MinimumMemory, $vmObj.MemoryMinimum) - $changeProperty['MemoryMinimum'] = $MinimumMemory - } - if ($PSBoundParameters.ContainsKey('MaximumMemory') -and ($vmObj.Memorymaximum -ne $MaximumMemory)) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'MaximumMemory', $MaximumMemory, $vmObj.MemoryMaximum) - $changeProperty['MemoryMaximum'] = $MaximumMemory - } - } - - # If the VM does not have the right processor count, stop the VM, set the right memory, start the VM - if ($PSBoundParameters.ContainsKey('ProcessorCount') -and ($vmObj.ProcessorCount -ne $ProcessorCount)) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'ProcessorCount', $ProcessorCount, $vmObj.ProcessorCount) - $changeProperty['ProcessorCount'] = $ProcessorCount - } - - # Stop the VM, set the right properties, start the VM only if there are properties to change - if ($changeProperty.Count -gt 0) - { - Set-VMProperty -Name $Name -VMCommand 'Set-VM' -ChangeProperty $changeProperty -WaitForIP $WaitForIP -RestartIfNeeded $RestartIfNeeded - Write-Verbose -Message ($script:localizedData.VMPropertiesUpdated -f $Name) - } - - <# - Special cases to disable dynamic memory: - - If startup, minimum and maximum memory are specified with equal values or - - If only startup memory is specified, but neither minimum nor maximum - #> - if ( ($PSBoundParameters.ContainsKey('StartupMemory') -and - ($StartupMemory -eq $MinimumMemory) -and - ($StartupMemory -eq $MaximumMemory) - ) -or - ( $PSBoundParameters.ContainsKey('StartupMemory') -and - (-not $PSBoundParameters.ContainsKey('MinimumMemory')) -and - (-not $PSBoundParameters.ContainsKey('MaximumMemory')) - ) - ) - { - # Refresh VM properties - $vmObj = Get-VM -Name $Name -ErrorAction SilentlyContinue - if ($vmObj.DynamicMemoryEnabled) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'DynamicMemoryEnabled', $false, $vmObj.DynamicMemoryEnabled) - $setVMPropertyParams = @{ - VMName = $Name - VMCommand = 'Set-VM' - ChangeProperty = @{ - StaticMemory = $true - DynamicMemory = $false - } - WaitForIP = $WaitForIP - RestartIfNeeded = $RestartIfNeeded - } - Set-VMProperty @setVMPropertyParams - Write-Verbose -Message ($script:localizedData.VMPropertiesUpdated -f $Name) - } - } - - # Set VM network switches. This can be done while the VM is running. - for ($i = 0; $i -lt $SwitchName.Count; $i++) - { - $switch = $SwitchName[$i] - $nic = $vmObj.NetworkAdapters[$i] - if ($nic) - { - # We cannot change the MAC address whilst the VM is running.. This is changed later - if ($nic.SwitchName -ne $switch) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'NIC', $switch, $nic.SwitchName) - $nic | Connect-VMNetworkAdapter -SwitchName $switch - Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'NIC', $switch) - } - } - else - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'NIC', $switch, '') - if ($MACAddress -and (-not [System.String]::IsNullOrEmpty($MACAddress[$i]))) - { - Add-VMNetworkAdapter -VMName $Name -SwitchName $switch -StaticMacAddress $MACAddress[$i] - Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'NIC', $switch) - } - else - { - Add-VMNetworkAdapter -VMName $Name -SwitchName $switch - Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'NIC', $switch) - } - # Refresh the NICs after we've added one - $vmObj = Get-VM -Name $Name -ErrorAction SilentlyContinue - } - } - - # If the VM does not have the right MACAddress, stop the VM, set the right MACAddress, start the VM - for ($i = 0; $i -lt $MACAddress.Count; $i++) - { - $address = $MACAddress[$i] - $nic = $vmObj.NetworkAdapters[$i] - if ($nic.MacAddress -ne $address) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'MACAddress', $address, $nic.MacAddress) - Set-VMMACAddress -Name $Name -NICIndex $i -MACAddress $address -WaitForIP $WaitForIP -RestartIfNeeded $RestartIfNeeded - } - } - - if ($Generation -eq 2) - { - # Retrive the current secure boot state - $vmSecureBoot = Test-VMSecureBoot -Name $Name - if ($SecureBoot -ne $vmSecureBoot) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'SecureBoot', $SecureBoot, $vmSecureBoot) - - if (-not $SecureBoot) - { - $enableSecureBoot = 'On' - } - else - { - $enableSecureBoot = 'Off' - } - - # Cannot change the secure boot state whilst the VM is powered on. - $setVMPropertyParams = @{ - VMName = $Name - VMCommand = 'Set-VMFirmware' - ChangeProperty = @{ - EnableSecureBoot = $enableSecureBoot - } - RestartIfNeeded = $RestartIfNeeded - } - Set-VMProperty @setVMPropertyParams - Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'SecureBoot', $SecureBoot) - } - } - - if ($Notes -ne $null) - { - # If the VM notes do not match the desire notes, update them. This can be done while the VM is running. - if ($vmObj.Notes -ne $Notes) - { - Set-Vm -Name $Name -Notes $Notes - } - } - - # If the VM doesn't have Guest Service Interface correctly configured, update it. - $guestServiceId = 'Microsoft:{0}\6C09BB55-D683-4DA0-8931-C9BF705F6480' -f $vmObj.Id - - $guestService = $vmObj | Get-VMIntegrationService | Where-Object -FilterScript { $_.Id -eq $guestServiceId } - if ($guestService.Enabled -eq $false -and $EnableGuestService) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'EnableGuestService', $EnableGuestService, $guestService.Enabled) - $guestService | Enable-VMIntegrationService - Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'EnableGuestService', $EnableGuestService) - } - elseif ($guestService.Enabled -and -not $EnableGuestService) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'EnableGuestService', $EnableGuestService, $guestService.Enabled) - $guestService | Disable-VMIntegrationService - Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'EnableGuestService', $EnableGuestService) - } - - # If AutomaticCheckpointsEnabled is set in configuration - if ($PSBoundParameters.ContainsKey('AutomaticCheckpointsEnabled')) - { - if ($vmObj.AutomaticCheckpointsEnabled -ne $AutomaticCheckpointsEnabled) - { - Set-VM -Name $Name -AutomaticCheckpointsEnabled $AutomaticCheckpointsEnabled - } - } - } - } - - # VM is not present, create one - else - { - Write-Verbose -Message ($script:localizedData.VMDoesNotExist -f $Name) - if ($Ensure -eq 'Present') - { - Write-Verbose -Message ($script:localizedData.CreatingVM -f $Name) - - $parameters = @{ } - $parameters['Name'] = $Name - $parameters['VHDPath'] = $VhdPath - $parameters['Generation'] = $Generation - - # Optional parameters - if ($SwitchName) - { - $parameters['SwitchName'] = $SwitchName[0] - } - if ($Path) - { - $parameters['Path'] = $Path - } - $defaultStartupMemory = 512MB - if ($PSBoundParameters.ContainsKey('StartupMemory')) - { - $parameters['MemoryStartupBytes'] = $StartupMemory - } - elseif ($PSBoundParameters.ContainsKey('MinimumMemory') -and ($defaultStartupMemory -lt $MinimumMemory)) - { - $parameters['MemoryStartupBytes'] = $MinimumMemory - } - elseif ($PSBoundParameters.ContainsKey('MaximumMemory') -and ($defaultStartupMemory -gt $MaximumMemory)) - { - $parameters['MemoryStartupBytes'] = $MaximumMemory - } - $null = New-VM @parameters - - $parameters = @{ } - $parameters['Name'] = $Name - $parameters['StaticMemory'] = $true - $parameters['DynamicMemory'] = $false - if ($PSBoundParameters.ContainsKey('MinimumMemory') -or $PSBoundParameters.ContainsKey('MaximumMemory')) - { - $parameters['DynamicMemory'] = $true - $parameters['StaticMemory'] = $false - if ($PSBoundParameters.ContainsKey('MinimumMemory')) - { - $parameters['MemoryMinimumBytes'] = $MinimumMemory - } - if ($PSBoundParameters.ContainsKey('MaximumMemory')) - { - $parameters['MemoryMaximumBytes'] = $MaximumMemory - } - } - - if ($Notes) - { - $parameters['Notes'] = $Notes - } - - if ($PSBoundParameters.ContainsKey('ProcessorCount')) - { - $parameters['ProcessorCount'] = $ProcessorCount - } - - # If AutomaticCheckpointsEnabled is set in configuration - if ($PSBoundParameters.ContainsKey('AutomaticCheckpointsEnabled')) - { - $parameters['AutomaticCheckpointsEnabled'] = $AutomaticCheckpointsEnabled - } - - $null = Set-VM @parameters - - # Special case: Disable dynamic memory if startup, minimum and maximum memory are equal - if ($PSBoundParameters.ContainsKey('StartupMemory') -and - ($StartupMemory -eq $MinimumMemory) -and - ($StartupMemory -eq $MaximumMemory)) - { - Set-VMMemory -VMName $Name -DynamicMemoryEnabled $false - } - - # There's always a NIC added with New-VM - if ($MACAddress) - { - Set-VMNetworkAdapter -VMName $Name -StaticMacAddress $MACAddress[0] - } - - # Add additional NICs - for ($i = 1; $i -lt $SwitchName.Count; $i++) - { - $addVMNetworkAdapterParams = @{ - VMName = $Name - SwitchName = $SwitchName[$i] - } - if ($MACAddress -and (-not [System.String]::IsNullOrEmpty($MACAddress[$i]))) - { - $addVMNetworkAdapterParams['StaticMacAddress'] = $MACAddress[$i] - } - Add-VMNetworkAdapter @addVMNetworkAdapterParams - Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'NIC', $SwitchName[$i]) - } - - if ($Generation -eq 2) - { - <# - Secure boot is only applicable to Generation 2 VMs and it defaults to on. - Therefore, we only need to explicitly set it to off if specified. - #> - if ($SecureBoot -eq $false) - { - Set-VMFirmware -VMName $Name -EnableSecureBoot Off - } - } - - if ($EnableGuestService) - { - $guestServiceId = 'Microsoft:{0}\6C09BB55-D683-4DA0-8931-C9BF705F6480' -f (Get-VM -Name $Name).Id - Get-VMIntegrationService -VMName $Name | Where-Object -FilterScript { $_.Id -eq $guestServiceId } | Enable-VMIntegrationService - } - - Write-Verbose -Message ($script:localizedData.VMCreated -f $Name) - - if ($State) - { - Set-VMState -Name $Name -State $State -WaitForIP $WaitForIP - Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'State', $State) - } - - } - } -} - -function Test-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - # Name of the VM - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - # VHD associated with the VM - [Parameter(Mandatory = $true)] - [System.String] - $VhdPath, - - # Virtual switch associated with the VM - [Parameter()] - [System.String[]] - $SwitchName, - - # State of the VM - [Parameter()] - [ValidateSet('Running', 'Paused', 'Off')] - [System.String] - $State, - - # Folder where the VM data will be stored - [Parameter()] - [System.String] - $Path, - - # Virtual machine generation - [Parameter()] - [ValidateRange(1, 2)] - [System.UInt32] - $Generation = 1, - - # Startup RAM for the VM - [Parameter()] - [ValidateRange(32MB, 65536MB)] - [System.UInt64] - $StartupMemory, - - # Minimum RAM for the VM. This enables dynamic memory - [Parameter()] - [ValidateRange(32MB, 65536MB)] - [System.UInt64] - $MinimumMemory, - - # Maximum RAM for the VM. This enables dynamic memory - [Parameter()] - [ValidateRange(32MB, 1048576MB)] - [System.UInt64] - $MaximumMemory, - - # MAC address of the VM - [Parameter()] - [System.String[]] - $MACAddress, - - # Processor count for the VM - [Parameter()] - [System.UInt32] - $ProcessorCount, - - # Waits for VM to get valid IP address - [Parameter()] - [System.Boolean] - $WaitForIP, - - # If specified, shutdowns and restarts the VM as needed for property changes - [Parameter()] - [System.Boolean] - $RestartIfNeeded, - - # Should the VM be created or deleted - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present', - - [Parameter()] - [System.String] - $Notes, - - # Enable secure boot for Generation 2 VMs - [Parameter()] - [System.Boolean] - $SecureBoot = $true, - - [Parameter()] - [System.Boolean] - $EnableGuestService = $false, - - # Enable AutomaticCheckpoints - [Parameter()] - [System.Boolean] - $AutomaticCheckpointsEnabled - ) - - # Check if Hyper-V module is present for Hyper-V cmdlets - if (!(Get-Module -ListAvailable -Name Hyper-V)) - { - throw ($script:localizedData.RoleMissingError -f 'Hyper-V') - } - - # Check if 1 or 0 VM with name = $name exist - if ((Get-VM -Name $Name -ErrorAction SilentlyContinue).count -gt 1) - { - throw ($script:localizedData.MoreThanOneVMExistsError -f $Name) - } - - # Check if AutomaticCheckpointsEnabled is set in configuration - if ($PSBoundParameters.ContainsKey('AutomaticCheckpointsEnabled')) - { - <# - Check if AutomaticCheckpoints are supported - If AutomaticCheckpoints are supported, parameter exists on Set-VM - #> - if (-Not (Get-Command -Name Set-VM -Module Hyper-V).Parameters.ContainsKey('AutomaticCheckpointsEnabled')) - { - throw ($script:localizedData.AutomaticCheckpointsUnsupported) - } - } - - try - { - $vmObj = Get-VM -Name $Name -ErrorAction Stop - if ($Ensure -eq 'Present') - { - # Check if $VhdPath exist - if (!(Test-Path $VhdPath)) - { - throw ($script:localizedData.VhdPathDoesNotExistError -f $VhdPath) - } - - # Check if Minimum memory is less than StartUpmemory - if ($PSBoundParameters.ContainsKey('StartupMemory') -and - $PSBoundParameters.ContainsKey('MinimumMemory') -and - ($MinimumMemory -gt $StartupMemory)) - { - throw ($script:localizedData.MinMemGreaterThanStartupMemError -f $MinimumMemory, $StartupMemory) - } - - # Check if Minimum memory is greater than Maximummemory - if ($PSBoundParameters.ContainsKey('MaximumMemory') -and - $PSBoundParameters.ContainsKey('MinimumMemory') -and - ($MinimumMemory -gt $MaximumMemory)) - { - throw ($script:localizedData.MinMemGreaterThanMaxMemError -f $MinimumMemory, $MaximumMemory) - } - - # Check if Startup memory is greater than Maximummemory - if ($PSBoundParameters.ContainsKey('MaximumMemory') -and - $PSBoundParameters.ContainsKey('StartupMemory') -and - ($StartupMemory -gt $MaximumMemory)) - { - throw ($script:localizedData.StartUpMemGreaterThanMaxMemError -f $StartupMemory, $MaximumMemory) - } - - <# - VM Generation has no direct relation to the virtual hard disk format and cannot be changed - after the virtual machine has been created. Generation 2 VMs do not support .VHD files. - #> - if (($Generation -eq 2) -and ($VhdPath.Split('.')[-1] -eq 'vhd')) - { - throw ($script:localizedData.VhdUnsupportedOnGen2VMError) - } - - # Check if $Path exist - if ($Path -and !(Test-Path -Path $Path)) - { - throw ($script:localizedData.PathDoesNotExistError -f $Path) - } - - $vhdChain = @(Get-VhdHierarchy -VhdPath ($vmObj.HardDrives[0].Path)) - if ($vhdChain -notcontains $VhdPath) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'VhdPath', $VhdPath, ($vhdChain -join ',')) - return $false - } - - if ($state -and ($vmObj.State -ne $State)) - { - return $false - } - - if ($PSBoundParameters.ContainsKey('StartupMemory') -and - ($vmObj.MemoryStartup -ne $StartupMemory)) - { - return $false - } - - if ($PSBoundParameters.ContainsKey('MaximumMemory') -and - ($vmObj.MemoryMaximum -ne $MaximumMemory)) - { - return $false - } - - if ($PSBoundParameters.ContainsKey('MinimumMemory') -and - ($vmObj.MemoryMinimum -ne $MinimumMemory)) - { - return $false - } - - # If startup memory but neither minimum nor maximum memory specified, dynamic memory should be disabled - if ($PSBoundParameters.ContainsKey('StartupMemory') -and - ( -not $PSBoundParameters.ContainsKey('MinimumMemory')) -and - ( -not $PSBoundParameters.ContainsKey('MaximumMemory')) -and - $vmobj.DynamicMemoryEnabled) - { - return $false - } - - # If startup, minimum and maximum memory are specified with the same values, dynamic memory should be disabled - if ($PSBoundParameters.ContainsKey('StartupMemory') -and - $PSBoundParameters.ContainsKey('MinimumMemory') -and - $PSBoundParameters.ContainsKey('MaximumMemory') -and - ($StartupMemory -eq $MinimumMemory) -and - ($StartupMemory -eq $MaximumMemory) -and - $vmobj.DynamicMemoryEnabled) - { - return $false - } - - if ($vmObj.HardDrives.Path -notcontains $VhdPath) - { - return $false - } - - for ($i = 0; $i -lt $SwitchName.Count; $i++) - { - if ($vmObj.NetworkAdapters[$i].SwitchName -ne $SwitchName[$i]) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'SwitchName', $SwitchName[$i], $vmObj.NetworkAdapters[$i].SwitchName) - return $false - } - } - - for ($i = 0; $i -lt $MACAddress.Count; $i++) - { - if ($vmObj.NetworkAdapters[$i].MACAddress -ne $MACAddress[$i]) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'MACAddress', $MACAddress[$i], $vmObj.NetworkAdapters[$i].MACAddress) - return $false - } - } - - # $Generation always exists, only check if parameter has been explicitly specified - if ($PSBoundParameters.ContainsKey('Generation') -and ($Generation -ne $vmObj.Generation)) - { - return $false - } - - if ($PSBoundParameters.ContainsKey('ProcessorCount') -and ($vmObj.ProcessorCount -ne $ProcessorCount)) - { - return $false - } - - if ($vmObj.Generation -eq 2) - { - $vmSecureBoot = Test-VMSecureBoot -Name $Name - if ($SecureBoot -ne $vmSecureBoot) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'SecureBoot', $SecureBoot, $vmSecureBoot) - return $false - } - } - - $guestServiceId = 'Microsoft:{0}\6C09BB55-D683-4DA0-8931-C9BF705F6480' -f $vmObj.Id - $guestService = $vmObj | Get-VMIntegrationService | Where-Object -FilterScript { $_.Id -eq $guestServiceId } - if ($guestService.Enabled -ne $EnableGuestService) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'EnableGuestService', $EnableGuestService, $guestService.Enabled) - return $false - } - - # If AutomaticCheckpointsEnabled is set in configuration - if ($PSBoundParameters.ContainsKey('AutomaticCheckpointsEnabled')) - { - if ($vmObj.AutomaticCheckpointsEnabled -ne $AutomaticCheckpointsEnabled) - { - Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'AutomaticCheckpointsEnabled', $AutomaticCheckpointsEnabled, $vmObj.AutomaticCheckpointsEnabled) - return $false - } - } - - return $true - } - else - { - return $false - } - } - catch [System.Management.Automation.ActionPreferenceStopException] - { - ($Ensure -eq 'Absent') - } -} - -#region Helper function - -# Returns VM VHDs, including snapshots and differencing disks -function Get-VhdHierarchy -{ - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VhdPath - ) - - $vmVhdPath = Get-VHD -Path $VhdPath - Write-Output -InputObject $vmVhdPath.Path - while (-not [System.String]::IsNullOrEmpty($vmVhdPath.ParentPath)) - { - $vmVhdPath.ParentPath - $vmVhdPath = (Get-VHD -Path $vmVhdPath.ParentPath) - } -} - -<# - The 'Set-VMProperty' method cannot be used as it cannot deal with piped - command in it's current implementation -#> -function Set-VMMACAddress -{ - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - [Parameter(Mandatory = $true)] - [System.String] - $MACAddress, - - [Parameter(Mandatory = $true)] - [Int] - $NICIndex, - - [Parameter()] - [System.Boolean] - $WaitForIP, - - [Parameter()] - [System.Boolean] - $RestartIfNeeded - ) - $vmObj = Get-VM -Name $Name - $originalState = $vmObj.state - if ($originalState -ne 'Off' -and $RestartIfNeeded) - { - Set-VMState -Name $Name -State Off - $vmObj.NetworkAdapters[$NICIndex] | Set-VMNetworkAdapter -StaticMacAddress $MACAddress - - # Can not move a off VM to paused, but only to running state - if ($originalState -eq 'Running') - { - Set-VMState -Name $Name -State Running -WaitForIP $WaitForIP - } - - # Cannot make a paused VM to go back to Paused state after turning Off - if ($originalState -eq 'Paused') - { - Write-Warning -Message ($script:localizedData.VMStateWillBeOffWarning -f $Name) - } - } - elseif ($originalState -eq 'Off') - { - $vmObj.NetworkAdapters[$NICIndex] | Set-VMNetworkAdapter -StaticMacAddress $MACAddress - Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'MACAddress', $MACAddress) - } - else - { - Write-Error -Message ($script:localizedData.CannotUpdatePropertiesOnlineError -f $Name, $vmObj.State) - } -} - -function Test-VMSecureBoot -{ - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Name - ) - $vm = Get-VM -Name $Name - return (Get-VMFirmware -VM $vm).SecureBoot -eq 'On' -} - -#endregion - -Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.schema.mof b/DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.schema.mof deleted file mode 100644 index 7a2541e6..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.schema.mof +++ /dev/null @@ -1,30 +0,0 @@ -[ClassVersion("1.0.0"), FriendlyName("xVMHyperV")] -class MSFT_xVMHyperV : OMI_BaseResource -{ - [Key, Description("Name of the VM")] String Name; - [Required, Description("VHD associated with the VM")] String VhdPath; - [Write, Description("Virtual switch(es) associated with the VM")] String SwitchName[]; - [Write, Description("State of the VM."), ValueMap{"Running","Paused","Off"}, Values{"Running","Paused","Off"}] String State; - [Write, Description("Folder where the VM data will be stored")] String Path; - [Write, Description("Virtual machine generation")] Uint32 Generation; - [Write, Description("Startup RAM for the VM.")] Uint64 StartupMemory; - [Write, Description("Minimum RAM for the VM. This enables dynamic memory.")] Uint64 MinimumMemory; - [Write, Description("Maximum RAM for the VM. This enable dynamic memory.")] Uint64 MaximumMemory; - [Write, Description("MAC address(es) of the VM NICs.")] String MACAddress[]; - [Write, Description("Processor count for the VM")] Uint32 ProcessorCount; - [Write, Description("Waits for VM to get valid IP address.")] Boolean WaitForIP; - [Write, Description("If specified, shutdowns and restarts the VM as needed for property changes")] Boolean RestartIfNeeded; - [Write, Description("Should the VM be created or deleted"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; - [Write, Description("Notes about the VM.")] String Notes; - [Write, Description("Enable secure boot for Generation 2 VMs.")] Boolean SecureBoot; - [Write, Description("Enable Guest Service Interface for the VM.")] Boolean EnableGuestService; - [Write, Description("Enable AutomaticCheckpoints for the VM.")] Boolean AutomaticCheckpointsEnabled; - [Read, Description("VM unique ID")] String ID; - [Read, Description("Status of the VM")] String Status; - [Read, Description("CPU Usage of the VM")] Uint32 CPUUsage; - [Read, Description("Memory assigned to the VM")] Uint64 MemoryAssigned; - [Read, Description("Uptime of the VM")] String Uptime; - [Read, Description("Creation time of the VM")] DateTime CreationTime; - [Read, Description("Does VM has dynamic memory enabled")] Boolean HasDynamicMemory; - [Read, Description("Network adapters' IP addresses of the VM")] String NetworkAdapters[]; -}; diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/README.md b/DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/README.md deleted file mode 100644 index 5f10c9bf..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Description - -Manages VMs in a Hyper-V host. - -The following properties **cannot** be changed after VM creation: - -* VhdPath -* Path -* Generation - -## Requirements - -* The Hyper-V Role has to be installed on the machine. -* The Hyper-V PowerShell module has to be installed on the machine. diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/en-US/about_xVMHyperV.help.txt b/DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/en-US/about_xVMHyperV.help.txt deleted file mode 100644 index f445009e..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMHyperV/en-US/about_xVMHyperV.help.txt +++ /dev/null @@ -1,123 +0,0 @@ -.NAME - xVMHyperV - -.DESCRIPTION - Manages VMs in a Hyper-V host. - - The following properties cannot be changed after VM creation: - - * VhdPath - * Path - * Generation - - ## Requirements - - * The Hyper-V Role has to be installed on the machine. - * The Hyper-V PowerShell module has to be installed on the machine. - -.PARAMETER Name - Key - String - Name of the VM - -.PARAMETER VhdPath - Required - String - VHD associated with the VM - -.PARAMETER SwitchName - Write - StringArray - Virtual switch(es) associated with the VM - -.PARAMETER State - Write - String - Allowed values: Running, Paused, Off - State of the VM. - -.PARAMETER Path - Write - String - Folder where the VM data will be stored - -.PARAMETER Generation - Write - UInt32 - Virtual machine generation - -.PARAMETER StartupMemory - Write - UInt64 - Startup RAM for the VM. - -.PARAMETER MinimumMemory - Write - UInt64 - Minimum RAM for the VM. This enables dynamic memory. - -.PARAMETER MaximumMemory - Write - UInt64 - Maximum RAM for the VM. This enable dynamic memory. - -.PARAMETER MACAddress - Write - StringArray - MAC address(es) of the VM NICs. - -.PARAMETER ProcessorCount - Write - UInt32 - Processor count for the VM - -.PARAMETER WaitForIP - Write - Boolean - Waits for VM to get valid IP address. - -.PARAMETER RestartIfNeeded - Write - Boolean - If specified, shutdowns and restarts the VM as needed for property changes - -.PARAMETER Ensure - Write - String - Allowed values: Present, Absent - Should the VM be created or deleted - -.PARAMETER Notes - Write - String - Notes about the VM. - -.PARAMETER SecureBoot - Write - Boolean - Enable secure boot for Generation 2 VMs. - -.PARAMETER EnableGuestService - Write - Boolean - Enable Guest Service Interface for the VM. - -.PARAMETER AutomaticCheckpointsEnabled - Write - Boolean - Enable AutomaticCheckpoints for the VM. - -.PARAMETER ID - Read - String - VM unique ID - -.PARAMETER Status - Read - String - Status of the VM - -.PARAMETER CPUUsage - Read - UInt32 - CPU Usage of the VM - -.PARAMETER MemoryAssigned - Read - UInt64 - Memory assigned to the VM - -.PARAMETER Uptime - Read - String - Uptime of the VM - -.PARAMETER CreationTime - Read - DateTime - Creation time of the VM - -.PARAMETER HasDynamicMemory - Read - Boolean - Does VM has dynamic memory enabled - -.PARAMETER NetworkAdapters - Read - StringArray - Network adapters' IP addresses of the VM - diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 b/DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 deleted file mode 100644 index d1ed7ae3..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 +++ /dev/null @@ -1,709 +0,0 @@ -$script:dscResourceCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/DscResource.Common' - -Import-Module -Name $script:dscResourceCommonModulePath - -$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' - -<# -.SYNOPSIS - Gets MSFT_xVMNetworkAdapter resource current state. - -.PARAMETER Id - Specifies an unique identifier for the network adapter. - -.PARAMETER Name - Specifies a name for the network adapter that needs to be connected to a VM or management OS. - -.PARAMETER SwitchName - Specifies the name of the switch to which the new VM network adapter will be connected. - -.PARAMETER VMName - Specifies the name of the VM to which the network adapter will be connected. - Specify VMName as ManagementOS if you wish to connect the adapter to host OS. - -.PARAMETER IpAddress - Specifies the IpAddress information for the network adapter. -#> -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Id, - - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - [Parameter(Mandatory = $true)] - [System.String] - $SwitchName, - - [Parameter(Mandatory = $true)] - [System.String] - $VMName - ) - - $configuration = @{ - Id = $Id - Name = $Name - SwitchName = $SwitchName - VMName = $VMName - } - - $arguments = @{ - Name = $Name - } - - if ($VMName -ne 'ManagementOS') - { - $arguments.Add('VMName', $VMName) - } - else - { - $arguments.Add('ManagementOS', $true) - $arguments.Add('SwitchName', $SwitchName) - } - - Write-Verbose -Message $script:localizedData.GetVMNetAdapter - $netAdapter = Get-VMNetworkAdapter @arguments -ErrorAction SilentlyContinue - - if ($netAdapter) - { - Write-Verbose -Message $script:localizedData.FoundVMNetAdapter - if ($VMName -eq 'ManagementOS') - { - $configuration.Add('MacAddress', $netAdapter.MacAddress) - $configuration.Add('DynamicMacAddress', $false) - } - elseif ($netAdapter.VMName) - { - $configuration.Add('MacAddress', $netAdapter.MacAddress) - $configuration.Add('DynamicMacAddress', $netAdapter.DynamicMacAddressEnabled) - } - - $networkInfo = Get-NetworkInformation -VMName $VMName -Name $Name - if ($networkInfo) - { - $item = New-CimInstance -ClassName MSFT_xNetworkSettings -Property $networkInfo -Namespace root/microsoft/windows/desiredstateconfiguration -ClientOnly - $configuration.Add('NetworkSetting', $item) - } - - $configuration.Add('Ensure', 'Present') - - Write-Verbose -Message $script:localizedData.GetVMNetAdapterVlan - $netAdapterVlan = Get-VMNetworkAdapterVlan -VMNetworkAdapter $netAdapter - if ($netAdapterVlan.OperationMode -ne 'Untagged') - { - $configuration.Add('VlanId', $netAdapterVlan.AccessVlanId) - } - } - else - { - Write-Verbose -Message $script:localizedData.NoVMNetAdapterFound - $configuration.Add('Ensure', 'Absent') - } - - return $configuration -} - -<# -.SYNOPSIS - Sets MSFT_xVMNetworkAdapter resource state. - -.PARAMETER Id - Specifies an unique identifier for the network adapter. - -.PARAMETER Name - Specifies a name for the network adapter that needs to be connected to a VM or management OS. - -.PARAMETER SwitchName - Specifies the name of the switch to which the new VM network adapter will be connected. - -.PARAMETER VMName - Specifies the name of the VM to which the network adapter will be connected. - Specify VMName as ManagementOS if you wish to connect the adapter to host OS. - -.PARAMETER MacAddress - Specifies the MAC address for the network adapter. This is not applicable if VMName - is set to ManagementOS. Use this parameter to specify a static MAC address. - -.PARAMETER IpAddress - Specifies the IpAddress information for the network adapter. - -.PARAMETER VlanId - Specifies the Vlan Id for the network adapter. - -.PARAMETER Ensure - Specifies if the network adapter should be Present or Absent. -#> -function Set-TargetResource -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Id, - - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - [Parameter(Mandatory = $true)] - [System.String] - $SwitchName, - - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter()] - [System.String] - $MacAddress, - - [Parameter()] - [Microsoft.Management.Infrastructure.CimInstance] - $NetworkSetting, - - [Parameter()] - [System.String] - $VlanId, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present' - ) - - $arguments = @{ - Name = $Name - } - - if ($VMName -ne 'ManagementOS') - { - $arguments.Add('VMName', $VMName) - } - else - { - $arguments.Add('ManagementOS', $true) - $arguments.Add('SwitchName', $SwitchName) - } - - Write-Verbose -Message $script:localizedData.GetVMNetAdapter - $netAdapterExists = Get-VMNetworkAdapter @arguments -ErrorAction SilentlyContinue - - if ($Ensure -eq 'Present') - { - if ($netAdapterExists) - { - Write-Verbose -Message $script:localizedData.FoundVMNetAdapter - if (($VMName -ne 'ManagementOS')) - { - if ($MacAddress) - { - if ($netAdapterExists.DynamicMacAddressEnabled) - { - Write-Verbose -Message $script:localizedData.EnableStaticMacAddress - $updateMacAddress = $true - } - elseif ($MacAddress -ne $netAdapterExists.StaicMacAddress) - { - Write-Verbose -Message $script:localizedData.EnableStaticMacAddress - $updateMacAddress = $true - } - } - else - { - if (-not $netAdapterExists.DynamicMacAddressEnabled) - { - Write-Verbose -Message $script:localizedData.EnableDynamicMacAddress - $updateMacAddress = $true - } - } - - if ($netAdapterExists.SwitchName -ne $SwitchName) - { - Write-Verbose -Message $script:localizedData.PerformSwitchConnect - Connect-VMNetworkAdapter -VMNetworkAdapter $netAdapterExists -SwitchName $SwitchName -ErrorAction Stop -Verbose - } - - if (($updateMacAddress)) - { - Write-Verbose -Message $script:localizedData.PerformVMNetModify - - $setArguments = @{ } - $setArguments.Add('VMNetworkAdapter', $netAdapterExists) - if ($MacAddress) - { - $setArguments.Add('StaticMacAddress', $MacAddress) - } - else - { - $setArguments.Add('DynamicMacAddress', $true) - } - Set-VMNetworkAdapter @setArguments -ErrorAction Stop - } - } - } - else - { - if ($VMName -ne 'ManagementOS') - { - if (-not $MacAddress) - { - $arguments.Add('DynamicMacAddress', $true) - } - else - { - $arguments.Add('StaticMacAddress', $MacAddress) - } - $arguments.Add('SwitchName', $SwitchName) - } - Write-Verbose -Message $script:localizedData.AddVMNetAdapter - $netAdapterExists = Add-VMNetworkAdapter @arguments -Passthru -ErrorAction Stop - } - - if ($VmName -ne 'ManagementOS') - { - $networkInfo = Get-NetworkInformation -VMName $VMName -Name $Name - if (-not $NetworkSetting) - { - if ($networkInfo) - { - Write-Verbose -Message $script:localizedData.EnableDhcp - Set-NetworkInformation -VMName $VMName -Name $Name -Dhcp - } - } - else - { - $parameters = @{ } - if ($ipAddress = $NetworkSetting.CimInstanceProperties['IpAddress'].Value) - { - if (-not $ipAddress) - { - throw $script:localizedData.MissingIPAndSubnet - } - $parameters.Add('IPAddress', $ipAddress) - } - if ($subnet = $NetworkSetting.CimInstanceProperties['Subnet'].Value) - { - if (-not $subnet) - { - throw $script:localizedData.MissingIPAndSubnet - } - $parameters.Add('Subnet', $subnet) - } - if ($defaultGateway = $NetworkSetting.CimInstanceProperties['DefaultGateway'].Value) - { - $parameters.Add('DefaultGateway', $defaultGateway) - } - if ($dnsServer = $NetworkSetting.CimInstanceProperties['DnsServer'].Value) - { - $parameters.Add('DnsServer', $dnsServer) - } - - Set-NetworkInformation -VMName $VMName -Name $Name @parameters - } - - Write-Verbose -Message $script:localizedData.GetVMNetAdapterVlan - $netAdapterVlan = Get-VMNetworkAdapterVlan -VMNetworkAdapter $netAdapterExists - if ($netAdapterVlan) - { - if ($VlanId) - { - $setVlan = $true - } - else - { - Write-Verbose -Message $script:localizedData.RemovingVlanTag - Set-VMNetworkAdapterVlan -VMNetworkAdapter $netAdapterExists -Untagged - } - } - elseif ($VlanId) - { - $setVlan = $true - } - - if ($setVlan) - { - Write-Verbose -Message $script:localizedData.SettingVlan - Set-VMNetworkAdapterVlan -VMNetworkAdapter $netAdapterExists -Access -VlanId $VlanId - } - } - } - else - { - Write-Verbose -Message $script:localizedData.RemoveVMNetAdapter - Remove-VMNetworkAdapter @arguments -ErrorAction Stop - } -} - -<# -.SYNOPSIS - Tests if MSFT_xVMNetworkAdapter resource state is indeed desired state or not. - -.PARAMETER Id - Specifies an unique identifier for the network adapter. - -.PARAMETER Name - Specifies a name for the network adapter that needs to be connected to a VM or management OS. - -.PARAMETER SwitchName - Specifies the name of the switch to which the new VM network adapter will be connected. - -.PARAMETER VMName - Specifies the name of the VM to which the network adapter will be connected. - Specify VMName as ManagementOS if you wish to connect the adapter to host OS. - -.PARAMETER MacAddress - Specifies the MAC address for the network adapter. This is not applicable if VMName - is set to ManagementOS. Use this parameter to specify a static MAC address. - -.PARAMETER IpAddress - Specifies the IpAddress information for the network adapter. - -.PARAMETER VlanId - Specifies the Vlan Id for the network adapter. - -.PARAMETER Ensure - Specifies if the network adapter should be Present or Absent. -#> -function Test-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Id, - - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - [Parameter(Mandatory = $true)] - [System.String] - $SwitchName, - - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter()] - [System.String] - $MacAddress, - - [Parameter()] - [Microsoft.Management.Infrastructure.CimInstance] - $NetworkSetting, - - [Parameter()] - [System.String] - $VlanId, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present' - ) - - $arguments = @{ - Name = $Name - } - - if ($VMName -ne 'ManagementOS') - { - $arguments.Add('VMName', $VMName) - } - else - { - $arguments.Add('ManagementOS', $true) - $arguments.Add('SwitchName', $SwitchName) - } - - Write-Verbose -Message $script:localizedData.GetVMNetAdapter - $netAdapterExists = Get-VMNetworkAdapter @arguments -ErrorAction SilentlyContinue - - if ($Ensure -eq 'Present') - { - if ($netAdapterExists) - { - if ($VMName -ne 'ManagementOS') - { - if ($MacAddress) - { - if ($netAdapterExists.DynamicMacAddressEnabled) - { - Write-Verbose -Message $script:localizedData.EnableStaticMacAddress - return $false - } - elseif ($netAdapterExists.MacAddress -ne $MacAddress) - { - Write-Verbose -Message $script:localizedData.StaticAddressDoesNotMatch - return $false - } - } - else - { - if (-not $netAdapterExists.DynamicMacAddressEnabled) - { - Write-Verbose -Message $script:localizedData.EnableDynamicMacAddress - return $false - } - } - - $networkInfo = Get-NetworkInformation -VMName $VMName -Name $Name - if (-not $NetworkSetting) - { - if ($networkInfo) - { - Write-Verbose -Message $script:localizedData.NotDhcp - return $false - } - } - else - { - if (-not $networkInfo) - { - Write-Verbose -Message $script:localizedData.Dhcp - return $false - } - else - { - $ipAddress = $NetworkSetting.CimInstanceProperties['IpAddress'].Value - $subnet = $NetworkSetting.CimInstanceProperties['Subnet'].Value - $defaultGateway = $NetworkSetting.CimInstanceProperties['DefaultGateway'].Value - $dnsServer = $NetworkSetting.CimInstanceProperties['DnsServer'].Value - - if (-not $IpAddress -or -not $subnet) - { - throw $script:localizedData.MissingIPAndSubnet - } - - if ($ipAddress -and -not $networkInfo.IPAddress.Split(',').Contains($ipAddress)) - { - Write-Verbose -Message $script:localizedData.IPAddressNotConfigured - return $false - } - - if ($defaultGateway -and -not $networkInfo.DefaultGateway.Split(',').Contains($defaultGateway)) - { - Write-Verbose -Message $script:localizedData.GatewayNotConfigured - return $false - } - - if ($dnsServer -and -not $networkInfo.DNSServer.Split(',').Contains($dnsServer)) - { - Write-Verbose -Message $script:localizedData.DNSServerNotConfigured - return $false - } - } - } - - Write-Verbose -Message $script:localizedData.GetVMNetAdapterVlan - $netAdapterVlan = Get-VMNetworkAdapterVlan -VMNetworkAdapter $netAdapterExists - if ($netAdapterVlan) - { - if ($netAdapterVlan.OperationMode -eq 'Untagged') - { - if ($VlanId) - { - Write-Verbose -Message $script:localizedData.VlanNotUntagged - return $false - } - } - else - { - if ($VlanId) - { - if ($netAdapterVlan.AccessVlanId -ne $VlanId) - { - Write-Verbose -Message $script:localizedData.VlanDoesNotMatch - return $false - } - } - else - { - Write-Verbose -Message $script:localizedData.VlanShouldntBeTagged - return $false - } - } - } - elseif ($VlanId) - { - Write-Verbose -Message $script:localizedData.VlanNotUntagged - return $false - } - - if ($netAdapterExists.SwitchName -ne $SwitchName) - { - Write-Verbose -Message $script:localizedData.SwitchIsDifferent - return $false - } - else - { - Write-Verbose -Message $script:localizedData.VMNetAdapterExistsNoActionNeeded - return $true - } - - } - else - { - Write-Verbose -Message $script:localizedData.VMNetAdapterExistsNoActionNeeded - return $true - } - } - else - { - Write-Verbose -Message $script:localizedData.VMNetAdapterDoesNotExistShouldAdd - return $false - } - } - else - { - if ($netAdapterExists) - { - Write-Verbose -Message $script:localizedData.VMNetAdapterExistsShouldRemove - return $false - } - else - { - Write-Verbose -Message $script:localizedData.VMNetAdapterDoesNotExistNoActionNeeded - return $true - } - } -} - -function Get-NetworkInformation -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter(Mandatory = $true)] - [System.String] - $Name - ) - - $vm = Get-WmiObject -Namespace 'root\virtualization\v2' -Class 'Msvm_ComputerSystem' | Where-Object { $_.ElementName -ieq "$VmName" } - $vmSettings = $vm.GetRelated('Msvm_VirtualSystemSettingData') | Where-Object { $_.VirtualSystemType -eq 'Microsoft:Hyper-V:System:Realized' } - $vmNetAdapter = $vmSettings.GetRelated('Msvm_SyntheticEthernetPortSettingData') | Where-Object { $_.ElementName -ieq "$Name" } - $networkSettings = $vmNetAdapter.GetRelated('Msvm_GuestNetworkAdapterConfiguration') - - if ($networkSettings.DHCPEnabled) - { - return $null - } - else - { - return @{ - IpAddress = $networkSettings.IPAddresses -join ',' - Subnet = $networkSettings.Subnets -join ',' - DefaultGateway = $networkSettings.DefaultGateways -join ',' - DnsServer = $networkSettings.DNSServers -join ',' - } - } - -} - -function Set-NetworkInformation -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - [Parameter(ParameterSetName = 'Dhcp')] - [switch] - $Dhcp, - - [Parameter(Mandatory = $true, ParameterSetName = 'Static')] - [System.String] - $IPAddress, - - [Parameter(Mandatory = $true, ParameterSetName = 'Static')] - [System.String] - $Subnet, - - [Parameter(ParameterSetName = 'Static')] - [System.String] - $DefaultGateway, - - [Parameter(ParameterSetName = 'Static')] - [System.String] - $DnsServer - ) - - $vm = Get-WmiObject -Namespace 'root\virtualization\v2' -Class 'Msvm_ComputerSystem' | Where-Object { $_.ElementName -ieq "$VmName" } - $vmSettings = $vm.GetRelated('Msvm_VirtualSystemSettingData') | Where-Object { $_.VirtualSystemType -eq 'Microsoft:Hyper-V:System:Realized' } - $vmNetAdapter = $vmSettings.GetRelated('Msvm_SyntheticEthernetPortSettingData') | Where-Object { $_.ElementName -ieq $Name } - $networkSettings = $vmNetAdapter.GetRelated('Msvm_GuestNetworkAdapterConfiguration') | Select-Object -First 1 - - switch ($PSCmdlet.ParameterSetName) - { - 'Dhcp' - { - $networkSettings.DHCPEnabled = $true - $networkSettings.IPAddresses = @() - $networkSettings.Subnets = @() - $networkSettings.DefaultGateways = @() - $networkSettings.DNSServers = @() - } - - 'Static' - { - $networkSettings.IPAddresses = $IPAddress - $networkSettings.Subnets = $Subnet - - if ($DefaultGateway) - { - $networkSettings.DefaultGateways = $DefaultGateway - } - - if ($DnsServer) - { - $networkSettings.DNSServers = $DNSServer - } - - $networkSettings.DHCPEnabled = $false - } - } - - $networkSettings.ProtocolIFType = 4096 - - $service = Get-WmiObject -Class 'Msvm_VirtualSystemManagementService' -Namespace 'root\virtualization\v2' - $setIP = $service.SetGuestNetworkAdapterConfiguration($vm, $networkSettings.GetText(1)) - - if ($setIP.ReturnValue -eq 4096) - { - $job = [WMI]$setIP.job - - while ($job.JobState -eq 3 -or $job.JobState -eq 4) - { - Start-Sleep 1 - $job = [WMI]$setIP.job - } - - if ($job.JobState -ne 7) - { - throw $job.GetError().Error - } - } -} - -Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof b/DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof deleted file mode 100644 index 89291345..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof +++ /dev/null @@ -1,23 +0,0 @@ - -[ClassVersion("2.0.0.0")] -Class xNetworkSettings -{ - [Write] string IpAddress; - [Write] string Subnet; - [Write] string DefaultGateway; - [Write] string DnsServer; -}; - -[ClassVersion("2.0.0.0"), FriendlyName("xVMNetworkAdapter")] -class MSFT_xVMNetworkAdapter : OMI_BaseResource -{ - [Key] String Id; - [Required] String Name; - [Required] String SwitchName; - [Required] String VMName; - [Write] String MacAddress; - [Write, EmbeddedInstance("xNetworkSettings")] String NetworkSetting; - [Write] String VlanId; - [Write, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; - [Read] Boolean DynamicMacAddress; -}; diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/README.md b/DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/README.md deleted file mode 100644 index d7412852..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Description - -Manages VM net adapters attached to a Hyper-V virtual machine or the -management OS. - -## Requirements - -* The Hyper-V Role has to be installed on the machine. -* The Hyper-V PowerShell module has to be installed on the machine. diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/en-US/about_xVMNetworkAdapter.help.txt b/DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/en-US/about_xVMNetworkAdapter.help.txt deleted file mode 100644 index abaaa03d..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMNetworkAdapter/en-US/about_xVMNetworkAdapter.help.txt +++ /dev/null @@ -1,49 +0,0 @@ -.NAME - xVMNetworkAdapter - -.DESCRIPTION - Manages VM net adapters attached to a Hyper-V virtual machine or the - management OS. - - ## Requirements - - * The Hyper-V Role has to be installed on the machine. - * The Hyper-V PowerShell module has to be installed on the machine. - -.PARAMETER Id - Key - String - Network adapters' IP addresses of the VM - -.PARAMETER Name - Required - String - Network adapters' IP addresses of the VM - -.PARAMETER SwitchName - Required - String - Network adapters' IP addresses of the VM - -.PARAMETER VMName - Required - String - Network adapters' IP addresses of the VM - -.PARAMETER MacAddress - Write - String - Network adapters' IP addresses of the VM - -.PARAMETER NetworkSetting - Write - Instance - Network adapters' IP addresses of the VM - -.PARAMETER VlanId - Write - String - Network adapters' IP addresses of the VM - -.PARAMETER Ensure - Write - String - Allowed values: Present, Absent - Network adapters' IP addresses of the VM - -.PARAMETER DynamicMacAddress - Read - Boolean - Network adapters' IP addresses of the VM - diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.psm1 b/DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.psm1 deleted file mode 100644 index 23620a55..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.psm1 +++ /dev/null @@ -1,433 +0,0 @@ -$script:dscResourceCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/DscResource.Common' -$script:hyperVDscCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/HyperVDsc.Common' - -Import-Module -Name $script:dscResourceCommonModulePath -Import-Module -Name $script:hyperVDscCommonModulePath - -$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' - -<# -.SYNOPSIS - Gets MSFT_xVMProcessor resource current state. - -.PARAMETER VMName - Specifies the name of the virtual machine on which the processor is to be configured. -#> -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName - ) - - Assert-Module -ModuleName 'Hyper-V' - Write-Verbose -Message ($script:localizedData.QueryingVMProcessor -f $VMName) - $vmProcessor = Get-VMProcessor -VMName $VMName -ErrorAction Stop - $configuration = @{ - VMName = $VMName - EnableHostResourceProtection = $vmProcessor.EnableHostResourceProtection - ExposeVirtualizationExtensions = $vmProcessor.ExposeVirtualizationExtensions - HwThreadCountPerCore = $vmProcessor.HwThreadCountPerCore - Maximum = $vmProcessor.Maximum - MaximumCountPerNumaNode = $vmProcessor.MaximumCountPerNumaNode - MaximumCountPerNumaSocket = $vmProcessor.MaximumCountPerNumaSocket - RelativeWeight = $vmProcessor.RelativeWeight - Reserve = $vmProcessor.Reserve - ResourcePoolName = $vmProcessor.ResourcePoolName - CompatibilityForMigrationEnabled = $vmProcessor.CompatibilityForMigrationEnabled - CompatibilityForOlderOperatingSystemsEnabled = $vmProcessor.CompatibilityForOlderOperatingSystemsEnabled - RestartIfNeeded = $false - } - return $configuration -} - -<# -.SYNOPSIS - Tests if MSFT_xVMProcessor resource state is in the desired state or not. - -.PARAMETER VMName - Specifies the name of the virtual machine on which the processor is to be configured. - -.PARAMETER EnableHostResourceProtection - Specifies whether to enable host resource protection. - NOTE: Only supported on Windows 10 and Server 2016. - -.PARAMETER ExposeVirtualizationExtensions - Specifies whether nested virtualization is enabled. - NOTE: Only supported on Windows 10 and Server 2016. - -.PARAMETER HwThreadCountPerCore - Specifies the maximum thread core per processor core. - NOTE: Only supported on Windows 10 and Server 2016. - -.PARAMETER Maximum - Specifies the maximum percentage of resources available to the virtual machine - processor to be configured. Allowed values range from 0 to 100. - -.PARAMETER MaximumCountPerNumaNode - Specifies the maximum number of processors per NUMA node to be configured for - the virtual machine. - -.PARAMETER MaximumCountPerNumaSocket - Specifies the maximum number of sockets per NUMA node to be configured for - the virtual machine. - -.PARAMETER RelativeWeight - Specifies the priority for allocating the physical computer's processing - power to this virtual machine relative to others. Allowed values range - from 1 to 10000. - -.PARAMETER Reserve - Specifies the percentage of processor resources to be reserved for this - virtual machine. Allowed values range from 0 to 100. - -.PARAMETER ResourcePoolName - Specifies the name of the processor resource pool to be used. - -.PARAMETER CompatibilityForMigrationEnabled - Specifies whether the virtual processors features are to be limited - for compatibility when migrating the virtual machine to another host. - -.PARAMETER CompatibilityForOlderOperatingSystemsEnabled - Specifies whether the virtual processor’s features are to be limited - for compatibility with older operating systems. - -.PARAMETER RestartIfNeeded - If specified, shutdowns and restarts the VM if needed for property - changes. -#> -function Test-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter()] - [System.Boolean] - $EnableHostResourceProtection, - - [Parameter()] - [System.Boolean] - $ExposeVirtualizationExtensions, - - [Parameter()] - [System.UInt64] - $HwThreadCountPerCore, - - [Parameter()] - [ValidateRange(0, 100)] - [System.UInt64] - $Maximum, - - [Parameter()] - [System.UInt32] - $MaximumCountPerNumaNode, - - [Parameter()] - [System.UInt32] - $MaximumCountPerNumaSocket, - - [Parameter()] - [ValidateRange(0, 10000)] - [System.UInt32] - $RelativeWeight, - - [Parameter()] - [ValidateRange(0, 100)] - [System.UInt64] - $Reserve, - - [Parameter()] - [System.String] - $ResourcePoolName, - - [Parameter()] - [System.Boolean] - $CompatibilityForMigrationEnabled, - - [Parameter()] - [System.Boolean] - $CompatibilityForOlderOperatingSystemsEnabled, - - [Parameter()] - [System.Boolean] - $RestartIfNeeded - ) - - Assert-Module -ModuleName 'Hyper-V' - Assert-TargetResourceParameter @PSBoundParameters - - $targetResource = Get-TargetResource -VMName $VMName - $excludedTestParameters = @('RestartIfNeeded') - $isTargetResourceCompliant = $true - - foreach ($parameter in $PSBoundParameters.GetEnumerator()) - { - if (($targetResource.ContainsKey($parameter.Key)) -and - ($parameter.Key -notin $excludedTestParameters) -and - ($parameter.Value -ne $targetResource[$parameter.Key])) - { - $isTargetResourceCompliant = $false - Write-Verbose -Message ($script:localizedData.PropertyMismatch -f $parameter.Key, - $parameter.Value, $targetResource[$parameter.Key]) - } - } - - if ($isTargetResourceCompliant) - { - Write-Verbose -Message ($script:localizedData.VMProcessorInDesiredState -f $VMName) - } - else - { - Write-Verbose -Message ($script:localizedData.VMProcessorNotInDesiredState -f $VMName) - } - - return $isTargetResourceCompliant -} #end function - -<# -.SYNOPSIS - Configures MSFT_xVMProcessor resource state. - -.PARAMETER VMName - Specifies the name of the virtual machine on which the processor is to be configured. - -.PARAMETER EnableHostResourceProtection - Specifies whether to enable host resource protection. - NOTE: Only supported on Windows 10 and Server 2016. - -.PARAMETER ExposeVirtualizationExtensions - Specifies whether nested virtualization is enabled. - NOTE: Only supported on Windows 10 and Server 2016. - -.PARAMETER HwThreadCountPerCore - Specifies the maximum thread core per processor core - NOTE: Only supported on Windows 10 and Server 2016. - -.PARAMETER Maximum - Specifies the maximum percentage of resources available to the virtual machine - processor to be configured. Allowed values range from 0 to 100. - -.PARAMETER MaximumCountPerNumaNode - Specifies the maximum number of processors per NUMA node to be configured for - the virtual machine. - -.PARAMETER MaximumCountPerNumaSocket - Specifies the maximum number of sockets per NUMA node to be configured for - the virtual machine. - -.PARAMETER RelativeWeight - Specifies the priority for allocating the physical computer's processing - power to this virtual machine relative to others. Allowed values range - from 1 to 10000. - -.PARAMETER Reserve - Specifies the percentage of processor resources to be reserved for this - virtual machine. Allowed values range from 0 to 100. - -.PARAMETER ResourcePoolName - Specifies the name of the processor resource pool to be used. - -.PARAMETER CompatibilityForMigrationEnabled - Specifies whether the virtual processors features are to be limited - for compatibility when migrating the virtual machine to another host. - -.PARAMETER CompatibilityForOlderOperatingSystemsEnabled - Specifies whether the virtual processor’s features are to be limited - for compatibility with older operating systems. - -.PARAMETER RestartIfNeeded - If specified, shutdowns and restarts the VM if needed for property - changes. -#> -function Set-TargetResource -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter()] - [System.Boolean] - $EnableHostResourceProtection, - - [Parameter()] - [System.Boolean] - $ExposeVirtualizationExtensions, - - [Parameter()] - [System.UInt64] - $HwThreadCountPerCore, - - [Parameter()] - [ValidateRange(0, 100)] - [System.UInt64] - $Maximum, - - [Parameter()] - [System.UInt32] - $MaximumCountPerNumaNode, - - [Parameter()] - [System.UInt32] - $MaximumCountPerNumaSocket, - - [Parameter()] - [ValidateRange(0, 10000)] - [System.UInt32] - $RelativeWeight, - - [Parameter()] - [ValidateRange(0, 100)] - [System.UInt64] - $Reserve, - - [Parameter()] - [System.String] - $ResourcePoolName, - - [Parameter()] - [System.Boolean] - $CompatibilityForMigrationEnabled, - - [Parameter()] - [System.Boolean] - $CompatibilityForOlderOperatingSystemsEnabled, - - [Parameter()] - [System.Boolean] - $RestartIfNeeded - ) - - Assert-Module -ModuleName 'Hyper-V' - Assert-TargetResourceParameter @PSBoundParameters - - # Parameters requiring shutdown. - $restartRequiredParameterNames = @( - 'ExposeVirtualizationExtensions', - 'CompatibilityForMigrationEnabled', - 'CompatibilityForOlderOperatingSystemsEnabled', - 'HwThreadCountPerCore', - 'MaximumCountPerNumaNode', - 'MaximumCountPerNumaSocket', - 'ResourcePoolName' - ) - $isRestartRequired = $false - $vmObject = Get-VM -Name $VMName - - # Only check for restart required parameters if VM is not off - if ($vmObject.State -ne 'Off') - { - foreach ($parameterName in $restartRequiredParameterNames) - { - if ($PSBoundParameters.ContainsKey($parameterName)) - { - if (-not $RestartIfNeeded) - { - $errorMessage = $localized.CannotUpdateVmOnlineError -f $parameterName - - New-InvalidOperationException -Message $errorMessage - } - else - { - $isRestartRequired = $true - } - } - } #end foreach parameter - } - - $null = $PSBoundParameters.Remove('RestartIfNeeded') - $null = $PSBoundParameters.Remove('VMName') - - if (-not $isRestartRequired) - { - # No parameter specified that requires a restart, so disable the restart flag - Write-Verbose -Message ($script:localizedData.UpdatingVMProperties -f $VMName) - Set-VMProcessor -VMName $VMName @PSBoundParameters - Write-Verbose -Message ($script:localizedData.VMPropertiesUpdated -f $VMName) - } - else - { - # Restart is required and that requires turning VM off - $setVMPropertyParameters = @{ - VMName = $VMName - VMCommand = 'Set-VMProcessor' - ChangeProperty = $PSBoundParameters - RestartIfNeeded = $true - Verbose = $Verbose - } - Set-VMProperty @setVMPropertyParameters - } -} #end function - -<# -.SYNOPSIS - Ensures OS supports the supplied parameters. - -.PARAMETER EnableHostResourceProtection - Specifies whether to enable host resource protection. - NOTE: Only supported on Windows 10, Server 2016 and Nano. - -.PARAMETER ExposeVirtualizationExtensions - Specifies whether nested virtualization is enabled. - NOTE: Only supported on Windows 10, Server 2016 and Nano. - -.PARAMETER HwThreadCountPerCore - Specifies the maximum thread core per processor core - NOTE: Only supported on Windows 10, Server 2016 and Nano. - -.PARAMETER RemainingArgument - Catch all to enable splatting of remaining parameters. -#> -function Assert-TargetResourceParameter -{ - [CmdletBinding()] - param - ( - [Parameter()] - [System.Boolean] - $EnableHostResourceProtection, - - [Parameter()] - [System.Boolean] - $ExposeVirtualizationExtensions, - - [Parameter()] - [System.UInt64] - $HwThreadCountPerCore, - - [Parameter(ValueFromRemainingArguments)] - [System.Object[]] - $RemainingArguments - ) - - # Get-CimInstance returns build number as a string - $win32OperatingSystem = Get-CimInstance -ClassName Win32_OperatingSystem -Verbose:$false - $osBuildNumber = $win32OperatingSystem.BuildNumber -as [System.Int64] - $build14393RequiredParameterNames = @( - 'EnableHostResourceProtection', - 'ExposeVirtualizationExtensions', - 'HwThreadCountPerCore' - ) - - foreach ($parameterName in $build14393RequiredParameterNames) - { - if (($PSBoundParameters.ContainsKey($parameterName)) -and ($osBuildNumber -lt 14393)) - { - $errorMessage = $script:localizedData.UnsupportedSystemError -f $parameterName, 14393 - New-InvalidOperationException -Message $errorMessage - } - } -} #end function - -Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.schema.mof b/DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.schema.mof deleted file mode 100644 index 0b3c1746..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.schema.mof +++ /dev/null @@ -1,17 +0,0 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xVMProcessor")] -class MSFT_xVMProcessor : OMI_BaseResource -{ - [Key, Description("Specifies the name of the virtual machine on which the processor is to be configured.")] String VMName; - [Write, Description("Specifies whether to enable host resource protection.")] Boolean EnableHostResourceProtection; - [Write, Description("Specifies whether nested virtualization is enabled.")] Boolean ExposeVirtualizationExtensions; - [Write, Description("Specifies the maximum thread core per processor core.")] Uint64 HwThreadCountPerCore; - [Write, Description("Specifies the maximum percentage of resources available to the virtual machine processor to be configured. Allowed values range from 0 to 100.")] Uint64 Maximum; - [Write, Description("Specifies the maximum number of processors per NUMA node to be configured for the virtual machine.")] Uint32 MaximumCountPerNumaNode; - [Write, Description("Specifies the maximum number of sockets per NUMA node to be configured for the virtual machine.")] Uint32 MaximumCountPerNumaSocket; - [Write, Description("Specifies the priority for allocating the physical computer's processing power to this virtual machine relative to others. Allowed values range from 1 to 10000.")] Uint32 RelativeWeight; - [Write, Description("Specifies the percentage of processor resources to be reserved for this virtual machine. Allowed values range from 0 to 100.")] Uint64 Reserve; - [Write, Description("Specifies the name of the processor resource pool to be used.")] String ResourcePoolName; - [Write, Description("Specifies whether the virtual processors features are to be limited for compatibility when migrating the virtual machine to another host.")] Boolean CompatibilityForMigrationEnabled; - [Write, Description("Specifies whether the virtual processor’s features are to be limited for compatibility with older operating systems.")] Boolean CompatibilityForOlderOperatingSystemsEnabled; - [Write, Description("If specified, shutdowns and restarts the VM if needed for property changes.")] Boolean RestartIfNeeded; -}; diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/README.md b/DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/README.md deleted file mode 100644 index 9297c923..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMProcessor/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Description - -Manages Hyper-V virtual machine processor options. - -## Requirements - -* The Hyper-V Role has to be installed on the machine. -* The Hyper-V PowerShell module has to be installed on the machine. diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.psm1 b/DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.psm1 deleted file mode 100644 index bf23d585..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.psm1 +++ /dev/null @@ -1,222 +0,0 @@ -$script:dscResourceCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/DscResource.Common' -$script:hyperVDscCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/HyperVDsc.Common' - -Import-Module -Name $script:dscResourceCommonModulePath -Import-Module -Name $script:hyperVDscCommonModulePath - -$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' - -<# - .SYNOPSIS - Returns the current status of the VM SCSI controller. - - .PARAMETER VMName - Specifies the name of the virtual machine whose SCSI controller status is to be fetched. - - .PARAMETER ControllerNumber - Specifies the number of the controller to which the hard disk drive is to be set. - If not specified, the controller number defaults to 0. -#> -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter(Mandatory = $true)] - [ValidateSet(0, 1, 2, 3)] - [System.UInt32] - $ControllerNumber - ) - - Assert-Module -ModuleName 'Hyper-V' - - $controller = Get-VMScsiController -VMName $VMName -ControllerNumber $ControllerNumber - if ($null -eq $controller) - { - Write-Verbose -Message ($script:localizedData.ControllerNotFound -f $ControllerNumber, $VMName) - $ensure = 'Absent' - } - else - { - Write-Verbose -Message ($script:localizedData.ControllerFound -f $ControllerNumber, $VMName) - $ensure = 'Present' - } - - return @{ - VMName = $Controller.VMName - ControllerNumber = $Controller.ControllerNumber - RestartIfNeeded = $false - Ensure = $ensure - } -} - -<# - .SYNOPSIS - Tests the state of a VM SCSI controller. - - .PARAMETER VMName - Specifies the name of the virtual machine whose SCSI controller is to be tested. - - .PARAMETER ControllerNumber - Specifies the number of the controller to which the hard disk drive is to be set. - If not specified, the controller number defaults to 0. - - .PARAMETER RestartIfNeeded - Specifies if the VM should be restarted if needed for property changes. - - .PARAMETER Ensure - Specifies if the SCSI controller should exist or not. Default to Present. -#> -function Test-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter(Mandatory = $true)] - [ValidateSet(0, 1, 2, 3)] - [System.UInt32] - $ControllerNumber, - - [Parameter()] - [System.Boolean] - $RestartIfNeeded, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present' - ) - - $null = $PSBoundParameters.Remove('RestartIfNeeded') - $resource = Get-TargetResource -VMName $VMName -ControllerNumber $ControllerNumber - - $isCompliant = $true - foreach ($key in $resource.Keys) - { - Write-Verbose -Message ($script:localizedData.ComparingParameter -f $key, - $PSBoundParameters[$key], - $resource[$key]) - $isCompliant = $isCompliant -and ($PSBoundParameters[$key] -eq $resource[$key]) - } - - return $isCompliant -} - -<# - .SYNOPSIS - Manipulates the state of a VM SCSI controller. - - .PARAMETER VMName - Specifies the name of the virtual machine whose SCSI controller is to be manipulated. - - .PARAMETER ControllerNumber - Specifies the number of the controller to which the hard disk drive is to be set. - If not specified, the controller number defaults to 0. - - .PARAMETER RestartIfNeeded - Specifies if the VM should be restarted if needed for property changes. - - .PARAMETER Ensure - Specifies if the SCSI controller should exist or not. Defaults to Present. -#> -function Set-TargetResource -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName, - - [Parameter(Mandatory = $true)] - [ValidateSet(0, 1, 2, 3)] - [System.UInt32] - $ControllerNumber, - - [Parameter()] - [System.Boolean] - $RestartIfNeeded, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present' - ) - - Assert-Module -ModuleName 'Hyper-V' - - # Getting the state of the VM so we can restore it later - $existingVmState = (Get-VMHyperV -VMName $VMName).State - - if ((-not $RestartIfNeeded) -and ($existingVmState -ne 'Off')) - { - $errorMessage = $script:localizedData.CannotUpdateVmOnlineError -f $VMName - - New-InvalidOperationException -Message $errorMessage - } - - [System.Int32] $scsiControllerCount = @(Get-VMScsiController -VMName $VMName).Count - if ($Ensure -eq 'Present') - { - if ($scsiControllerCount -lt $ControllerNumber) - { - <# - All intermediate controllers should be present on the system as we cannot create - a controller at a particular location. For example, we cannot explicitly create - controller #2 - it will only be controller #2 if controllers #0 and #1 are already - added/present in the VM. - #> - $errorMessage = $script:localizedData.CannotAddScsiControllerError -f $ControllerNumber - - New-InvalidOperationException -Message $errorMessage - } - - Set-VMState -Name $VMName -State 'Off' - Write-Verbose -Message ($script:localizedData.AddingController -f $scsiControllerCount) - Add-VMScsiController -VMName $VMName - } - else - { - if ($scsiControllerCount -ne ($ControllerNumber + 1)) - { - <# - All intermediate controllers should be present on the system. Whilst we can remove - a controller at a particular location, all remaining controller numbers may be - reordered. For example, if we remove controller at position #1, then a controller - that was at position #2 will become controller number #1. - #> - $errorMessage = $script:localizedData.CannotRemoveScsiControllerError -f $ControllerNumber - - New-InvalidOperationException -Message $errorMessage - } - - Set-VMState -Name $VMName -State 'Off' - Write-Verbose -Message ($script:localizedData.CheckingExistingDisks -f $ControllerNumber) - $controller = Get-VMScsiController -VMName $VmName -ControllerNumber $ControllerNumber - - foreach ($drive in $controller.Drives) - { - $warningMessage = $script:localizedData.RemovingDiskWarning -f $drive.Path, $ControllerNumber - Write-Warning -Message $warningMessage - Remove-VMHardDiskDrive -VMHardDiskDrive $drive - } - - Write-Verbose -Message ($script:localizedData.RemovingController -f $ControllerNumber, $VMName) - Remove-VMScsiController -VMScsiController $controller - } - - # Restore the previous state - Set-VMState -Name $VMName -State $existingVmState -} - -Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.schema.mof b/DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.schema.mof deleted file mode 100644 index 1eebb011..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.schema.mof +++ /dev/null @@ -1,8 +0,0 @@ -[ClassVersion("1.0.0"), FriendlyName("xVMScsiController")] -class MSFT_xVMScsiController : OMI_BaseResource -{ - [Key, Description("Specifies the name of the virtual machine whose SCSI controller status is to be controlled")] String VMName; - [Key, Description("Specifies the number of the SCSI controller whose status is to be controlled. If not specified, it defaults to 0."), ValueMap{"0","1","2","3"}, Values{"0","1","2","3"}] Uint32 ControllerNumber; - [Write, Description("Specifies if the SCSI controller should exist or not. If not specified, it defaults to Present."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; - [Write, Description("Specifies if the VM should be restarted if needed for property changes. If not specified, it defaults to False.")] Boolean RestartIfNeeded; -}; diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/README.md b/DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/README.md deleted file mode 100644 index 859f31e7..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Description - -Manages the SCSI controllers attached to a Hyper-V virtual machine. - -When removing a controller, all the disks still connected to the controller -will be detached. - -## Requirements - -* The Hyper-V Role has to be installed on the machine. -* The Hyper-V PowerShell module has to be installed on the machine. diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/en-US/about_xVMScsiController.help.txt b/DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/en-US/about_xVMScsiController.help.txt deleted file mode 100644 index 8a3eca25..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMScsiController/en-US/about_xVMScsiController.help.txt +++ /dev/null @@ -1,32 +0,0 @@ -.NAME - xVMScsiController - -.DESCRIPTION - Manages the SCSI controllers attached to a Hyper-V virtual machine. - - When removing a controller, all the disks still connected to the controller - will be detached. - - ## Requirements - - * The Hyper-V Role has to be installed on the machine. - * The Hyper-V PowerShell module has to be installed on the machine. - -.PARAMETER VMName - Key - String - Specifies the name of the virtual machine whose SCSI controller status is to be controlled - -.PARAMETER ControllerNumber - Key - UInt32 - Allowed values: 0, 1, 2, 3 - Specifies the number of the SCSI controller whose status is to be controlled. If not specified, it defaults to 0. - -.PARAMETER Ensure - Write - String - Allowed values: Present, Absent - Specifies if the SCSI controller should exist or not. If not specified, it defaults to Present. - -.PARAMETER RestartIfNeeded - Write - Boolean - Specifies if the VM should be restarted if needed for property changes. If not specified, it defaults to False. - diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.psm1 b/DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.psm1 deleted file mode 100644 index e23bc072..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.psm1 +++ /dev/null @@ -1,697 +0,0 @@ -$script:dscResourceCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/DscResource.Common' -$script:hyperVDscCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/HyperVDsc.Common' - -Import-Module -Name $script:dscResourceCommonModulePath -Import-Module -Name $script:hyperVDscCommonModulePath - -$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' - -<# -.SYNOPSIS - Gets MSFT_xVMSwitch resource current state. - -.PARAMETER Name - Name of the VM Switch. - -.PARAMETER Type - Type of switch. -#> -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - [Parameter(Mandatory = $true)] - [ValidateSet('External', 'Internal', 'Private')] - [System.String] - $Type - ) - - Write-Verbose -Message "Getting settings for VM Switch '$Name'" - - # Check if Hyper-V module is present for Hyper-V cmdlets - if (!(Get-Module -ListAvailable -Name Hyper-V)) - { - $errorMessage = $script:localizedData.HyperVNotInstalledError - - New-ObjectNotFoundException -Message $errorMessage - } - - $switch = Get-VMSwitch -Name $Name -SwitchType $Type -ErrorAction SilentlyContinue - - if ($null -ne $switch) - { - $ensure = 'Present' - if ($switch.SwitchType -eq 'External') - { - if ($switch.EmbeddedTeamingEnabled -ne $true) - { - $netAdapterName = (Get-NetAdapter -InterfaceDescription $switch.NetAdapterInterfaceDescription -ErrorAction SilentlyContinue).Name - $description = $switch.NetAdapterInterfaceDescription - - $loadBalancingAlgorithm = 'NA' - } - else - { - $netAdapterName = (Get-NetAdapter -InterfaceDescription $switch.NetAdapterInterfaceDescriptions).Name - $description = $switch.NetAdapterInterfaceDescriptions - - $loadBalancingAlgorithm = ($switch | Get-VMSwitchTeam).LoadBalancingAlgorithm.toString() - } - } - else - { - $netAdapterName = $null - $description = $null - } - } - else - { - $ensure = 'Absent' - } - - $returnValue = @{ - Name = $switch.Name - Type = $switch.SwitchType - NetAdapterName = [System.String[]] $netAdapterName - AllowManagementOS = $switch.AllowManagementOS - EnableEmbeddedTeaming = $switch.EmbeddedTeamingEnabled - LoadBalancingAlgorithm = $loadBalancingAlgorithm - Ensure = $ensure - Id = $switch.Id - NetAdapterInterfaceDescription = $description - } - - if ($null -ne $switch.BandwidthReservationMode) - { - $returnValue['BandwidthReservationMode'] = $switch.BandwidthReservationMode - } - else - { - $returnValue['BandwidthReservationMode'] = 'NA' - } - - return $returnValue -} - -<# -.SYNOPSIS - Configures MSFT_xVMSwitch resource state. - -.PARAMETER Name - Name of the VM Switch. - -.PARAMETER Type - Type of switch. - -.PARAMETER NetAdapterName - Network adapter name(s) for external switch type. - -.PARAMETER AllowManagementOS - Specify if the VM host has access to the physical NIC. - -.PARAMETER EnableEmbeddedTeaming - Should embedded NIC teaming be used (Windows Server 2016 only). - -.PARAMETER BandwidthReservationMode - Type of Bandwidth Reservation Mode to use for the switch. - -.PARAMETER LoadBalancingAlgorithm - The load balancing algorithm that this switch team use. - -.PARAMETER Id - Desired unique ID of the Hyper-V Switch (Windows Server 2016 only). - -.PARAMETER Ensure - Whether switch should be present or absent. -#> -function Set-TargetResource -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - [Parameter(Mandatory = $true)] - [ValidateSet('External', 'Internal', 'Private')] - [System.String] - $Type, - - [Parameter()] - [ValidateNotNullOrEmpty()] - [System.String[]] - $NetAdapterName, - - [Parameter()] - [System.Boolean] - $AllowManagementOS = $false, - - [Parameter()] - [System.Boolean] - $EnableEmbeddedTeaming = $false, - - [Parameter()] - [ValidateSet('Default', 'Weight', 'Absolute', 'None', 'NA')] - [System.String] - $BandwidthReservationMode = 'NA', - - [Parameter()] - [ValidateSet('Dynamic', 'HyperVPort')] - [System.String] - $LoadBalancingAlgorithm, - - [Parameter()] - [ValidateNotNullOrEmpty()] - [ValidateScript( - { - $testGuid = New-Guid - if ([guid]::TryParse($_, [ref]$testGuid)) - { - return $true - } - else - { - throw 'The VMSwitch Id must be in GUID format!' - } - } - )] - [System.String] - $Id, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present' - ) - - # Check if Hyper-V module is present for Hyper-V cmdlets - if (!(Get-Module -ListAvailable -Name Hyper-V)) - { - $errorMessage = $script:localizedData.HyperVNotInstalledError - - New-ObjectNotFoundException -Message $errorMessage - } - - # Check to see if the BandwidthReservationMode chosen is supported in the OS - elseif (($BandwidthReservationMode -ne 'NA') -and ((Get-OSVersion) -lt [version]'6.2.0')) - { - $errorMessage = $script:localizedData.BandwidthReservationModeError - - New-InvalidOperationException -Message $errorMessage - } - - if ($EnableEmbeddedTeaming -eq $true -and (Get-OSVersion).Major -lt 10) - { - $errorMessage = $script:localizedData.SETServer2016Error - - New-InvalidOperationException -Message $errorMessage - } - - if (($PSBoundParameters.ContainsKey('Id')) -and (Get-OSVersion).Major -lt 10) - { - $errorMessage = $script:localizedData.VMSwitchIDServer2016Error - - New-InvalidOperationException -Message $errorMessage - } - - if ($Ensure -eq 'Present') - { - $switch = (Get-VMSwitch -Name $Name -SwitchType $Type -ErrorAction SilentlyContinue) - - # If switch is present and it is external type, that means it doesn't have right properties (TEST code ensures that) - if ($switch -and ($switch.SwitchType -eq 'External')) - { - $removeReaddSwitch = $false - - Write-Verbose -Message ($script:localizedData.CheckingSwitchMessage -f $Name) - if ($switch.EmbeddedTeamingEnabled -eq $false -or $null -eq $switch.EmbeddedTeamingEnabled) - { - if ((Get-NetAdapter -Name $NetAdapterName).InterfaceDescription -ne $switch.NetAdapterInterfaceDescription) - { - Write-Verbose -Message ($script:localizedData.NetAdapterInterfaceIncorrectMessage -f $Name) - $removeReaddSwitch = $true - } - } - else - { - $adapters = (Get-NetAdapter -InterfaceDescription $switch.NetAdapterInterfaceDescriptions -ErrorAction SilentlyContinue).Name - if ($null -ne (Compare-Object -ReferenceObject $adapters -DifferenceObject $NetAdapterName)) - { - Write-Verbose -Message ($script:localizedData.SwitchIncorrectNetworkAdapters -f $Name) - $removeReaddSwitch = $true - } - } - - if (($BandwidthReservationMode -ne 'NA') -and ($switch.BandwidthReservationMode -ne $BandwidthReservationMode)) - { - Write-Verbose -Message ($script:localizedData.BandwidthReservationModeIncorrect -f $Name) - $removeReaddSwitch = $true - } - - if ($null -ne $switch.EmbeddedTeamingEnabled -and - $switch.EmbeddedTeamingEnabled -ne $EnableEmbeddedTeaming) - { - Write-Verbose -Message ($script:localizedData.EnableEmbeddedTeamingIncorrect -f $Name) - $removeReaddSwitch = $true - } - - if ($null -ne $switch.EmbeddedTeamingEnabled -and - $switch.EmbeddedTeamingEnabled -ne $EnableEmbeddedTeaming) - { - Write-Verbose -Message ($script:localizedData.EnableEmbeddedTeamingIncorrect -f $Name) - $removeReaddSwitch = $true - } - - if ($PSBoundParameters.ContainsKey('Id') -and $switch.Id -ne $Id) - { - Write-Verbose -Message ($script:localizedData.IdIncorrect -f $Name) - $removeReaddSwitch = $true - } - - if ($removeReaddSwitch) - { - Write-Verbose -Message ($script:localizedData.RemoveAndReaddSwitchMessage -f $Name) - $switch | Remove-VMSwitch -Force - $parameters = @{ } - $parameters['Name'] = $Name - $parameters['NetAdapterName'] = $NetAdapterName - - if ($BandwidthReservationMode -ne 'NA') - { - $parameters['MinimumBandwidthMode'] = $BandwidthReservationMode - } - - if ($PSBoundParameters.ContainsKey('AllowManagementOS')) - { - $parameters['AllowManagementOS'] = $AllowManagementOS - } - - if ($PSBoundParameters.ContainsKey('EnableEmbeddedTeaming')) - { - $parameters['EnableEmbeddedTeaming'] = $EnableEmbeddedTeaming - } - - if ($PSBoundParameters.ContainsKey('Id')) - { - $parameters['Id'] = $Id.ToString() - } - - $null = New-VMSwitch @parameters - # Since the switch is recreated, the $switch variable is stale and needs to be reassigned - $switch = (Get-VMSwitch -Name $Name -SwitchType $Type -ErrorAction SilentlyContinue) - } - else - { - Write-Verbose -Message ($script:localizedData.SwitchCorrectNetAdapterAndBandwidthMode -f $Name, ($NetAdapterName -join ','), $BandwidthReservationMode) - } - - Write-Verbose -Message ($script:localizedData.CheckAllowManagementOS -f $Name) - if ($PSBoundParameters.ContainsKey('AllowManagementOS') -and ($switch.AllowManagementOS -ne $AllowManagementOS)) - { - Write-Verbose -Message ($script:localizedData.AllowManagementOSIncorrect -f $Name) - $switch | Set-VMSwitch -AllowManagementOS $AllowManagementOS - Write-Verbose -Message ($script:localizedData.AllowManagementOSUpdated -f $Name, $AllowManagementOS) - } - else - { - Write-Verbose -Message ($script:localizedData.AllowManagementOSCorrect -f $Name) - } - } - - # If the switch is not present, create one - else - { - Write-Verbose -Message ($script:localizedData.PresentNotCorrect -f $Name, $Ensure) - Write-Verbose -Message $script:localizedData.CreatingSwitch - $parameters = @{ } - $parameters['Name'] = $Name - - if ($BandwidthReservationMode -ne 'NA') - { - $parameters['MinimumBandwidthMode'] = $BandwidthReservationMode - } - - if ($NetAdapterName) - { - $parameters['NetAdapterName'] = $NetAdapterName - if ($PSBoundParameters.ContainsKey('AllowManagementOS')) - { - $parameters['AllowManagementOS'] = $AllowManagementOS - } - } - else - { - $parameters['SwitchType'] = $Type - } - - if ($PSBoundParameters.ContainsKey('EnableEmbeddedTeaming')) - { - $parameters['EnableEmbeddedTeaming'] = $EnableEmbeddedTeaming - } - - if ($PSBoundParameters.ContainsKey('Id')) - { - $parameters['Id'] = $Id - } - - $switch = New-VMSwitch @parameters - Write-Verbose -Message ($script:localizedData.PresentCorrect -f $Name, $Ensure) - } - - # Set the load balancing algorithm if it's a SET Switch and the parameter is specified - if ($EnableEmbeddedTeaming -eq $true -and $PSBoundParameters.ContainsKey('LoadBalancingAlgorithm')) - { - Write-Verbose -Message ($script:localizedData.SetLoadBalancingAlgorithmMessage -f $Name, $LoadBalancingAlgorithm) - Set-VMSwitchTeam -Name $switch.Name -LoadBalancingAlgorithm $LoadBalancingAlgorithm -Verbose - } - } - # Ensure is set to 'Absent', remove the switch - else - { - Get-VMSwitch $Name -ErrorAction SilentlyContinue | Remove-VMSwitch -Force - } -} - -<# -.SYNOPSIS - Tests if MSFT_xVMSwitch resource state is in the desired state or not. - -.PARAMETER Name - Name of the VM Switch. - -.PARAMETER Type - Type of switch. - -.PARAMETER NetAdapterName - Network adapter name(s) for external switch type. - -.PARAMETER AllowManagementOS - Specify if the VM host has access to the physical NIC. - -.PARAMETER EnableEmbeddedTeaming - Should embedded NIC teaming be used (Windows Server 2016 only). - -.PARAMETER BandwidthReservationMode - Type of Bandwidth Reservation Mode to use for the switch. - -.PARAMETER LoadBalancingAlgorithm - The load balancing algorithm that this switch team use. - -.PARAMETER Id - Desired unique ID of the Hyper-V Switch (Windows Server 2016 only). - -.PARAMETER Ensure - Whether switch should be present or absent. -#> -function Test-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $Name, - - [Parameter(Mandatory = $true)] - [ValidateSet('External', 'Internal', 'Private')] - [System.String] - $Type, - - [Parameter()] - [ValidateNotNullOrEmpty()] - [System.String[]] - $NetAdapterName, - - [Parameter()] - [System.Boolean] - $AllowManagementOS = $false, - - [Parameter()] - [System.Boolean] - $EnableEmbeddedTeaming = $false, - - [Parameter()] - [ValidateSet('Default', 'Weight', 'Absolute', 'None', 'NA')] - [System.String] - $BandwidthReservationMode = 'NA', - - [Parameter()] - [ValidateSet('Dynamic', 'HyperVPort')] - [System.String] - $LoadBalancingAlgorithm, - - [Parameter()] - [ValidateNotNullOrEmpty()] - [ValidateScript( - { - $testGuid = New-Guid - - if ([guid]::TryParse($_, [ref]$testGuid)) - { - return $true - } - else - { - throw 'The VMSwitch Id must be in GUID format!' - } - } - )] - [System.String] - $Id, - - [Parameter()] - [ValidateSet('Present', 'Absent')] - [System.String] - $Ensure = 'Present' - ) - - # Check if Hyper-V module is present for Hyper-V cmdlets - if (!(Get-Module -ListAvailable -Name Hyper-V)) - { - $errorMessage = $script:localizedData.HyperVNotInstalledError - New-ObjectNotFoundException -Message $errorMessage - } - - #region input validation - if ($Type -eq 'External' -and !($NetAdapterName)) - { - $errorMessage = $script:localizedData.NetAdapterNameRequiredError - - New-InvalidArgumentException -ArgumentName 'Type' -Message $errorMessage - } - - if ($Type -ne 'External' -and $NetAdapterName) - { - $errorMessage = $script:localizedData.NetAdapterNameNotRequiredError - - New-InvalidArgumentException -ArgumentName 'Type' -Message $errorMessage - } - - if (($BandwidthReservationMode -ne 'NA') -and ((Get-OSVersion) -lt [version]'6.2.0')) - { - $errorMessage = $script:localizedData.BandwidthReservationModeError - - New-InvalidArgumentException -ArgumentName 'BandwidthReservationMode' -Message $errorMessage - } - - if ($EnableEmbeddedTeaming -eq $true -and (Get-OSVersion).Major -lt 10) - { - $errorMessage = $script:localizedData.SETServer2016Error - - New-InvalidArgumentException -ArgumentName 'EnableEmbeddedTeaming' -Message $errorMessage - } - - if (($PSBoundParameters.ContainsKey('Id')) -and (Get-OSVersion).Major -lt 10) - { - $errorMessage = $script:localizedData.VMSwitchIDServer2016Error - - New-InvalidOperationException -Message $errorMessage - } - #endregion - - try - { - # Check if switch exists - Write-Verbose -Message ($script:localizedData.PresentChecking -f $Name, $Ensure) - $switch = Get-VMSwitch -Name $Name -SwitchType $Type -ErrorAction Stop - - # If switch exists - if ($null -ne $switch) - { - Write-Verbose -Message ($script:localizedData.SwitchPresent -f $Name) - # If switch should be present, check the switch type - if ($Ensure -eq 'Present') - { - ## Only check the BandwidthReservationMode if specified - if ($PSBoundParameters.ContainsKey('BandwidthReservationMode')) - { - # If the BandwidthReservationMode is correct, or if $switch.BandwidthReservationMode is $null which means it isn't supported on the OS - Write-Verbose -Message ($script:localizedData.CheckingBandwidthReservationMode -f $Name) - if ($switch.BandwidthReservationMode -eq $BandwidthReservationMode -or $null -eq $switch.BandwidthReservationMode) - { - Write-Verbose -Message ($script:localizedData.BandwidthReservationModeCorrect -f $Name) - } - else - { - Write-Verbose -Message ($script:localizedData.BandwidthReservationModeIncorrect -f $Name) - return $false - } - } - - # If switch is the external type, check additional properties - if ($Type -eq 'External') - { - if ($EnableEmbeddedTeaming -eq $false) - { - Write-Verbose -Message ($script:localizedData.CheckingNetAdapterInterface -f $Name) - $adapter = $null - try - { - $adapter = Get-NetAdapter -Name $NetAdapterName -ErrorAction SilentlyContinue - } - catch - { - # There are scenarios where the SilentlyContinue error action is not honoured, - # so this block serves to handle those and the write-verbose message is here - # to ensure that script analyser doesn't see an empty catch block to throw an - # error - Write-Verbose -Message $script:localizedData.NetAdapterNotFound - } - - if ($adapter.InterfaceDescription -ne $switch.NetAdapterInterfaceDescription) - { - return $false - } - else - { - Write-Verbose -Message ($script:localizedData.NetAdapterInterfaceCorrect -f $Name) - } - } - else - { - Write-Verbose -Message ($script:localizedData.CheckingNetAdapterInterfaces -f $Name) - if ($null -ne $switch.NetAdapterInterfaceDescriptions) - { - $adapters = (Get-NetAdapter -InterfaceDescription $switch.NetAdapterInterfaceDescriptions -ErrorAction SilentlyContinue).Name - if ($null -ne (Compare-Object -ReferenceObject $adapters -DifferenceObject $NetAdapterName)) - { - Write-Verbose -Message ($script:localizedData.IncorrectNetAdapterInterfaces -f $Name) - return $false - } - else - { - Write-Verbose -Message ($script:localizedData.CorrectNetAdapterInterfaces -f $Name) - } - } - else - { - Write-Verbose -Message ($script:localizedData.IncorrectNetAdapterInterfaces -f $Name) - return $false - } - } - - if ($PSBoundParameters.ContainsKey('AllowManagementOS')) - { - Write-Verbose -Message ($script:localizedData.CheckAllowManagementOS -f $Name) - if (($switch.AllowManagementOS -ne $AllowManagementOS)) - { - return $false - } - else - { - Write-Verbose -Message ($script:localizedData.AllowManagementOSCorrect -f $Name) - } - } - - if ($PSBoundParameters.ContainsKey('LoadBalancingAlgorithm')) - { - Write-Verbose -Message ($script:localizedData.CheckingLoadBalancingAlgorithm -f $Name) - $loadBalancingAlgorithm = ($switch | Get-VMSwitchTeam).LoadBalancingAlgorithm.toString() - if ($loadBalancingAlgorithm -ne $LoadBalancingAlgorithm) - { - return $false - } - else - { - Write-Verbose -Message ($script:localizedData.LoadBalancingAlgorithmCorrect -f $Name) - } - } - } - - # Only check embedded teaming if specified - if ($PSBoundParameters.ContainsKey('EnableEmbeddedTeaming') -eq $true) - { - Write-Verbose -Message ($script:localizedData.CheckEnableEmbeddedTeaming -f $Name) - if ($switch.EmbeddedTeamingEnabled -eq $EnableEmbeddedTeaming -or $null -eq $switch.EmbeddedTeamingEnabled) - { - Write-Verbose -Message ($script:localizedData.EnableEmbeddedTeamingCorrect -f $Name) - } - else - { - Write-Verbose -Message ($script:localizedData.EnableEmbeddedTeamingIncorrect -f $Name) - return $false - } - } - - # Check if the Switch has the desired ID - if ($PSBoundParameters.ContainsKey('Id') -eq $true) - { - Write-Verbose -Message ($script:localizedData.CheckID -f $Name) - if ($switch.Id.Guid -eq $Id) - { - Write-Verbose -Message ($script:localizedData.IdCorrect -f $Name) - } - else - { - Write-Verbose -Message ($script:localizedData.IdIncorrect -f $Name) - return $false - } - } - - return $true - } - # If switch should be absent, but is there, return $false - else - { - return $false - } - } - else - { - if ($Ensure -eq 'Present') - { - return $false - } - else - { - return $true - } - } - } - - # If no switch was present - catch [System.Management.Automation.ActionPreferenceStopException] - { - Write-Verbose -Message ($script:localizedData.SwitchNotPresent -f $Name) - return ($Ensure -eq 'Absent') - } -} - -<# -.SYNOPSIS -Returns the OS version -#> -function Get-OSVersion -{ - [Environment]::OSVersion.Version -} - -Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.schema.mof b/DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.schema.mof deleted file mode 100644 index 4f6df352..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.schema.mof +++ /dev/null @@ -1,14 +0,0 @@ -[ClassVersion("1.0.0.0"), FriendlyName("xVMSwitch")] -class MSFT_xVMSwitch : OMI_BaseResource -{ - [Key, Description("Name of the VM Switch")] String Name; - [Key, Description("Type of switch"), ValueMap{"External","Internal","Private"}, Values{"External","Internal","Private"}] String Type; - [Write, Description("Network adapter name(s) for external switch type")] String NetAdapterName[]; - [Write, Description("Specify if the VM host has access to the physical NIC")] Boolean AllowManagementOS; - [Write, Description("Should embedded NIC teaming be used (Windows Server 2016 only)")] Boolean EnableEmbeddedTeaming; - [Write, Description("Type of Bandwidth Reservation Mode to use for the switch"), ValueMap{"Default","Weight","Absolute","None","NA"}, Values{"Default","Weight","Absolute","None","NA"}] String BandwidthReservationMode; - [Write, Description("Specifies the load balancing algorithm that this switch team uses"), ValueMap{"Dynamic","HyperVPort"}, Values{"Dynamic","HyperVPort"}] String LoadBalancingAlgorithm; - [Write, Description("Whether switch should be present or absent"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; - [Write, Description("Unique ID for the switch (Only settable on Windows Server 2016!)")] String Id; - [Read, Description("Description of the network interface")] String NetAdapterInterfaceDescription; -}; diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/README.md b/DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/README.md deleted file mode 100644 index 45a75171..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Description - -Manages virtual switches in a Hyper-V host. - -## Requirements - -* The Hyper-V Role has to be installed on the machine. -* The Hyper-V PowerShell module has to be installed on the machine. diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/en-us/about_xVMSwitch.help.txt b/DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/en-us/about_xVMSwitch.help.txt deleted file mode 100644 index cc9e5202..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVMSwitch/en-us/about_xVMSwitch.help.txt +++ /dev/null @@ -1,55 +0,0 @@ -.NAME - xVMSwitch - -.DESCRIPTION - Manages virtual switches in a Hyper-V host. - - ## Requirements - - * The Hyper-V Role has to be installed on the machine. - * The Hyper-V PowerShell module has to be installed on the machine. - -.PARAMETER Name - Key - String - Name of the VM Switch - -.PARAMETER Type - Key - String - Allowed values: External, Internal, Private - Type of switch - -.PARAMETER NetAdapterName - Write - StringArray - Network adapter name(s) for external switch type - -.PARAMETER AllowManagementOS - Write - Boolean - Specify if the VM host has access to the physical NIC - -.PARAMETER EnableEmbeddedTeaming - Write - Boolean - Should embedded NIC teaming be used (Windows Server 2016 only) - -.PARAMETER BandwidthReservationMode - Write - String - Allowed values: Default, Weight, Absolute, None, NA - Type of Bandwidth Reservation Mode to use for the switch - -.PARAMETER LoadBalancingAlgorithm - Write - String - Allowed values: Dynamic, HyperVPort - Specifies the load balancing algorithm that this switch team uses - -.PARAMETER Ensure - Write - String - Allowed values: Present, Absent - Whether switch should be present or absent - -.PARAMETER Id - Write - String - Unique ID for the switch (Only settable on Windows Server 2016!) - -.PARAMETER NetAdapterInterfaceDescription - Read - String - Description of the network interface - diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.psm1 b/DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.psm1 deleted file mode 100644 index e05f6002..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.psm1 +++ /dev/null @@ -1,551 +0,0 @@ - -$script:dscResourceCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/DscResource.Common' - -Import-Module -Name $script:dscResourceCommonModulePath - -$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' - -<# -# Get the current configuration of the machine -# This function is called when you do Get-DscConfiguration after the configuration is set. -#> -function Get-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VhdPath, - - [Parameter(Mandatory = $true)] - [Microsoft.Management.Infrastructure.CimInstance[]] - $FileDirectory, - - [Parameter()] - [ValidateSet('ModifiedDate', 'SHA-1', 'SHA-256', 'SHA-512')] - [System.String] - $CheckSum = 'ModifiedDate' - ) - - if ( -not (Test-path $VhdPath)) - { - $item = New-CimInstance -ClassName MSFT_FileDirectoryConfiguration -Property @{ - DestinationPath = $VhdPath - Ensure = 'Absent' - } -Namespace 'root/microsoft/windows/desiredstateconfiguration' -ClientOnly - - return @{ - VhdPath = $VhdPath - FileDirectory = $item - } - } - - # Mount VHD. - $mountVHD = EnsureVHDState -Mounted -vhdPath $vhdPath - - $itemsFound = foreach ($Item in $FileDirectory) - { - $item = GetItemToCopy -item $item - - $mountedDrive = $mountVHD | - Get-Disk | - Get-Partition | - Where-Object -FilterScript { - $_.Type -ne 'Recovery' - } | - Get-Volume - - $letterDrive = (-join $mountedDrive.DriveLetter) + ':\' - - # show the drive letters. - Get-PSDrive | Write-Verbose - - $finalPath = Join-Path $letterDrive $item.DestinationPath - - Write-Verbose "Getting the current value at $finalPath ..." - - if (Test-Path $finalPath) - { - New-CimInstance -ClassName MSFT_FileDirectoryConfiguration -Property @{ - DestinationPath = $finalPath - Ensure = 'Present' - } -Namespace 'root/microsoft/windows/desiredstateconfiguration' -ClientOnly - } - else - { - New-CimInstance -ClassName MSFT_FileDirectoryConfiguration -Property @{ - DestinationPath = $finalPath - Ensure = 'Absent' - } -Namespace 'root/microsoft/windows/desiredstateconfiguration' -ClientOnly - } - } - - # Dismount VHD. - EnsureVHDState -Dismounted -vhdPath $VhdPath - - # Return the result. - return @{ - VhdPath = $VhdPath - FileDirectory = $itemsFound - } -} - - -# This is a resource method that gets called if the Test-TargetResource returns false. -function Set-TargetResource -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VhdPath, - - [Parameter(Mandatory = $true)] - [Microsoft.Management.Infrastructure.CimInstance[]] - $FileDirectory, - - [Parameter()] - [ValidateSet('ModifiedDate', 'SHA-1', 'SHA-256', 'SHA-512')] - [System.String] - $CheckSum = 'ModifiedDate' - ) - - if (-not (Test-Path $VhdPath)) - { - throw "Specified destination path $VhdPath does not exist!" - } - - # mount the VHD. - $mountedVHD = EnsureVHDState -Mounted -vhdPath $VhdPath - - try - { - # show the drive letters. - Get-PSDrive | Write-Verbose - - $mountedDrive = $mountedVHD | Get-Disk | Get-Partition | Where-Object -FilterScript { $_.Type -ne 'Recovery' } | Get-Volume - - foreach ($item in $FileDirectory) - { - $itemToCopy = GetItemToCopy -item $item - $letterDrive = (-join $mountedDrive.DriveLetter) + ':\' - $finalDestinationPath = $letterDrive - $finalDestinationPath = Join-Path $letterDrive $itemToCopy.DestinationPath - - # if the destination should be removed - if (-not($itemToCopy.Ensure)) - { - if (Test-Path $finalDestinationPath) - { - SetVHDFile -destinationPath $finalDestinationPath -ensure:$false -recurse:($itemToCopy.Recurse) - } - } - else - { - # Copy Scenario - if ($itemToCopy.SourcePath) - { - SetVHDFile -sourcePath $itemToCopy.SourcePath -destinationPath $finalDestinationPath -recurse:($itemToCopy.Recurse) -force:($itemToCopy.Force) - } - elseif ($itemToCopy.Content) - { - # if the type is not specified assume it is a file. - if (-not ($itemToCopy.Type)) - { - $itemToCopy.Type = 'File' - } - - # Create file/folder scenario - SetVHDFile -destinationPath $finalDestinationPath -type $itemToCopy.Type -force:($itemToCopy.Force) -content $itemToCopy.Content - } - - # Set Attribute scenario - if ($itemToCopy.Attributes) - { - SetVHDFile -destinationPath $finalDestinationPath -attribute $itemToCopy.Attributes -force:($itemToCopy.Force) - } - } - - } - } - finally - { - EnsureVHDState -Dismounted -vhdPath $VhdPath - } -} - -# This function returns if the current configuration of the machine is the same as the desired configration for this resource. -function Test-TargetResource -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VhdPath, - - [Parameter(Mandatory = $true)] - [Microsoft.Management.Infrastructure.CimInstance[]] - $FileDirectory, - - [Parameter()] - [ValidateSet('ModifiedDate', 'SHA-1', 'SHA-256', 'SHA-512')] - [System.String] - $CheckSum = 'ModifiedDate' - ) - - # If the VHD path does not exist throw an error and stop. - if ( -not (Test-Path $VhdPath)) - { - throw "VHD does not exist in the specified path $VhdPath" - } - - # mount the vhd. - $mountedVHD = EnsureVHDState -Mounted -vhdPath $VhdPath - - try - { - # Show the drive letters after mount - Get-PSDrive | Write-Verbose - - $mountedDrive = $mountedVHD | Get-Disk | Get-Partition | Where-Object -FilterScript { $_.Type -ne 'Recovery' } | Get-Volume - $letterDrive = (-join $mountedDrive.DriveLetter) + ':\' - Write-Verbose $letterDrive - - # return test result equal to true unless one of the tests in the loop below fails. - $result = $true - - foreach ($item in $FileDirectory) - { - $itemToCopy = GetItemToCopy -item $item - $destination = $itemToCopy.DestinationPath - Write-Verbose ("Testing the file with relative VHD destination $destination") - $destination = $itemToCopy.DestinationPath - $finalDestinationPath = $letterDrive - $finalDestinationPath = Join-Path $letterDrive $destination - - if (Test-Path $finalDestinationPath) - { - if ( -not ($itemToCopy.Ensure)) - { - $result = $false - break - } - else - { - $itemToCopyIsFile = Test-Path $itemToCopy.SourcePath -PathType Leaf - $destinationIsFolder = Test-Path $finalDestinationPath -PathType Container - - if ($itemToCopyIsFile -and $destinationIsFolder) - { - # Verify if the file exist inside the folder - $fileName = Split-Path $itemToCopy.SourcePath -Leaf - Write-Verbose "Checking if $fileName exist under $finalDestinationPath" - $fileExistInDestination = Test-Path (Join-Path $finalDestinationPath $fileName) - - # Report if the file exist on the destination folder. - Write-Verbose "File exist on the destination under $finalDestinationPath :- $fileExistInDestination" - $result = $fileExistInDestination - $result = $result -and -not(ItemHasChanged -sourcePath $itemToCopy.SourcePath -destinationPath (Join-Path $finalDestinationPath $fileName) -CheckSum $CheckSum) - } - - if (($itemToCopy.Type -eq 'Directory') -and ($itemToCopy.Recurse)) - { - $result = $result -and -not(ItemHasChanged -sourcePath $itemToCopy.SourcePath -destinationPath $finalDestinationPath -CheckSum $CheckSum) - - if (-not ($result)) - { - break - } - } - } - } - else - { - # If Ensure is specified as Present or if Ensure is not specified at all. - if (($itemToCopy.Ensure)) - { - $result = $false - break - } - } - - # Check the attribute - if ($itemToCopy.Attributes) - { - $currentAttribute = @(Get-ItemProperty -Path $finalDestinationPath | ForEach-Object -MemberName Attributes) - $result = $currentAttribute.Contains($itemToCopy.Attributes) - } - } - } - finally - { - EnsureVHDState -Dismounted -vhdPath $VhdPath - } - - - Write-Verbose "Test returned $result" - return $result -} - -# Assert the state of the VHD. -function EnsureVHDState -{ - [CmdletBinding(DefaultParameterSetName = 'Mounted')] - param - ( - [Parameter(ParameterSetName = 'Mounted')] - [switch]$Mounted, - - [Parameter(ParameterSetName = 'Dismounted')] - [switch]$Dismounted, - - [Parameter(Mandatory = $true)] - $vhdPath - ) - - if (-not (Get-Module -ListAvailable 'Hyper-V')) - { - throw 'Hyper-v-Powershell Windows Feature is required to run this resource. Please install Hyper-v feature and try again' - } - - if ($PSCmdlet.ParameterSetName -eq 'Mounted') - { - # Try mounting the VHD. - $mountedVHD = Mount-VHD -Path $vhdPath -Passthru -ErrorAction SilentlyContinue -ErrorVariable var - - # If mounting the VHD failed. Dismount the VHD and mount it again. - if ($var) - { - Write-Verbose 'Mounting Failed. Attempting to dismount and mount it back' - Dismount-VHD $vhdPath - $mountedVHD = Mount-VHD -Path $vhdPath -Passthru -ErrorAction SilentlyContinue - - return $mountedVHD - } - else - { - return $mountedVHD - } - } - else - { - Dismount-VHD $vhdPath -ea SilentlyContinue - - } -} - -# Change the Cim Instance objects in to a hash table containing property value pair. -function GetItemToCopy -{ - param - ( - [Parameter()] - [Microsoft.Management.Infrastructure.CimInstance] - $item - ) - - #Initialize Return Object - $returnValue = @{ } - - #Define Default Values - - $DesiredProperties = [ordered]@{ - 'SourcePath' = $null - 'DestinationPath' = $null - 'Ensure' = 'Present' - 'Recurse' = 'True' - 'Force' = 'True' - 'Content' = $null - 'Attributes' = $null - 'Type' = 'Directory' - } - - [System.String[]] ($DesiredProperties.Keys) | Foreach-Object -Process { - #Get Property Value - $thisItem = $item.CimInstanceProperties[$_].Value - - if (-not $thisItem -and $_ -in $DefaultValues.Keys) - { - #If unset and a default value is defined enter here - if ($_ -eq 'Type') - { - #Special behavior for the Type property based on SourcePath - #This relies on SourcePath preceeding Type in the list of keys (the reason for using OrderedDictionary) - if (Test-Path $returnValue.SourcePath -PathType Leaf ) - { - #If the sourcepath resolves to a file, set the default to File instad of Directory - $DefaultValues.Type = 'File' - } - } - - $returnValue[$_] = $DefaultValues[$_] - } - else - { - #If value present or no default value enter here - $returnValue[$_] = $item.CimInstanceProperties[$_].Value - } - } - - #Relies on default values in the $DesiredProperties object being the $True equivalent values - $PropertyValuesToBoolean = @( - 'Force', - 'Recurse', - 'Ensure' - ) - - # Convert string values to boolean for ease of programming. - $PropertyValuesToBoolean | ForEach-Object -Process { - $returnValue[$_] = $returnValue[$_] -eq $DesiredProperties[$_] - } - - - $returnValue.Keys | ForEach-Object -Process { - Write-Verbose "$_ => $($returnValue[$_])" - } - - return $returnValue -} - - -# This is the main function that gets called after the file is mounted to perform copy, set or new operations on the mounted drive. -function SetVHDFile -{ - [CmdletBinding(DefaultParameterSetName = 'Copy')] - param - ( - [Parameter(Mandatory = $true, ParameterSetName = 'Copy')] - $sourcePath, - - [Parameter()] - [switch] - $recurse, - - [Parameter()] - [switch] - $force, - - [Parameter(ParameterSetName = 'New')] - $type, - - [Parameter(ParameterSetName = 'New')] - $content, - - [Parameter(Mandatory = $true)] - $destinationPath, - - [Parameter(Mandatory = $true, ParameterSetName = 'Set')] - $attribute, - - [Parameter(Mandatory = $true, ParameterSetName = 'Delete')] - [switch] - $ensure - ) - - Write-Verbose "Setting the VHD file $($PSCmdlet.ParameterSetName)" - if ($PSCmdlet.ParameterSetName -eq 'Copy') - { - New-Item -Path (Split-Path $destinationPath) -ItemType Directory -ErrorAction SilentlyContinue - Copy-Item -Path $sourcePath -Destination $destinationPath -Force:$force -Recurse:$recurse -ErrorAction SilentlyContinue - } - elseif ($PSCmdlet.ParameterSetName -eq 'New') - { - if ($type -eq 'Directory') - { - New-Item -Path $destinationPath -ItemType $type - } - else - { - New-Item -Path $destinationPath -ItemType $type - $content | Out-File $destinationPath - } - - } - elseif ($PSCmdlet.ParameterSetName -eq 'Set') - { - Write-Verbose "Attempting to change the attribute of the file $destinationPath to value $attribute" - Set-ItemProperty -Path $destinationPath -Name Attributes -Value $attribute - } - elseif (!($ensure)) - { - Remove-Item -Path $destinationPath -Force:$force -Recurse:$recurse - } -} - -# Detect if the item to be copied is modified version of the orginal. -function ItemHasChanged -{ - param - ( - [Parameter(Mandatory = $true)] - [ValidateScript( { Test-Path $_ })] - $sourcePath, - - [Parameter(Mandatory = $true)] - [ValidateScript( { Test-Path $_ })] - $destinationPath, - - [Parameter()] - [ValidateSet('ModifiedDate', 'SHA-1', 'SHA-256', 'SHA-512')] - $CheckSum = 'ModifiedDate' - ) - - $itemIsFolder = Test-Path $sourcePath -Type Container - $sourceItems = $null - $destinationItems = $null - - if ($itemIsFolder) - { - $sourceItems = Get-ChildItem "$sourcePath\*.*" -Recurse - $destinationItems = Get-ChildItem "$destinationPath\*.*" -Recurse - - } - else - { - $sourceItems = Get-ChildItem $sourcePath - $destinationItems = Get-ChildItem $destinationPath - - } - - if (-not ($destinationItems)) - { - return $true - } - - # Compute the difference using the algorithem specified. - $difference = $null - - switch ($CheckSum) - { - 'ModifiedDate' - { - $difference = Compare-Object -ReferenceObject $sourceItems -DifferenceObject $destinationItems -Property LastWriteTime - } - - 'SHA-1' - { - $difference = Compare-Object -ReferenceObject ($sourceItems | Get-FileHash -Algorithm SHA1) -DifferenceObject ($destinationItems | Get-FileHash -Algorithm SHA1) -Property Hash - } - - 'SHA-256' - { - $difference = Compare-Object -ReferenceObject ($sourceItems | Get-FileHash -Algorithm SHA256) -DifferenceObject ($destinationItems | Get-FileHash -Algorithm SHA256) -Property Hash - } - - 'SHA-512' - { - $difference = Compare-Object -ReferenceObject ($sourceItems | Get-FileHash -Algorithm SHA512) -DifferenceObject ($destinationItems | Get-FileHash -Algorithm SHA512) -Property Hash - } - } - - # If there are object difference between the item at the source and Items at the distenation. - return ($null -ne $difference) - -} - -Export-ModuleMember -Function *-TargetResource diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.schema.mof b/DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.schema.mof deleted file mode 100644 index b221b4b4..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.schema.mof +++ /dev/null @@ -1,24 +0,0 @@ - -[ClassVersion("1.0.0.0")] -Class MSFT_xFileDirectory -{ - [Required] string DestinationPath; - [Write] string SourcePath; - [Write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure; - [Write,ValueMap{"File", "Directory"},Values{"File", "Directory"}] string Type; - [Write] boolean Recurse; - [Write] boolean Force ; - [write] string Content; - [Write,ValueMap{"ReadOnly", "Hidden", "System", "Archive"},Values{"ReadOnly", "Hidden", "System", "Archive"}] string Attributes[]; -}; - -[ClassVersion("1.0.0.0"), FriendlyName("xVhdFile")] -class MSFT_xVhdFileDirectory : OMI_BaseResource -{ - [Key, Description("Path to the VHD")] String VhdPath; - [Required, EmbeddedInstance("MSFT_xFileDirectory"), Description("The FileDirectory objects to copy to the VHD")] String FileDirectory[]; - [Write,ValueMap{"ModifiedDate","SHA-1","SHA-256","SHA-512"},Values{"ModifiedDate","SHA-1","SHA-256","SHA-512"}] string CheckSum; -}; - - - diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/README.md b/DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/README.md deleted file mode 100644 index 205db6b8..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Description - -Manages files or directories in a VHD. - -You can use it to copy files/folders to the VHD, remove files/folders -from a VHD, and change attributes of a file in a VHD (e.g. change a -file attribute to 'ReadOnly' or 'Hidden'). This resource is particularly -useful when bootstrapping DSC Configurations into a VM. - -## Requirements - -* The Hyper-V Role has to be installed on the machine. -* The Hyper-V PowerShell module has to be installed on the machine. diff --git a/DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/en-US/about_xVhdFile.help.txt b/DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/en-US/about_xVhdFile.help.txt deleted file mode 100644 index 478a7117..00000000 --- a/DSCResources/xHyper-V/DSCResources/MSFT_xVhdFileDirectory/en-US/about_xVhdFile.help.txt +++ /dev/null @@ -1,29 +0,0 @@ -.NAME - xVhdFile - -.DESCRIPTION - Manages files or directories in a VHD. - - You can use it to copy files/folders to the VHD, remove files/folders - from a VHD, and change attributes of a file in a VHD (e.g. change a - file attribute to 'ReadOnly' or 'Hidden'). This resource is particularly - useful when bootstrapping DSC Configurations into a VM. - - ## Requirements - - * The Hyper-V Role has to be installed on the machine. - * The Hyper-V PowerShell module has to be installed on the machine. - -.PARAMETER VhdPath - Key - String - Path to the VHD - -.PARAMETER FileDirectory - Required - InstanceArray - The FileDirectory objects to copy to the VHD - -.PARAMETER CheckSum - Write - String - Allowed values: ModifiedDate, SHA-1, SHA-256, SHA-512 - The FileDirectory objects to copy to the VHD - diff --git a/DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/DscResource.Common.psd1 b/DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/DscResource.Common.psd1 deleted file mode 100644 index 1eb5556b..00000000 --- a/DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/DscResource.Common.psd1 +++ /dev/null @@ -1,79 +0,0 @@ -@{ - # Script module or binary module file associated with this manifest. - RootModule = 'DscResource.Common.psm1' - - # Version number of this module. - ModuleVersion = '0.10.3' - - # ID used to uniquely identify this module - GUID = '9c9daa5b-5c00-472d-a588-c96e8e498450' - - # Author of this module - Author = 'DSC Community' - - # Company or vendor of this module - CompanyName = 'DSC Community' - - # Copyright statement for this module - Copyright = 'Copyright the DSC Community contributors. All rights reserved.' - - # Description of the functionality provided by this module - Description = 'Common functions used in DSC Resources' - - # Minimum version of the PowerShell engine required by this module - PowerShellVersion = '4.0' - - # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. - FunctionsToExport = @('Assert-BoundParameter','Assert-IPAddress','Assert-Module','Compare-DscParameterState','Compare-ResourcePropertyState','ConvertFrom-DscResourceInstance','ConvertTo-CimInstance','ConvertTo-HashTable','Get-ComputerName','Get-LocalizedData','Get-TemporaryFolder','New-InvalidArgumentException','New-InvalidDataException','New-InvalidOperationException','New-InvalidResultException','New-NotImplementedException','New-ObjectNotFoundException','Remove-CommonParameter','Set-DscMachineRebootRequired','Set-PSModulePath','Test-DscParameterState','Test-IsNanoServer') - - # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. - CmdletsToExport = @() - - # Variables to export from this module - VariablesToExport = @() - - # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. - AliasesToExport = @() - - # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. - PrivateData = @{ - - PSData = @{ - # Tags applied to this module. These help with module discovery in online galleries. - Tags = @('DSC', 'Localization') - - # A URL to the license for this module. - LicenseUri = 'https://github.com/dsccommunity/DscResource.Common/blob/main/LICENSE' - - # A URL to the main website for this project. - ProjectUri = 'https://github.com/dsccommunity/DscResource.Common' - - # A URL to an icon representing this module. - IconUri = 'https://dsccommunity.org/images/DSC_Logo_300p.png' - - # ReleaseNotes of this module - ReleaseNotes = '## [0.10.3] - 2021-06-26 - -### Added - -- Added cmdlet `ConvertFrom-DscResourceInstance` which can be used to convert any - object to in another format. It accepts objects from pipeline. [issue #71](https://github.com/dsccommunity/DscResource.Common/issues/71). -- Now code coverage is uploaded to codecov.io. - -### Changed - -- Unit tests are now running using Pester 5 ([issue #40](https://github.com/dsccommunity/DscResource.Common/issues/40)). -- Excludes the PowerShell module script file _DscResource.Common.psm1_ located - in folder _source_ from the HQRM testing. - -' - - Prerelease = '' - } # End of PSData hashtable - - } # End of PrivateData hashtable -} - - - - diff --git a/DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/DscResource.Common.psm1 b/DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/DscResource.Common.psm1 deleted file mode 100644 index da3a3ba6..00000000 --- a/DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/DscResource.Common.psm1 +++ /dev/null @@ -1,2615 +0,0 @@ -#Region './prefix.ps1' 0 -$script:modulesFolderPath = Split-Path -Path $PSScriptRoot -Parent -#EndRegion './prefix.ps1' 2 -#Region './Private/Test-DscObjectHasProperty.ps1' 0 -<# - .SYNOPSIS - Tests if an object has a property. - - .DESCRIPTION - Tests if the specified object has the specified property and return - $true or $false. - - .PARAMETER Object - Specifies the object to test for the specified property. - - .PARAMETER PropertyName - Specifies the property name to test for. - - .EXAMPLE - Test-DscObjectHasProperty -Object 'AnyString' -PropertyName 'Length' -#> -function Test-DscObjectHasProperty -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [Parameter(Mandatory = $true)] - [System.Object] - $Object, - - [Parameter(Mandatory = $true)] - [System.String] - $PropertyName - ) - - if ($Object.PSObject.Properties.Name -contains $PropertyName) - { - return [System.Boolean] $Object.$PropertyName - } - - return $false -} -#EndRegion './Private/Test-DscObjectHasProperty.ps1' 40 -#Region './Private/Test-DscPropertyState.ps1' 0 -<# - .SYNOPSIS - Compares the current and the desired value of a property. - - .DESCRIPTION - This function is used to compare the current and the desired value of a - property. - - .PARAMETER Values - This is set to a hash table with the current value (the CurrentValue key) - and desired value (the DesiredValue key). - - .EXAMPLE - Test-DscPropertyState -Values @{ - CurrentValue = 'John' - DesiredValue = 'Alice' - } - - .EXAMPLE - Test-DscPropertyState -Values @{ - CurrentValue = 1 - DesiredValue = 2 - } - - .NOTES - This function is used by the cmdlet Compare-ResourcePropertyState. -#> -function Test-DscPropertyState -{ - [CmdletBinding()] - [OutputType([System.Boolean])] - param - ( - [Parameter(Mandatory = $true)] - [System.Collections.Hashtable] - $Values - ) - - if ($null -eq $Values.CurrentValue -and $null -eq $Values.DesiredValue) - { - # Both values are $null so return $true - $returnValue = $true - } - elseif ($null -eq $Values.CurrentValue -or $null -eq $Values.DesiredValue) - { - # Either CurrentValue or DesiredValue are $null so return $false - $returnValue = $false - } - elseif ( - $Values.DesiredValue -is [Microsoft.Management.Infrastructure.CimInstance[]] ` - -or $Values.DesiredValue -is [System.Array] -and $Values.DesiredValue[0] -is [Microsoft.Management.Infrastructure.CimInstance] - ) - { - if (-not $Values.ContainsKey('KeyProperties')) - { - $errorMessage = $script:localizedData.KeyPropertiesMissing - - New-InvalidOperationException -Message $errorMessage - } - - $propertyState = @() - - <# - It is a collection of CIM instances, then recursively call - Test-DscPropertyState for each CIM instance in the collection. - #> - foreach ($desiredCimInstance in $Values.DesiredValue) - { - $currentCimInstance = $Values.CurrentValue - - <# - Use the CIM instance Key properties to filter out the current - values if the exist. - #> - foreach ($keyProperty in $Values.KeyProperties) - { - $currentCimInstance = $currentCimInstance | - Where-Object -Property $keyProperty -EQ -Value $desiredCimInstance.$keyProperty - } - - if ($currentCimInstance.Count -gt 1) - { - $errorMessage = $script:localizedData.TooManyCimInstances - - New-InvalidOperationException -Message $errorMessage - } - - if ($currentCimInstance) - { - $keyCimInstanceProperties = $currentCimInstance.CimInstanceProperties | - Where-Object -FilterScript { - $_.Name -in $Values.KeyProperties - } - - <# - For each key property build a string representation of the - property name and its value. - #> - $keyPropertyValues = $keyCimInstanceProperties.ForEach({'{0}="{1}"' -f $_.Name, ($_.Value -join ',')}) - - Write-Debug -Message ( - $script:localizedData.TestingCimInstance -f @( - $currentCimInstance.CimClass.CimClassName, - ($keyPropertyValues -join ';') - ) - ) - } - else - { - $keyCimInstanceProperties = $desiredCimInstance.CimInstanceProperties | - Where-Object -FilterScript { - $_.Name -in $Values.KeyProperties - } - - <# - For each key property build a string representation of the - property name and its value. - #> - $keyPropertyValues = $keyCimInstanceProperties.ForEach({'{0}="{1}"' -f $_.Name, ($_.Value -join ',')}) - - Write-Debug -Message ( - $script:localizedData.MissingCimInstance -f @( - $desiredCimInstance.CimClass.CimClassName, - ($keyPropertyValues -join ';') - ) - ) - } - - # Recursively call Test-DscPropertyState with the CimInstance to evaluate. - $propertyState += Test-DscPropertyState -Values @{ - CurrentValue = $currentCimInstance - DesiredValue = $desiredCimInstance - } - } - - # Return $false if one property is found to not be in desired state. - $returnValue = -not ($false -in $propertyState) - } - elseif ($Values.DesiredValue -is [Microsoft.Management.Infrastructure.CimInstance]) - { - $propertyState = @() - - <# - It is a CIM instance, recursively call Test-DscPropertyState for each - CIM instance property. - #> - $desiredCimInstanceProperties = $Values.DesiredValue.CimInstanceProperties | - Select-Object -Property @('Name', 'Value') - - if ($desiredCimInstanceProperties) - { - foreach ($desiredCimInstanceProperty in $desiredCimInstanceProperties) - { - <# - Recursively call Test-DscPropertyState to evaluate each property - in the CimInstance. - #> - $propertyState += Test-DscPropertyState -Values @{ - CurrentValue = $Values.CurrentValue.($desiredCimInstanceProperty.Name) - DesiredValue = $desiredCimInstanceProperty.Value - } - } - } - else - { - if ($Values.CurrentValue.CimInstanceProperties.Count -gt 0) - { - # Current value did not have any CIM properties, but desired state has. - $propertyState += $false - } - } - - # Return $false if one property is found to not be in desired state. - $returnValue = -not ($false -in $propertyState) - } - elseif ($Values.DesiredValue -is [System.Array] -or $Values.CurrentValue -is [System.Array]) - { - $compareObjectParameters = @{ - ReferenceObject = $Values.CurrentValue - DifferenceObject = $Values.DesiredValue - } - - $arrayCompare = Compare-Object @compareObjectParameters - - if ($null -ne $arrayCompare) - { - Write-Debug -Message $script:localizedData.ArrayDoesNotMatch - - $arrayCompare | - ForEach-Object -Process { - if ($_.SideIndicator -eq '=>') - { - Write-Debug -Message ( - $script:localizedData.ArrayValueIsAbsent -f $_.InputObject - ) - } - else - { - Write-Debug -Message ( - $script:localizedData.ArrayValueIsPresent -f $_.InputObject - ) - } - } - - $returnValue = $false - } - else - { - $returnValue = $true - } - } - elseif ($Values.CurrentValue -ne $Values.DesiredValue) - { - $desiredType = $Values.DesiredValue.GetType() - - $returnValue = $false - - $supportedTypes = @( - 'String' - 'Int32' - 'UInt32' - 'Int16' - 'UInt16' - 'Single' - 'Boolean' - ) - - if ($desiredType.Name -notin $supportedTypes) - { - Write-Warning -Message ($script:localizedData.UnableToCompareType -f $desiredType.Name) - } - else - { - Write-Debug -Message ( - $script:localizedData.PropertyValueOfTypeDoesNotMatch ` - -f $desiredType.Name, $Values.CurrentValue, $Values.DesiredValue - ) - } - } - else - { - $returnValue = $true - } - - return $returnValue -} -#EndRegion './Private/Test-DscPropertyState.ps1' 247 -#Region './Public/Assert-BoundParameter.ps1' 0 -<# - .SYNOPSIS - Throws an error if there is a bound parameter that exists in both the - mutually exclusive lists. - - .DESCRIPTION - Throws an error if there is a bound parameter that exists in both the - mutually exclusive lists. - - .PARAMETER BoundParameterList - The parameters that should be evaluated against the mutually exclusive - lists MutuallyExclusiveList1 and MutuallyExclusiveList2. This parameter is - normally set to the $PSBoundParameters variable. - - .PARAMETER MutuallyExclusiveList1 - An array of parameter names that are not allowed to be bound at the - same time as those in MutuallyExclusiveList2. - - .PARAMETER MutuallyExclusiveList2 - An array of parameter names that are not allowed to be bound at the - same time as those in MutuallyExclusiveList1. - - .EXAMPLE - $assertBoundParameterParameters = @{ - BoundParameterList = $PSBoundParameters - MutuallyExclusiveList1 = @( - 'Parameter1' - ) - MutuallyExclusiveList2 = @( - 'Parameter2' - ) - } - - Assert-BoundParameter @assertBoundParameterParameters - - This example throws an exception if `$PSBoundParameters` contains both - the parameters `Parameter1` and `Parameter2`. -#> -function Assert-BoundParameter -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [AllowEmptyCollection()] - [System.Collections.Hashtable] - $BoundParameterList, - - [Parameter(Mandatory = $true)] - [System.String[]] - $MutuallyExclusiveList1, - - [Parameter(Mandatory = $true)] - [System.String[]] - $MutuallyExclusiveList2 - ) - - $itemFoundFromList1 = $BoundParameterList.Keys.Where({ $_ -in $MutuallyExclusiveList1 }) - $itemFoundFromList2 = $BoundParameterList.Keys.Where({ $_ -in $MutuallyExclusiveList2 }) - - if ($itemFoundFromList1.Count -gt 0 -and $itemFoundFromList2.Count -gt 0) - { - $errorMessage = ` - $script:localizedData.ParameterUsageWrong ` - -f ($MutuallyExclusiveList1 -join "','"), ($MutuallyExclusiveList2 -join "','") - - New-InvalidArgumentException -ArgumentName 'Parameters' -Message $errorMessage - } -} -#EndRegion './Public/Assert-BoundParameter.ps1' 70 -#Region './Public/Assert-IPAddress.ps1' 0 -<# - .SYNOPSIS - Asserts that the specified IP address is valid. - - .DESCRIPTION - Checks the IP address so that it is valid and do not conflict with address - family. If any problems are detected an exception will be thrown. - - .PARAMETER AddressFamily - IP address family that the supplied Address should be in. Valid values are - 'IPv4' or 'IPv6'. - - .PARAMETER Address - Specifies an IPv4 or IPv6 address. - - .EXAMPLE - Assert-IPAddress -Address '127.0.0.1' - - This will assert that the supplied address is a valid IPv4 address. - If it is not an exception will be thrown. - - .EXAMPLE - Assert-IPAddress -Address 'fe80:ab04:30F5:002b::1' - - This will assert that the supplied address is a valid IPv6 address. - If it is not an exception will be thrown. - - .EXAMPLE - Assert-IPAddress -Address 'fe80:ab04:30F5:002b::1' -AddressFamily 'IPv6' - - This will assert that address is valid and that it matches the - supplied address family. If the supplied address family does not match - the address an exception will be thrown. -#> -function Assert-IPAddress -{ - [CmdletBinding()] - param - ( - [Parameter()] - [ValidateSet('IPv4', 'IPv6')] - [System.String] - $AddressFamily, - - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $Address - ) - - [System.Net.IPAddress] $ipAddress = $null - - if (-not ([System.Net.IPAddress]::TryParse($Address, [ref] $ipAddress))) - { - New-InvalidArgumentException ` - -Message ($script:localizedData.AddressFormatError -f $Address) ` - -ArgumentName 'Address' - } - - if ($AddressFamily) - { - switch ($AddressFamily) - { - 'IPv4' - { - if ($ipAddress.AddressFamily -ne [System.Net.Sockets.AddressFamily]::InterNetwork.ToString()) - { - New-InvalidArgumentException ` - -Message ($script:localizedData.AddressIPv6MismatchError -f $Address, $AddressFamily) ` - -ArgumentName 'AddressFamily' - } - } - - 'IPv6' - { - if ($ipAddress.AddressFamily -ne [System.Net.Sockets.AddressFamily]::InterNetworkV6.ToString()) - { - New-InvalidArgumentException ` - -Message ($script:localizedData.AddressIPv4MismatchError -f $Address, $AddressFamily) ` - -ArgumentName 'AddressFamily' - } - } - } - } -} -#EndRegion './Public/Assert-IPAddress.ps1' 86 -#Region './Public/Assert-Module.ps1' 0 -<# - .SYNOPSIS - Assert if the specific module is available to be imported. - - .DESCRIPTION - Assert if the specific module is available to be imported. - - .PARAMETER ModuleName - Specifies the name of the module to assert. - - .PARAMETER ImportModule - Specifies to import the module if it is asserted. - - .PARAMETER Force - Specifies to forcibly import the module even if it is already in the - session. This parameter is ignored unless parameter `ImportModule` is - also used. - - .EXAMPLE - Assert-Module -ModuleName 'DhcpServer' - - This asserts that the module DhcpServer is available on the system. - - .EXAMPLE - Assert-Module -ModuleName 'DhcpServer' -ImportModule - - This asserts that the module DhcpServer is available on the system and - imports it. - - .EXAMPLE - Assert-Module -ModuleName 'DhcpServer' -ImportModule -Force - - This asserts that the module DhcpServer is available on the system and - forcibly imports it. -#> -function Assert-Module -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $ModuleName, - - [Parameter()] - [System.Management.Automation.SwitchParameter] - $ImportModule, - - [Parameter()] - [System.Management.Automation.SwitchParameter] - $Force - ) - - <# - If the module is already in the session there is no need to use -ListAvailable. - This is a fix for issue #66. - #> - if (-not (Get-Module -Name $ModuleName)) - { - if (-not (Get-Module -Name $ModuleName -ListAvailable)) - { - $errorMessage = $script:localizedData.ModuleNotFound -f $ModuleName - New-ObjectNotFoundException -Message $errorMessage - } - - # Only import it here if $Force is not set, otherwise it will be imported below. - if ($ImportModule -and -not $Force) - { - Import-Module -Name $ModuleName - } - } - - # Always import the module even if already in session. - if ($ImportModule -and $Force) - { - Import-Module -Name $ModuleName -Force - } -} -#EndRegion './Public/Assert-Module.ps1' 79 -#Region './Public/Compare-DscParameterState.ps1' 0 -<# - .SYNOPSIS - This method is used to compare current and desired values for any DSC resource. - - .DESCRIPTION - This function compare the parameter status of DSC resource parameters against - the current values present on the system, and return a hashtable with the metadata - from the comparison. - - .PARAMETER CurrentValues - A hashtable with the current values on the system, obtained by e.g. - Get-TargetResource. - - .PARAMETER DesiredValues - The hashtable of desired values. For example $PSBoundParameters with the - desired values. - - .PARAMETER Properties - This is a list of properties in the desired values list should be checked. - If this is empty then all values in DesiredValues are checked. - - .PARAMETER ExcludeProperties - This is a list of which properties in the desired values list should be checked. - If this is empty then all values in DesiredValues are checked. - - .PARAMETER TurnOffTypeChecking - Indicates that the type of the parameter should not be checked. - - .PARAMETER ReverseCheck - Indicates that a reverse check should be done. The current and desired state - are swapped for another test. - - .PARAMETER SortArrayValues - If the sorting of array values does not matter, values are sorted internally - before doing the comparison. - - .PARAMETER IncludeInDesiredState - Indicates that result adds the properties in the desired state. - By default, this command returns only the properties not in desired state. - - .PARAMETER IncludeValue - Indicates that result contains the ActualValue and ExcpectedValue properties. - - .EXAMPLE - $currentValues = @{ - String = 'This is a string' - Int = 1 - Bool = $true - } - - $desiredValues = @{ - String = 'This is a string' - Int = 99 - } - - Compare-DscParameterState -CurrentValues $currentValues -DesiredValues $desiredValues - - Name Value - ---- ----- - Property Int - InDesiredState False - ExpectedType System.Int32 - ActualType System.Int32 - ``` - - The function Compare-DscParameterState compare the value of each hashtable based - on the keys present in $desiredValues hashtable. The result indicates that Int - property is not in the desired state. - No information about Bool property, because it is not in $desiredValues hashtable. - - .EXAMPLE - $currentValues = @{ - String = 'This is a string' - Int = 1 - Bool = $true - } - - $desiredValues = @{ - String = 'This is a string' - Int = 99 - Bool = $false - } - - $excludeProperties = @('Bool') - - Compare-DscParameterState ` - -CurrentValues $currentValues ` - -DesiredValues $desiredValues ` - -ExcludeProperties $ExcludeProperties - - Name Value - ---- ----- - Property Int - InDesiredState False - ExpectedType System.Int32 - ActualType System.Int32 - ``` - - The function Compare-DscParameterState compare the value of each hashtable based - on the keys present in $desiredValues hashtable and without those in $excludeProperties. - The result indicates that Int property is not in the desired state. - No information about Bool property, because it is in $excludeProperties. - - .EXAMPLE - $serviceParameters = @{ - Name = $Name - } - - $returnValue = Compare-DscParameterState ` - -CurrentValues (Get-Service @serviceParameters) ` - -DesiredValues $PSBoundParameters ` - -Properties @( - 'Name' - 'Status' - 'StartType' - ) - - This compares the values in the current state against the desires state. - The command Get-Service is called using just the required parameters - to get the values in the current state. The parameter 'Properties' - is used to specify the properties 'Name','Status' and - 'StartType' for the comparison. - -#> -function Compare-DscParameterState -{ - [CmdletBinding()] - [OutputType([System.Object[]])] - param - ( - [Parameter(Mandatory = $true)] - [System.Object] - $CurrentValues, - - [Parameter(Mandatory = $true)] - [System.Object] - $DesiredValues, - - [Parameter()] - [System.String[]] - [Alias('ValuesToCheck')] - $Properties, - - [Parameter()] - [System.String[]] - $ExcludeProperties, - - [Parameter()] - [System.Management.Automation.SwitchParameter] - $TurnOffTypeChecking, - - [Parameter()] - [System.Management.Automation.SwitchParameter] - $ReverseCheck, - - [Parameter()] - [System.Management.Automation.SwitchParameter] - $SortArrayValues, - - [Parameter()] - [System.Management.Automation.SwitchParameter] - $IncludeInDesiredState, - - [Parameter()] - [System.Management.Automation.SwitchParameter] - $IncludeValue - ) - - $returnValue = @() - #region ConvertCIm to Hashtable - if ($CurrentValues -is [Microsoft.Management.Infrastructure.CimInstance] -or - $CurrentValues -is [Microsoft.Management.Infrastructure.CimInstance[]]) - { - $CurrentValues = ConvertTo-HashTable -CimInstance $CurrentValues - } - - if ($DesiredValues -is [Microsoft.Management.Infrastructure.CimInstance] -or - $DesiredValues -is [Microsoft.Management.Infrastructure.CimInstance[]]) - { - $DesiredValues = ConvertTo-HashTable -CimInstance $DesiredValues - } - #endregion Endofconverion - #region CheckType of object - $types = 'System.Management.Automation.PSBoundParametersDictionary', - 'System.Collections.Hashtable', - 'Microsoft.Management.Infrastructure.CimInstance' - - if ($DesiredValues.GetType().FullName -notin $types) - { - New-InvalidArgumentException ` - -Message ($script:localizedData.InvalidDesiredValuesError -f $DesiredValues.GetType().FullName) ` - -ArgumentName 'DesiredValues' - } - - if ($CurrentValues.GetType().FullName -notin $types) - { - New-InvalidArgumentException ` - -Message ($script:localizedData.InvalidCurrentValuesError -f $CurrentValues.GetType().FullName) ` - -ArgumentName 'CurrentValues' - } - #endregion checktype - #region check if CimInstance and not have properties in parameters invoke exception - if ($DesiredValues -is [Microsoft.Management.Infrastructure.CimInstance] -and -not $Properties) - { - New-InvalidArgumentException ` - -Message $script:localizedData.InvalidPropertiesError ` - -ArgumentName Properties - } - #endregion check cim and properties - #Clean value if there are a common parameters provide from Test/Get-TargetResource parameter - $desiredValuesClean = Remove-CommonParameter -Hashtable $DesiredValues - #region generate keyList based on $Properties and $excludeProperties value - if (-not $Properties) - { - $keyList = $desiredValuesClean.Keys - } - else - { - $keyList = $Properties - } - - if ($ExcludeProperties) - { - $keyList = $keyList | Where-Object -FilterScript { $_ -notin $ExcludeProperties } - } - #endregion - #region enumerate of each key in list - foreach ($key in $keyList) - { - #generate default value - $InDesiredStateTable = [ordered]@{ - Property = $key - InDesiredState = $true - } - $returnValue += $InDesiredStateTable - #get value of each key - $desiredValue = $desiredValuesClean.$key - $currentValue = $CurrentValues.$key - - #Check if IncludeValue parameter is used. - if ($IncludeValue) - { - $InDesiredStateTable['ExpectedValue'] = $desiredValue - $InDesiredStateTable['ActualValue'] = $currentValue - } - - #region convert to hashtable if value of key is CimInstance - if ($desiredValue -is [Microsoft.Management.Infrastructure.CimInstance] -or - $desiredValue -is [Microsoft.Management.Infrastructure.CimInstance[]]) - { - $desiredValue = ConvertTo-HashTable -CimInstance $desiredValue - } - if ($currentValue -is [Microsoft.Management.Infrastructure.CimInstance] -or - $currentValue -is [Microsoft.Management.Infrastructure.CimInstance[]]) - { - $currentValue = ConvertTo-HashTable -CimInstance $currentValue - } - #endregion converttohashtable - #region gettype of value to check if they are the same. - if ($null -ne $desiredValue) - { - $desiredType = $desiredValue.GetType() - } - else - { - $desiredType = @{ - Name = 'Unknown' - } - } - - $InDesiredStateTable['ExpectedType'] = $desiredType - - if ($null -ne $currentValue) - { - $currentType = $currentValue.GetType() - } - else - { - $currentType = @{ - Name = 'Unknown' - } - } - - $InDesiredStateTable['ActualType'] = $currentType - - #endregion - #region check if the desiredtype if a credential object. Only if the current type isn't unknown. - if ($currentType.Name -ne 'Unknown' -and $desiredType.Name -eq 'PSCredential') - { - # This is a credential object. Compare only the user name - if ($currentType.Name -eq 'PSCredential' -and $currentValue.UserName -eq $desiredValue.UserName) - { - Write-Verbose -Message ($script:localizedData.MatchPsCredentialUsernameMessage -f $currentValue.UserName, $desiredValue.UserName) - continue # pass to the next key - } - elseif ($currentType.Name -ne 'string') - { - Write-Verbose -Message ($script:localizedData.NoMatchPsCredentialUsernameMessage -f $currentValue.UserName, $desiredValue.UserName) - $InDesiredStateTable.InDesiredState = $false - } - - # Assume the string is our username when the matching desired value is actually a credential - if ($currentType.Name -eq 'string' -and $currentValue -eq $desiredValue.UserName) - { - Write-Verbose -Message ($script:localizedData.MatchPsCredentialUsernameMessage -f $currentValue, $desiredValue.UserName) - continue # pass to the next key - } - else - { - Write-Verbose -Message ($script:localizedData.NoMatchPsCredentialUsernameMessage -f $currentValue, $desiredValue.UserName) - $InDesiredStateTable.InDesiredState = $false - } - } - #endregion test credential - #region Test type of object. And if they're not InDesiredState, generate en exception - if (-not $TurnOffTypeChecking) - { - if (($desiredType.Name -ne 'Unknown' -and $currentType.Name -ne 'Unknown') -and - $desiredType.FullName -ne $currentType.FullName) - { - Write-Verbose -Message ($script:localizedData.NoMatchTypeMismatchMessage -f $key, $currentType.FullName, $desiredType.FullName) - $InDesiredStateTable.InDesiredState = $false - continue # pass to the next key - } - } - #endregion TestType - #region Check if the value of Current and desired state is the same but only if they are not an array - if ($currentValue -eq $desiredValue -and -not $desiredType.IsArray) - { - Write-Verbose -Message ($script:localizedData.MatchValueMessage -f $desiredType.FullName, $key, $currentValue, $desiredValue) - continue # pass to the next key - } - #endregion check same value - #region Check if the DesiredValuesClean has the key and if it don't have, it's not necessary to check his value - if ($desiredValuesClean.GetType().Name -in 'HashTable', 'PSBoundParametersDictionary') - { - $checkDesiredValue = $desiredValuesClean.ContainsKey($key) - } - else - { - $checkDesiredValue = Test-DscObjectHasProperty -Object $desiredValuesClean -PropertyName $key - } - # if there no key, don't need to check - if (-not $checkDesiredValue) - { - Write-Verbose -Message ($script:localizedData.MatchValueMessage -f $desiredType.FullName, $key, $currentValue, $desiredValue) - continue # pass to the next key - } - #endregion - #region Check if desired type is array, ifno Hashtable and currenttype hashtable to - if ($desiredType.IsArray) - { - Write-Verbose -Message ($script:localizedData.TestDscParameterCompareMessage -f $key, $desiredType.FullName) - # Check if the currentValues and desiredValue are empty array. - if (-not $currentValue -and -not $desiredValue) - { - Write-Verbose -Message ($script:localizedData.MatchValueMessage -f $desiredType.FullName, $key, 'empty array', 'empty array') - continue - } - elseif (-not $currentValue) - { - #If only currentvalue is empty, the configuration isn't compliant. - Write-Verbose -Message ($script:localizedData.NoMatchValueMessage -f $desiredType.FullName, $key, $currentValue, $desiredValue) - $InDesiredStateTable.InDesiredState = $false - continue - } - elseif ($currentValue.Count -ne $desiredValue.Count) - { - #If there is a difference between the number of objects in arrays, this isn't compliant. - Write-Verbose -Message ($script:localizedData.NoMatchValueDifferentCountMessage -f $desiredType.FullName, $key, $currentValue.Count, $desiredValue.Count) - $InDesiredStateTable.InDesiredState = $false - continue - } - else - { - $desiredArrayValues = $desiredValue - $currentArrayValues = $currentValue - # if the sortArrayValues parameter is using, sort value of array - if ($SortArrayValues) - { - $desiredArrayValues = @($desiredArrayValues | Sort-Object) - $currentArrayValues = @($currentArrayValues | Sort-Object) - } - <# - for all object in collection, check their type.ConvertoString if they are script block. - - #> - for ($i = 0; $i -lt $desiredArrayValues.Count; $i++) - { - if ($desiredArrayValues[$i]) - { - $desiredType = $desiredArrayValues[$i].GetType() - } - else - { - $desiredType = @{ - Name = 'Unknown' - } - } - - if ($currentArrayValues[$i]) - { - $currentType = $currentArrayValues[$i].GetType() - } - else - { - $currentType = @{ - Name = 'Unknown' - } - } - - if (-not $TurnOffTypeChecking) - { - if (($desiredType.Name -ne 'Unknown' -and $currentType.Name -ne 'Unknown') -and - $desiredType.FullName -ne $currentType.FullName) - { - Write-Verbose -Message ($script:localizedData.NoMatchElementTypeMismatchMessage -f $key, $i, $currentType.FullName, $desiredType.FullName) - $InDesiredStateTable.InDesiredState = $false - continue - } - } - - <# - Convert a scriptblock into a string as scriptblocks are not comparable - if currentvalue is scriptblock and if desired value is string, - we invoke the result of script block. Ifno, we convert to string. - if Desired value - #> - - $wasCurrentArrayValuesConverted = $false - if ($currentArrayValues[$i] -is [scriptblock]) - { - $currentArrayValues[$i] = if ($desiredArrayValues[$i] -is [string]) - { - $currentArrayValues[$i] = $currentArrayValues[$i].Invoke() - } - else - { - $currentArrayValues[$i].ToString() - } - $wasCurrentArrayValuesConverted = $true - } - - if ($desiredArrayValues[$i] -is [scriptblock]) - { - $desiredArrayValues[$i] = if ($currentArrayValues[$i] -is [string] -and -not $wasCurrentArrayValuesConverted) - { - $desiredArrayValues[$i].Invoke() - } - else - { - $desiredArrayValues[$i].ToString() - } - } - - if ($desiredType -eq [System.Collections.Hashtable] -and $currentType -eq [System.Collections.Hashtable]) - { - $param = $PSBoundParameters - $param.CurrentValues = $currentArrayValues[$i] - $param.DesiredValues = $desiredArrayValues[$i] - - 'IncludeInDesiredState','IncludeValue' | ForEach-Object { - if ($param.ContainsKey($_)) - { - $null = $param.Remove($_) - } - } - - if ($InDesiredStateTable.InDesiredState) - { - $InDesiredStateTable.InDesiredState = Test-DscParameterState @param - } - else - { - Test-DscParameterState @param | Out-Null - } - continue - } - - if ($desiredArrayValues[$i] -ne $currentArrayValues[$i]) - { - Write-Verbose -Message ($script:localizedData.NoMatchElementValueMismatchMessage -f $i, $desiredType.FullName, $key, $currentArrayValues[$i], $desiredArrayValues[$i]) - $InDesiredStateTable.InDesiredState = $false - continue - } - else - { - Write-Verbose -Message ($script:localizedData.MatchElementValueMessage -f $i, $desiredType.FullName, $key, $currentArrayValues[$i], $desiredArrayValues[$i]) - continue - } - } - - } - } - elseif ($desiredType -eq [System.Collections.Hashtable] -and $currentType -eq [System.Collections.Hashtable]) - { - $param = $PSBoundParameters - $param.CurrentValues = $currentValue - $param.DesiredValues = $desiredValue - - 'IncludeInDesiredState','IncludeValue' | ForEach-Object { - if ($param.ContainsKey($_)) - { - $null = $param.Remove($_) - } - } - - if ($InDesiredStateTable.InDesiredState) - { - $InDesiredStateTable.InDesiredState = Test-DscParameterState @param - } - else - { - Test-DscParameterState @param | Out-Null - } - continue - } - else - { - #Convert a scriptblock into a string as scriptblocks are not comparable - $wasCurrentValue = $false - if ($currentValue -is [scriptblock]) - { - $currentValue = if ($desiredValue -is [string]) - { - $currentValue = $currentValue.Invoke() - } - else - { - $currentValue.ToString() - } - $wasCurrentValue = $true - } - if ($desiredValue -is [scriptblock]) - { - $desiredValue = if ($currentValue -is [string] -and -not $wasCurrentValue) - { - $desiredValue.Invoke() - } - else - { - $desiredValue.ToString() - } - } - - if ($desiredValue -ne $currentValue) - { - Write-Verbose -Message ($script:localizedData.NoMatchValueMessage -f $desiredType.FullName, $key, $currentValue, $desiredValue) - $InDesiredStateTable.InDesiredState = $false - } - } - #endregion check type - } - #endregion end of enumeration - if ($ReverseCheck) - { - Write-Verbose -Message $script:localizedData.StartingReverseCheck - $reverseCheckParameters = $PSBoundParameters - $reverseCheckParameters.CurrentValues = $DesiredValues - $reverseCheckParameters.DesiredValues = $CurrentValues - $null = $reverseCheckParameters.Remove('ReverseCheck') - - if ($returnValue) - { - $returnValue = Compare-DscParameterState @reverseCheckParameters - } - else - { - $null = Compare-DscParameterState @reverseCheckParameters - } - } - - # Remove in desired state value if IncludeDesirateState parameter is not use - if (-not $IncludeInDesiredState) - { - [array]$returnValue = $returnValue.where({$_.InDesiredState -eq $false}) - } - - #change verbose message - if ($IncludeInDesiredState.IsPresent) - { - $returnValue.ForEach({ - if ($_.InDesiredState) - { - $localizedString = $script:localizedData.PropertyInDesiredStateMessage - } - else - { - $localizedString = $script:localizedData.PropertyNotInDesiredStateMessage - } - - Write-Verbose -Message ($localizedString -f $_.Property) - }) - } - <# - If Compare-DscParameterState is used in precedent step, don't need to convert it - We use .foreach() method as we are sure that $returnValue is an array. - #> - [Array]$returnValue = @( - $returnValue.foreach( - { - if ($_ -is [System.Collections.Hashtable]) - { - [pscustomobject]$_ - } - else - { - $_ - } - } - ) - ) - - return $returnValue -} -#EndRegion './Public/Compare-DscParameterState.ps1' 616 -#Region './Public/Compare-ResourcePropertyState.ps1' 0 -<# - .SYNOPSIS - Compare current and desired property values for any DSC resource. - - .DESCRIPTION - This function is used to compare current and desired property values for any - DSC resource, and return a hashtable with the metadata from the comparison. - - .PARAMETER CurrentValues - The current values that should be compared to to desired values. Normally - the values returned from Get-TargetResource. - - .PARAMETER DesiredValues - The values set in the configuration and is provided in the call to the - functions *-TargetResource, and that will be compared against current - values. Normally set to $PSBoundParameters. - - .PARAMETER Properties - An array of property names, from the keys provided in DesiredValues, that - will be compared. If this parameter is left out, all the keys in the - DesiredValues will be compared. - - .PARAMETER IgnoreProperties - An array of property names, from the keys provided in DesiredValues, that - will be ignored in the comparison. If this parameter is left out, all the - keys in the DesiredValues will be compared. - - .PARAMETER CimInstanceKeyProperties - A hashtable containing a key for each property that contain a collection - of CimInstances and the value is an array of strings of the CimInstance - key properties. - @{ - Permission = @('State') - } - - .EXAMPLE - $compareTargetResourceStateParameters = @{ - CurrentValues = (Get-TargetResource $PSBoundParameters) - DesiredValues = $PSBoundParameters - } - - $propertyState = Compare-ResourcePropertyState @compareTargetResourceStateParameters - - This examples call Compare-ResourcePropertyState with the current state - and the desired state and returns a hashtable array of all the properties - that was evaluated based on the properties pass in the parameter DesiredValues. -#> -function Compare-ResourcePropertyState -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable[]])] - param - ( - [Parameter(Mandatory = $true)] - [System.Collections.Hashtable] - $CurrentValues, - - [Parameter(Mandatory = $true)] - [System.Collections.Hashtable] - $DesiredValues, - - [Parameter()] - [ValidateNotNullOrEmpty()] - [System.String[]] - $Properties, - - [Parameter()] - [ValidateNotNullOrEmpty()] - [System.String[]] - $IgnoreProperties, - - [Parameter()] - [ValidateNotNull()] - [System.Collections.Hashtable] - $CimInstanceKeyProperties = @{} - ) - - if ($PSBoundParameters.ContainsKey('Properties')) - { - # Filter out the parameters (keys) not specified in Properties - $desiredValuesToRemove = $DesiredValues.Keys | - Where-Object -FilterScript { - $_ -notin $Properties - } - - $desiredValuesToRemove | - ForEach-Object -Process { - $DesiredValues.Remove($_) - } - } - else - { - <# - Remove any common parameters that might be part of DesiredValues, - if it $PSBoundParameters was used to pass the desired values. - #> - $commonParametersToRemove = $DesiredValues.Keys | - Where-Object -FilterScript { - $_ -in [System.Management.Automation.PSCmdlet]::CommonParameters ` - -or $_ -in [System.Management.Automation.PSCmdlet]::OptionalCommonParameters - } - - $commonParametersToRemove | - ForEach-Object -Process { - $DesiredValues.Remove($_) - } - } - - # Remove any properties that should be ignored. - if ($PSBoundParameters.ContainsKey('IgnoreProperties')) - { - $IgnoreProperties | - ForEach-Object -Process { - if ($DesiredValues.ContainsKey($_)) - { - $DesiredValues.Remove($_) - } - } - } - - $compareTargetResourceStateReturnValue = @() - - foreach ($parameterName in $DesiredValues.Keys) - { - Write-Debug -Message ($script:localizedData.EvaluatePropertyState -f $parameterName) - - $parameterState = @{ - ParameterName = $parameterName - Expected = $DesiredValues.$parameterName - Actual = $CurrentValues.$parameterName - } - - # Check if the parameter is in compliance. - $isPropertyInDesiredState = Test-DscPropertyState -Values @{ - CurrentValue = $CurrentValues.$parameterName - DesiredValue = $DesiredValues.$parameterName - KeyProperties = $CimInstanceKeyProperties.$parameterName - } - - if ($isPropertyInDesiredState) - { - Write-Verbose -Message ($script:localizedData.PropertyInDesiredState -f $parameterName) - - $parameterState['InDesiredState'] = $true - } - else - { - Write-Verbose -Message ($script:localizedData.PropertyNotInDesiredState -f $parameterName) - - $parameterState['InDesiredState'] = $false - } - - $compareTargetResourceStateReturnValue += $parameterState - } - - return $compareTargetResourceStateReturnValue -} -#EndRegion './Public/Compare-ResourcePropertyState.ps1' 158 -#Region './Public/ConvertFrom-DscResourceInstance.ps1' 0 - -<# - .SYNOPSIS - Convert any object to hashtable. - - .DESCRIPTION - This function is used to convert a psobject into a hashtable. - - .PARAMETER InputObject - The object that should be convert to hashtable. - - .PARAMETER OutPutFormat - Set the format you do want to convert the object. The default value is HashTable. - It's the only value accepted at this time. - - .OUTPUTS - Hashtable - - .EXAMPLE - - $Object = [pscustomobject]=@{ - FirstName = 'John' - LastName = 'Smith' - } - - ConvertFrom-DscResourceInstance -InputObject $Object - - This creates a pscustomobject and converts its properties/values to Hashtable Key/Value. - - .EXAMPLE - - $ObjectArray = [pscustomobject]=@{ - FirstName = 'John' - LastName = 'Smith' - },[pscustomobject]=@{ - FirstName = 'Peter' - LastName = 'Smith' - } - - $ObjectArray | ConvertFrom-DscResourceInstance - - This creates pscustomobjects and converts there properties/values to Hashtable Keys/Values through the pipeline. -#> -function ConvertFrom-DscResourceInstance -{ - [CmdletBinding()] - [OutputType([Hashtable])] - param - ( - [Parameter(Mandatory = $true, ValueFromPipeline = $true)] - [PSObject] - $InputObject, - - [Parameter()] - [ValidateSet('HashTable')] - [String] - $OutPutFormat = 'HashTable' - - ) - process { - - switch ($OutPutFormat) - { - 'HashTable' - { - $Result = @{} - foreach ($obj in $InputObject) - { - $obj.psobject.Properties | Foreach-Object { - $Result[$_.Name] = $_.Value - } - } - } - } - - return $Result - } -} -#EndRegion './Public/ConvertFrom-DscResourceInstance.ps1' 79 -#Region './Public/ConvertTo-CimInstance.ps1' 0 -<# - .SYNOPSIS - Converts a hashtable into a CimInstance array. - - .DESCRIPTION - This function is used to convert a hashtable into MSFT_KeyValuePair objects. - These are stored as an CimInstance array. DSC cannot handle hashtables but - CimInstances arrays storing MSFT_KeyValuePair. - - .PARAMETER Hashtable - A hashtable with the values to convert. - - .OUTPUTS - An object array with CimInstance objects. - - .EXAMPLE - ConvertTo-CimInstance -Hashtable @{ - String = 'a string' - Bool = $true - Int = 99 - Array = 'a, b, c' - } - - This example returns an CimInstance with the provided hashtable values. -#> -function ConvertTo-CimInstance -{ - [CmdletBinding()] - [OutputType([System.Object[]])] - param - ( - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'Hashtable')] - [System.Collections.Hashtable] - $Hashtable - ) - - process - { - foreach ($item in $Hashtable.GetEnumerator()) - { - New-CimInstance -ClassName 'MSFT_KeyValuePair' -Namespace 'root/microsoft/Windows/DesiredStateConfiguration' -Property @{ - Key = $item.Key - Value = if ($item.Value -is [array]) - { - $item.Value -join ',' - } - else - { - $item.Value - } - } -ClientOnly - } - } -} -#EndRegion './Public/ConvertTo-CimInstance.ps1' 55 -#Region './Public/ConvertTo-HashTable.ps1' 0 -<# - .SYNOPSIS - Converts CimInstances into a hashtable. - - .DESCRIPTION - This function is used to convert a CimInstance array containing - MSFT_KeyValuePair objects into a hashtable. - - .PARAMETER CimInstance - An array of CimInstances or a single CimInstance object to convert. - - .OUTPUTS - Hashtable - - .EXAMPLE - $newInstanceParameters = @{ - ClassName = 'MSFT_KeyValuePair' - Namespace = 'root/microsoft/Windows/DesiredStateConfiguration' - ClientOnly = $true - } - - $cimInstance = [Microsoft.Management.Infrastructure.CimInstance[]] ( - (New-CimInstance @newInstanceParameters -Property @{ - Key = 'FirstName' - Value = 'John' - }), - - (New-CimInstance @newInstanceParameters -Property @{ - Key = 'LastName' - Value = 'Smith' - }) - ) - - ConvertTo-HashTable -CimInstance $cimInstance - - This creates a array om CimInstances of the class name MSFT_KeyValuePair - and passes it to ConvertTo-HashTable which returns a hashtable. -#> -function ConvertTo-HashTable -{ - [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] - param - ( - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'CimInstance')] - [AllowEmptyCollection()] - [Microsoft.Management.Infrastructure.CimInstance[]] - $CimInstance - ) - - begin - { - $result = @{ } - } - - process - { - foreach ($ci in $CimInstance) - { - $result.Add($ci.Key, $ci.Value) - } - } - - end - { - $result - } -} -#EndRegion './Public/ConvertTo-HashTable.ps1' 69 -#Region './Public/Get-ComputerName.ps1' 0 -<# - .SYNOPSIS - Returns the computer name cross-plattform. - - .DESCRIPTION - The variable `$env:COMPUTERNAME` does not exist cross-platform which - hinders development and testing on macOS and Linux. Instead this cmdlet - can be used to get the computer name cross-plattform. - - .EXAMPLE - Get-ComputerName - - This example returns the computer name cross-plattform. -#> -function Get-ComputerName -{ - [CmdletBinding()] - [OutputType([System.String])] - param () - - $computerName = $null - - if ($IsLinux -or $IsMacOs) - { - $computerName = hostname - } - else - { - <# - We could run 'hostname' on Windows too, but $env:COMPUTERNAME - is more widely used. - #> - $computerName = $env:COMPUTERNAME - } - - return $computerName -} -#EndRegion './Public/Get-ComputerName.ps1' 38 -#Region './Public/Get-LocalizedData.ps1' 0 -<# - .SYNOPSIS - Gets language-specific data into scripts and functions based on the UI culture - that is selected for the operating system. - Similar to Import-LocalizedData, with extra parameter 'DefaultUICulture'. - - .DESCRIPTION - The Get-LocalizedData cmdlet dynamically retrieves strings from a subdirectory - whose name matches the UI language set for the current user of the operating system. - It is designed to enable scripts to display user messages in the UI language selected - by the current user. - - Get-LocalizedData imports data from .psd1 files in language-specific subdirectories - of the script directory and saves them in a local variable that is specified in the - command. The cmdlet selects the subdirectory and file based on the value of the - $PSUICulture automatic variable. When you use the local variable in the script to - display a user message, the message appears in the user's UI language. - - You can use the parameters of G-LocalizedData to specify an alternate UI culture, - path, and file name, to add supported commands, and to suppress the error message that - appears if the .psd1 files are not found. - - The G-LocalizedData cmdlet supports the script internationalization - initiative that was introduced in Windows PowerShell 2.0. This initiative - aims to better serve users worldwide by making it easy for scripts to display - user messages in the UI language of the current user. For more information - about this and about the format of the .psd1 files, see about_Script_Internationalization. - - .PARAMETER BindingVariable - Specifies the variable into which the text strings are imported. Enter a variable - name without a dollar sign ($). - - In Windows PowerShell 2.0, this parameter is required. In Windows PowerShell 3.0, - this parameter is optional. If you omit this parameter, Import-LocalizedData - returns a hash table of the text strings. The hash table is passed down the pipeline - or displayed at the command line. - - When using Import-LocalizedData to replace default text strings specified in the - DATA section of a script, assign the DATA section to a variable and enter the name - of the DATA section variable in the value of the BindingVariable parameter. Then, - when Import-LocalizedData saves the imported content in the BindingVariable, the - imported data will replace the default text strings. If you are not specifying - default text strings, you can select any variable name. - - .PARAMETER UICulture - Specifies an alternate UI culture. The default is the value of the $PsUICulture - automatic variable. Enter a UI culture in - format, such as - en-US, de-DE, or ar-SA. - - The value of the UICulture parameter determines the language-specific subdirectory - (within the base directory) from which Import-LocalizedData gets the .psd1 file - for the script. - - The cmdlet searches for a subdirectory with the same name as the value of the - UICulture parameter or the $PsUICulture automatic variable, such as de-DE or - ar-SA. If it cannot find the directory, or the directory does not contain a .psd1 - file for the script, it searches for a subdirectory with the name of the language - code, such as de or ar. If it cannot find the subdirectory or .psd1 file, the - command fails and the data is displayed in the default language specified in the - script. - - .PARAMETER BaseDirectory - Specifies the base directory where the .psd1 files are located. The default is - the directory where the script is located. Import-LocalizedData searches for - the .psd1 file for the script in a language-specific subdirectory of the base - directory. - - .PARAMETER FileName - Specifies the name of the data file (.psd1) to be imported. Enter a file name. - You can specify a file name that does not include its .psd1 file name extension, - or you can specify the file name including the .psd1 file name extension. - - The FileName parameter is required when Import-LocalizedData is not used in a - script. Otherwise, the parameter is optional and the default value is the base - name of the script. You can use this parameter to direct Import-LocalizedData - to search for a different .psd1 file. - - For example, if the FileName is omitted and the script name is FindFiles.ps1, - Import-LocalizedData searches for the FindFiles.psd1 data file. - - .PARAMETER SupportedCommand - Specifies cmdlets and functions that generate only data. - - Use this parameter to include cmdlets and functions that you have written or - tested. For more information, see about_Script_Internationalization. - - .PARAMETER DefaultUICulture - Specifies which UICulture to default to if current UI culture or its parents - culture don't have matching data file. - - For example, if you have a data file in 'en-US' but not in 'en' or 'en-GB' and - your current culture is 'en-GB', you can default back to 'en-US'. - - .NOTES - Before using Import-LocalizedData, localize your user messages. Format the messages - for each locale (UI culture) in a hash table of key/value pairs, and save the - hash table in a file with the same name as the script and a .psd1 file name extension. - Create a directory under the script directory for each supported UI culture, and - then save the .psd1 file for each UI culture in the directory with the UI - culture name. - - For example, localize your user messages for the de-DE locale and format them in - a hash table. Save the hash table in a .psd1 file. Then create a de-DE - subdirectory under the script directory, and save the de-DE .psd1 - file in the de-DE subdirectory. Repeat this method for each locale that you support. - - Import-LocalizedData performs a structured search for the localized user - messages for a script. - - Import-LocalizedData begins the search in the directory where the script file - is located (or the value of the BaseDirectory parameter). It then searches within - the base directory for a subdirectory with the same name as the value of the - $PsUICulture variable (or the value of the UICulture parameter), such as de-DE or - ar-SA. Then, it searches in that subdirectory for a .psd1 file with the same name - as the script (or the value of the FileName parameter). - - If Import-LocalizedData cannot find a subdirectory with the name of the UI culture, - or the subdirectory does not contain a .psd1 file for the script, it searches for - a .psd1 file for the script in a subdirectory with the name of the language code, - such as de or ar. If it cannot find the subdirectory or .psd1 file, the command - fails, the data is displayed in the default language in the script, and an error - message is displayed explaining that the data could not be imported. To suppress - the message and fail gracefully, use the ErrorAction common parameter with a value - of SilentlyContinue. - - If Import-LocalizedData finds the subdirectory and the .psd1 file, it imports the - hash table of user messages into the value of the BindingVariable parameter in the - command. Then, when you display a message from the hash table in the variable, the - localized message is displayed. - - For more information, see about_Script_Internationalization. - - .EXAMPLE - $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' - - This is an example that can be used in DSC resources to import the - localized strings and if the current UI culture localized folder does - not exist the UI culture 'en-US' is returned. -#> -function Get-LocalizedData -{ - [CmdletBinding(DefaultParameterSetName = 'DefaultUICulture')] - param - ( - [Parameter(Position = 0)] - [Alias('Variable')] - [ValidateNotNullOrEmpty()] - [System.String] - $BindingVariable, - - [Parameter(Position = 1, ParameterSetName = 'TargetedUICulture')] - [System.String] - $UICulture, - - [Parameter()] - [System.String] - $BaseDirectory, - - [Parameter()] - [System.String] - $FileName, - - [Parameter()] - [System.String[]] - $SupportedCommand, - - [Parameter(Position = 1, ParameterSetName = 'DefaultUICulture')] - [System.String] - $DefaultUICulture = 'en-US' - ) - - begin - { - <# - Because Proxy Command changes the Invocation origin, we need to be explicit - when handing the pipeline back to original command. - #> - if (!$PSBoundParameters.ContainsKey('FileName')) - { - if ($myInvocation.ScriptName) - { - $file = [System.IO.FileInfo] $myInvocation.ScriptName - } - else - { - $file = [System.IO.FileInfo] $myInvocation.MyCommand.Module.Path - } - - $FileName = $file.BaseName - - $PSBoundParameters.Add('FileName', $file.Name) - } - - if ($PSBoundParameters.ContainsKey('BaseDirectory')) - { - $callingScriptRoot = $BaseDirectory - } - else - { - $callingScriptRoot = $MyInvocation.PSScriptRoot - - $PSBoundParameters.Add('BaseDirectory', $callingScriptRoot) - } - - if ($PSBoundParameters.ContainsKey('DefaultUICulture') -and !$PSBoundParameters.ContainsKey('UICulture')) - { - <# - We don't want the resolution to eventually return the ModuleManifest - so we run the same GetFilePath() logic than here: - https://github.com/PowerShell/PowerShell/blob/master/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Import-LocalizedData.cs#L302-L333 - and if we see it will return the wrong thing, set the UICulture to DefaultUI culture, and return the logic to Import-LocalizedData - #> - $currentCulture = Get-UICulture - - $evaluateDefaultCulture = $true - - <# - If the LCID is 127 then use default UI culture instead. - - See more information in issue https://github.com/dsccommunity/DscResource.Common/issues/11. - #> - if ($currentCulture.LCID -eq 127) - { - $currentCulture = New-Object -TypeName 'System.Globalization.CultureInfo' -ArgumentList @($DefaultUICulture) - $PSBoundParameters['UICulture'] = $DefaultUICulture - - $evaluateDefaultCulture = $false - } - - $languageFile = $null - - $localizedFileNames = @( - $FileName + '.psd1' - $FileName + '.strings.psd1' - ) - - while ($null -ne $currentCulture -and $currentCulture.Name -and -not $languageFile) - { - foreach ($fullFileName in $localizedFileNames) - { - $filePath = [System.IO.Path]::Combine($callingScriptRoot, $CurrentCulture.Name, $fullFileName) - - if (Test-Path -Path $filePath) - { - Write-Debug -Message "Found $filePath" - - $languageFile = $filePath - - # Set the filename to the file we found. - $PSBoundParameters['FileName'] = $fullFileName - - # Exit loop if we find the first filename. - break - } - else - { - Write-Debug -Message "File $filePath not found" - } - } - - if (-not $languageFile) - { - <# - Evaluate the parent culture if there is one. - - If the parent culture is LCID 127 then move to the default culture. - See more information in issue https://github.com/dsccommunity/DscResource.Common/issues/11. - #> - if ($currentCulture.Parent -and $currentCulture.Parent.LCID -ne 127) - { - $currentCulture = $currentCulture.Parent - } - else - { - if ($evaluateDefaultCulture) - { - $evaluateDefaultCulture = $false - - <# - Could not find localized strings file for the the operating - system UI culture. Evaluating the default UI culture (which - defaults to 'en-US' if not specifically set). - #> - $currentCulture = New-Object -TypeName 'System.Globalization.CultureInfo' -ArgumentList @($DefaultUICulture) - $PSBoundParameters['UICulture'] = $DefaultUICulture - } - else - { - <# - Already evaluated everything we could, exit and let - Import-LocalizedData throw an exception. - #> - break - } - } - } - } - - <# - Removes the parameter DefaultUICulture so that isn't used when - calling Import-LocalizedData. - #> - $null = $PSBoundParameters.Remove('DefaultUICulture') - } - - try - { - $outBuffer = $null - - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref] $outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 - } - - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\Import-LocalizedData', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = { & $wrappedCmd @PSBoundParameters } - - $steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin) - $steppablePipeline.Begin($PSCmdlet) - } - catch - { - throw - } - } - - process - { - try - { - $steppablePipeline.Process($_) - } - catch - { - throw - } - } - - end - { - if ($BindingVariable -and ($valueToBind = Get-Variable -Name $BindingVariable -ValueOnly -ErrorAction 'Ignore')) - { - # Bringing the variable to the parent scope - Set-Variable -Scope 1 -Name $BindingVariable -Force -ErrorAction 'SilentlyContinue' -Value $valueToBind - } - - try - { - $steppablePipeline.End() - } - catch - { - throw - } - } -} -#EndRegion './Public/Get-LocalizedData.ps1' 357 -#Region './Public/Get-TemporaryFolder.ps1' 0 -<# - .SYNOPSIS - Returns the path of the current user's temporary folder. - - .DESCRIPTION - Returns the path of the current user's temporary folder. - - .NOTES - This is the same as doing the following - - Windows: $env:TEMP - - macOS: $env:TMPDIR - - Linux: /tmp/ - - .EXAMPLE - Get-TemporaryFolder - - Returns the current user temporary folder on the current operating system. -#> -function Get-TemporaryFolder -{ - [CmdletBinding()] - [OutputType([System.String])] - param () - - return [IO.Path]::GetTempPath() -} -#EndRegion './Public/Get-TemporaryFolder.ps1' 27 -#Region './Public/New-InvalidArgumentException.ps1' 0 -<# - .SYNOPSIS - Creates and throws an invalid argument exception. - - .DESCRIPTION - Creates and throws an invalid argument exception. - - .PARAMETER Message - The message explaining why this error is being thrown. - - .PARAMETER ArgumentName - The name of the invalid argument that is causing this error to be thrown. - - .EXAMPLE - $errorMessage = $script:localizedData.ActionCannotBeUsedInThisContextMessage ` - -f $Action, $Parameter - - New-InvalidArgumentException -ArgumentName 'Action' -Message $errorMessage -#> -function New-InvalidArgumentException -{ - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $Message, - - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $ArgumentName - ) - - $argumentException = New-Object -TypeName 'ArgumentException' ` - -ArgumentList @($Message, $ArgumentName) - - $newObjectParameters = @{ - TypeName = 'System.Management.Automation.ErrorRecord' - ArgumentList = @($argumentException, $ArgumentName, 'InvalidArgument', $null) - } - - $errorRecord = New-Object @newObjectParameters - - throw $errorRecord -} -#EndRegion './Public/New-InvalidArgumentException.ps1' 49 -#Region './Public/New-InvalidDataException.ps1' 0 -<# - .SYNOPSIS - Creates and throws an invalid data exception. - - .DESCRIPTION - Creates and throws an invalid data exception. - - .PARAMETER ErrorId - The error Id to assign to the exception. - - .PARAMETER ErrorMessage - The error message to assign to the exception. - - .EXAMPLE - if ( -not $resultOfEvaluation ) - { - $errorMessage = $script:localizedData.InvalidData -f $Action - - New-InvalidDataException -ErrorId 'InvalidDataError' -ErrorMessage $errorMessage - } -#> -function New-InvalidDataException -{ - [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $ErrorId, - - [Parameter(Mandatory = $true)] - [System.String] - $ErrorMessage - ) - - $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidData - $exception = New-Object ` - -TypeName System.InvalidOperationException ` - -ArgumentList $ErrorMessage - $errorRecord = New-Object ` - -TypeName System.Management.Automation.ErrorRecord ` - -ArgumentList $exception, $ErrorId, $errorCategory, $null - - throw $errorRecord -} -#EndRegion './Public/New-InvalidDataException.ps1' 47 -#Region './Public/New-InvalidOperationException.ps1' 0 -<# - .SYNOPSIS - Creates and throws an invalid operation exception. - - .DESCRIPTION - Creates and throws an invalid operation exception. - - .PARAMETER Message - The message explaining why this error is being thrown. - - .PARAMETER ErrorRecord - The error record containing the exception that is causing this terminating error. - - .EXAMPLE - try - { - Start-Process @startProcessArguments - } - catch - { - $errorMessage = $script:localizedData.InstallationFailedMessage -f $Path, $processId - New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ - } -#> -function New-InvalidOperationException -{ - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $Message, - - [Parameter()] - [ValidateNotNull()] - [System.Management.Automation.ErrorRecord] - $ErrorRecord - ) - - if ($null -eq $ErrorRecord) - { - $invalidOperationException = New-Object -TypeName 'InvalidOperationException' ` - -ArgumentList @($Message) - } - else - { - $invalidOperationException = New-Object -TypeName 'InvalidOperationException' ` - -ArgumentList @($Message, $ErrorRecord.Exception) - } - - $newObjectParameters = @{ - TypeName = 'System.Management.Automation.ErrorRecord' - ArgumentList = @( - $invalidOperationException.ToString(), - 'MachineStateIncorrect', - 'InvalidOperation', - $null - ) - } - - $errorRecordToThrow = New-Object @newObjectParameters - - throw $errorRecordToThrow -} -#EndRegion './Public/New-InvalidOperationException.ps1' 67 -#Region './Public/New-InvalidResultException.ps1' 0 -<# - .SYNOPSIS - Creates and throws an invalid result exception. - - .DESCRIPTION - Creates and throws an invalid result exception. - - .PARAMETER Message - The message explaining why this error is being thrown. - - .PARAMETER ErrorRecord - The error record containing the exception that is causing this terminating error. - - .EXAMPLE - try - { - $numberOfObjects = Get-ChildItem -Path $path - if ($numberOfObjects -eq 0) - { - throw 'To few files.' - } - } - catch - { - $errorMessage = $script:localizedData.TooFewFilesMessage -f $path - New-InvalidResultException -Message $errorMessage -ErrorRecord $_ - } -#> -function New-InvalidResultException -{ - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $Message, - - [Parameter()] - [ValidateNotNull()] - [System.Management.Automation.ErrorRecord] - $ErrorRecord - ) - - if ($null -eq $ErrorRecord) - { - $exception = New-Object -TypeName 'System.Exception' ` - -ArgumentList @($Message) - } - else - { - $exception = New-Object -TypeName 'System.Exception' ` - -ArgumentList @($Message, $ErrorRecord.Exception) - } - - $newObjectParameters = @{ - TypeName = 'System.Management.Automation.ErrorRecord' - ArgumentList = @( - $exception.ToString(), - 'MachineStateIncorrect', - 'InvalidResult', - $null - ) - } - - $errorRecordToThrow = New-Object @newObjectParameters - - throw $errorRecordToThrow -} -#EndRegion './Public/New-InvalidResultException.ps1' 71 -#Region './Public/New-NotImplementedException.ps1' 0 -<# - .SYNOPSIS - Creates and throws an not implemented exception. - - .DESCRIPTION - Creates and throws an not implemented exception. - - .PARAMETER Message - The message explaining why this error is being thrown. - - .PARAMETER ErrorRecord - The error record containing the exception that is causing this terminating error. - - .EXAMPLE - if ($runFeature) - { - $errorMessage = $script:localizedData.FeatureMissing -f $path - New-NotImplementedException -Message $errorMessage -ErrorRecord $_ - } - - Throws an not implemented exception if the variable $runFeature contains - a value. -#> -function New-NotImplementedException -{ - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $Message, - - [Parameter()] - [ValidateNotNull()] - [System.Management.Automation.ErrorRecord] - $ErrorRecord - ) - - if ($null -eq $ErrorRecord) - { - $invalidOperationException = New-Object -TypeName 'NotImplementedException' ` - -ArgumentList @($Message) - } - else - { - $invalidOperationException = New-Object -TypeName 'NotImplementedException' ` - -ArgumentList @($Message, $ErrorRecord.Exception) - } - - $newObjectParameters = @{ - TypeName = 'System.Management.Automation.ErrorRecord' - ArgumentList = @( - $invalidOperationException.ToString(), - 'MachineStateIncorrect', - 'NotImplemented', - $null - ) - } - - $errorRecordToThrow = New-Object @newObjectParameters - - throw $errorRecordToThrow -} -#EndRegion './Public/New-NotImplementedException.ps1' 66 -#Region './Public/New-ObjectNotFoundException.ps1' 0 - -<# - .SYNOPSIS - Creates and throws an object not found exception. - - .DESCRIPTION - Creates and throws an object not found exception. - - .PARAMETER Message - The message explaining why this error is being thrown. - - .PARAMETER ErrorRecord - The error record containing the exception that is causing this terminating error. - - .EXAMPLE - try - { - Get-ChildItem -Path $path - } - catch - { - $errorMessage = $script:localizedData.PathNotFoundMessage -f $path - New-ObjectNotFoundException -Message $errorMessage -ErrorRecord $_ - } -#> -function New-ObjectNotFoundException -{ - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $Message, - - [Parameter()] - [ValidateNotNull()] - [System.Management.Automation.ErrorRecord] - $ErrorRecord - ) - - if ($null -eq $ErrorRecord) - { - $exception = New-Object -TypeName 'System.Exception' ` - -ArgumentList @($Message) - } - else - { - $exception = New-Object -TypeName 'System.Exception' ` - -ArgumentList @($Message, $ErrorRecord.Exception) - } - - $newObjectParameters = @{ - TypeName = 'System.Management.Automation.ErrorRecord' - ArgumentList = @( - $exception.ToString(), - 'MachineStateIncorrect', - 'ObjectNotFound', - $null - ) - } - - $errorRecordToThrow = New-Object @newObjectParameters - - throw $errorRecordToThrow -} -#EndRegion './Public/New-ObjectNotFoundException.ps1' 68 -#Region './Public/Remove-CommonParameter.ps1' 0 -<# - .SYNOPSIS - Removes common parameters from a hashtable. - - .DESCRIPTION - This function serves the purpose of removing common parameters and option - common parameters from a parameter hashtable. - - .PARAMETER Hashtable - The parameter hashtable that should be pruned. - - .EXAMPLE - Remove-CommonParameter -Hashtable $PSBoundParameters - - Returns a new hashtable without the common and optional common parameters. -#> -function Remove-CommonParameter -{ - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSUseShouldProcessForStateChangingFunctions', - '', - Justification = 'ShouldProcess is not supported in DSC resources.' - )] - [OutputType([System.Collections.Hashtable])] - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.Collections.Hashtable] - $Hashtable - ) - - $inputClone = $Hashtable.Clone() - - $commonParameters = [System.Management.Automation.PSCmdlet]::CommonParameters - $commonParameters += [System.Management.Automation.PSCmdlet]::OptionalCommonParameters - - $Hashtable.Keys | Where-Object -FilterScript { - $_ -in $commonParameters - } | ForEach-Object -Process { - $inputClone.Remove($_) - } - - return $inputClone -} -#EndRegion './Public/Remove-CommonParameter.ps1' 46 -#Region './Public/Set-DscMachineRebootRequired.ps1' 0 -<# - .SYNOPSIS - Set the DSC reboot required status variable. - - .DESCRIPTION - Sets the global DSCMachineStatus variable to a value of 1. - This function is used to set the global variable that indicates - to the LCM that a reboot of the node is required. - - .EXAMPLE - PS C:\> Set-DscMachineRebootRequired - - Sets the $global:DSCMachineStatus variable to 1. - - .NOTES - This function is implemented so that individual resource modules - do not need to use and therefore suppress Global variables - directly. It also enables mocking to increase testability of - consumers. -#> -function Set-DscMachineRebootRequired -{ - [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] - # Suppressing this rule because $global:DSCMachineStatus is used to trigger a reboot. - [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')] - <# - Suppressing this rule because $global:DSCMachineStatus is only set, - never used (by design of Desired State Configuration). - #> - [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '')] - [CmdletBinding()] - param - ( - ) - - $global:DSCMachineStatus = 1 -} -#EndRegion './Public/Set-DscMachineRebootRequired.ps1' 38 -#Region './Public/Set-PSModulePath.ps1' 0 - -<# - .SYNOPSIS - Set environment variable PSModulePath in the current session or machine - wide. - - .DESCRIPTION - This is a wrapper to set environment variable PSModulePath in current - session or machine wide. - - .PARAMETER Path - A string with all the paths separated by semi-colons. - - .PARAMETER Machine - If set the PSModulePath will be changed machine wide. If not set, only - the current session will be changed. - - .EXAMPLE - Set-PSModulePath -Path ';' - - .EXAMPLE - Set-PSModulePath -Path ';' -Machine -#> -function Set-PSModulePath -{ - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSUseShouldProcessForStateChangingFunctions', - '', - Justification = 'ShouldProcess is not supported in DSC resources.' - )] - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $Path, - - [Parameter()] - [System.Management.Automation.SwitchParameter] - $Machine - ) - - if ($Machine.IsPresent) - { - [System.Environment]::SetEnvironmentVariable('PSModulePath', $Path, [System.EnvironmentVariableTarget]::Machine) - } - else - { - $env:PSModulePath = $Path - } -} -#EndRegion './Public/Set-PSModulePath.ps1' 53 -#Region './Public/Test-DscParameterState.ps1' 0 -<# - .SYNOPSIS - This method is used to test current and desired values for any DSC resource. - - .DESCRIPTION - This function tests the parameter status of DSC resource parameters against - the current values present on the system. - - .PARAMETER CurrentValues - A hashtable with the current values on the system, obtained by e.g. - Get-TargetResource. - - .PARAMETER DesiredValues - The hashtable of desired values. For example $PSBoundParameters with the - desired values. - - .PARAMETER Properties - This is a list of properties in the desired values list should be checked. - If this is empty then all values in DesiredValues are checked. - - .PARAMETER ExcludeProperties - This is a list of which properties in the desired values list should be checked. - If this is empty then all values in DesiredValues are checked. - - .PARAMETER TurnOffTypeChecking - Indicates that the type of the parameter should not be checked. - - .PARAMETER ReverseCheck - Indicates that a reverse check should be done. The current and desired state - are swapped for another test. - - .PARAMETER SortArrayValues - If the sorting of array values does not matter, values are sorted internally - before doing the comparison. - - .EXAMPLE - $currentState = Get-TargetResource @PSBoundParameters - - $returnValue = Test-DscParameterState -CurrentValues $currentState -DesiredValues $PSBoundParameters - - The function Get-TargetResource is called first using all bound parameters - to get the values in the current state. The result is then compared to the - desired state by calling `Test-DscParameterState`. - - .EXAMPLE - $getTargetResourceParameters = @{ - ServerName = $ServerName - InstanceName = $InstanceName - Name = $Name - } - - $returnValue = Test-DscParameterState ` - -CurrentValues (Get-TargetResource @getTargetResourceParameters) ` - -DesiredValues $PSBoundParameters ` - -ExcludeProperties @( - 'FailsafeOperator' - 'NotificationMethod' - ) - - This compares the values in the current state against the desires state. - The function Get-TargetResource is called using just the required parameters - to get the values in the current state. The parameter 'ExcludeProperties' - is used to exclude the properties 'FailsafeOperator' and - 'NotificationMethod' from the comparison. - - .EXAMPLE - $getTargetResourceParameters = @{ - ServerName = $ServerName - InstanceName = $InstanceName - Name = $Name - } - - $returnValue = Test-DscParameterState ` - -CurrentValues (Get-TargetResource @getTargetResourceParameters) ` - -DesiredValues $PSBoundParameters ` - -Properties ServerName, Name - - This compares the values in the current state against the desires state. - The function Get-TargetResource is called using just the required parameters - to get the values in the current state. The 'Properties' parameter is used - to to only compare the properties 'ServerName' and 'Name'. -#> -function Test-DscParameterState -{ - [CmdletBinding()] - [OutputType([Bool])] - param - ( - [Parameter(Mandatory = $true)] - [System.Object] - $CurrentValues, - - [Parameter(Mandatory = $true)] - [System.Object] - $DesiredValues, - - [Parameter()] - [System.String[]] - [Alias('ValuesToCheck')] - $Properties, - - [Parameter()] - [System.String[]] - $ExcludeProperties, - - [Parameter()] - [System.Management.Automation.SwitchParameter] - $TurnOffTypeChecking, - - [Parameter()] - [System.Management.Automation.SwitchParameter] - $ReverseCheck, - - [Parameter()] - [System.Management.Automation.SwitchParameter] - $SortArrayValues - ) - - $returnValue = $true - - $resultCompare = Compare-DscParameterState @PSBoundParameters - - if ($resultCompare.InDesiredState -contains $false) - { - $returnValue = $false - } - - return $returnValue -} -#EndRegion './Public/Test-DscParameterState.ps1' 130 -#Region './Public/Test-IsNanoServer.ps1' 0 -<# - .SYNOPSIS - Tests if the current OS is a Nano server. - - .DESCRIPTION - Tests if the current OS is a Nano server. - - .EXAMPLE - Test-IsNanoServer - - Returns $true if the current operating system is Nano Server, if not $false - is returned. -#> -function Test-IsNanoServer -{ - [OutputType([System.Boolean])] - [CmdletBinding()] - param () - - $productDatacenterNanoServer = 143 - $productStandardNanoServer = 144 - - $operatingSystemSKU = (Get-CimInstance -ClassName Win32_OperatingSystem).OperatingSystemSKU - - Write-Verbose -Message ($script:localizedData.TestIsNanoServerOperatingSystemSku -f $operatingSystemSKU) - - return ($operatingSystemSKU -in ($productDatacenterNanoServer, $productStandardNanoServer)) -} -#EndRegion './Public/Test-IsNanoServer.ps1' 29 -#Region './suffix.ps1' 0 -$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' -#EndRegion './suffix.ps1' 2 diff --git a/DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/en-US/DscResource.Common.strings.psd1 b/DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/en-US/DscResource.Common.strings.psd1 deleted file mode 100644 index 14c3a4fd..00000000 --- a/DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/en-US/DscResource.Common.strings.psd1 +++ /dev/null @@ -1,38 +0,0 @@ -# Localized English (en-US) strings. - -ConvertFrom-StringData @' - TestIsNanoServerOperatingSystemSku = OperatingSystemSKU {0} was returned by Win32_OperatingSystem when detecting if operating system is Nano Server. (DRC0008) - ModuleNotFound = Please ensure that the PowerShell module '{0}' is installed. (DRC0009) - ParameterUsageWrong = None of the parameter(s) '{0}' may be used at the same time as any of the parameter(s) '{1}'. (DRC0010) - AddressFormatError = Address '{0}' is not in the correct format. Please correct the Address parameter in the configuration and try again. (DRC0011) - AddressIPv4MismatchError = Address '{0}' is in IPv4 format, which does not match server address family {1}. Please correct either of them in the configuration and try again. (DRC0012) - AddressIPv6MismatchError = Address '{0}' is in IPv6 format, which does not match server address family {1}. Please correct either of them in the configuration and try again. (DRC0013) - InvalidDesiredValuesError = Property 'DesiredValues' in Test-DscParameterState must be either a Hashtable or CimInstance. Type detected was '{0}'. (DRC0014) - InvalidCurrentValuesError = Property 'CurrentValues' in Test-DscParameterState must be either a Hashtable, CimInstance, or CimIntance[]. Type detected was '{0}'. (DRC0015) - InvalidPropertiesError = If 'DesiredValues' is a CimInstance then property 'Properties' must contain a value. (DRC0016) - MatchPsCredentialUsernameMessage = MATCH: PSCredential username match. Current state is '{0}' and desired state is '{1}'. (DRC0017) - NoMatchPsCredentialUsernameMessage = NOTMATCH: PSCredential username mismatch. Current state is '{0}' and desired state is '{1}'. (DRC0018) - NoMatchTypeMismatchMessage = NOTMATCH: Type mismatch for property '{0}' Current state type is '{1}' and desired type is '{2}'. (DRC0019) - MatchValueMessage = MATCH: Value (type '{0}') for property '{1}' does match. Current state is '{2}' and desired state is '{3}'. (DRC0020) - NoMatchValueMessage = NOTMATCH: Value (type '{0}') for property '{1}' does not match. Current state is '{2}' and desired state is '{3}'. (DRC0021) - NoMatchValueDifferentCountMessage = NOTMATCH: Value (type '{0}') for property '{1}' does have a different count. Current state count is '{2}' and desired state count is '{3}'. (DRC0022) - NoMatchElementTypeMismatchMessage = NOTMATCH: Type mismatch for property '{0}' Current state type of element [{1}] is '{2}' and desired type is '{3}'. (DRC0023) - NoMatchElementValueMismatchMessage = NOTMATCH: Value [{0}] (type '{1}') for property '{2}' does match. Current state is '{3}' and desired state is '{4}'. (DRC0024) - MatchElementValueMessage = MATCH: Value [{0}] (type '{1}') for property '{2}' does match. Current state is '{3}' and desired state is '{4}'. (DRC0025) - PropertyInDesiredStateMessage = Property '{0}' is in desired state. (DRC0026) - StartingReverseCheck = Starting with a reverse check. (DRC0027) - TestDscParameterCompareMessage = Comparing values in property '{0}'. (DRC0028) - TooManyCimInstances = More than one CIM instance was returned from the current state. (DRC0029) - TestingCimInstance = Testing CIM instance '{0}' with the key properties '{1}'. (DRC0030) - MissingCimInstance = The CIM instance '{0}' with the key properties '{1}' is missing. (DRC0031) - ArrayValueIsAbsent = The array value '{0}' is absent. (DRC0032) - ArrayValueIsPresent = The array value '{0}' is present. (DRC0033) - KeyPropertiesMissing = The hashtable passed to function Test-DscPropertyState is missing the key 'KeyProperties'. This must be set to the property names that makes each instance in the CIM instance collection unique. (DRC0034) - ArrayDoesNotMatch = One or more values in an array does not match the desired state. Details of the changes are below. (DRC0035) - PropertyValueOfTypeDoesNotMatch = {0} value does not match. Current value is '{1}', but expected the value '{2}'. (DRC0036) - UnableToCompareType = Unable to compare the type {0} as it is not handled by the Test-DscPropertyState cmdlet. (DRC0037) - EvaluatePropertyState = Evaluating the state of the property '{0}'. (DRC0038) - PropertyInDesiredState = The parameter '{0}' is in desired state. (DRC0039) - PropertyNotInDesiredState = The parameter '{0}' is not in desired state. (DRC0040) - PropertyNotInDesiredStateMessage = Property '{0}' is not in desired state. (DRC0041) -'@ diff --git a/DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/en-US/about_DscResource.Common.help.txt b/DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/en-US/about_DscResource.Common.help.txt deleted file mode 100644 index 2a996770..00000000 --- a/DSCResources/xHyper-V/Modules/DscResource.Common/0.10.3/en-US/about_DscResource.Common.help.txt +++ /dev/null @@ -1,26 +0,0 @@ -TOPIC - about_DscResource.Common - -SHORT DESCRIPTION - Common functions used in DSC tesources. - -LONG DESCRIPTION - This module contains common functions that are used in DSC resources. - -EXAMPLES - PS C:\> Get-Command -Module DscResource.Common - -NOTE: - Thank you to the DSC Community contributors who contributed to this module by - writing code, sharing opinions, and provided feedback. - -TROUBLESHOOTING NOTE: - Go to the Github repository for read about issues, submit a new issue, and read - about new releases. https://github.com/dsccommunity/DscResource.Common - -SEE ALSO - - https://github.com/dsccommunity/DscResource.Common - -KEYWORDS - DSC, Localization - diff --git a/DSCResources/xHyper-V/Modules/HyperVDsc.Common/HyperVDsc.Common.psd1 b/DSCResources/xHyper-V/Modules/HyperVDsc.Common/HyperVDsc.Common.psd1 deleted file mode 100644 index 83cc2a7a..00000000 --- a/DSCResources/xHyper-V/Modules/HyperVDsc.Common/HyperVDsc.Common.psd1 +++ /dev/null @@ -1,57 +0,0 @@ -# -# Module manifest for module 'HyperVDsc.Common' -# -# Generated by: DSC Community -# -# Generated on: 3/8/2020 -# - -@{ - - # Script module or binary module file associated with this manifest. - RootModule = 'HyperVDsc.Common.psm1' - - # Version number of this module. - ModuleVersion = '1.0.0' - - # ID used to uniquely identify this module - GUID = '0fc40913-c3b0-4930-9b20-3e479f424b5a' - - # Author of this module - Author = 'DSC Community' - - # Company or vendor of this module - CompanyName = 'DSC Community' - - # Copyright statement for this module - Copyright = 'Copyright the DSC Community contributors. All rights reserved.' - - # Description of the functionality provided by this module - Description = 'Functions used by the DSC resources in xHyper-V.' - - # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. - FunctionsToExport = @( - 'Set-VMProperty' - 'Set-VMState' - 'Wait-VMIPAddress' - 'ConvertTo-TimeSpan' - 'ConvertFrom-TimeSpan' - 'Get-VMHyperV' - ) - - # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. - CmdletsToExport = @() - - # Variables to export from this module - VariablesToExport = @() - - # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. - AliasesToExport = @() - - # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. - PrivateData = @{ - PSData = @{ - } # End of PSData hashtable - } # End of PrivateData hashtable -} - diff --git a/DSCResources/xHyper-V/Modules/HyperVDsc.Common/HyperVDsc.Common.psm1 b/DSCResources/xHyper-V/Modules/HyperVDsc.Common/HyperVDsc.Common.psm1 deleted file mode 100644 index 6795cf46..00000000 --- a/DSCResources/xHyper-V/Modules/HyperVDsc.Common/HyperVDsc.Common.psm1 +++ /dev/null @@ -1,341 +0,0 @@ -$script:dscResourceCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../DscResource.Common' - -Import-Module -Name $script:dscResourceCommonModulePath - -$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' - -<# - .SYNOPSIS - Sets one or more virtual machine properties, powering the VM - off if required. - - .PARAMETER Name - Name of the virtual machine to apply the changes to. - - .PARAMETER VMName - Name of the virtual machine to apply the changes to. - - .PARAMETER VMCommand - The Hyper-V cmdlet name to call to enact the changes. - - .PARAMETER ChangeProperty - The collection of cmdlet parameter names and values to pass to the command. - - .PARAMETER WaitForIP - Waits for the virtual machine to report an IP address when transitioning - into a running state. - - .PARAMETER RestartIfNeeded - Power cycle the virtual machine if changes are required. -#> -function Set-VMProperty -{ - [CmdletBinding(DefaultParameterSetName = 'Name')] - param - ( - [Parameter(Mandatory = $true, ParameterSetName = 'Name')] - [System.String] - $Name, - - [Parameter(Mandatory = $true, ParameterSetName = 'VMName')] - [System.String] - $VMName, - - [Parameter(Mandatory = $true)] - [System.String] - $VMCommand, - - [Parameter(Mandatory = $true)] - [System.Collections.Hashtable] - $ChangeProperty, - - [Parameter()] - [System.Boolean] - $WaitForIP, - - [Parameter()] - [System.Boolean] - $RestartIfNeeded - ) - - if ($PSBoundParameters.ContainsKey('VMName')) - { - # Add the -Name property to the ChangeProperty hashtable for splatting - $ChangeProperty['VMName'] = $VMName - - # Set the common parameters for splatting against Get-VM and Set-VMState - $vmCommonProperty = @{ - Name = $VMName - } - - # Ensure that the name parameter is set for verbose messages - $Name = $VMName - } - else - { - # Add the -Name property to the ChangeProperty hashtable for splatting - $ChangeProperty['Name'] = $Name - - # Set the common parameters for splatting against Get-VM and Set-VMState - $vmCommonProperty = @{ - Name = $Name - } - } - - $vmObject = Get-VM @vmCommonProperty - $vmOriginalState = $vmObject.State - - if ($vmOriginalState -ne 'Off' -and $RestartIfNeeded) - { - # Turn the vm off to make changes - Set-VMState @vmCommonProperty -State Off - - Write-Verbose -Message ($script:localizedData.UpdatingVMProperties -f $Name) - # Make changes using the passed hashtable - & $VMCommand @ChangeProperty - - # Cannot move an off VM to a paused state - only to running state - if ($vmOriginalState -eq 'Running') - { - Set-VMState @vmCommonProperty -State Running -WaitForIP $WaitForIP - } - - Write-Verbose -Message ($script:localizedData.VMPropertiesUpdated -f $Name) - - # Cannot restore a vm to a paused state - if ($vmOriginalState -eq 'Paused') - { - Write-Warning -Message ($script:localizedData.VMStateWillBeOffWarning -f $Name) - } - } - elseif ($vmOriginalState -eq 'Off') - { - Write-Verbose -Message ($script:localizedData.UpdatingVMProperties -f $Name) - & $VMCommand @ChangeProperty - Write-Verbose -Message ($script:localizedData.VMPropertiesUpdated -f $Name) - } - else - { - $errorMessage = $script:localizedData.CannotUpdatePropertiesOnlineError -f $Name, $vmOriginalState - New-InvalidOperationException -Message $errorMessage - } -} #end function - -<# - .SYNOPSIS - Sets one or more virtual machine properties, powering the VM - off if required. - - .PARAMETER Name - Name of the virtual machine to apply the changes to. - - .PARAMETER State - The target power state of the virtual machine. - - .PARAMETER ChangeProperty - The collection of cmdlet parameter names and values to pass to the command. - - .PARAMETER WaitForIP - Waits for the virtual machine to be report an IP address when transitioning - into a running state. -#> -function Set-VMState -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [Alias('VMName')] - [System.String] - $Name, - - [Parameter(Mandatory = $true)] - [ValidateSet('Running','Paused','Off')] - [System.String] - $State, - - [Parameter()] - [System.Boolean] - $WaitForIP - ) - - switch ($State) - { - 'Running' { - $vmCurrentState = (Get-VM -Name $Name).State - if ($vmCurrentState -eq 'Paused') - { - # If VM is in paused state, use resume-vm to make it running - Write-Verbose -Message ($script:localizedData.ResumingVM -f $Name) - Resume-VM -Name $Name - } - elseif ($vmCurrentState -eq 'Off') - { - # If VM is Off, use start-vm to make it running - Write-Verbose -Message ($script:localizedData.StartingVM -f $Name) - Start-VM -Name $Name - } - - if ($WaitForIP) - { - Wait-VMIPAddress -Name $Name -Verbose - } - } - 'Paused' { - if ($vmCurrentState -ne 'Off') - { - Write-Verbose -Message ($script:localizedData.SuspendingVM -f $Name) - Suspend-VM -Name $Name - } - } - 'Off' { - if ($vmCurrentState -ne 'Off') - { - Write-Verbose -Message ($script:localizedData.StoppingVM -f $Name) - Stop-VM -Name $Name -Force -WarningAction SilentlyContinue - } - } - } -} #end function - -<# - .SYNOPSIS - Waits for a virtual machine to be assigned an IP address. - - .PARAMETER Name - Name of the virtual machine to apply the changes to. - - .PARAMETER Timeout - Number of seconds to wait before timing out. Defaults to 300 (5 minutes). -#> -function Wait-VMIPAddress -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [Alias('VMName')] - [System.String] - $Name, - - [Parameter()] - [System.Int32] - $Timeout = 300 - ) - - [System.Int32] $elapsedSeconds = 0 - while ((Get-VMNetworkAdapter -VMName $Name).IpAddresses.Count -lt 2) - { - Write-Verbose -Message ($script:localizedData.WaitingForVMIPAddress -f $Name) - Start-Sleep -Seconds 3 - - $elapsedSeconds += 3 - if ($elapsedSeconds -gt $Timeout) - { - $errorMessage = $script:localizedData.WaitForVMIPAddressTimeoutError -f $Name, $Timeout - - New-ObjectNotFoundException -Message $errorMessage - } - } -} #end function - -<# - .SYNOPSIS - Converts a number of seconds, minutes, hours or days into a System.TimeSpan object. - - .PARAMETER TimeInterval - The total number of seconds, minutes, hours or days to convert. - - .PARAMETER TimeSpanType - Convert using specified interval type. -#> -function ConvertTo-TimeSpan -{ - [CmdletBinding()] - [OutputType([System.TimeSpan])] - param - ( - [Parameter(Mandatory = $true)] - [System.UInt32] - $TimeInterval, - - [Parameter(Mandatory = $true)] - [ValidateSet('Seconds','Minutes','Hours','Days')] - [System.String] - $TimeIntervalType - ) - - $newTimeSpanParams = @{ } - switch ($TimeIntervalType) - { - 'Seconds' { $newTimeSpanParams['Seconds'] = $TimeInterval } - 'Minutes' { $newTimeSpanParams['Minutes'] = $TimeInterval } - 'Hours' { $newTimeSpanParams['Hours'] = $TimeInterval } - 'Days' { $newTimeSpanParams['Days'] = $TimeInterval } - } - return (New-TimeSpan @newTimeSpanParams) -} #end function ConvertTo-TimeSpan - -<# - .SYNOPSIS - Converts a System.TimeSpan into the number of seconds, minutes, hours or days. - - .PARAMETER TimeSpan - TimeSpan to convert into an integer - - .PARAMETER TimeSpanType - Convert timespan into the total number of seconds, minutes, hours or days. -#> -function ConvertFrom-TimeSpan -{ - [CmdletBinding()] - [OutputType([System.Int32])] - param - ( - [Parameter(Mandatory = $true)] - [System.TimeSpan] - $TimeSpan, - - [Parameter(Mandatory = $true)] - [ValidateSet('Seconds','Minutes','Hours','Days')] - [System.String] - $TimeSpanType - ) - - switch ($TimeSpanType) - { - 'Seconds' { return $TimeSpan.TotalSeconds -as [System.UInt32] } - 'Minutes' { return $TimeSpan.TotalMinutes -as [System.UInt32] } - 'Hours' { return $TimeSpan.TotalHours -as [System.UInt32] } - 'Days' { return $TimeSpan.TotalDays -as [System.UInt32] } - } -} #end function ConvertFrom-TimeSpan - -<# - .SYNOPSIS - Helper function for retrieving a virtual machine, ensuring only one VM is resolved - - .PARAMETER VMName - Name of the Hyper-V virtual machine to return -#> -function Get-VMHyperV -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $VMName - ) - - $vm = Get-VM -Name $VMName -ErrorAction SilentlyContinue - - # Check if 1 or 0 VM with name = $name exist - if ($vm.count -gt 1) - { - $errorMessage = $script:localizedData.MoreThanOneVMExistsError -f $VMName - New-InvalidResultException -Message $errorMessage - } - - return $vm -} #end function Get-VMHyperV diff --git a/DSCResources/xHyper-V/Modules/HyperVDsc.Common/en-US/HyperVDsc.Common.strings.psd1 b/DSCResources/xHyper-V/Modules/HyperVDsc.Common/en-US/HyperVDsc.Common.strings.psd1 deleted file mode 100644 index bcfab654..00000000 --- a/DSCResources/xHyper-V/Modules/HyperVDsc.Common/en-US/HyperVDsc.Common.strings.psd1 +++ /dev/null @@ -1,13 +0,0 @@ -ConvertFrom-StringData @' - UpdatingVMProperties = Updating VM '{0}' properties. - VMPropertiesUpdated = VM '{0}' properties have been updated. - WaitingForVMIPAddress = Waiting for IP Address for VM '{0}' ... - StoppingVM = Stopping VM '{0}'. - SuspendingVM = Suspending VM '{0}'. - StartingVM = Starting VM '{0}'. - ResumingVM = Resuming VM '{0}'. - VMStateWillBeOffWarning = VM '{0}' state will be 'OFF' and not 'Paused'. - CannotUpdatePropertiesOnlineError = Can not change properties for VM '{0}' in '{1}' state unless 'RestartIfNeeded' is set to true. - WaitForVMIPAddressTimeoutError = Waiting for VM '{0}' IP address timed out after {1} seconds. - MoreThanOneVMExistsError = More than one VM with the name '{0}' exists. -'@ diff --git a/DSCResources/xHyper-V/en-US/about_xHyper-V.help.txt b/DSCResources/xHyper-V/en-US/about_xHyper-V.help.txt deleted file mode 100644 index d0cf7811..00000000 --- a/DSCResources/xHyper-V/en-US/about_xHyper-V.help.txt +++ /dev/null @@ -1,25 +0,0 @@ -TOPIC - about_xHyper-V - -SHORT DESCRIPTION - DSC resources for deployment and configuration of Microsoft Hyper-V. - -LONG DESCRIPTION - This module contains DSC resources for deployment and configuration of Microsoft Hyper-V. - -EXAMPLES - PS C:\> Get-DscResource -Module xHyper-V - -NOTE: - Thank you to the DSC Community contributors who contributed to this module by - writing code, sharing opinions, and provided feedback. - -TROUBLESHOOTING NOTE: - Go to the Github repository for read about issues, submit a new issue, and read - about new releases. https://github.com/dsccommunity/xHyper-V - -SEE ALSO - - https://github.com/dsccommunity/xHyper-V - -KEYWORDS - DSC, DscResource, Hyper-V, HyperV diff --git a/DSCResources/xHyper-V/xHyper-V.psd1 b/DSCResources/xHyper-V/xHyper-V.psd1 deleted file mode 100644 index 32740d02..00000000 --- a/DSCResources/xHyper-V/xHyper-V.psd1 +++ /dev/null @@ -1,107 +0,0 @@ -@{ - # Version number of this module. - moduleVersion = '3.18.0' - - # ID used to uniquely identify this module - GUID = 'f5a5f169-7026-4053-932a-19a7c37b1ca5' - - # Author of this module - Author = 'DSC Community' - - # Company or vendor of this module - CompanyName = 'DSC Community' - - # Copyright statement for this module - Copyright = 'Copyright the DSC Community contributors. All rights reserved.' - - # Description of the functionality provided by this module - Description = 'This module contains DSC resources for deployment and configuration of Microsoft Hyper-V.' - - # Minimum version of the Windows PowerShell engine required by this module - PowerShellVersion = '4.0' - - # Minimum version of the common language runtime (CLR) required by this module - CLRVersion = '4.0' - - # Functions to export from this module - FunctionsToExport = @() - - # Cmdlets to export from this module - CmdletsToExport = @() - - # Variables to export from this module - VariablesToExport = @() - - # Aliases to export from this module - AliasesToExport = @() - - DscResourcesToExport = @('xVHD','xVhdFile','xVMDvdDrive','xVMHardDiskDrive','xVMHost','xVMHyperV','xVMNetworkAdapter','xVMProcessor','xVMScsiController','xVMSwitch') - - # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. - PrivateData = @{ - PSData = @{ - # Set to a prerelease string value if the release should be a prerelease. - Prerelease = '' - - # Tags applied to this module. These help with module discovery in online galleries. - Tags = @('DesiredStateConfiguration', 'DSC', 'DSCResourceKit', 'DSCResource') - - # A URL to the license for this module. - LicenseUri = 'https://github.com/dsccommunity/xHyper-V/blob/master/LICENSE' - - # A URL to the main website for this project. - ProjectUri = 'https://github.com/dsccommunity/xHyper-V' - - # A URL to an icon representing this module. - IconUri = 'https://dsccommunity.org/images/DSC_Logo_300p.png' - - # ReleaseNotes of this module - ReleaseNotes = '## [3.18.0] - 2022-06-04 - -### Added - -- xHyper-V - - Added automatic release with a new CI pipeline. - - Added stubs for the powershell module Hyper-V that are used for - all unit tests. -- xVhdFileDirectory - - Added initial set of unit tests - -### Deprecated - -- **The module _xHyper-V_ will be renamed to _HyperVDsc_ - ([issue #62](https://github.com/dsccommunity/xHyper-V/issues/62)). - The version `v3.18.0` will be the the last release of _xHyper-V_. - Version `v4.0.0` will be released as _HyperVDsc_, it will be - released shortly after the `v3.18.0` release to be able to start transition - to the new module. The prefix ''x'' will be removed from all resources in - _HyperVDsc_.** -- xHyper-V - - The resource will not be tested for Windows Server 2008 R2 since - that operating system has reach end-of-life. - -### Removed - -- xVMSwitch - - Removed the unit test that simulated functionality on Windows Server 2008 R2 - since that operating system has reach end-of-life. No functionality was - removed from the resource, but in a future release the resource might stop - working for Windows Server 2008 R2. - -### Changed - -- Update the pipeline files to the lates from Sampler. - -### Fixed - -- xVMDvdDrive - - Fixed VMName property in example. -- xVMNetworkAdapter - - Fixed MacAddress sample data. -- xVMSwitch - - Correctly return the state as `$true` or `$false` depending on the - `Ensure` property when the switch does not exist. -' - } # End of PSData hashtable - } # End of PrivateData hashtable -} diff --git a/DSCResources/xHyper-V/xHyper-V.psm1 b/DSCResources/xHyper-V/xHyper-V.psm1 deleted file mode 100644 index 81d556e2..00000000 --- a/DSCResources/xHyper-V/xHyper-V.psm1 +++ /dev/null @@ -1,4 +0,0 @@ -<# - This file is intentionally left empty. It is must be left here for the module - manifest to refer to. It is recreated during the build process. -#>