From aff660f3a76edb6f60e243e7a8bc450b56340cc0 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Thu, 19 Mar 2020 17:58:47 +0100 Subject: [PATCH] Merge dev to master (#185) --- .MetaTestOptIn.json | 3 - .gitattributes | 6 + .../ISSUE_TEMPLATE/Problem_with_resource.md | 2 +- .github/PULL_REQUEST_TEMPLATE.md | 22 +- .gitignore | 4 +- .markdownlint.json | 10 + .vscode/analyzersettings.psd1 | 15 +- .vscode/settings.json | 29 +- .vscode/tasks.json | 125 + CHANGELOG.md | 215 +- CODE_OF_CONDUCT.md | 3 + CONTRIBUTING.md | 7 + Examples/Sample_xVMHost_Paths.ps1 | 22 - ...NetworkAdapter_VMStaticNetworkSettings.ps1 | 20 - Examples/Sample_xVhdFileExamples.ps1 | 171 - GitVersion.yml | 34 + HISTORIC_CHANGELOG.md | 206 + LICENSE | 4 +- Misc/VHDResourceGenerator.ps1 | 13 - Misc/VMHardDiskDriveGenerator.ps1 | 8 - Misc/VMResourceGenerator.ps1 | 26 - Misc/VMScsiControllerGenerator.ps1 | 5 - Misc/VMSwitchGenerator.ps1 | 8 - README.md | 84 +- RequiredModules.psd1 | 26 + Resolve-Dependency.ps1 | 288 + Resolve-Dependency.psd1 | 5 + Tests/Unit/HyperVCommon.tests.ps1 | 338 - Tests/Unit/MSFT_xVMHyperV.Tests.ps1 | 669 - appveyor.yml | 42 - azure-pipelines.yml | 230 + build.ps1 | 385 + build.yaml | 106 + .codecov.yml => codecov.yml | 10 +- .../DSCResources}/MSFT_xVHD/MSFT_xVHD.psm1 | 72 +- .../MSFT_xVHD/MSFT_xVHD.schema.mof | 0 .../MSFT_xVHD/en-US/MSFT_xVHD.strings.psd1 | 2 + .../MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.psm1 | 198 +- .../MSFT_xVMDvdDrive.schema.mof | 0 .../en-US}/MSFT_xVMDvdDrive.strings.psd1 | 0 .../MSFT_xVMHardDiskDrive.psm1 | 73 +- .../MSFT_xVMHardDiskDrive.schema.mof | 0 .../en-US/MSFT_xVMHardDiskDrive.strings.psd1 | 2 +- .../MSFT_xVMHost/MSFT_xVMHost.psm1 | 51 +- .../MSFT_xVMHost/MSFT_xVMHost.schema.mof | 0 .../en-US/MSFT_xVMHost.strings.psd1 | 2 +- .../MSFT_xVMHyperV/MSFT_xVMHyperV.psm1 | 303 +- .../MSFT_xVMHyperV/MSFT_xVMHyperV.schema.mof | 0 .../en-US/MSFT_xVMHyperV.strings.psd1 | 4 - .../MSFT_xVMNetworkAdapter.psm1 | 334 +- .../MSFT_xVMNetworkAdapter.schema.mof | 0 .../en-US/MSFT_xVMNetworkAdapter.strings.psd1 | 7 - .../MSFT_xVMProcessor/MSFT_xVMProcessor.psm1 | 94 +- .../MSFT_xVMProcessor.schema.mof | 0 .../en-US/MSFT_xVMProcessor.strings.psd1 | 5 +- .../MSFT_xVMScsiController.psm1 | 74 +- .../MSFT_xVMScsiController.schema.mof | 0 .../en-US/MSFT_xVMScsiController.strings.psd1 | 2 +- .../MSFT_xVMSwitch/MSFT_xVMSwitch.psm1 | 358 +- .../MSFT_xVMSwitch/MSFT_xVMSwitch.schema.mof | 0 .../en-US}/MSFT_xVMSwitch.strings.psd1 | 0 .../MSFT_xVhdFileDirectory.psm1 | 375 +- .../MSFT_xVhdFileDirectory.schema.mof | 0 .../en-US/MSFT_xVhdFileDirectory.strings.psd1 | 2 + .../Sample_EndToEndXHyperV_RunningVM.ps1 | 62 + ...VMHardDiskDrive_VMWith4AdditionalDisks.ps1 | 8 +- ...ample_xVMHardDiskDrive_VMWithExtraDisk.ps1 | 2 +- source/Examples/Sample_xVMHost_Paths.ps1 | 20 + .../Examples}/Sample_xVMHyperV_Complete.ps1 | 54 +- .../Sample_xVMHyperV_DynamicMemory.ps1 | 32 +- .../Sample_xVMHyperV_MultipleNICs.ps1 | 28 +- .../Examples}/Sample_xVMHyperV_Simple.ps1 | 17 +- .../Sample_xVMHyperV_SimpleWithDVDDrive.ps1 | 20 +- ...MHyperV_SimpleWithNestedVirtualization.ps1 | 10 +- .../Sample_xVMNetworkAdapter_ManagementOS.ps1 | 4 +- ...xVMNetworkAdapter_MultipleManagementOS.ps1 | 4 +- .../Sample_xVMNetworkAdapter_MultipleVM.ps1 | 4 +- ...xVMNetworkAdapter_MultipleVMMACAddress.ps1 | 8 +- ...NetworkAdapter_VMStaticNetworkSettings.ps1 | 21 + ...Sample_xVMNetworkAdapter_VMVlanTagging.ps1 | 6 +- ...ample_xVMScsiController_AddControllers.ps1 | 7 +- .../Examples}/Sample_xVMSwitch_External.ps1 | 19 +- .../Sample_xVMSwitch_ExternalSET.ps1 | 10 +- .../Sample_xVMSwitch_ExternalSET_LBMode.ps1 | 12 +- .../Examples}/Sample_xVMSwitch_Internal.ps1 | 10 +- .../Sample_xVhd_AdditionalPropertyVHD.ps1 | 14 +- .../Examples/Sample_xVhd_ChangeAttribute.ps1 | 28 + .../Examples/Sample_xVhd_CopyFileOrFolder.ps1 | 26 + .../Examples/Sample_xVhd_DiffVHD.ps1 | 16 +- .../Examples/Sample_xVhd_FixedVHD.ps1 | 14 +- .../Sample_xVhd_MissingPropertyVHD.ps1 | 10 +- .../Examples/Sample_xVhd_NewVHD.ps1 | 14 +- .../Sample_xVhd_RemoveFileOrFolderFromVHD.ps1 | 26 + .../HyperVDsc.Common/HyperVDsc.Common.psd1 | 57 + .../HyperVDsc.Common/HyperVDsc.Common.psm1 | 149 +- .../en-US/HyperVDsc.Common.strings.psd1 | 3 - source/build.psd1 | 6 + source/en-US/about_xHyper-V.help.txt | 25 + source/xHyper-V.psd1 | 89 + .../Integration/IntegrationTestsCommon.psm1 | 28 +- .../MSFT_xVMDvdDrive.Integration.Tests.ps1 | 55 +- .../MSFT_xVMDvdDrive_add.config.ps1 | 2 +- .../MSFT_xVMDvdDrive_remove.config.ps1 | 2 +- .../MSFT_xVMHost.Integration.Tests.ps1 | 54 +- .../Integration/MSFT_xVMHost_set.config.ps1 | 4 +- .../MSFT_xVMProcessor.Integration.Tests.ps1 | 37 +- .../MSFT_xVMProcessor_set.config.ps1 | 2 +- tests/Unit/HyperVDsc.Common.Tests.ps1 | 315 + .../Unit/MSFT_xVHD.Tests.ps1 | 120 +- .../Unit/MSFT_xVMDvdDrive.Tests.ps1 | 335 +- .../Unit/MSFT_xVMHardDiskDrive.Tests.ps1 | 257 +- .../Unit/MSFT_xVMHost.Tests.ps1 | 285 +- tests/Unit/MSFT_xVMHyperV.Tests.ps1 | 964 + .../Unit/MSFT_xVMNetworkAdapter.Tests.ps1 | 272 +- .../Unit/MSFT_xVMProcessor.Tests.ps1 | 225 +- .../Unit/MSFT_xVMScsiController.Tests.ps1 | 264 +- ...MSwitch_BandwidthReservationMode.Tests.ps1 | 276 +- ..._xVMSwitch_EnableEmbeddedTeaming.Tests.ps1 | 396 +- .../Unit/MSFT_xVMSwitch_Id.Tests.ps1 | 185 +- tests/Unit/MSFT_xVhdFileDirectory.Tests.ps1 | 531 + tests/Unit/Stubs/Hyper-V.stubs.psm1 | 20501 ++++++++++++++++ tests/Unit/Stubs/README.md | 124 + xHyper-V.psd1 | 75 - 123 files changed, 26685 insertions(+), 4558 deletions(-) delete mode 100644 .MetaTestOptIn.json create mode 100644 .markdownlint.json create mode 100644 .vscode/tasks.json create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md delete mode 100644 Examples/Sample_xVMHost_Paths.ps1 delete mode 100644 Examples/Sample_xVMNetworkAdapter_VMStaticNetworkSettings.ps1 delete mode 100644 Examples/Sample_xVhdFileExamples.ps1 create mode 100644 GitVersion.yml create mode 100644 HISTORIC_CHANGELOG.md delete mode 100644 Misc/VHDResourceGenerator.ps1 delete mode 100644 Misc/VMHardDiskDriveGenerator.ps1 delete mode 100644 Misc/VMResourceGenerator.ps1 delete mode 100644 Misc/VMScsiControllerGenerator.ps1 delete mode 100644 Misc/VMSwitchGenerator.ps1 create mode 100644 RequiredModules.psd1 create mode 100644 Resolve-Dependency.ps1 create mode 100644 Resolve-Dependency.psd1 delete mode 100644 Tests/Unit/HyperVCommon.tests.ps1 delete mode 100644 Tests/Unit/MSFT_xVMHyperV.Tests.ps1 delete mode 100644 appveyor.yml create mode 100644 azure-pipelines.yml create mode 100644 build.ps1 create mode 100644 build.yaml rename .codecov.yml => codecov.yml (70%) rename {DSCResources => source/DSCResources}/MSFT_xVHD/MSFT_xVHD.psm1 (85%) rename {DSCResources => source/DSCResources}/MSFT_xVHD/MSFT_xVHD.schema.mof (100%) create mode 100644 source/DSCResources/MSFT_xVHD/en-US/MSFT_xVHD.strings.psd1 rename {DSCResources => source/DSCResources}/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.psm1 (64%) rename {DSCResources => source/DSCResources}/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.schema.mof (100%) rename {DSCResources/MSFT_xVMDvdDrive/en-us => source/DSCResources/MSFT_xVMDvdDrive/en-US}/MSFT_xVMDvdDrive.strings.psd1 (100%) rename {DSCResources => source/DSCResources}/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.psm1 (75%) rename {DSCResources => source/DSCResources}/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.schema.mof (100%) rename {DSCResources => source/DSCResources}/MSFT_xVMHardDiskDrive/en-US/MSFT_xVMHardDiskDrive.strings.psd1 (92%) rename {DSCResources => source/DSCResources}/MSFT_xVMHost/MSFT_xVMHost.psm1 (91%) rename {DSCResources => source/DSCResources}/MSFT_xVMHost/MSFT_xVMHost.schema.mof (100%) rename DSCResources/MSFT_xVMHost/en-US/MSFT_xVMHost.psd1 => source/DSCResources/MSFT_xVMHost/en-US/MSFT_xVMHost.strings.psd1 (90%) rename {DSCResources => source/DSCResources}/MSFT_xVMHyperV/MSFT_xVMHyperV.psm1 (73%) rename {DSCResources => source/DSCResources}/MSFT_xVMHyperV/MSFT_xVMHyperV.schema.mof (100%) rename DSCResources/MSFT_xVMHyperV/en-US/MSFT_xVMHyperV.psd1 => source/DSCResources/MSFT_xVMHyperV/en-US/MSFT_xVMHyperV.strings.psd1 (95%) rename {DSCResources => source/DSCResources}/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 (67%) rename {DSCResources => source/DSCResources}/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof (100%) rename DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.psd1 => source/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.strings.psd1 (76%) rename {DSCResources => source/DSCResources}/MSFT_xVMProcessor/MSFT_xVMProcessor.psm1 (80%) rename {DSCResources => source/DSCResources}/MSFT_xVMProcessor/MSFT_xVMProcessor.schema.mof (100%) rename DSCResources/MSFT_xVMProcessor/en-US/MSFT_xVMProcessor.psd1 => source/DSCResources/MSFT_xVMProcessor/en-US/MSFT_xVMProcessor.strings.psd1 (69%) rename {DSCResources => source/DSCResources}/MSFT_xVMScsiController/MSFT_xVMScsiController.psm1 (67%) rename {DSCResources => source/DSCResources}/MSFT_xVMScsiController/MSFT_xVMScsiController.schema.mof (100%) rename {DSCResources => source/DSCResources}/MSFT_xVMScsiController/en-US/MSFT_xVMScsiController.strings.psd1 (93%) rename {DSCResources => source/DSCResources}/MSFT_xVMSwitch/MSFT_xVMSwitch.psm1 (56%) rename {DSCResources => source/DSCResources}/MSFT_xVMSwitch/MSFT_xVMSwitch.schema.mof (100%) rename {DSCResources/MSFT_xVMSwitch/en-us => source/DSCResources/MSFT_xVMSwitch/en-US}/MSFT_xVMSwitch.strings.psd1 (100%) rename {DSCResources => source/DSCResources}/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.psm1 (54%) rename {DSCResources => source/DSCResources}/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.schema.mof (100%) create mode 100644 source/DSCResources/MSFT_xVhdFileDirectory/en-US/MSFT_xVhdFileDirectory.strings.psd1 create mode 100644 source/Examples/Sample_EndToEndXHyperV_RunningVM.ps1 rename {Examples => source/Examples}/Sample_xVMHardDiskDrive_VMWith4AdditionalDisks.ps1 (94%) rename {Examples => source/Examples}/Sample_xVMHardDiskDrive_VMWithExtraDisk.ps1 (97%) create mode 100644 source/Examples/Sample_xVMHost_Paths.ps1 rename {Examples => source/Examples}/Sample_xVMHyperV_Complete.ps1 (71%) rename {Examples => source/Examples}/Sample_xVMHyperV_DynamicMemory.ps1 (57%) rename {Examples => source/Examples}/Sample_xVMHyperV_MultipleNICs.ps1 (76%) rename {Examples => source/Examples}/Sample_xVMHyperV_Simple.ps1 (67%) rename {Examples => source/Examples}/Sample_xVMHyperV_SimpleWithDVDDrive.ps1 (71%) rename {Examples => source/Examples}/Sample_xVMHyperV_SimpleWithNestedVirtualization.ps1 (89%) rename {Examples => source/Examples}/Sample_xVMNetworkAdapter_ManagementOS.ps1 (68%) rename {Examples => source/Examples}/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 (78%) rename {Examples => source/Examples}/Sample_xVMNetworkAdapter_MultipleVM.ps1 (83%) rename {Examples => source/Examples}/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 (67%) create mode 100644 source/Examples/Sample_xVMNetworkAdapter_VMStaticNetworkSettings.ps1 rename {Examples => source/Examples}/Sample_xVMNetworkAdapter_VMVlanTagging.ps1 (62%) rename {Examples => source/Examples}/Sample_xVMScsiController_AddControllers.ps1 (86%) rename {Examples => source/Examples}/Sample_xVMSwitch_External.ps1 (63%) rename {Examples => source/Examples}/Sample_xVMSwitch_ExternalSET.ps1 (85%) rename {Examples => source/Examples}/Sample_xVMSwitch_ExternalSET_LBMode.ps1 (81%) rename {Examples => source/Examples}/Sample_xVMSwitch_Internal.ps1 (74%) rename Examples/Sample_xVHD_AdditionalPropertyVHD.ps1 => source/Examples/Sample_xVhd_AdditionalPropertyVHD.ps1 (81%) create mode 100644 source/Examples/Sample_xVhd_ChangeAttribute.ps1 create mode 100644 source/Examples/Sample_xVhd_CopyFileOrFolder.ps1 rename Examples/Sample_xVHD_DiffVHD.ps1 => source/Examples/Sample_xVhd_DiffVHD.ps1 (83%) rename Examples/Sample_xVHD_FixedVHD.ps1 => source/Examples/Sample_xVhd_FixedVHD.ps1 (85%) rename Examples/Sample_xVHD_MissingPropertyVHD.ps1 => source/Examples/Sample_xVhd_MissingPropertyVHD.ps1 (80%) rename Examples/Sample_xVHD_NewVHD.ps1 => source/Examples/Sample_xVhd_NewVHD.ps1 (84%) create mode 100644 source/Examples/Sample_xVhd_RemoveFileOrFolderFromVHD.ps1 create mode 100644 source/Modules/HyperVDsc.Common/HyperVDsc.Common.psd1 rename DSCResources/HyperVCommon/HyperVCommon.psm1 => source/Modules/HyperVDsc.Common/HyperVDsc.Common.psm1 (65%) rename DSCResources/HyperVCommon/en-us/HyperVCommon.strings.psd1 => source/Modules/HyperVDsc.Common/en-US/HyperVDsc.Common.strings.psd1 (88%) create mode 100644 source/build.psd1 create mode 100644 source/en-US/about_xHyper-V.help.txt create mode 100644 source/xHyper-V.psd1 rename {Tests => tests}/Integration/IntegrationTestsCommon.psm1 (64%) rename {Tests => tests}/Integration/MSFT_xVMDvdDrive.Integration.Tests.ps1 (70%) rename {Tests => tests}/Integration/MSFT_xVMDvdDrive_add.config.ps1 (88%) rename {Tests => tests}/Integration/MSFT_xVMDvdDrive_remove.config.ps1 (89%) rename {Tests => tests}/Integration/MSFT_xVMHost.Integration.Tests.ps1 (59%) rename {Tests => tests}/Integration/MSFT_xVMHost_set.config.ps1 (87%) rename {Tests => tests}/Integration/MSFT_xVMProcessor.Integration.Tests.ps1 (71%) rename {Tests => tests}/Integration/MSFT_xVMProcessor_set.config.ps1 (89%) create mode 100644 tests/Unit/HyperVDsc.Common.Tests.ps1 rename Tests/Unit/MSFT_xVHD.tests.ps1 => tests/Unit/MSFT_xVHD.Tests.ps1 (76%) rename Tests/Unit/MSFT_xVMDvdDrive.tests.ps1 => tests/Unit/MSFT_xVMDvdDrive.Tests.ps1 (77%) rename {Tests => tests}/Unit/MSFT_xVMHardDiskDrive.Tests.ps1 (50%) rename Tests/Unit/MSFT_xVMHost.tests.ps1 => tests/Unit/MSFT_xVMHost.Tests.ps1 (59%) create mode 100644 tests/Unit/MSFT_xVMHyperV.Tests.ps1 rename {Tests => tests}/Unit/MSFT_xVMNetworkAdapter.Tests.ps1 (55%) rename {Tests => tests}/Unit/MSFT_xVMProcessor.Tests.ps1 (56%) rename {Tests => tests}/Unit/MSFT_xVMScsiController.Tests.ps1 (50%) rename {Tests => tests}/Unit/MSFT_xVMSwitch_BandwidthReservationMode.Tests.ps1 (68%) rename {Tests => tests}/Unit/MSFT_xVMSwitch_EnableEmbeddedTeaming.Tests.ps1 (56%) rename {Tests => tests}/Unit/MSFT_xVMSwitch_Id.Tests.ps1 (71%) create mode 100644 tests/Unit/MSFT_xVhdFileDirectory.Tests.ps1 create mode 100644 tests/Unit/Stubs/Hyper-V.stubs.psm1 create mode 100644 tests/Unit/Stubs/README.md delete mode 100644 xHyper-V.psd1 diff --git a/.MetaTestOptIn.json b/.MetaTestOptIn.json deleted file mode 100644 index f79f878..0000000 --- a/.MetaTestOptIn.json +++ /dev/null @@ -1,3 +0,0 @@ -[ - "Common Tests - Validate Markdown Files" -] diff --git a/.gitattributes b/.gitattributes index 5613d53..d49b050 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,8 @@ # Needed for publishing of examples, build worker defaults to core.autocrlf=input. * text eol=crlf + +# Ensure any exe files are treated as binary +*.exe binary +*.jpg binary +*.xl* binary +*.pfx binary diff --git a/.github/ISSUE_TEMPLATE/Problem_with_resource.md b/.github/ISSUE_TEMPLATE/Problem_with_resource.md index 2431f65..159e81c 100644 --- a/.github/ISSUE_TEMPLATE/Problem_with_resource.md +++ b/.github/ISSUE_TEMPLATE/Problem_with_resource.md @@ -54,4 +54,4 @@ about: If you have a problem, bug, or enhancement with a resource in this resour $PSVersionTable --> -#### Version of the DSC module that was used ('dev' if using current dev branch) +#### Version of the DSC module that was used diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 50e18d3..73031e9 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -14,15 +14,19 @@ #### Pull Request (PR) description #### This Pull Request (PR) fixes the following issues #### Task list @@ -34,14 +38,16 @@ Change to [x] for each task in the task list that applies to your PR. For those task that don't apply to you PR, leave those as is. --> -- [ ] Added an entry under the Unreleased section of the change log in the CHANGELOG.md. - Entry should say what was changed, and how that affects users (if applicable). +- [ ] Added an entry to the change log under the Unreleased section of the + file CHANGELOG.md. Entry should say what was changed and how that + affects users (if applicable), and reference the issue being resolved + (if applicable). - [ ] Resource documentation added/updated in README.md. - [ ] Resource parameter descriptions added/updated in README.md, schema.mof and comment-based help. - [ ] Comment-based help added/updated. - [ ] Localization strings added/updated in all localization files as appropriate. - [ ] Examples appropriately added/updated. -- [ ] Unit tests added/updated. See [DSC Resource Testing Guidelines](https://github.com/PowerShell/DscResources/blob/master/TestsGuidelines.md). -- [ ] Integration tests added/updated (where possible). See [DSC Resource Testing Guidelines](https://github.com/PowerShell/DscResources/blob/master/TestsGuidelines.md). -- [ ] New/changed code adheres to [DSC Resource Style Guidelines](https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md) and [Best Practices](https://github.com/PowerShell/DscResources/blob/master/BestPractices.md). +- [ ] Unit tests added/updated. See [DSC Community Testing Guidelines](https://dsccommunity.org/guidelines/testing-guidelines). +- [ ] Integration tests added/updated (where possible). See [DSC Community Testing Guidelines](https://dsccommunity.org/guidelines/testing-guidelines). +- [ ] New/changed code adheres to [DSC Community Style Guidelines](https://dsccommunity.org/styleguidelines). diff --git a/.gitignore b/.gitignore index b03606a..3563fb1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -DSCResource.Tests +output/ +.vs +.vscode diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 0000000..87b7da5 --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,10 @@ +{ + "default": true, + "MD029": { + "style": "one" + }, + "MD013": true, + "MD024": false, + "MD034": false, + "no-hard-tabs": true +} diff --git a/.vscode/analyzersettings.psd1 b/.vscode/analyzersettings.psd1 index be415e4..78312d2 100644 --- a/.vscode/analyzersettings.psd1 +++ b/.vscode/analyzersettings.psd1 @@ -1,11 +1,6 @@ @{ - <# - For the custom rules to work, the DscResource.Tests repo must be - cloned. It is automatically clone as soon as any unit or - integration tests are run. - #> - CustomRulePath = '.\DSCResource.Tests\DscResource.AnalyzerRules' - + CustomRulePath = '.\output\RequiredModules\DscResource.AnalyzerRules' + includeDefaultRules = $true IncludeRules = @( # DSC Resource Kit style guideline rules. 'PSAvoidDefaultValueForMandatoryParameter', @@ -43,11 +38,7 @@ 'PSUseDeclaredVarsMoreThanAssignments', 'PSUsePSCredentialType', - <# - This is to test all the DSC Resource Kit custom rules. - The name of the function-blocks of each custom rule start - with 'Measure*'. - #> 'Measure-*' ) + } diff --git a/.vscode/settings.json b/.vscode/settings.json index 0969e57..1bf119a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,14 +1,39 @@ { "powershell.codeFormatting.openBraceOnSameLine": false, - "powershell.codeFormatting.newLineAfterOpenBrace": false, + "powershell.codeFormatting.newLineAfterOpenBrace": true, "powershell.codeFormatting.newLineAfterCloseBrace": true, "powershell.codeFormatting.whitespaceBeforeOpenBrace": true, "powershell.codeFormatting.whitespaceBeforeOpenParen": true, "powershell.codeFormatting.whitespaceAroundOperator": true, "powershell.codeFormatting.whitespaceAfterSeparator": true, "powershell.codeFormatting.ignoreOneLineBlock": false, + "powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationAfterEveryPipeline", "powershell.codeFormatting.preset": "Custom", + "powershell.codeFormatting.alignPropertyValuePairs": true, "files.trimTrailingWhitespace": true, "files.insertFinalNewline": true, - "powershell.scriptAnalysis.settingsPath": ".vscode\\analyzersettings.psd1" + "powershell.scriptAnalysis.settingsPath": ".vscode\\analyzersettings.psd1", + "powershell.scriptAnalysis.enable": true, + "files.associations": { + "*.ps1xml": "xml" + }, + "cSpell.words": [ + "COMPANYNAME", + "ICONURI", + "LICENSEURI", + "PROJECTURI", + "RELEASENOTES", + "buildhelpers", + "endregion", + "gitversion", + "icontains", + "keepachangelog", + "notin", + "pscmdlet", + "steppable" + ], + "[markdown]": { + "files.trimTrailingWhitespace": true, + "files.encoding": "utf8" + } } diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..4085e3e --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,125 @@ +{ + "version": "2.0.0", + "_runner": "terminal", + "windows": { + "options": { + "shell": { + "executable": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", + "args": [ + "-NoProfile", + "-ExecutionPolicy", + "Bypass", + "-Command" + ] + } + } + }, + "linux": { + "options": { + "shell": { + "executable": "/usr/bin/pwsh", + "args": [ + "-NoProfile", + "-Command" + ] + } + } + }, + "osx": { + "options": { + "shell": { + "executable": "/usr/local/bin/pwsh", + "args": [ + "-NoProfile", + "-Command" + ] + } + } + }, + "tasks": [ + { + "label": "build", + "type": "shell", + "command": "&${cwd}/build.ps1", + "args": ["-AutoRestore"], + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "new", + "clear": false + }, + "runOptions": { + "runOn": "default" + }, + "problemMatcher": [ + { + "owner": "powershell", + "fileLocation": [ + "absolute" + ], + "severity": "error", + "pattern": [ + { + "regexp": "^\\s*(\\[-\\]\\s*.*?)(\\d+)ms\\s*$", + "message": 1 + }, + { + "regexp": "(.*)", + "code": 1 + }, + { + "regexp": "" + }, + { + "regexp": "^.*,\\s*(.*):\\s*line\\s*(\\d+).*", + "file": 1, + "line": 2 + } + ] + } + ] + }, + { + "label": "test", + "type": "shell", + "command": "&${cwd}/build.ps1", + "args": ["-AutoRestore","-Tasks","test"], + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "dedicated", + "showReuseMessage": true, + "clear": false + }, + "problemMatcher": [ + { + "owner": "powershell", + "fileLocation": [ + "absolute" + ], + "severity": "error", + "pattern": [ + { + "regexp": "^\\s*(\\[-\\]\\s*.*?)(\\d+)ms\\s*$", + "message": 1 + }, + { + "regexp": "(.*)", + "code": 1 + }, + { + "regexp": "" + }, + { + "regexp": "^.*,\\s*(.*):\\s*line\\s*(\\d+).*", + "file": 1, + "line": 2 + } + ] + } + ] + } + ] +} diff --git a/CHANGELOG.md b/CHANGELOG.md index d82d90d..24c389b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,198 +1,41 @@ # Change log for xHyper-V -## Unreleased +The format is based on and uses the types of changes according to [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## 3.17.0.0 +For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md). -* MSFT_xVMNetworkAdapter: - * Added NetworkSettings to be able to statically set IPAddress. - * Added option for Vlan tagging. You can now setup a Network Adapeter as an access switch on a specific Vlan. +## [Unreleased] -## 3.16.0.0 +### Added -* MSFT_xVMHyperV: - * Moved localization string data to own file. - * Fixed code styling issues. - * Fixed bug where StartupMemory was not evaluated in Test-TargetResource. - * Redo of abandoned PRs: - * [PR #148](https://github.com/PowerShell/xHyper-V/pull/148), Fixes [Issue #149](https://github.com/PowerShell/xHyper-V/issues/149). - * [PR #67](https://github.com/PowerShell/xHyper-V/pull/67), Fixes [Issue #145](https://github.com/PowerShell/xHyper-V/issues/145). - * Fixed Get throws error when NetworkAdapters are not attached or missing properties. +- 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 -## 3.15.0.0 +### Deprecated -* Explicitly removed extra hidden files from release package. +- xHyper-V + - The resource will not be tested for Windows Server 2008 R2 since + that operating system has reach end-of-life. -## 3.14.0.0 +### Removed -* MSFT_xVMHost: - * Added support to Enable / Disable VM Live Migration. Fixes [Issue #155](https://github.com/PowerShell/xHyper-V/issues/155). +- 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. -## 3.13.0.0 +### Fixed -* MSFT_xVMSwitch: - * Changed 'Id' parameter form read only to optional so the VMSwitch ID can be set on Windows Server 2016. This is important for SDN setups where the VMSwitch ID must remain the same when a Hyper-V host is re-installed. - * Update appveyor.yml to use the default template. - * Added default template files .codecov.yml, .gitattributes, and .gitignore, and - .vscode folder. - -## 3.12.0.0 - -* Changes to xHyper-V - * Removed alignPropertyValuePairs from the Visual Studio Code default style - formatting settings (issue #110). - -## 3.11.0.0 - -* Added the following resources: - * MSFT_xVMHardDiskDrive to manage additional attached VHD/Xs. - * MSFT_xVMScsiController to manage virtual machine SCSI controllers. -* MSFT_xVMSwitch: - * Added parameter to specify the Load Balancing Algorithm of a vSwitch with Switch Embedded Teaming (SET). - -## 3.10.0.0 - -* MSFT_xVMHyperV: - * Added support for configuring automatic snapshots. - -## 3.9.0.0 - -* MSFT_xVMHyperV: - * Enable / disable dynamic memory for client and server SKUs in identical way. - * Increased xVMHyperV StartupMemory and MinimumMemory limits from 17GB to 64GB. - * EnableGuestService works on localized OS (language independent). - * Adds missing Hyper-V-PowerShell feature in examples. -* Added the following resources: - * MSFT_xVMProcessor to manage virtual machine processor options. - * MSFT_xVMHost to managing Hyper-V host settings. -* MSFT_xVMSwitch: - * Added support for Switch Embedded Teaming (SET) in Server 2016. - * Fixed a bug where Get-TargetResource threw an error if a non External switch - is used. - * Updated unit tests to use template version 1.2.0. - * Style fixes. - * Added support for Localization. -* xHyper-V module: - * Added vs code formatting rule settings. - * Fix Markdown rule violations in Readme.md. - * Added .MetaTestOptIn.json for Markdown common test to be included. - * Added Appveyor badge for Dev branch in Readme.md and moved to Branches section. - * Added missing properties for all resources in Readme.md. - * Added and corrected missing / wrong DataTypes and Dsc attributes in Readme.md. - * Updated Readme to match DscResources style. - * Created change log and linked to it from Readme. - * Removed version info from Readme. - * Updated appveyor.yml to use Appveyor module. - * Examples: - * Removed code from Readme and linked to example files instead. - * Moved code to new example files where there was only code in Readme. - * Codecov: - * Updated appveyor.yml to include codecov. - * Added .codecov.yml. - * Added codecov badges to Readme. -* MSFT_xVHD: - * Support setting the disk type. - * Added unit tests. - * Added example Sample\_xVHD\_FixedVHD.ps1 - * Style fixes - -## 3.8.0.0 - -* Fix bug in xVMDvdDrive with hardcoded VM Name. -* Corrected Markdown rule violations in Readme.md. - -## 3.7.0.0 - -* Adding a new resource - * MSFT_xVMNetworkAdapter: Attaches a new VM network adapter to the management - OS or VM. - -## 3.6.0.0 - -* xVHD: Updated incorrect property name MaximumSize in error message -* Fix Markdown rule violations in Readme.md identified by [markdownlint](https://github.com/mivok/markdownlint/blob/master/docs/RULES.md). -* Created standard Unit/Integration test folder structure. -* Moved unit tests into Unit test folder. -* Renamed the unit tests to meet standards. -* Added the following resources: - * xVMDvdDrive to manage DVD drives attached to a Hyper-V virtual machine. - -## 3.5.0.0 - -* Converted appveyor.yml to install Pester from PSGallery instead of from Chocolatey. -* MSFT_xVMHyperV: Fixed bug in Test-TargetResource throwing when a Vhd's ParentPath - property was null. - -## 3.4.0.0 - -* MSFT_xVMHyperV: Fixed bug causing Test-TargetResource to fail when VM had snapshots. -* MSFT_xVMHyperV: Adds localization support. -* MSFT_xVMSwitch: Fixes bug where virtual switches are duplicated when - BandwidthReservationMode is not specified. - -## 3.3.0.0 - -* xHyperV: Added SecureBoot parameter to enable control of the secure boot BIOS - setting on generation 2 VMs. - * Fixed drive letter when mounting VHD when calling resource xVhdFile. Fixes #20. -* MSFT_xVMHyperV: Changed the SwitchName parameter to string[] to support - assigning multiple NICs to virtual machines. -* MSFT_xVMHyperV: Changed the MACAddress parameter to string[] to support - assigning multiple MAC addresses to virtual machines. -* MSFT_xVMHyperV: Added enabling of Guest Service Interface. -* MSFT_xVMSwitch: Added the BandwidthReservationMode parameter which specifies - how minimum bandwidth is to be configured on a virtual switch - -## 3.2.0.0 - -* Added data type System.String to CheckSum parameter of Get/Set/Test-TargetResource - functions and aligned indentation. -* Minor fixes - -## 3.1.0.0 - -* xVMHyperV: Fixed bug in mof schema (Generation property had two types) -* xVhdFileDirectory: Fixed typo in type comparison -* Readme updates - -## 3.0.0.0 - -* Decoupled VM generation from underlying VHD format in xVMHyperV resource. - * __Breaking change:__ xVMHyperV resource: Generation property type changed - from a String to an Integer. - * The initial generation property was tied to the virtual disk format which was - incorrect and has been rectified. - * This change will only impact configurations that have previously explicitly - specified the VM generation is either "vhd" or "vhdx". - -## 2.4.0.0 - -* Fixed VM power state issue in xVMHyperV resource - -## 2.3.0 - -* Fixed check for presence of param AllowManagementOS. - -## 2.2.1 - -## 2.1 - -* Added logic to automatically adjust VM's startup memory when only minimum and - maximum memory is specified in configuration -* Fixed the issue that a manually stopped VM cannot be brought back to running - state with DSC - -## 2.0 - -* Added xVhdFileDirectory Resource -* Allowed name to be specified with the extension in xVhd (e.g. the Vhd name could - either be "sample" or "sample.vhd") -* When a VHD cannot be removed because it is already being used by another process, - an error will be thrown. - -## 1.0.0.0 - -* Initial release with the following resources - * xVhd - * xVMHyperV - * xVMSwitch +- 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. diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..d7589dd --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,3 @@ +# Code of Conduct + +This project has adopted the [DSC Community Code of Conduct](https://dsccommunity.org/code_of_conduct). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..3544bcc --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,7 @@ +# Contributing + +Please check out common DSC Community [contributing guidelines](https://dsccommunity.org/guidelines/contributing). + +## Running the Tests + +If want to know how to run this module's tests you can look at the [Testing Guidelines](https://dsccommunity.org/guidelines/testing-guidelines/#running-tests) diff --git a/Examples/Sample_xVMHost_Paths.ps1 b/Examples/Sample_xVMHost_Paths.ps1 deleted file mode 100644 index 044bc55..0000000 --- a/Examples/Sample_xVMHost_Paths.ps1 +++ /dev/null @@ -1,22 +0,0 @@ -Configuration HyperVHostPaths -{ - param - ( - [Parameter(Mandatory=$true, Position=0)] - [ValidateScript({Test-Path $_})] - $VirtualHardDiskPath, - - [Parameter(Mandatory=$true, Position=1)] - [ValidateScript({Test-Path $_})] - $VirtualMachinePath - ) - - Import-DscResource -moduleName xHyper-V - - xVMHost HyperVHostPaths - { - IsSingleInstance = 'Yes' - VirtualHardDiskPath = $VirtualHardDiskPath - VirtualMachinePath = $VirtualMachinePath - } -} diff --git a/Examples/Sample_xVMNetworkAdapter_VMStaticNetworkSettings.ps1 b/Examples/Sample_xVMNetworkAdapter_VMStaticNetworkSettings.ps1 deleted file mode 100644 index 2d192bc..0000000 --- a/Examples/Sample_xVMNetworkAdapter_VMStaticNetworkSettings.ps1 +++ /dev/null @@ -1,20 +0,0 @@ -Configuration VMAdapter -{ - Import-DscResource -ModuleName xHyper-V -Name xVMNetworkAdapter - Import-DscResource -ModuleName PSDesiredStateConfiguration - - xVMNetworkAdapter MyVM01NIC { - Id = 'MyVM01-NIC' - Name = 'MyVM01-NIC' - SwitchName = 'SETSwitch' - MacAddress = '001523be0c' - VMName = 'MyVM01' - NetworkSetting = xNetworkSettings { - IpAddress = "192.168.0.100" - Subnet = "255.255.255.255" - DefaultGateway = "192.168.0.1" - DnsServer = "192.168.0.1" - } - Ensure = 'Present' - } -} diff --git a/Examples/Sample_xVhdFileExamples.ps1 b/Examples/Sample_xVhdFileExamples.ps1 deleted file mode 100644 index 93052c3..0000000 --- a/Examples/Sample_xVhdFileExamples.ps1 +++ /dev/null @@ -1,171 +0,0 @@ -# sample values used for testing. -$sampleVhdPath = "C:\test_vhds\RenameComputer.Vhd" - -# sample text file that you want to copy in the VHD. -$sampletxt = "C:\sample.txt" - -# This path is the relative path to mounted drive letter. -$sampleVhdDestinationPath = "xvhdFileExample\CopiedFile" - -# A local folder that you want to copy in to the VHD. -$samplefolder = "c:\SampleFolder" - -Configuration xVhdD_CopyFileOrFolder -{ - - Param( - [Parameter(Mandatory=$true, Position=0)] - [validatescript({Test-Path $_})] - $vhdPath, - [Parameter(Mandatory=$true)] - [validatescript({Test-Path $_})] - $itemToCopy, - [Parameter(Mandatory=$true)] - $relativeDestinationPath - ) - - Import-DscResource -moduleName xHyper-V - - xVhdFile FileCopy - { - VhdPath = $vhdPath - FileDirectory = MSFT_xFileDirectory { - SourcePath = $itemToCopy - DestinationPath = $relativeDestinationPath - } - - } - -} - -# Copy File/Folder example -xVhdD_CopyFileOrFolder -vhdPath $sampleVhdPath -itemToCopy $sampletxt -relativeDestinationPath $sampleVhdDestinationPath -Start-DscConfiguration -ComputerName localhost -Path $pwd\xVhdD_CopyFileOrFolder\ -Wait -Verbose - -xVhdD_CopyFileOrFolder -vhdPath $sampleVhdPath -itemToCopy $samplefolder -relativeDestinationPath $sampleVhdDestinationPath -Start-DscConfiguration -ComputerName localhost -Path $pwd\xVhdD_CopyFileOrFolder\ -Wait -Verbose - -Configuration RemoveFileOrFolderFromVHD -{ - param( - [Parameter(Mandatory=$true, Position=0)] - [validatescript({Test-Path $_})] - $vhdPath, - [Parameter(Mandatory=$true)] - $relativeDestinationPath, - $Ensure = 'Absent' - ) - Import-DscResource -moduleName xHyper-V - xVhdFile RemoveFile - { - VhdPath = $vhdPath - FileDirectory = MSFT_xFileDirectory { - DestinationPath = $relativeDestinationPath - Ensure = $Ensure - } - - } - -} - -RemoveFileOrFolderFromVHD -vhdPath $sampleVhdPath -relativeDestinationPath $sampleVhdDestinationPath -Start-DscConfiguration -ComputerName localhost -Path $pwd\RemoveFileOrFolderFromVHD\ -Wait -Verbose - -Configuration ChangeAttribute -{ - param( - [Parameter(Mandatory=$true, Position=0)] - [validatescript({Test-Path $_})] - $vhdPath, - [Parameter(Mandatory=$true)] - $relativeDestinationPath, - [ValidateSet ("Archive", "Hidden", "ReadOnly", "System" )] $attribute - ) - - Import-DscResource -moduleName xHyper-V - xVhdFile Change-Attribute - { - VhdPath = $vhdPath - FileDirectory = MSFT_xFileDirectory { - DestinationPath = $relativeDestinationPath - Attributes = $attribute - } - - } -} - -ChangeAttribute -vhdPath $sampleVhdPath -relativeDestinationPath $sampleVhdDestinationPath -attribute 'ReadOnly' -Start-DscConfiguration -ComputerName localhost -Path $pwd\RemoveFileOrFolderFromVHD\ -Wait -Verbose - -# End to end sample for x-Hyper-v -Configuration Sample_EndToEndXHyperV_RunningVM -{ - - param - ( - [Parameter(Mandatory)] - $vhdPath, - [Parameter(Mandatory)] - $name, - [Parameter(Mandatory)] - [validatescript({Test-Path $_})] - $unattendedFilePathToCopy - ) - - Import-DscResource -module xHyper-V - - # Create a switch to be used by the VM - xVMSwitch switch - { - Name = "Test-Switch" - Ensure = "Present" - Type = "Internal" - } - - # Create new VHD file. - xVHD NewVHD1 - { - - Ensure = "Present" - Name = $name - Path = (Split-Path $vhdPath) - Generation = "vhd" - ParentPath = $vhdPath - - } - - # Customize VHD by copying a folders/files to the VHD before a VM can be created - # Example below shows copying unattended.xml before a VM can be created - xVhdFile CopyUnattendxml - { - VhdPath = $vhdPath - FileDirectory = MSFT_xFileDirectory { - SourcePath = $unattendedFilePathToCopy - DestinationPath = "unattended.xml" - } - - } - - # create the testVM out of the vhd. - xVMHyperV testvm - { - Name = "$($name)_vm" - SwitchName = "Test-Switch" - VhdPath = Join-path (Split-Path $vhdPath) "$name.vhd" - ProcessorCount = 2 - MaximumMemory = 1GB - MinimumMemory = 512MB - RestartIfNeeded = "TRUE" - DependsOn = "[xVHD]NewVHD1","[xVMSwitch]switch","[xVhdFile]CopyUnattendxml" - State = "Running" - - } - -} - -# Create a mof file. -Sample_EndToEndXHyperV_RunningVM -vhdPath $sampleVhdPath -name TestMachine -unattendedFilePathToCopy C:\temp\unattended.xml - -# Run the configuration on localhost. -Start-DscConfiguration -Path $pwd\Sample_EndToEndXHyperV_RunningVM -ComputerName localhost -Verbose -Wait - diff --git a/GitVersion.yml b/GitVersion.yml new file mode 100644 index 0000000..d32f847 --- /dev/null +++ b/GitVersion.yml @@ -0,0 +1,34 @@ +mode: ContinuousDelivery +next-version: 3.18.0 +major-version-bump-message: '\s?(breaking|major|breaking\schange)' +minor-version-bump-message: '\s?(add|feature|minor)' +patch-version-bump-message: '\s?(fix|patch)' +no-bump-message: '\+semver:\s?(none|skip)' +assembly-informational-format: "{NuGetVersionV2}+Sha.{Sha}.Date.{CommitDate}" +branches: + master: + tag: preview + pull-request: + tag: PR + feature: + tag: useBranchName + increment: Minor + regex: f(eature(s)?)?[\/-] + source-branches: ["master"] + hotfix: + tag: fix + increment: Patch + regex: (hot)?fix(es)?[\/-] + source-branches: ["master"] + +ignore: + # Ignored these SHA to prevent wrongly raising major version + # when module was converted to new CI pipeline. + sha: + [ + 47725eb4a8db5857ce134d66cb355cf2e7544017, + c0224e8821e6098bf09c4d08be878f2fabe778d5, + c55655f98b81b6e1e9a058da3e1a6cc2f5f33917, + 11555429e61770c46af67860df87008a17c3df0, + ] +merge-message-formats: {} diff --git a/HISTORIC_CHANGELOG.md b/HISTORIC_CHANGELOG.md new file mode 100644 index 0000000..c3cc2b3 --- /dev/null +++ b/HISTORIC_CHANGELOG.md @@ -0,0 +1,206 @@ +# Historic change log for xHyper-V + +The release notes in the PowerShell Module manifest cannot exceed 10000 +characters. Due to a bug in the CI deploy pipeline this is not handled. +This file is to temporary move the older change log history to keep the +change log short. + +## [3.17.0.0] - 2019-10-30 + +- MSFT_xVMNetworkAdapter: + - Added NetworkSettings to be able to statically set IPAddress. + - Added option for VLAN tagging. You can now setup a Network Adapter as + an access switch on a specific VLAN. + +## [3.16.0.0] - 2019-02-20 + +- MSFT_xVMHyperV: + - Moved localization string data to own file. + - Fixed code styling issues. + - Fixed bug where StartupMemory was not evaluated in Test-TargetResource. + - Redo of abandoned PRs: + - [PR #148](https://github.com/PowerShell/xHyper-V/pull/148), Fixes [Issue #149](https://github.com/PowerShell/xHyper-V/issues/149). + - [PR #67](https://github.com/PowerShell/xHyper-V/pull/67), Fixes [Issue #145](https://github.com/PowerShell/xHyper-V/issues/145). + - Fixed Get throws error when NetworkAdapters are not attached or missing + properties. + +## [3.15.0.0] - 2019-01-09 + +- Explicitly removed extra hidden files from release package. + +## [3.14.0.0] - 2018-11-28 + +- MSFT_xVMHost: + - Added support to Enable / Disable VM Live Migration. Fixes [Issue #155](https://github.com/PowerShell/xHyper-V/issues/155). + +## [3.13.0.0] - 2018-10-24 + +- MSFT_xVMSwitch: + - Changed 'Id' parameter form read only to optional so the VMSwitch ID can + be set on Windows Server 2016. This is important for SDN setups where the + VMSwitch ID must remain the same when a Hyper-V host is re-installed. + - Update appveyor.yml to use the default template. + - Added default template files .codecov.yml, .gitattributes, and .gitignore, + and .vscode folder. + +## [3.12.0.0] - 2018-06-13 + +- Changes to xHyper-V + - Removed alignPropertyValuePairs from the Visual Studio Code default style + formatting settings (issue #110). + +## [3.11.0.0] - 2018-02-07 + +- Added the following resources: + - MSFT_xVMHardDiskDrive to manage additional attached VHD/Xs. + - MSFT_xVMScsiController to manage virtual machine SCSI controllers. +- MSFT_xVMSwitch: + - Added parameter to specify the Load Balancing Algorithm of a vSwitch + with Switch Embedded Teaming (SET). + +## [3.10.0.0] - 2017-12-20 + +- MSFT_xVMHyperV: + - Added support for configuring automatic snapshots. + +## [3.9.0.0] - 2017-07-12 + +- MSFT_xVMHyperV: + - Enable / disable dynamic memory for client and server SKUs in identical way. + - Increased xVMHyperV StartupMemory and MinimumMemory limits from 17GB to 64GB. + - EnableGuestService works on localized OS (language independent). + - Adds missing Hyper-V-PowerShell feature in examples. +- Added the following resources: + - MSFT_xVMProcessor to manage virtual machine processor options. + - MSFT_xVMHost to managing Hyper-V host settings. +- MSFT_xVMSwitch: + - Added support for Switch Embedded Teaming (SET) in Server 2016. + - Fixed a bug where Get-TargetResource threw an error if a non External switch + is used. + - Updated unit tests to use template version 1.2.0. + - Style fixes. + - Added support for Localization. +- xHyper-V module: + - Added vs code formatting rule settings. + - Fix Markdown rule violations in Readme.md. + - Added .MetaTestOptIn.json for Markdown common test to be included. + - Added Appveyor badge for Dev branch in Readme.md and moved to Branches section. + - Added missing properties for all resources in Readme.md. + - Added and corrected missing / wrong DataTypes and Dsc attributes in Readme.md. + - Updated Readme to match DscResources style. + - Created change log and linked to it from Readme. + - Removed version info from Readme. + - Updated appveyor.yml to use Appveyor module. + - Examples: + - Removed code from Readme and linked to example files instead. + - Moved code to new example files where there was only code in Readme. + - Codecov: + - Updated appveyor.yml to include codecov. + - Added .codecov.yml. + - Added codecov badges to Readme. +- MSFT_xVHD: + - Support setting the disk type. + - Added unit tests. + - Added example Sample\_xVHD\_FixedVHD.ps1 + - Style fixes + +## [3.8.0.0] - 2017-05-31 + +- Fix bug in xVMDvdDrive with hardcoded VM Name. +- Corrected Markdown rule violations in Readme.md. + +## [3.7.0.0] - 2017-01-26 + +- Adding a new resource + - MSFT_xVMNetworkAdapter: Attaches a new VM network adapter to the management + OS or VM. + +## [3.6.0.0] - 2016-12-14 + +- xVHD: Updated incorrect property name MaximumSize in error message +- Fix Markdown rule violations in Readme.md identified by [markdownlint](https://github.com/mivok/markdownlint/blob/master/docs/RULES.md). +- Created standard Unit/Integration test folder structure. +- Moved unit tests into Unit test folder. +- Renamed the unit tests to meet standards. +- Added the following resources: + - xVMDvdDrive to manage DVD drives attached to a Hyper-V virtual machine. + +## [3.5.0.0] - 2016-08-10 + +- Converted appveyor.yml to install Pester from PSGallery instead of from Chocolatey. +- MSFT_xVMHyperV: Fixed bug in Test-TargetResource throwing when a Vhd's ParentPath + property was null. + +## [3.4.0.0] - 2016-03-30 + +- MSFT_xVMHyperV: Fixed bug causing Test-TargetResource to fail when VM had snapshots. +- MSFT_xVMHyperV: Adds localization support. +- MSFT_xVMSwitch: Fixes bug where virtual switches are duplicated when + BandwidthReservationMode is not specified. + +## [3.3.0.0] - 2016-02-02 + +- xHyperV: Added SecureBoot parameter to enable control of the secure boot BIOS + setting on generation 2 VMs. + - Fixed drive letter when mounting VHD when calling resource xVhdFile. Fixes #20. +- MSFT_xVMHyperV: Changed the SwitchName parameter to string[] to support + assigning multiple NICs to virtual machines. +- MSFT_xVMHyperV: Changed the MACAddress parameter to string[] to support + assigning multiple MAC addresses to virtual machines. +- MSFT_xVMHyperV: Added enabling of Guest Service Interface. +- MSFT_xVMSwitch: Added the BandwidthReservationMode parameter which specifies + how minimum bandwidth is to be configured on a virtual switch + +## [3.2.0.0] - 2015-09-11 + +- Added data type System.String to CheckSum parameter of Get/Set/Test-TargetResource + functions and aligned indentation. +- Minor fixes + +## [3.1.0.0] - 2015-08-11 + +- xVMHyperV: Fixed bug in mof schema (Generation property had two types) +- xVhdFileDirectory: Fixed typo in type comparison +- Readme updates + +## [3.0.0.0] - 2015-07-24 + +- Decoupled VM generation from underlying VHD format in xVMHyperV resource. + - BREAKING CHANGE: xVMHyperV resource: Generation property type changed + from a String to an Integer. + - The initial generation property was tied to the virtual disk format which was + incorrect and has been rectified. + - This change will only impact configurations that have previously explicitly + specified the VM generation is either "vhd" or "vhdx". + +## [2.4.0.0] - 2015-06-09 + +- Fixed VM power state issue in xVMHyperV resource + +## [2.3.0] - 2015-05-01 + +- Fixed check for presence of param AllowManagementOS. + +## [2.2.1] - 2015-04-23 + +### [2.1] - + +- Added logic to automatically adjust VM's startup memory when only minimum and + maximum memory is specified in configuration +- Fixed the issue that a manually stopped VM cannot be brought back to running + state with DSC + +### [2.0] - + +- Added xVhdFileDirectory Resource +- Allowed name to be specified with the extension in xVhd (e.g. the Vhd name could + either be "sample" or "sample.vhd") +- When a VHD cannot be removed because it is already being used by another process, + an error will be thrown. + +## [1.0.0.0] - 2015-04-15 + +- Initial release with the following resources + - xVhd + - xVMHyperV + - xVMSwitch diff --git a/LICENSE b/LICENSE index 567fd6a..f4c3ee9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Microsoft Corporation. +Copyright (c) DSC Community contributors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE. diff --git a/Misc/VHDResourceGenerator.ps1 b/Misc/VHDResourceGenerator.ps1 deleted file mode 100644 index 1a00958..0000000 --- a/Misc/VHDResourceGenerator.ps1 +++ /dev/null @@ -1,13 +0,0 @@ - $name = New-DscResourceProperty -Name Name -Type String -Attribute Key -Description "Name of the VHD File" - $path = New-DscResourceProperty -Name Path -Type String -Attribute Key -Description "Folder where the VHD will be created" - $parentPath = New-DscResourceProperty -Name ParentPath -Type String -Attribute Write -Description "Parent VHD file path, for differencing disk" - $generation = New-DscResourceProperty -Name Generation -Type String -Attribute Write -ValidateSet "Vhd","Vhdx" -Description "Virtual disk format - Vhd or Vhdx" - $ensure = New-DscResourceProperty -Name Ensure -Type String -Attribute Write -ValidateSet "Present","Absent" -Description "Should the VHD be created or deleted" - $MaximumSizeBytes = New-DscResourceProperty -Name MaximumSizeBytes -Type Uint32 -Attribute Write -Description "Maximum size of Vhd to be created" - - $id = New-DscResourceProperty -Name ID -Type String -Attribute Read -Description "Virtual Disk Identifier" - $type = New-DscResourceProperty -Name Type -Type String -Attribute Read -Description "Type of Vhd - Dynamic, Fixed, Differencing" - $FileSizeBytes = New-DscResourceProperty -Name FileSizeBytes -Type Uint32 -Attribute Read -Description "Current size of the VHD" - $IsAttached = New-DscResourceProperty -Name IsAttached -Type Boolean -Attribute Read -Description "Is the VHD attached to a VM or not" - - New-DscResource -Name MSFT_xVHD -Properties $name,$path,$parentPath,$generation,$ensure,$id,$type,$MaximumSizeBytes,$FileSizeBytes,$IsAttached -Path . -ClassVersion 1.0.0 -FriendlyName xVHD diff --git a/Misc/VMHardDiskDriveGenerator.ps1 b/Misc/VMHardDiskDriveGenerator.ps1 deleted file mode 100644 index 37f2a6b..0000000 --- a/Misc/VMHardDiskDriveGenerator.ps1 +++ /dev/null @@ -1,8 +0,0 @@ -New-xDscResource -Name MSFT_xVMHardDiskDrive -Path . -ClassVersion 1.0.0 -FriendlyName xVMHardDiskDrive -Property $( - New-xDscResourceProperty -Name VMName -Type String -Attribute Key -Description "Specifies the name of the virtual machine whose hard disk drive is to be manipulated" - New-xDscResourceProperty -Name Path -Type String -Attribute Key -Description "Specifies the full path to the location of the VHD that represents the hard disk drive" - New-xDscResourceProperty -Name ControllerType -Type String -Attribute Write -ValidateSet "IDE","SCSI" -Description "Specifies the controller type - IDE/SCSI where the disk is attached" - New-xDscResourceProperty -Name ControllerNumber -Type Uint32 -Attribute Write -ValidateSet 0,1,2,3 -Description "Specifies the number of the controller where the disk is attached" - New-xDscResourceProperty -Name ControllerLocation -Type Uint32 -Attribute Write -Description "Specifies the number of the location on the controller where the disk is attached" - New-xDscResourceProperty -Name Ensure -Type String -Attribute Write -ValidateSet "Present","Absent" -Description "Specifies if the hard disk drive must be present or absent" -) diff --git a/Misc/VMResourceGenerator.ps1 b/Misc/VMResourceGenerator.ps1 deleted file mode 100644 index 41d2451..0000000 --- a/Misc/VMResourceGenerator.ps1 +++ /dev/null @@ -1,26 +0,0 @@ - $name = New-xDscResourceProperty -Name Name -Type String -Attribute Key -Description "Name of the VM" - $vhdPath = New-xDscResourceProperty -Name VhdPath -Type String -Attribute Required -Description "VHD associated with the VM" - $switchName = New-xDscResourceProperty -Name SwitchName -Type String -Attribute Write -Description "Virtual switch associated with the VM" - $path = New-xDscResourceProperty -Name Path -Type String -Attribute Write -Description "Folder where the VM data will be stored" - $generation = New-xDscResourceProperty -Name Generation -Type String -Attribute Write -ValidateSet "Vhd","Vhdx" -Description "Associated Virtual disk format - Vhd or Vhdx" - $ensure = New-xDscResourceProperty -Name Ensure -Type String -Attribute Write -ValidateSet "Present","Absent" -Description "Should the VM be created or deleted" - $startupMem = New-xDscResourceProperty -Name StartupMemory -Type Uint64 -Attribute Write -Description "Startup RAM for the VM." - $minMem = New-xDscResourceProperty -Name MinimumMemory -Type Uint64 -Attribute Write -Description "Minimum RAM for the VM. This enables dynamic memory." - $maxMem = New-xDscResourceProperty -Name MaximumMemory -Type Uint64 -Attribute Write -Description "Maximum RAM for the VM. This enable dynamic memory." - $macAddress = New-xDscResourceProperty -Name MACAddress -Type String -Attribute Write -Description "MAC address of the VM." - $waitForIP = New-xDscResourceProperty -Name WaitForIP -Type Boolean -Attribute Write -Description "Waits for VM to get valid IP address." - $state = New-xDscResourceProperty -Name State -Type String -Attribute Write -ValidateSet "Running","Paused","Off" -Description "State of the VM." - $notes = New-xDscResourceProperty -Name Notes -Type String -Attribute Write -Description "Notes about the VM." - $procCount = New-xDscResourceProperty -Name ProcessorCount -Type Uint32 -Attribute Write -Description "Processor count for the VM" - $restartIfNeeded = New-xDscResourceProperty -Name RestartIfNeeded -Type Boolean -Attribute Write -Description "If specified, shutsdown and restarts the VM if needed for resource change" - - $id = New-xDscResourceProperty -Name ID -Type String -Attribute Read -Description "VM unique ID" - $status = New-xDscResourceProperty -Name Status -Type String -Attribute Read -Description "Status of the VM" - $CPUUsage = New-xDscResourceProperty -Name CPUUsage -Type Uint32 -Attribute Read -Description "CPU Usage of the VM" - $memAssigned = New-xDscResourceProperty -Name MemoryAssigned -Type Uint64 -Attribute Read -Description "Memory assigned to the VM" - $uptime = New-xDscResourceProperty -Name Uptime -Type String -Attribute Read -Description "Uptime of the VM" - $creationTime = New-xDscResourceProperty -Name CreationTime -Type DateTime -Attribute Read -Description "Creation time of the VM" - $hasDynamicMemory = New-xDscResourceProperty -Name HasDynamicMemory -Type Boolean -Attribute Read -Description "Does VM has dynamic memory enabled" - $networkAdapters = New-xDscResourceProperty -Name NetworkAdapters -Type String[] -Attribute Read -Description "Network adapters of the VM" - - New-xDscResource -Name MSFT_xVMHyperV -Property @($name,$vhdPath,$switchName,$state,$path,$generation,$startupMem,$minMem,$maxMem,$macAddress,$procCount,$waitForIP,$restartIfNeeded,$ensure, $notes,$id,$status,$CPUUsage,$memAssigned,$uptime,$creationTime,$hasDynamicMemory,$networkAdapters) -Path . -ClassVersion 1.0.0 -FriendlyName xVMHyperV diff --git a/Misc/VMScsiControllerGenerator.ps1 b/Misc/VMScsiControllerGenerator.ps1 deleted file mode 100644 index 4dd414a..0000000 --- a/Misc/VMScsiControllerGenerator.ps1 +++ /dev/null @@ -1,5 +0,0 @@ -New-xDscResource -Name MSFT_xVMScsiController -Path . -ClassVersion 1.0.0 -FriendlyName xVMScsiController -Property $( - New-xDscResourceProperty -Name VMName -Type String -Attribute Key -Description "Specifies the name of the virtual machine whose SCSI controller status is to be controlled" - New-xDscResourceProperty -Name ControllerNumber -Type Uint32 -Attribute Key -ValidateSet 0,1,2,3 -Description "Specifies the number of the SCSI controller whose status is to be controlled" - New-xDscResourceProperty -Name Ensure -Type String -Attribute Write -ValidateSet "Present","Absent" -Description "Specifies if the SCSI controller should exist or not" -) diff --git a/Misc/VMSwitchGenerator.ps1 b/Misc/VMSwitchGenerator.ps1 deleted file mode 100644 index 4d27ea9..0000000 --- a/Misc/VMSwitchGenerator.ps1 +++ /dev/null @@ -1,8 +0,0 @@ - $name = New-DscResourceProperty -Name Name -Type String -Attribute Key -Description "Name of the VM Switch" - $type = New-DscResourceProperty -Name Type -Type String -Attribute Key -ValidateSet "Internal","Private" -Description "Type of switch" - $netAdapter = New-DscResourceProperty -Name NetAdapterName -Type String -Attribute Write -Description "Network adapter name for external switch type" - $allowManagementOS = New-DscResourceProperty -Name AllowManagementOS -Type Boolean -Attribute Write -Description "Specify is the VM host has access to the physical NIC" - $ensure = New-DscResourceProperty -Name Ensure -Type String -Attribute Write -ValidateSet "Present","Absent" -Description "Whether switch should be present or absent" - $id = New-DscResourceProperty -Name Id -Type String -Attribute Read -Description "Unique ID for the switch" - $netDescription = New-DscResourceProperty -Name NetAdapterInterfaceDescription -Type String -Attribute Read -Description "Description of the network interface" - New-DscResource -Name MSFT_xVMSwitch -Path . -Properties $name,$type,$netAdapter,$allowManagementOS,$ensure,$id,$netDescription -ClassVersion 1.0.0.0 -FriendlyName xVMSwitch diff --git a/README.md b/README.md index ce8f76f..987765f 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,29 @@ # xHyper-V -The **xHyper-V** module contains DSC resources for deployment and configuration of - Hyper-V hosts, virtual machines and related resources. +[![Build Status](https://dev.azure.com/dsccommunity/xHyper-V/_apis/build/status/dsccommunity.xHyper-V?branchName=master)](https://dev.azure.com/dsccommunity/xHyper-V/_build/latest?definitionId=25&branchName=master) +![Azure DevOps coverage (branch)](https://img.shields.io/azure-devops/coverage/dsccommunity/xHyper-V/25/master) +[![codecov](https://codecov.io/gh/dsccommunity/xHyper-V/branch/master/graph/badge.svg)](https://codecov.io/gh/dsccommunity/xHyper-V) +[![Azure DevOps tests](https://img.shields.io/azure-devops/tests/dsccommunity/xHyper-V/25/master)](https://dsccommunity.visualstudio.com/xHyper-V/_test/analytics?definitionId=25&contextType=build) +[![PowerShell Gallery (with prereleases)](https://img.shields.io/powershellgallery/vpre/xHyper-V?label=xHyper-V%20Preview)](https://www.powershellgallery.com/packages/xHyper-V/) +[![PowerShell Gallery](https://img.shields.io/powershellgallery/v/xHyper-V?label=xHyper-V)](https://www.powershellgallery.com/packages/xHyper-V/) -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). -For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) - or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any - additional questions or comments. +The **xHyper-V** module contains DSC resources for deployment and configuration +of Hyper-V hosts, virtual machines and related resources. -## Branches +## Code of Conduct -### master +This project has adopted this [Code of Conduct](CODE_OF_CONDUCT.md). -[![Build status](https://ci.appveyor.com/api/projects/status/tsdbv0hgrxvmbo5y/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/xhyper-v/branch/master) -[![codecov](https://codecov.io/gh/PowerShell/xHyper-V/branch/master/graph/badge.svg)](https://codecov.io/gh/PowerShell/xHyper-V/branch/master) +## Releases -This is the branch containing the latest release - no contributions should be -made directly to this branch. - -### dev - -[![Build status](https://ci.appveyor.com/api/projects/status/tsdbv0hgrxvmbo5y/branch/dev?svg=true)](https://ci.appveyor.com/project/PowerShell/xhyper-v/branch/dev) -[![codecov](https://codecov.io/gh/PowerShell/xHyper-V/branch/dev/graph/badge.svg)](https://codecov.io/gh/PowerShell/xHyper-V/branch/dev) - -This is the development branch to which contributions should be proposed by -contributors as pull requests. This development branch will periodically be -merged to the master branch, and be released to [PowerShell Gallery](https://www.powershellgallery.com/). +For each merge to the branch `master` a preview release will be +deployed to [PowerShell Gallery](https://www.powershellgallery.com/). +Periodically a release version tag will be pushed which will deploy a +full release to [PowerShell Gallery](https://www.powershellgallery.com/). ## Contributing -Please check out common DSC Resources [contributing guidelines](https://github.com/PowerShell/DscResource.Kit/blob/master/CONTRIBUTING.md). +Please check out common DSC Community [contributing guidelines](https://dsccommunity.org/guidelines/contributing). ## Change log @@ -86,9 +80,9 @@ Manages VHDs in a Hyper-V host. #### Examples xVHD -* [Create a new VHD](/Examples/Sample_xVHD_NewVHD.ps1) -* [Create a new Fixed VHD](/Examples/Sample_xVHD_FixedVHD.ps1) -* [Create a differencing VHD](/Examples/Sample_xVHD_DiffVHD.ps1) +* [Create a new VHD](/source/Examples/Sample_xVHD_NewVHD.ps1) +* [Create a new Fixed VHD](/source/Examples/Sample_xVHD_FixedVHD.ps1) +* [Create a differencing VHD](/source/Examples/Sample_xVHD_DiffVHD.ps1) ### xVhdFile @@ -144,7 +138,7 @@ None #### Examples xVhdFile -* [Multiple examples](/Examples/Sample_xVhdFileExamples.ps1) +* [Multiple examples](/source/Examples) ### xVMDvdDrive @@ -174,7 +168,7 @@ None #### Examples xVMDvdDrive -* [Create a VM, given a VHDX and add a DVD Drives](/Examples/Sample_xVMHyperV_SimpleWithDVDDrive.ps1) +* [Create a VM, given a VHDX and add a DVD Drives](/source/Examples/Sample_xVMHyperV_SimpleWithDVDDrive.ps1) ### xVMHardDiskDrive @@ -212,8 +206,8 @@ None #### Examples xVMHardDiskDrive -* [Create a VM, with an OS drive and an additional data drive](/Examples/Sample_xVMHardDiskDrive_VMWithExtraDisk.ps1) -* [Create a VM, with an OS drive and 4 data drives](/Examples/Sample_xVMHardDiskDrive_VMWith4AdditionalDisks.ps1) +* [Create a VM, with an OS drive and an additional data drive](/source/Examples/Sample_xVMHardDiskDrive_VMWithExtraDisk.ps1) +* [Create a VM, with an OS drive and 4 data drives](/source/Examples/Sample_xVMHardDiskDrive_VMWith4AdditionalDisks.ps1) ### xVMHost @@ -281,7 +275,7 @@ None #### Examples xVMHost -* [Change VM Host paths](/Examples/Sample_xVMHost_Paths.ps1) +* [Change VM Host paths](/source/Examples/Sample_xVMHost_Paths.ps1) ### xVMHyperV @@ -347,10 +341,10 @@ The following properties **cannot** be changed after VM creation: #### Examples xVMHyperV -* [Create a VM (Simple)](/Examples/Sample_xVMHyperV_Simple.ps1) -* [Create a VM with dynamic memory](/Examples/Sample_xVMHyperV_DynamicMemory.ps1) -* [Create a VM (Complete)](/Examples/Sample_xVMHyperV_Complete.ps1) -* [Create a VM with multiple NICs attached to multiple switches](/Examples/Sample_xVMHyperV_MultipleNICs.ps1) +* [Create a VM (Simple)](/source/Examples/Sample_xVMHyperV_Simple.ps1) +* [Create a VM with dynamic memory](/source/Examples/Sample_xVMHyperV_DynamicMemory.ps1) +* [Create a VM (Complete)](/source/Examples/Sample_xVMHyperV_Complete.ps1) +* [Create a VM with multiple NICs attached to multiple switches](/source/Examples/Sample_xVMHyperV_MultipleNICs.ps1) ### xVMNetworkAdapter @@ -397,12 +391,12 @@ Manages VMNetadapters attached to a Hyper-V virtual machine or the management OS #### Examples xVMNetworkAdapter -* [Add a new VM Network adapter in the management OS](/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1) -* [Add multiple VM Network adapters to a VM](/Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1) -* [Add a couple of VM Network adapters in the management OS](/Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1) -* [Add multiple VM Network adapters to a VM using status MAC addresses](/Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1) -* [Add VM Network adapters to a VM with a Vlan tag](/Examples/Sample_xVMNetworkAdapter_VMVlanTagging.ps1) -* [Add VM Network adapters to a VM with a static IpAddress](/Examples/Sample_xVMNetworkAdapter_VMStaticNetworkSettings.ps1) +* [Add a new VM Network adapter in the management OS](/source/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1) +* [Add multiple VM Network adapters to a VM](/source/Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1) +* [Add a couple of VM Network adapters in the management OS](/source/Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1) +* [Add multiple VM Network adapters to a VM using status MAC addresses](/source/Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1) +* [Add VM Network adapters to a VM with a Vlan tag](/source/Examples/Sample_xVMNetworkAdapter_VMVlanTagging.ps1) +* [Add VM Network adapters to a VM with a static IpAddress](/source/Examples/Sample_xVMNetworkAdapter_VMStaticNetworkSettings.ps1) ### xVMProcessor @@ -453,7 +447,7 @@ None #### Examples xVMProcessor -* [Create a secure boot gen 2 VM for a given VHD with nested virtualisation enabled](/Examples/Sample_xVMHyperV_SimpleWithNestedVirtualization.ps1) +* [Create a secure boot gen 2 VM for a given VHD with nested virtualisation enabled](/source/Examples/Sample_xVMHyperV_SimpleWithNestedVirtualization.ps1) ### xVMScsiController @@ -480,7 +474,7 @@ None #### Examples xVMScsiController -* [Add a secondary SCSI controller](/Examples/Sample_xVMScsiController_AddControllers.ps1) +* [Add a secondary SCSI controller](/source/Examples/Sample_xVMScsiController_AddControllers.ps1) ### xVMSwitch @@ -518,6 +512,6 @@ Manages virtual switches in a Hyper-V host. #### Examples xVMSwitch -* [Create an internal VM Switch](/Examples/Sample_xVMSwitch_Internal.ps1) -* [Create an external VM Switch](/Examples/Sample_xVMSwitch_External.ps1) -* [Create an external VM Switch with embedded teaming](/Examples/Sample_xVMSwitch_ExternalSET.ps1) +* [Create an internal VM Switch](/source/Examples/Sample_xVMSwitch_Internal.ps1) +* [Create an external VM Switch](/source/Examples/Sample_xVMSwitch_External.ps1) +* [Create an external VM Switch with embedded teaming](/source/Examples/Sample_xVMSwitch_ExternalSET.ps1) diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 new file mode 100644 index 0000000..de9946e --- /dev/null +++ b/RequiredModules.psd1 @@ -0,0 +1,26 @@ +@{ + PSDependOptions = @{ + AddToPath = $true + Target = 'output\RequiredModules' + Parameters = @{ + Repository = '' + } + } + + InvokeBuild = 'latest' + PSScriptAnalyzer = 'latest' + Pester = 'latest' + Plaster = 'latest' + ModuleBuilder = '1.0.0' + ChangelogManagement = 'latest' + Sampler = 'latest' + MarkdownLinkCheck = 'latest' + 'DscResource.Test' = 'latest' + 'DscResource.AnalyzerRules' = 'latest' + xDscResourceDesigner = 'latest' + 'DscResource.DocGenerator' = 'latest' + + # Build dependent modules + 'DscResource.Common' = 'latest' +} + diff --git a/Resolve-Dependency.ps1 b/Resolve-Dependency.ps1 new file mode 100644 index 0000000..9541f73 --- /dev/null +++ b/Resolve-Dependency.ps1 @@ -0,0 +1,288 @@ +[CmdletBinding()] +param +( + [Parameter()] + [String] + $DependencyFile = 'RequiredModules.psd1', + + [Parameter()] + [String] + # Path for PSDepend to be bootstrapped and save other dependencies. + # Can also be CurrentUser or AllUsers if you wish to install the modules in such scope + # Default to $PWD.Path/output/modules + $PSDependTarget = (Join-Path $PSScriptRoot './output/RequiredModules'), + + [Parameter()] + [uri] + # URI to use for Proxy when attempting to Bootstrap PackageProvider & PowerShellGet + $Proxy, + + [Parameter()] + # Credential to contact the Proxy when provided + [PSCredential]$ProxyCredential, + + [Parameter()] + [ValidateSet('CurrentUser', 'AllUsers')] + [String] + # Scope to bootstrap the PackageProvider and PSGet if not available + $Scope = 'CurrentUser', + + [Parameter()] + [String] + # Gallery to use when bootstrapping PackageProvider, PSGet and when calling PSDepend (can be overridden in Dependency files) + $Gallery = 'PSGallery', + + [Parameter()] + [PSCredential] + # Credentials to use with the Gallery specified above + $GalleryCredential, + + + [Parameter()] + [switch] + # Allow you to use a locally installed version of PowerShellGet older than 1.6.0 (not recommended, default to $False) + $AllowOldPowerShellGetModule, + + [Parameter()] + [String] + # Allow you to specify a minimum version fo PSDepend, if you're after specific features. + $MinimumPSDependVersion, + + [Parameter()] + [Switch] + $AllowPrerelease, + + [Parameter()] + [Switch] + $WithYAML +) + +# Load Defaults for parameters values from Resolve-Dependency.psd1 if not provided as parameter +try +{ + Write-Verbose -Message "Importing Bootstrap default parameters from '$PSScriptRoot/Resolve-Dependency.psd1'." + $ResolveDependencyDefaults = Import-PowerShellDataFile -Path (Join-Path $PSScriptRoot '.\Resolve-Dependency.psd1' -Resolve -ErrorAction Stop) + $ParameterToDefault = $MyInvocation.MyCommand.ParameterSets.Where{ $_.Name -eq $PSCmdlet.ParameterSetName }.Parameters.Keys + if ($ParameterToDefault.Count -eq 0) + { + $ParameterToDefault = $MyInvocation.MyCommand.Parameters.Keys + } + # Set the parameters available in the Parameter Set, or it's not possible to choose yet, so all parameters are an option + foreach ($ParamName in $ParameterToDefault) + { + if (-Not $PSBoundParameters.Keys.Contains($ParamName) -and $ResolveDependencyDefaults.ContainsKey($ParamName)) + { + Write-Verbose -Message "Setting $ParamName with $($ResolveDependencyDefaults[$ParamName])" + try + { + $variableValue = $ResolveDependencyDefaults[$ParamName] + if ($variableValue -is [string]) + { + $variableValue = $ExecutionContext.InvokeCommand.ExpandString($variableValue) + } + $PSBoundParameters.Add($ParamName, $variableValue) + Set-Variable -Name $ParamName -value $variableValue -Force -ErrorAction SilentlyContinue + } + catch + { + Write-Verbose -Message "Error adding default for $ParamName : $($_.Exception.Message)" + } + } + } +} +catch +{ + Write-Warning -Message "Error attempting to import Bootstrap's default parameters from $(Join-Path $PSScriptRoot '.\Resolve-Dependency.psd1'): $($_.Exception.Message)." +} + +Write-Progress -Activity "Bootstrap:" -PercentComplete 0 -CurrentOperation "NuGet Bootstrap" + +if (!(Get-PackageProvider -Name NuGet -ForceBootstrap -ErrorAction SilentlyContinue)) +{ + $providerBootstrapParams = @{ + Name = 'nuget' + force = $true + ForceBootstrap = $true + ErrorAction = 'Stop' + } + + switch ($PSBoundParameters.Keys) + { + 'Proxy' + { + $providerBootstrapParams.Add('Proxy', $Proxy) + } + 'ProxyCredential' + { + $providerBootstrapParams.Add('ProxyCredential', $ProxyCredential) + } + 'Scope' + { + $providerBootstrapParams.Add('Scope', $Scope) + } + } + + if ($AllowPrerelease) + { + $providerBootstrapParams.Add('AllowPrerelease', $true) + } + + Write-Information "Bootstrap: Installing NuGet Package Provider from the web (Make sure Microsoft addresses/ranges are allowed)" + $null = Install-PackageProvider @providerBootstrapParams + $latestNuGetVersion = (Get-PackageProvider -Name NuGet -ListAvailable | Select-Object -First 1).Version.ToString() + Write-Information "Bootstrap: Importing NuGet Package Provider version $latestNuGetVersion to current session." + $Null = Import-PackageProvider -Name NuGet -RequiredVersion $latestNuGetVersion -Force +} + +Write-Progress -Activity "Bootstrap:" -PercentComplete 10 -CurrentOperation "Ensuring Gallery $Gallery is trusted" + +# Fail if the given PSGallery is not Registered +$Policy = (Get-PSRepository $Gallery -ErrorAction Stop).InstallationPolicy +Set-PSRepository -Name $Gallery -InstallationPolicy Trusted -ErrorAction Ignore +try +{ + Write-Progress -Activity "Bootstrap:" -PercentComplete 25 -CurrentOperation "Checking PowerShellGet" + # Ensure the module is loaded and retrieve the version you have + $PowerShellGetVersion = (Import-Module PowerShellGet -PassThru -ErrorAction SilentlyContinue).Version + + Write-Verbose "Bootstrap: The PowerShellGet version is $PowerShellGetVersion" + # Versions below 1.6.0 are considered old, unreliable & not recommended + if (!$PowerShellGetVersion -or ($PowerShellGetVersion -lt [System.version]'1.6.0' -and !$AllowOldPowerShellGetModule)) + { + Write-Progress -Activity "Bootstrap:" -PercentComplete 40 -CurrentOperation "Installing newer version of PowerShellGet" + $InstallPSGetParam = @{ + Name = 'PowerShellGet' + Force = $True + SkipPublisherCheck = $true + AllowClobber = $true + Scope = $Scope + Repository = $Gallery + } + + switch ($PSBoundParameters.Keys) + { + 'Proxy' + { + $InstallPSGetParam.Add('Proxy', $Proxy) + } + 'ProxyCredential' + { + $InstallPSGetParam.Add('ProxyCredential', $ProxyCredential) + } + 'GalleryCredential' + { + $InstallPSGetParam.Add('Credential', $GalleryCredential) + } + } + + Install-Module @InstallPSGetParam + Remove-Module PowerShellGet -force -ErrorAction SilentlyContinue + Import-Module PowerShellGet -Force + $NewLoadedVersion = (Get-Module PowerShellGet).Version.ToString() + Write-Information "Bootstrap: PowerShellGet version loaded is $NewLoadedVersion" + Write-Progress -Activity "Bootstrap:" -PercentComplete 60 -CurrentOperation "Installing newer version of PowerShellGet" + } + + # Try to import the PSDepend module from the available modules + try + { + $ImportPSDependParam = @{ + Name = 'PSDepend' + ErrorAction = 'Stop' + Force = $true + } + + if ($MinimumPSDependVersion) + { + $ImportPSDependParam.add('MinimumVersion', $MinimumPSDependVersion) + } + $null = Import-Module @ImportPSDependParam + } + catch + { + # PSDepend module not found, installing or saving it + if ($PSDependTarget -in 'CurrentUser', 'AllUsers') + { + Write-Debug "PSDepend module not found. Attempting to install from Gallery $Gallery" + Write-Warning "Installing PSDepend in $PSDependTarget Scope" + $InstallPSDependParam = @{ + Name = 'PSDepend' + Repository = $Gallery + Force = $true + Scope = $PSDependTarget + SkipPublisherCheck = $true + AllowClobber = $true + } + + if ($MinimumPSDependVersion) + { + $InstallPSDependParam.add('MinimumVersion', $MinimumPSDependVersion) + } + + Write-Progress -Activity "Bootstrap:" -PercentComplete 75 -CurrentOperation "Installing PSDepend from $Gallery" + Install-Module @InstallPSDependParam + } + else + { + Write-Debug "PSDepend module not found. Attempting to Save from Gallery $Gallery to $PSDependTarget" + $SaveModuleParam = @{ + Name = 'PSDepend' + Repository = $Gallery + Path = $PSDependTarget + } + + if ($MinimumPSDependVersion) + { + $SaveModuleParam.add('MinimumVersion', $MinimumPSDependVersion) + } + + Write-Progress -Activity "Bootstrap:" -PercentComplete 75 -CurrentOperation "Saving & Importing PSDepend from $Gallery to $Scope" + Save-Module @SaveModuleParam + } + } + finally + { + Write-Progress -Activity "Bootstrap:" -PercentComplete 100 -CurrentOperation "Loading PSDepend" + # We should have successfully bootstrapped PSDepend. Fail if not available + Import-Module PSDepend -ErrorAction Stop + } + + if ($WithYAML) + { + if (-Not (Get-Module -ListAvailable -Name 'PowerShell-Yaml')) + { + Write-Verbose "PowerShell-Yaml module not found. Attempting to Save from Gallery $Gallery to $PSDependTarget" + $SaveModuleParam = @{ + Name = 'PowerShell-Yaml' + Repository = $Gallery + Path = $PSDependTarget + } + + Save-Module @SaveModuleParam + Import-Module "PowerShell-Yaml" -ErrorAction Stop + } + else + { + Write-Verbose "PowerShell-Yaml is already available" + } + } + + Write-Progress -Activity "PSDepend:" -PercentComplete 0 -CurrentOperation "Restoring Build Dependencies" + if (Test-Path $DependencyFile) + { + $PSDependParams = @{ + Force = $true + Path = $DependencyFile + } + + # TODO: Handle when the Dependency file is in YAML, and -WithYAML is specified + Invoke-PSDepend @PSDependParams + } + Write-Progress -Activity "PSDepend:" -PercentComplete 100 -CurrentOperation "Dependencies restored" -Completed +} +finally +{ + # Reverting the Installation Policy for the given gallery + Set-PSRepository -Name $Gallery -InstallationPolicy $Policy + Write-Verbose "Project Bootstrapped, returning to Invoke-Build" +} diff --git a/Resolve-Dependency.psd1 b/Resolve-Dependency.psd1 new file mode 100644 index 0000000..2ae8c0d --- /dev/null +++ b/Resolve-Dependency.psd1 @@ -0,0 +1,5 @@ +@{ + Gallery = 'PSGallery' + AllowPrerelease = $false + WithYAML = $true +} diff --git a/Tests/Unit/HyperVCommon.tests.ps1 b/Tests/Unit/HyperVCommon.tests.ps1 deleted file mode 100644 index 1158f2e..0000000 --- a/Tests/Unit/HyperVCommon.tests.ps1 +++ /dev/null @@ -1,338 +0,0 @@ -$script:DSCModuleName = 'xHyper-V' -$script:DSCResourceName = 'HyperVCommon' - -#region HEADER -# Unit Test Template Version: 1.1.0 -[String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) -} - -Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceName ` - -TestType Unit -#endregion HEADER - -# Begin Testing -try -{ - #region Pester Tests - - $LocalizedData = InModuleScope $script:DSCResourceName { - $LocalizedData - } - - InModuleScope $script:DSCResourceName { - - Describe 'HyperVCommon\Set-VMProperty' { - - function Get-VM { - param - ( - [System.String] - $Name - ) - } - - function Get-VMProcessor { - param - ( - [System.String] - $VMName - ) - } - - function Set-VMProcessor { - param - ( - [System.String] - $VMName - ) - } - - # Guard mocks - Mock Get-VM { } - Mock Set-VMState { } - Mock Get-VMProcessor { } - Mock Set-VMProcessor { } - - It "Should throw if VM is running and 'RestartIfNeeded' is False" { - Mock Get-VM { return @{ State = 'Running' } } - - $setVMPropertyParams = @{ - VMName = 'Test'; - VMCommand = 'Set-VMProcessor'; - ChangeProperty = @{ ResourcePoolName = 'Dummy' } - } - { Set-VMProperty @setVMPropertyParams } | Should Throw 'RestartIfNeeded' - } - - It "Should stop and restart VM when running and 'RestartIfNeeded' is True" { - Mock Get-VM { return @{ State = 'Running' } } - - $setVMPropertyParams = @{ - VMName = 'Test'; - VMCommand = 'Set-VMProcessor'; - ChangeProperty = @{ ResourcePoolName = 'Dummy' } - RestartIfNeeded = $true; - } - Set-VMProperty @setVMPropertyParams - - Assert-MockCalled Set-VMState -ParameterFilter { $State -eq 'Off' } -Scope It - Assert-MockCalled Set-VMState -ParameterFilter { $State -eq 'Running' } -Scope It - } - - } - - Describe 'HyperVCommon\Set-VMState' { - - function Get-VM { - param - ( - [System.String] - $Name - ) - } - - function Resume-VM { - param - ( - [System.String] - $Name - ) - } - - function Start-VM { - param - ( - [System.String] - $Name - ) - } - - function Stop-VM { - param - ( - [System.String] - $Name - ) - } - - function Suspend-VM { - param - ( - [System.String] - $Name - ) - } - - # Guard mocks - Mock Resume-VM { } - Mock Start-VM { } - Mock Stop-VM { } - Mock Suspend-VM { } - Mock Wait-VMIPAddress { } - - It 'Should resume VM when current "State" is "Paused" and target state is "Running"' { - Mock Get-VM { return @{ State = 'Paused' } } - - Set-VMState -Name 'TestVM' -State 'Running' - - Assert-MockCalled Resume-VM -Scope It - Assert-MockCalled Wait-VMIPAddress -Scope It -Exactly 0 - } - - It 'Should resume VM and wait when current "State" is "Paused" and target state is "Running"' { - Mock Get-VM { return @{ State = 'Paused' } } - - Set-VMState -Name 'TestVM' -State 'Running' -WaitForIP $true - - Assert-MockCalled Resume-VM -Scope It - Assert-MockCalled Wait-VMIPAddress -Scope It - } - - It 'Should start VM when current "State" is "Off" and target state is "Running"' { - Mock Get-VM { return @{ State = 'Off' } } - - Set-VMState -Name 'TestVM' -State 'Running' - - Assert-MockCalled Start-VM -Scope It - Assert-MockCalled Wait-VMIPAddress -Scope It -Exactly 0 - } - - It 'Should start VM and wait when current "State" is "Off" and target state is "Running"' { - Mock Get-VM { return @{ State = 'Off' } } - - Set-VMState -Name 'TestVM' -State 'Running' -WaitForIP $true - - Assert-MockCalled Start-VM -Scope It - Assert-MockCalled Wait-VMIPAddress -Scope It - } - - It 'Should suspend VM when current "State" is "Running" and target state is "Paused"' { - Mock Get-VM { return @{ State = 'Running' } } - - Set-VMState -Name 'TestVM' -State 'Paused' - - Assert-MockCalled Suspend-VM -Scope It - } - - It 'Should stop VM when current "State" is "Running" and target state is "Off"' { - Mock Get-VM { return @{ State = 'Running' } } - - Set-VMState -Name 'TestVM' -State 'Off' - - Assert-MockCalled Stop-VM -Scope It - } - - It 'Should stop VM when current "State" is "Paused" and target state is "Off"' { - Mock Get-VM { return @{ State = 'Paused' } } - - Set-VMState -Name 'TestVM' -State 'Off' - - Assert-MockCalled Stop-VM -Scope It - } - } # describe HyperVCommon\Set-VMState - } - - Describe 'HyperVCommon\Wait-VMIPAddress' { - - function Get-VMNetworkAdapter { - param - ( - [System.String] - $VMName - ) - } - - # Guard mocks - Mock Get-VMNetworkAdapter -ModuleName $script:DSCResourceName { } - - It 'Should return when VM network adapter reports 2 IP addresses' { - Mock Get-VMNetworkAdapter -ModuleName $script:DSCResourceName { return @{ IpAddresses = @('192.168.0.1','172.16.0.1') } } - - $result = Wait-VMIPAddress -Name 'Test' - - $result | Should BeNullOrEmpty - } - - It 'Should throw when after timeout is exceeded' { - Mock Get-VMNetworkAdapter -ModuleName $script:DSCResourceName { return $null } - - { Wait-VMIPAddress -Name 'Test' -Timeout 2 } | Should Throw 'timed out' - } - } # describe HyperVCommon\WaitVMIPAddress - - Describe 'HyperVCommon\ConvertTo-TimeSpan' { - - It 'Should convert 60 seconds to "System.TimeSpan" of 1 minute' { - $testSeconds = 60 - - $result = ConvertTo-TimeSpan -TimeInterval $testSeconds -TimeIntervalType Seconds - - $result.TotalMinutes | Should Be 1 - } - - It 'Should convert 60 minutes to "System.TimeSpan" of 60 minutes' { - $testMinutes = 60 - - $result = ConvertTo-TimeSpan -TimeInterval $testMinutes -TimeIntervalType Minutes - - $result.TotalHours | Should Be 1 - } - - It 'Should convert 48 hours to "System.TimeSpan" of 2 days' { - $testHours = 48 - - $result = ConvertTo-TimeSpan -TimeInterval $testHours -TimeIntervalType Hours - - $result.TotalDays | Should Be 2 - } - - } # describe HyperVCommon\ConvertTo-TimeSpan - - Describe 'HyperVCommon\ConvertFrom-TimeSpan' { - - It 'Should convert a "System.TimeSpan" of 1 minute to 60 seconds' { - $testTimeSpan = New-TimeSpan -Minutes 1 - - $result = ConvertFrom-TimeSpan -TimeSpan $testTimeSpan -TimeSpanType Seconds - - $result | Should Be 60 - } - - It 'Should convert a "System.TimeSpan" of 1 hour to 60 minutes' { - $testTimeSpan = New-TimeSpan -Hours 1 - - $result = ConvertFrom-TimeSpan -TimeSpan $testTimeSpan -TimeSpanType Minutes - - $result | Should Be 60 - } - - It 'Should convert a "System.TimeSpan" of 2 dayes to 48 hours' { - $testTimeSpan = New-TimeSpan -Days 2 - - $result = ConvertFrom-TimeSpan -TimeSpan $testTimeSpan -TimeSpanType Hours - - $result | Should Be 48 - } - - } # describe HyperVCommon\ConvertFrom-TimeSpan - - Describe 'HyperVCommon\Get-VMHyperV' { - - function Get-VM { - [CmdletBinding()] - param - ( - $Name - ) - } - - # Guard mocks - Mock Get-VM -ModuleName $script:DSCResourceName { } - - It 'Should not throw when no VM is found' { - Mock Get-VM -ModuleName $script:DSCResourceName { } - $testVMName = 'TestVM' - - $result = Get-VMHyperV -VMName $testVMName - - $result | Should BeNullOrEmpty - } - - It 'Should not throw when one VM is found' { - Mock Get-VM -ModuleName $script:DSCResourceName { - Write-Output -InputObject ([PSCustomObject] @{ Name = $VMName }) - } - $testVMName = 'TestVM' - - $result = Get-VMHyperV -VMName $testVMName - - $result.Name | Should Be $testVMName - } - - It 'Should throw when more than one VM is found' { - Mock Get-VM -ModuleName $script:DSCResourceName { - Write-Output -InputObject ([PSCustomObject] @{ Name = $VMName }) - Write-Output -InputObject ([PSCustomObject] @{ Name = $VMName }) - } - $testVMName = 'TestVM' - - { Get-VMHyperV -VMName $testVMName } | Should Throw 'More than one VM' - } - - } # describe HyperVCommon\Get-VMHyperV - -} -finally -{ - #region FOOTER - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion - -} diff --git a/Tests/Unit/MSFT_xVMHyperV.Tests.ps1 b/Tests/Unit/MSFT_xVMHyperV.Tests.ps1 deleted file mode 100644 index 2c7f8fd..0000000 --- a/Tests/Unit/MSFT_xVMHyperV.Tests.ps1 +++ /dev/null @@ -1,669 +0,0 @@ -[CmdletBinding()] -param() - -if (!$PSScriptRoot) # $PSScriptRoot is not defined in 2.0 -{ - $PSScriptRoot = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path) -} - -$ErrorActionPreference = 'stop' -Set-StrictMode -Version latest - -$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path - -$ModuleName = 'MSFT_xVMHyperV' -Import-Module (Join-Path $RepoRoot "DSCResources\$ModuleName\$ModuleName.psm1") -Force; - -Describe 'xVMHyper-V' { - InModuleScope $ModuleName { - - # Create empty functions to be able to mock the missing Hyper-V cmdlets - # CmdletBinding required on Get-VM to support $ErrorActionPreference - function Get-VM { [CmdletBinding()] param( [Parameter(ValueFromRemainingArguments)] $Name) } - # Generation parameter is required for the mocking -ParameterFilter to work - function New-VM { param ( $Generation) } - function Set-VM { param ( $Name, $AutomaticCheckpointsEnabled ) } - function Stop-VM { } - function Remove-VM { } - function Get-VMNetworkAdapter { } - function Set-VMNetworkAdapter { } - function Add-VMNetworkAdapter { } - function Connect-VMNetworkAdapter { param ( $SwitchName ) } - function Get-VMFirmware { } - function Set-VMFirmware { } - function Get-VMIntegrationService { param ([Parameter(ValueFromPipeline)] $VM, $Name)} - function Enable-VMIntegrationService { param ([Parameter(ValueFromPipeline)] $VM, $Name)} - function Disable-VMIntegrationService { param ([Parameter(ValueFromPipeline)] $VM, $name)} - function Get-VHD { param ( $Path ) } - function Set-VMMemory { } - - $stubVhdxDisk = New-Item -Path 'TestDrive:\TestVM.vhdx' -ItemType File; - $studVhdxDiskSnapshot = New-Item -Path "TestDrive:\TestVM_D0145678-1576-4435-AB18-9F000C1C17D0.avhdx" -ItemType File; - $stubVhdDisk = New-Item -Path 'TestDrive:\TestVM.vhd' -ItemType File; - $StubVMConfig = New-Item -Path 'TestDrive:\TestVM.xml' -ItemType File; - $stubNIC1 = @{ SwitchName = 'Test Switch 1'; MacAddress = 'AA-BB-CC-DD-EE-FF'; IpAddresses = @('192.168.0.1','10.0.0.1'); }; - $stubNIC2 = @{ SwitchName = 'Test Switch 2'; MacAddress = 'AA-BB-CC-DD-EE-FE'; IpAddresses = @('192.168.1.1'); }; - $stubVM = @{ - HardDrives = @( - @{ Path = $stubVhdxDisk.FullName; } - @{ Path = $stubVhdDisk.FullName; } - ); - #State = 'Running'; - Path = $StubVMConfig.FullPath; - Generation = 1; - SecureBoot = $true; - MemoryStartup = 512MB; - MinimumMemory = 128MB; - MaximumMemory = 4096MB; - ProcessorCount = 1; - ID = [System.Guid]::NewGuid().ToString(); - CPUUsage = 10; - MemoryAssigned = 512MB; - Uptime = New-TimeSpan -Hours 12; - CreationTime = (Get-Date).AddHours(-12); - DynamicMemoryEnabled = $true; - NetworkAdapters = @($stubNIC1,$stubNIC2); - Notes = ''; - } - $stubGuestServiceInterfaceId = 'Microsoft:{0}\6C09BB55-D683-4DA0-8931-C9BF705F6480' -f $stubVM.ID - - Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'RunningVM' } -MockWith { - $runningVM = $stubVM.Clone(); - $runningVM['State'] = 'Running'; - return [PSCustomObject] $runningVM; - } - Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'StoppedVM' } -MockWith { - $stoppedVM = $stubVM.Clone(); - $stoppedVM['State'] = 'Off'; - return [PSCustomObject] $stoppedVM; - } - Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'PausedVM' } -MockWith { - $pausedVM = $stubVM.Clone(); - $pausedVM['State'] = 'Paused'; - return [PSCustomObject] $pausedVM; - } - Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'NonexistentVM' } -MockWith { - Write-Error 'VM not found.'; - } - Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'DuplicateVM' } -MockWith { - return @([PSCustomObject] $stubVM, [PSCustomObject] $stubVM); - } - Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'Generation1Vhd' } -MockWith { - $vhdVM = $stubVM.Clone(); - $vhdVM['HardDrives'] = @( @{ Path = $stubVhdDisk.FullName } ); - return [PSCustomObject] $vhdVM; - } - Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'Generation2VM' } -MockWith { - $gen2VM = $stubVM.Clone(); - $gen2VM['Generation'] = 2; - return [PSCustomObject] $gen2VM; - } - Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'VMWithAutomaticCheckpoints'} -MockWith { - $AutomaticCheckPointVM = $stubVM.Clone(); - $AutomaticCheckPointVM['AutomaticCheckpointsEnabled'] = $true; - return [PSCustomObject] $AutomaticCheckPointVM; - } - Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'VMWithoutAutomaticCheckpoints'} -MockWith { - $NoAutomaticCheckPointVM = $stubVM.Clone() - $NoAutomaticCheckPointVM['AutomaticCheckpointsEnabled'] = $false - return [PSCustomObject] $NoAutomaticCheckPointVM - } - Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'VMAutomaticCheckpointsUnsupported'} -MockWith { - $AutomaticCheckPointUnsupportedVM = $stubVM.Clone() - return [PSCustomObject] $AutomaticCheckPointUnsupportedVM - } - Mock -CommandName Get-VMIntegrationService -MockWith {return [pscustomobject]@{Enabled=$false;Id=$stubGuestServiceInterfaceId}} - Mock -CommandName Get-Module -ParameterFilter { ($Name -eq 'Hyper-V') -and ($ListAvailable -eq $true) } -MockWith { return $true; } - Mock -CommandName Get-VhdHierarchy -ParameterFilter { $VhdPath.EndsWith('.vhd') } -MockWith { - # Return single Vhd chain for .vhds - return @($stubVhdDisk.FullName); - } - Mock -CommandName Get-VhdHierarchy -ParameterFilter { $VhdPath.EndsWith('.vhdx') } -MockWith { - # Return snapshot hierarchy for .vhdxs - return @($stubVhdxDiskSnapshot.FullName, $stubVhdxDisk.FullName); - } - Context 'Validates Get-TargetResource Method' { - - It 'Returns a hashtable' { - $targetResource = Get-TargetResource -Name 'RunningVM' -VhdPath $stubVhdxDisk.FullName; - $targetResource -is [System.Collections.Hashtable] | Should Be $true; - } - - It 'Throws when multiple VMs are present' { - { Get-TargetResource -Name 'DuplicateVM' -VhdPath $stubVhdxDisk.FullName } | Should Throw; - } - - It 'Does not call Get-VMFirmware if a generation 1 VM' { - Mock -CommandName Get-VMFirmware -MockWith { throw; } - $null = Get-TargetResource -Name 'RunningVM' -VhdPath $stubVhdxDisk.FullName; - Assert-MockCalled -CommandName Get-VMFirmware -Scope It -Exactly 0; - } - - It 'Calls Get-VMFirmware if a generation 2 VM' { - Mock -CommandName Get-VMFirmware -MockWith { return $true; } - $null = Get-TargetResource -Name 'Generation2VM' -VhdPath $stubVhdxDisk.FullName; - Assert-MockCalled -CommandName Get-VMFirmware -Scope It -Exactly 1; - } - - It 'Hash table contains key EnableGuestService' { - $targetResource = Get-TargetResource -Name 'RunningVM' -VhdPath $stubVhdxDisk.FullName; - $targetResource.ContainsKey('EnableGuestService') | Should Be $true; - } - It 'Hash table contains key AutomaticCheckpointEnabled' { - $targetResource = Get-TargetResource -Name 'VMWithAutomaticCheckpoints' -VhdPath $stubVhdxDisk.FullName; - $targetResource.ContainsKey('AutomaticCheckpointsEnabled') | Should Be $true; - } - It 'Throws when Hyper-V Tools are not installed' { - # This test needs to be the last in the Context otherwise all subsequent Get-Module checks will fail - Mock -CommandName Get-Module -ParameterFilter { ($Name -eq 'Hyper-V') -and ($ListAvailable -eq $true) } -MockWith { } - { Get-TargetResource -Name 'RunningVM' @testParams } | Should Throw; - } - } #end context Validates Get-TargetResource Method - - Context 'Validates Test-TargetResource Method' { - $testParams = @{ - VhdPath = $stubVhdxDisk.FullName; - } - - It 'Returns a boolean' { - $targetResource = Test-TargetResource -Name 'RunningVM' @testParams; - $targetResource -is [System.Boolean] | Should Be $true; - } - - It 'Returns $true when VM is present and "Ensure" = "Present"' { - Test-TargetResource -Name 'RunningVM' @testParams | Should Be $true; - } - - It 'Returns $false when VM is not present and "Ensure" = "Present"' { - Test-TargetResource -Name 'NonexistentVM' @testParams | Should Be $false; - } - - It 'Returns $true when VM is not present and "Ensure" = "Absent"' { - Test-TargetResource -Name 'NonexistentVM' -Ensure Absent @testParams | Should Be $true; - } - - It 'Returns $false when VM is present and "Ensure" = "Absent"' { - Test-TargetResource -Name 'RunningVM' -Ensure Absent @testParams | Should Be $false; - } - - It 'Returns $true when VM is in the "Running" state and no state is explicitly specified' { - Test-TargetResource -Name 'RunningVM' @testParams | Should Be $true; - } - - It 'Returns $true when VM is in the "Stopped" state and no state is explicitly specified' { - Test-TargetResource -Name 'StoppedVM' @testParams | Should Be $true; - } - - It 'Returns $true when VM is in the "Paused" state and no state is explicitly specified' { - Test-TargetResource -Name 'PausedVM' @testParams | Should Be $true; - } - - It 'Returns $true when VM is in the "Running" state and requested "State" = "Running"' { - Test-TargetResource -Name 'RunningVM' @testParams | Should Be $true; - } - - It 'Returns $true when VM is in the "Off" state and requested "State" = "Off"' { - Test-TargetResource -Name 'StoppedVM' -State Off @testParams | Should Be $true; - } - - It 'Returns $true when VM is in the "Paused" state and requested "State" = Paused"' { - Test-TargetResource -Name 'PausedVM' -State Paused @testParams | Should Be $true; - } - - It 'Returns $false when VM is in the "Running" state and requested "State" = "Off"' { - Test-TargetResource -Name 'RunningVM' -State Off @testParams | Should Be $false; - } - - It 'Returns $false when VM is in the "Off" state and requested "State" = "Runnning"' { - Test-TargetResource -Name 'StoppedVM' -State Running @testParams | Should Be $false; - } - - It 'Returns $true when VM .vhd file is specified with a generation 1 VM' { - Test-TargetResource -Name 'Generation1Vhd' -VhdPath $stubVhdDisk -Generation 1 -Verbose | Should Be $true; - } - - It 'Returns $true when VM .vhdx file is specified with a generation 1 VM' { - Test-TargetResource -Name 'StoppedVM' -VhdPath $stubVhdxDisk -Generation 1 | Should Be $true; - } - - It 'Returns $true when VM .vhdx file is specified with a generation 2 VM' { - Mock -CommandName Test-VMSecureBoot -MockWith { return $true; } - Test-TargetResource -Name 'Generation2VM' -Generation 2 @testParams | Should Be $true; - } - - It 'Throws when a VM .vhd file is specified with a generation 2 VM' { - { Test-TargetResource -Name 'Gen2VM' -VhdPath $stubVhdDisk -Generation 2 } | Should Throw; - } - - It 'Returns $true when multiple NICs are assigned in the correct order' { - Test-TargetResource -Name 'RunningVM' @testParams -SwitchName @($stubNIC1.SwitchName,$stubNIC2.SwitchName) | Should Be $true; - } - - It 'Returns $false when multiple NICs are not assigned/assigned in the wrong order' { - Test-TargetResource -Name 'RunningVM' @testParams -SwitchName @($stubNIC2.SwitchName,$stubNIC1.SwitchName) | Should Be $false; - } - - It 'Returns $true when multiple MAC addresses are assigned in the correct order' { - Test-TargetResource -Name 'RunningVM' @testParams -MACAddress @($stubNIC1.MACAddress,$stubNIC2.MACAddress) | Should Be $true; - } - - It 'Returns $false when multiple MAC addresses not assigned/assigned in the wrong order' { - Test-TargetResource -Name 'RunningVM' @testParams -MACAddress @($stubNIC1.MACAddress,$stubNIC2.MACAddress) | Should Be $true; - } - - It 'Returns $true regardless of "SecureBoot" setting on a generation 1 VM' { - Test-TargetResource -Name 'RunningVM' -SecureBoot $true @testParams | Should Be $true; - Test-TargetResource -Name 'RunningVM' -SecureBoot $false @testParams | Should Be $true; - } - - It 'Returns $true when SecureBoot is On and requested "SecureBoot" = "$true"' { - Mock -CommandName Test-VMSecureBoot -MockWith { return $true; } - Test-TargetResource -Name 'Generation2VM' -Generation 2 @testParams | Should Be $true; - } - - It 'Returns $false when SecureBoot is On and requested "SecureBoot" = "$false"' { - Mock -CommandName Test-VMSecureBoot -MockWith { return $true; } - Test-TargetResource -Name 'Generation2VM' -SecureBoot $false -Generation 2 @testParams | Should be $false; - } - - It 'Returns $true when VM has snapshot chain' { - Mock -CommandName Get-VhdHierarchy -MockWith { Write-Host $VhdPath; return @($studVhdxDiskSnapshot, $stubVhdxDisk); } - Test-TargetResource -Name 'Generation2VM' -VhdPath $stubVhdxDisk -Verbose | Should Be $true; - } - - It 'Returns $false when EnableGuestService is off and requested "EnableGuestService" = "$true"' { - Test-TargetResource -Name 'RunningVM' -EnableGuestService $true @testParams | Should be $false; - } - - It 'Returns $true when EnableGuestService is off and "EnableGuestService" is not requested"' { - Test-TargetResource -Name 'RunningVM' @testParams | Should be $true; - } - - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'Set-VM' -and $Module -eq 'Hyper-V'} -MockWith { - [pscustomobject]@{ - parameters = @{ - # Does not contains parameter AutomaticCheckpointsEnabled - } - } - } - It 'Throws when AutomaticCheckpointsEnabled is configured but not supported' { - { Test-TargetResource -Name 'VMAutomaticCheckpoinstUnsupported' -AutomaticCheckpointsEnabled $true @testParams } | Should Throw; - } - - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'Set-VM' -and $Module -eq 'Hyper-V'} -MockWith { - [pscustomobject]@{ - parameters = @{ - 'AutomaticCheckpointsEnabled' = '' - } - } - } - It 'Returns $true when AutomaticCheckpointsEnabled is on and requested "AutomaticCheckpointsEnabled" is not requested' { - Test-TargetResource -Name 'VMWithAutomaticCheckpoints' @testParams | Should be $true; - } - It 'Returns $true when AutomaticCheckpointsEnabled is on and requested "AutomaticCheckpointsEnabled" = "$true"' { - Test-TargetResource -Name 'VMWithAutomaticCheckpoints' -AutomaticCheckpointsEnabled $true @testParams | Should be $true; - } - It 'Returns $true when AutomaticCheckpointsEnabled is off and requested "AutomaticCheckpointsEnabled" = "$false"' { - Test-TargetResource -Name 'VMWithoutAutomaticCheckpoints' -AutomaticCheckpointsEnabled $false @testParams | Should be $true; - } - It 'Returns $false when AutomaticCheckpointsEnabled is off and requested "AutomaticCheckpointsEnabled" = "$true"' { - Test-TargetResource -Name 'VMWithoutAutomaticCheckpoints' -AutomaticCheckpointsEnabled $true @testParams | Should be $false; - } - It 'Returns $false when AutomaticCheckpointsEnabled is on and requested "AutomaticCheckpointsEnabled" = "$false"' { - Test-TargetResource -Name 'VMWithAutomaticCheckpoints' -AutomaticCheckpointsEnabled $false @testParams | Should be $false; - } - - It 'Returns $true when EnableGuestService is on and requested "EnableGuestService" = "$true"' { - Mock -CommandName Get-VMIntegrationService -MockWith {return [pscustomobject]@{Enabled=$true;Id=$stubGuestServiceInterfaceId}} - Test-TargetResource -Name 'RunningVM' -EnableGuestService $true @testParams | Should be $true; - } - - It 'Throws when Hyper-V Tools are not installed' { - # This test needs to be the last in the Context otherwise all subsequent Get-Module checks will fail - Mock -CommandName Get-Module -ParameterFilter { ($Name -eq 'Hyper-V') -and ($ListAvailable -eq $true) } -MockWith { } - { Test-TargetResource -Name 'RunningVM' @testParams } | Should Throw; - } - - } #end context Validates Test-TargetResource Method - - Context 'Validates Set-TargetResource Method' { - $testParams = @{ - VhdPath = $stubVhdxDisk.FullName; - } - - Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'NewVM' } -MockWith { } - Mock -CommandName New-VM -MockWith { - $newVM = $stubVM.Clone(); - $newVM['State'] = 'Off'; - $newVM['Generation'] = $Generation; - return $newVM; - } - Mock -CommandName Set-VM -MockWith { return $true; } - Mock -CommandName Stop-VM -MockWith { return $true; } # requires output to be able to pipe something into Remove-VM - Mock -CommandName Remove-VM -MockWith { return $true; } - Mock -CommandName Set-VMNetworkAdapter -MockWith { return $true; } - Mock -CommandName Get-VMNetworkAdapter -MockWith { return $stubVM.NetworkAdapters.IpAddresses; } - Mock -CommandName Set-VMState -MockWith { return $true; } - Mock -CommandName Set-VMMemory -MockWith { } - - It 'Removes an existing VM when "Ensure" = "Absent"' { - Set-TargetResource -Name 'RunningVM' -Ensure Absent @testParams; - Assert-MockCalled -CommandName Remove-VM -Scope It; - } - - It 'Creates and starts a VM VM with disabled dynamic memory that does not exist when "Ensure" = "Present" and "State" = "Running"' { - Set-TargetResource -Name 'NewVM' -State Running @testParams; - Assert-MockCalled -CommandName New-VM -Exactly -Times 1 -Scope It; - Assert-MockCalled -CommandName Set-VM -Exactly -Times 1 -Scope It; - Assert-MockCalled -CommandName Set-VMState -Exactly -Times 1 -Scope It; - } - - It 'Creates but does not start a VM with disabled dynamic memory that does not exist when "Ensure" = "Present"' { - Set-TargetResource -Name 'NewVM' @testParams; - Assert-MockCalled -CommandName New-VM -Exactly -Times 1 -Scope It; - Assert-MockCalled -CommandName Set-VM -Exactly -Times 1 -Scope It; - Assert-MockCalled -CommandName Set-VMState -Exactly -Times 0 -Scope It; - } - - It 'Creates but does not start a VM with disabled dynamic memory when only StartupMemory is specified' { - Set-TargetResource -Name 'NewVM' @testParams -StartupMemory 4GB; - Assert-MockCalled -CommandName New-VM -Exactly -Times 1 -Scope It; - Assert-MockCalled -CommandName Set-VM -Exactly -Times 1 -Scope It - Assert-MockCalled -CommandName Set-VMState -Exactly -Times 0 -Scope It; - } - - It 'Creates but does not start a VM with disabled dynamic memory when identical values for startup, minimum and maximum memory are specified' { - Set-TargetResource -Name 'NewVM' @testParams -StartupMemory 4GB -MinimumMemory 4GB -MaximumMemory 4GB; - Assert-MockCalled -CommandName New-VM -Exactly -Times 1 -Scope It - Assert-MockCalled -CommandName Set-VM -Exactly -Times 1 -Scope It - Assert-MockCalled -CommandName Set-VMMemory -Exactly -Times 1 -Scope It - Assert-MockCalled -CommandName Set-VMState -Exactly -Times 0 -Scope It - } - - It 'Creates but does not start a VM with enabled dynamic memory because a MinimumMemory value is specified' { - Set-TargetResource -Name 'NewVM' @testParams -MinimumMemory 512MB - Assert-MockCalled -CommandName New-VM -Exactly -Times 1 -Scope It - Assert-MockCalled -CommandName Set-VM -Exactly -Times 1 -Scope It - Assert-MockCalled -CommandName Set-VMMemory -Exactly -Times 0 -Scope It - Assert-MockCalled -CommandName Set-VMState -Exactly -Times 0 -Scope It - } - - It 'Creates but does not start a VM with enabled dynamic memory because a MaximumMemory value is specified' { - Set-TargetResource -Name 'NewVM' @testParams -MaximumMemory 16GB - Assert-MockCalled -CommandName New-VM -Exactly -Times 1 -Scope It - Assert-MockCalled -CommandName Set-VM -Exactly -Times 1 -Scope It - Assert-MockCalled -CommandName Set-VMMemory -Exactly -Times 0 -Scope It - Assert-MockCalled -CommandName Set-VMState -Exactly -Times 0 -Scope It - } - - It 'Does not change VM state when VM "State" = "Running" and requested "State" = "Running"' { - Set-TargetResource -Name 'RunningVM' -State Running @testParams; - Assert-MockCalled -CommandName Set-VMState -Exactly -Times 0 -Scope It; - } - - It 'Does not change VM state when VM "State" = "Off" and requested "State" = "Off"' { - Set-TargetResource -Name 'StoppedVM' -State Off @testParams; - Assert-MockCalled -CommandName Set-VMState -Exactly -Times 0 -Scope It; - } - - It 'Changes VM state when existing VM "State" = "Off" and requested "State" = "Running"' { - Set-TargetResource -Name 'StoppedVM' -State Running @testParams; - Assert-MockCalled -CommandName Set-VMState -Exactly -Times 1 -Scope It; - } - - It 'Changes VM state when existing VM "State" = "Running" and requested "State" = "Off"' { - Set-TargetResource -Name 'RunningVM' -State Off @testParams; - Assert-MockCalled -CommandName Set-VMState -Exactly -Times 1 -Scope It; - } - - It 'Creates a generation 1 VM by default/when not explicitly specified' { - Set-TargetResource -Name 'NewVM' @testParams; - Assert-MockCalled -CommandName New-VM -ParameterFilter { $Generation -eq 1 } -Scope It; - } - - It 'Creates a generation 1 VM when explicitly specified' { - Set-TargetResource -Name 'NewVM' -Generation 1 @testParams; - Assert-MockCalled -CommandName New-VM -ParameterFilter { $Generation -eq 1 } -Scope It; - } - - It 'Creates a generation 2 VM when explicitly specified' { - Set-TargetResource -Name 'NewVM' -Generation 2 @testParams; - Assert-MockCalled -CommandName New-VM -ParameterFilter { $Generation -eq 2 } -Scope It; - } - - It 'Calls "Add-VMNetworkAdapter" for each NIC when creating a new VM' { - Mock -CommandName Add-VMNetworkAdapter -MockWith { } - Set-TargetResource -Name 'NewVM' @testParams -SwitchName 'Switch1','Switch2'; - # The first NIC is assigned during the VM creation - Assert-MockCalled -CommandName Add-VMNetworkAdapter -Exactly 1 -Scope It; - } - - It 'Calls "Connect-VMNetworkAdapter" for each existing NIC when updating an existing VM' { - Mock -CommandName Connect-VMNetworkAdapter -MockWith { } - Set-TargetResource -Name 'StoppedVM' @testParams -SwitchName 'Switch1','Switch2'; - # The first NIC is assigned during the VM creation - Assert-MockCalled -CommandName Connect-VMNetworkAdapter -Exactly 2 -Scope It; - } - - It 'Calls "Add-VMNetworkAdapter" for each missing NIC when updating an existing VM' { - Mock -CommandName Connect-VMNetworkAdapter -MockWith { } - Mock -CommandName Add-VMNetworkAdapter -MockWith { } - Set-TargetResource -Name 'StoppedVM' @testParams -SwitchName 'Switch1','Switch2','Switch3'; - # The first NIC is assigned during the VM creation - Assert-MockCalled -CommandName Connect-VMNetworkAdapter -Exactly 2 -Scope It; - Assert-MockCalled -CommandName Add-VMNetworkAdapter -Exactly 1 -Scope It; - } - - It 'Does not change switch assignments if no switch assignments are specified' { - Mock -CommandName Connect-VMNetworkAdapter -MockWith { } - Set-TargetResource -Name 'StoppedVM' @testParams; - Assert-MockCalled -CommandName Connect-VMNetworkAdapter -Exactly 0 -Scope It; - } - - It 'Does not change NIC assignments if the switch assisgnments are correct' { - Mock -CommandName Set-VMNetworkAdapter -MockWith { } - Set-TargetResource -Name 'StoppedVM' @testParams -SwitchName $stubNIC1.SwitchName,$stubNIC2.SwitchName; - Assert-MockCalled -CommandName Set-VMNetworkAdapter -Exactly 0 -Scope It; - } - - It 'Errors when updating MAC addresses on a running VM and "RestartIfNeeded" = "$false"' { - { Set-TargetResource -Name 'RunningVM' @testParams -MACAddress 'AABBCCDDEEFE','AABBCCDDEEFF' -ErrorAction Stop } | Should Throw; - } - - It 'Does not change MAC addresses if no MAC addresses assignments are specified' { - Mock -CommandName Set-VMNetworkAdapter -ParameterFilter { $StaticMacAddress -ne $null } -MockWith { } - Set-TargetResource -Name 'StoppedVM' @testParams; - Assert-MockCalled -CommandName Set-VMNetworkAdapter -ParameterFilter { $StaticMacAddress -ne $null } -Exactly 0 -Scope It; - } - - It 'Calls "Set-VMNetworkAdapter" for each MAC address on a stopped VM' { - Mock -CommandName Set-VMNetworkAdapter -MockWith { } - Set-TargetResource -Name 'StoppedVM' @testParams -MACAddress 'AABBCCDDEEFE','AABBCCDDEEFF'; - # The first NIC is assigned during the VM creation - Assert-MockCalled -CommandName Set-VMNetworkAdapter -Exactly 2 -Scope It; - } - - It 'Does not change Secure Boot call "Set-VMProperty" when creating a generation 1 VM' { - Mock Set-VMProperty -MockWith { } - Set-TargetResource -Name 'RunningVM' @testParams; - Assert-MockCalled Set-VMProperty -ParameterFilter { $VMCommand -eq 'Set-VMFirmware' } -Exactly 0 -Scope It; - } - - It 'Does call "Set-VMProperty" when creating a generation 2 VM' { - Mock Test-VMSecureBoot -MockWith { return $true; } - Mock Set-VMProperty -MockWith { } - Set-TargetResource -Name 'RunningVM' -Generation 2 -SecureBoot $false @testParams; - Assert-MockCalled Set-VMProperty -ParameterFilter { $VMCommand -eq 'Set-VMFirmware' } -Exactly 1 -Scope It; - } - - It 'Does not change Secure Boot for generation 1 VM' { - Mock Test-VMSecureBoot -MockWith { return $true; } - Mock Set-VMProperty -MockWith { } - Set-TargetResource -Name 'StoppedVM' -SecureBoot $true @testParams; - Set-TargetResource -Name 'StoppedVM' -SecureBoot $false @testParams; - Assert-MockCalled Set-VMProperty -ParameterFilter { $VMCommand -eq 'Set-VMFirmware' } -Exactly 0 -Scope It; - } - - It 'Does not change Secure Boot for generation 2 VM with VM "SecureBoot" match' { - Mock Test-VMSecureBoot -MockWith { return $true; } - Mock Set-VMProperty -MockWith { } - Set-TargetResource -Name 'StoppedVM' -SecureBoot $true -Generation 2 @testParams; - Assert-MockCalled Set-VMProperty -ParameterFilter { $VMCommand -eq 'Set-VMFirmware' } -Exactly 0 -Scope It; - } - - It 'Does change Secure Boot for generation 2 VM with VM "SecureBoot" mismatch' { - Mock Test-VMSecureBoot -MockWith { return $false; } - Mock Set-VMProperty -MockWith { } - Set-TargetResource -Name 'StoppedVM' -SecureBoot $true -Generation 2 @testParams; - Assert-MockCalled Set-VMProperty -ParameterFilter { $VMCommand -eq 'Set-VMFirmware' } -Exactly 1 -Scope It; - } - - It 'Does call "Enable-VMIntegrationService" when "EnableGuestService" = "$true"' { - Mock -CommandName Enable-VMIntegrationService -MockWith { } - Set-TargetResource -Name 'RunningVM' -EnableGuestService $true @testParams - Assert-MockCalled -CommandName Enable-VMIntegrationService -Exactly -Times 1 -Scope It - } - - It 'Does call "Disable-VMIntegrationService" when "Guest Service Interface" = "Enabled" and "EnableGuestService" = "$false" specified' { - Mock -CommandName Disable-VMIntegrationService -MockWith { } - Mock -CommandName Get-VMIntegrationService -MockWith {return [pscustomobject]@{Enabled=$true;Id=$stubGuestServiceInterfaceId}} - Set-TargetResource -Name 'RunningVM' -EnableGuestService $false @testParams - Assert-MockCalled -CommandName Disable-VMIntegrationService -Exactly -Times 1 -Scope It - } - - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'Set-VM' -and $Module -eq 'Hyper-V'} -MockWith { - [pscustomobject]@{ - parameters = @{ - # Does not contain parameter AutomaticCheckpointsEnabled - } - } - } - It 'Throws when AutomaticCheckpointsEnabled is configured but not supported' { - { Set-TargetResource -Name 'VMAutomaticCheckpointsUnsupported' -AutomaticCheckpointsEnabled $true @testParams } | Should Throw; - } - It 'Does not call "Set-VM" when "AutomaticCheckpointsEnabled" is unsupported and unspecified' { - Set-TargetResource -Name 'VMAutomaticCheckpointsUnsupported' @testParams - Assert-MockCalled -CommandName Set-VM -Exactly -Times 0 -Scope It - } - - Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'Set-VM' -and $Module -eq 'Hyper-V'} -MockWith { - [pscustomobject]@{ - parameters = @{ - 'AutomaticCheckpointsEnabled' = '' - } - } - } - $AutomaticCheckpointsEnabledTestCases = @( - @{ - VMName = 'VMWithAutomaticCheckpoints' - SetAutomaticCheckpointsEnabled = $true - Assert = 'Does not call "Set-VM"' - Times = 0 - }, - @{ - VMName = 'VMWithoutAutomaticCheckpoints' - SetAutomaticCheckpointsEnabled = $false - Assert = 'Does not call "Set-VM"' - Times = 0 - }, - @{ - VMName = 'VMWithAutomaticCheckpoints' - SetAutomaticCheckpointsEnabled = $false - Assert = 'Does call "Set-VM"' - Times = 1 - }, - @{ - VMName = 'VMWithoutAutomaticCheckpoints' - SetAutomaticCheckpointsEnabled = $true - Assert = 'Does call "Set-VM"' - Times = 1 - } - ) - It ' on VM when "AutomaticCheckpointsEnabled" is set to ""' -TestCases $AutomaticCheckpointsEnabledTestCases { - Param($VMName,$SetAutomaticCheckpointsEnabled,$Times) - Set-TargetResource -Name $VMName -AutomaticCheckpointsEnabled $SetAutomaticCheckpointsEnabled @testParams - Assert-MockCalled -CommandName Set-VM -ParameterFilter {$Name -eq $VMName -and $AutomaticCheckpointsEnabled -eq $SetAutomaticCheckpointsEnabled} -Exactly -Times $Times -Scope It - } - It 'Disables dynamic memory of RuningVM if only StartupMemory specified' { - Mock Set-VMProperty -MockWith { } - Set-TargetResource -Name 'RunningVM' -StartupMemory 4GB @testParams - Assert-MockCalled -CommandName Set-VMProperty -ParameterFilter { - $VMCommand -eq 'Set-VM' -and - ($ChangeProperty.StaticMemory -eq $true) -and - ($ChangeProperty.DynamicMemory -eq $false) - } -Exactly -Times 1 -Scope It - } - - It 'Disables dynamic memory of RuningVM if StartupMemory, MinimumMemory and MaximumMemory are specified with the same values' { - Mock Set-VMProperty -MockWith { } - Set-TargetResource -Name 'RunningVM' -StartupMemory 4GB -MinimumMemory 4GB -MaximumMemory 4GB @testParams - Assert-MockCalled -CommandName Set-VMProperty -ParameterFilter { - $VMCommand -eq 'Set-VM' -and - ($ChangeProperty.StaticMemory -eq $true) -and - ($ChangeProperty.DynamicMemory -eq $false) - } -Exactly -Times 1 -Scope It - } - - It 'Enables dynamic memory of RuningVM if MinimumMemory is specified ' { - Mock Set-VMProperty -MockWith { } - Set-TargetResource -Name 'RunningVM' -MinimumMemory 4GB @testParams - Assert-MockCalled -CommandName Set-VMProperty -ParameterFilter { - $VMCommand -eq 'Set-VM' -and - ($ChangeProperty.StaticMemory -eq $false) -and - ($ChangeProperty.DynamicMemory -eq $true) - } -Exactly -Times 1 -Scope It - } - - It 'Enables dynamic memory of RuningVM if MaximumMemory is specified ' { - Mock Set-VMProperty -MockWith { } - Set-TargetResource -Name 'RunningVM' -MaximumMemory 4GB @testParams - Assert-MockCalled -CommandName Set-VMProperty -ParameterFilter { - $VMCommand -eq 'Set-VM' -and - ($ChangeProperty.StaticMemory -eq $false) -and - ($ChangeProperty.DynamicMemory -eq $true) - } -Exactly -Times 1 -Scope It - } - - It 'Throws when Hyper-V Tools are not installed' { - Mock -CommandName Get-Module -ParameterFilter { ($Name -eq 'Hyper-V') -and ($ListAvailable -eq $true) } -MockWith { } - { Set-TargetResource -Name 'RunningVM' @testParams } | Should Throw; - } - } #end context Validates Set-TargetResource Method - - Context 'Validates Test-VMSecureBoot Method' { - - It 'Returns $true when "SecureBoot" = "On"' { - Mock -CommandName Get-VM -MockWith { } - Mock -CommandName Get-VMFirmware -MockWith { return [PSCustomObject] @{ SecureBoot = 'On' }; } - Test-VMSecureBoot -Name 'TestVM' | Should Be $true; - } - - It 'Returns $false when "SecureBoot" = "Off"' { - Mock -CommandName Get-VM -MockWith { } - Mock -CommandName Get-VMFirmware -MockWith { return [PSCustomObject] @{ SecureBoot = 'Off' }; } - Test-VMSecureBoot -Name 'TestVM' | Should Be $false; - } - - } #end context Validates Test-VMSecureBoot Method - - Context 'Validates Get-VhdHierarchy Method' { - - It 'Does not throw with null parent path (#52)' { - - # Must use a different file extension to ensure existing mocks Get-VhdHierarchy or not called - $fakeVhdPath = 'BaseVhd.avhdx'; - Mock -CommandName Get-VHD -ParameterFilter { $Path -eq $fakeVhdPath } -MockWith { - return [PSCustomObject] @{ - Path = $fakeVhdPath; - ParentPath = $null; - } - } - - { Get-VhdHierarchy -VhdPath $fakeVhdPath } | Should Not Throw; - } - - } #end context validates Get-VhdHierarchy - - - } #end inmodulescope -} #end describe xVMHyper-V diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 0b5eafc..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,42 +0,0 @@ -#---------------------------------# -# environment configuration # -#---------------------------------# - -version: 3.9.{build}.0 -environment: - gallery_api: - secure: 9ekJzfsPCDBkyLrfmov83XbbhZ6E2N3z+B/Io8NbDetbHc6hWS19zsDmy7t0Vvxv - -install: - - git clone https://github.com/PowerShell/DscResource.Tests - - ps: Write-Verbose -Message "PowerShell version $($PSVersionTable.PSVersion)" -Verbose - - ps: Import-Module -Name "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" - - ps: Invoke-AppveyorInstallTask - -#---------------------------------# -# build configuration # -#---------------------------------# - -build: false - -#---------------------------------# -# test configuration # -#---------------------------------# - -test_script: - - ps: | - Invoke-AppveyorTestScriptTask -CodeCoverage -CodeCovIo - -# scripts to run before deployment -after_test: - - ps: | - Import-Module -Name "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" - Invoke-AppveyorAfterTestTask - -#---------------------------------# -# deployment configuration # -#---------------------------------# - -deploy_script: - - ps: | - Invoke-AppVeyorDeployTask diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..3dc0fe1 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,230 @@ +trigger: + branches: + include: + - master + paths: + exclude: + - CHANGELOG.md + tags: + include: + - "v*" + exclude: + - "*-*" +variables: + buildFolderName: output + buildArtifactName: output + testResultFolderName: testResults + testArtifactName: testResults + +stages: + - stage: Build + jobs: + - job: Package_Module + displayName: 'Package Module' + pool: + vmImage: 'ubuntu 16.04' + steps: + - task: GitVersion@5 + name: gitVersion + displayName: 'Evaluate Next Version' + inputs: + runtime: 'core' + configFilePath: 'GitVersion.yml' + - task: PowerShell@2 + name: package + displayName: 'Build & Package Module' + inputs: + filePath: './build.ps1' + arguments: '-ResolveDependency -tasks pack' + pwsh: true + env: + ModuleVersion: $(gitVersion.InformationalVersion) + - task: PublishBuildArtifacts@1 + displayName: 'Publish Build Artifact' + inputs: + pathToPublish: '$(buildFolderName)/' + artifactName: $(buildArtifactName) + publishLocation: 'Container' + + - stage: Test + dependsOn: Build + jobs: + - job: Test_HQRM + displayName: 'HQRM' + pool: + vmImage: 'windows-2019' + timeoutInMinutes: 0 + steps: + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifact' + inputs: + buildType: 'current' + downloadType: 'single' + artifactName: 'output' + downloadPath: '$(Build.SourcesDirectory)' + - task: PowerShell@2 + name: test + displayName: 'Run HQRM Test' + inputs: + filePath: './build.ps1' + arguments: '-Tasks hqrmtest' + pwsh: false + - task: PublishTestResults@2 + displayName: 'Publish Test Results' + condition: succeededOrFailed() + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: 'output/testResults/NUnit*.xml' + testRunTitle: 'HQRM' + + - job: Test_Unit + displayName: 'Unit' + pool: + vmImage: 'windows-2019' + timeoutInMinutes: 0 + steps: + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifact' + inputs: + buildType: 'current' + downloadType: 'single' + artifactName: $(buildArtifactName) + downloadPath: '$(Build.SourcesDirectory)' + - task: PowerShell@2 + name: test + displayName: 'Run Unit Test' + inputs: + filePath: './build.ps1' + arguments: "-Tasks test -PesterScript 'tests/Unit'" + pwsh: false + - task: PublishTestResults@2 + displayName: 'Publish Test Results' + condition: succeededOrFailed() + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml' + testRunTitle: 'Unit (Windows Server Core)' + - task: PublishBuildArtifacts@1 + displayName: 'Publish Test Artifact' + inputs: + pathToPublish: '$(buildFolderName)/$(testResultFolderName)/' + artifactName: $(testArtifactName) + publishLocation: 'Container' + + - job: Test_Integration + displayName: 'Integration' + pool: + vmImage: 'windows-2019' + timeoutInMinutes: 0 + steps: + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifact' + inputs: + buildType: 'current' + downloadType: 'single' + artifactName: $(buildArtifactName) + downloadPath: '$(Build.SourcesDirectory)' + - task: PowerShell@2 + name: configureWinRM + displayName: 'Configure WinRM' + inputs: + targetType: 'inline' + script: 'winrm quickconfig -quiet' + pwsh: false + - task: PowerShell@2 + name: test + displayName: 'Run Integration Test' + inputs: + filePath: './build.ps1' + arguments: "-Tasks test -PesterScript 'tests/Integration' -CodeCoverageThreshold 0" + pwsh: false + - task: PublishTestResults@2 + displayName: 'Publish Test Results' + condition: succeededOrFailed() + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: '$(buildFolderName)/$(testResultFolderName)/NUnit*.xml' + testRunTitle: 'Integration (Windows Server Core)' + + - job: Code_Coverage + displayName: 'Publish Code Coverage' + dependsOn: Test_Unit + pool: + vmImage: 'ubuntu 16.04' + timeoutInMinutes: 0 + steps: + - pwsh: | + $repositoryOwner,$repositoryName = $env:BUILD_REPOSITORY_NAME -split '/' + echo "##vso[task.setvariable variable=RepositoryOwner;isOutput=true]$repositoryOwner" + echo "##vso[task.setvariable variable=RepositoryName;isOutput=true]$repositoryName" + name: dscBuildVariable + displayName: 'Set Environment Variables' + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifact' + inputs: + buildType: 'current' + downloadType: 'single' + artifactName: $(buildArtifactName) + downloadPath: '$(Build.SourcesDirectory)' + - task: DownloadBuildArtifacts@0 + displayName: 'Download Test Artifact' + inputs: + buildType: 'current' + downloadType: 'single' + artifactName: $(testArtifactName) + downloadPath: '$(Build.SourcesDirectory)/$(buildFolderName)' + - task: PublishCodeCoverageResults@1 + displayName: 'Publish Azure Code Coverage' + condition: succeededOrFailed() + inputs: + codeCoverageTool: 'JaCoCo' + summaryFileLocation: '$(buildFolderName)/$(testResultFolderName)/JaCoCo_coverage.xml' + pathToSources: '$(Build.SourcesDirectory)/$(buildFolderName)/$(dscBuildVariable.RepositoryName)' + - script: | + bash <(curl -s https://codecov.io/bash) -f "./$(buildFolderName)/$(testResultFolderName)/JaCoCo_coverage.xml" + displayName: 'Upload to Codecov.io' + condition: succeededOrFailed() + + - stage: Deploy + dependsOn: Test + condition: | + and( + succeeded(), + or( + eq(variables['Build.SourceBranch'], 'refs/heads/master'), + startsWith(variables['Build.SourceBranch'], 'refs/tags/') + ), + contains(variables['System.TeamFoundationCollectionUri'], 'dsccommunity') + ) + jobs: + - job: Deploy_Module + displayName: 'Deploy Module' + pool: + vmImage: 'ubuntu 16.04' + steps: + - task: DownloadBuildArtifacts@0 + displayName: 'Download Build Artifact' + inputs: + buildType: 'current' + downloadType: 'single' + artifactName: 'output' + downloadPath: '$(Build.SourcesDirectory)' + - task: PowerShell@2 + name: publishRelease + displayName: 'Publish Release' + inputs: + filePath: './build.ps1' + arguments: '-tasks publish' + pwsh: true + env: + GitHubToken: $(GitHubToken) + GalleryApiToken: $(GalleryApiToken) + - task: PowerShell@2 + name: sendChangelogPR + displayName: 'Send Changelog PR' + inputs: + filePath: './build.ps1' + arguments: '-tasks Create_ChangeLog_GitHub_PR' + pwsh: true + env: + GitHubToken: $(GitHubToken) diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..f236bab --- /dev/null +++ b/build.ps1 @@ -0,0 +1,385 @@ +<# + .DESCRIPTION + Bootstrap and build script for PowerShell module pipeline +#> +[CmdletBinding()] +param +( + [Parameter(Position = 0)] + [string[]] + $Tasks = '.', + + [Parameter()] + [String] + $CodeCoverageThreshold = '', + + [Parameter()] + [validateScript( + { Test-Path -Path $_ } + )] + $BuildConfig, + + [Parameter()] + # A Specific folder to build the artefact into. + $OutputDirectory = 'output', + + [Parameter()] + # Subdirectory name to build the module (under $OutputDirectory) + $BuiltModuleSubdirectory = '', + + # Can be a path (relative to $PSScriptRoot or absolute) to tell Resolve-Dependency & PSDepend where to save the required modules, + # or use CurrentUser, AllUsers to target where to install missing dependencies + # You can override the value for PSDepend in the Build.psd1 build manifest + # This defaults to $OutputDirectory/modules (by default: ./output/modules) + [Parameter()] + $RequiredModulesDirectory = $(Join-Path 'output' 'RequiredModules'), + + [Parameter()] + [object[]] + $PesterScript, + + # Filter which tags to run when invoking Pester tests + # This is used in the Invoke-Pester.pester.build.ps1 tasks + [Parameter()] + [string[]] + $PesterTag, + + # Filter which tags to exclude when invoking Pester tests + # This is used in the Invoke-Pester.pester.build.ps1 tasks + [Parameter()] + [string[]] + $PesterExcludeTag, + + # Filter which tags to run when invoking DSC Resource tests + # This is used in the DscResource.Test.build.ps1 tasks + [Parameter()] + [string[]] + $DscTestTag, + + # Filter which tags to exclude when invoking DSC Resource tests + # This is used in the DscResource.Test.build.ps1 tasks + [Parameter()] + [string[]] + $DscTestExcludeTag, + + [Parameter()] + [Alias('bootstrap')] + [switch]$ResolveDependency, + + [Parameter(DontShow)] + [AllowNull()] + $BuildInfo, + + [Parameter()] + [switch] + $AutoRestore +) + +# The BEGIN block (at the end of this file) handles the Bootstrap of the Environment before Invoke-Build can run the tasks +# if the -ResolveDependency (aka Bootstrap) is specified, the modules are already available, and can be auto loaded + +process +{ + + if ($MyInvocation.ScriptName -notLike '*Invoke-Build.ps1') + { + # Only run the process block through InvokeBuild (Look at the Begin block at the bottom of this script) + return + } + + # Execute the Build Process from the .build.ps1 path. + Push-Location -Path $PSScriptRoot -StackName BeforeBuild + + try + { + Write-Host -ForeGroundColor magenta "[build] Parsing defined tasks" + + # Load Default BuildInfo if not provided as parameter + if (!$PSBoundParameters.ContainsKey('BuildInfo')) + { + try + { + if (Test-Path $BuildConfig) + { + $ConfigFile = (Get-Item -Path $BuildConfig) + Write-Host "[build] Loading Configuration from $ConfigFile" + $BuildInfo = switch -Regex ($ConfigFile.Extension) + { + # Native Support for PSD1 + '\.psd1' + { + Import-PowerShellDataFile -Path $BuildConfig + } + # Support for yaml when module PowerShell-Yaml is available + '\.[yaml|yml]' + { + Import-Module -ErrorAction Stop -Name 'powershell-yaml' + ConvertFrom-Yaml -Yaml (Get-Content -Raw $ConfigFile) + } + # Native Support for JSON and JSONC (by Removing comments) + '\.[json|jsonc]' + { + $JSONC = (Get-Content -Raw -Path $ConfigFile) + $JSON = $JSONC -replace '(?m)\s*//.*?$' -replace '(?ms)/\*.*?\*/' + # This should probably be converted to hashtable for splatting + $JSON | ConvertFrom-Json + } + default + { + Write-Error "Extension '$_' not supported. using @{}" + @{ } + } + } + } + else + { + Write-Host -Object "Configuration file $BuildConfig not found" -ForegroundColor Red + $BuildInfo = @{ } + } + } + catch + { + Write-Host -Object "Error loading Config $ConfigFile.`r`n Are you missing dependencies?" -ForegroundColor Yellow + Write-Host -Object "Make sure you run './build.ps1 -ResolveDependency -tasks noop' to restore the Required modules the first time" -ForegroundColor Yellow + $BuildInfo = @{ } + Write-Error $_.Exception.Message + } + } + + # If the Invoke-Build Task Header is specified in the Build Info, set it + if ($BuildInfo.TaskHeader) + { + Set-BuildHeader ([scriptblock]::Create($BuildInfo.TaskHeader)) + } + + # Import Tasks from modules via their exported aliases when defined in BUild Manifest + # https://github.com/nightroman/Invoke-Build/tree/master/Tasks/Import#example-2-import-from-a-module-with-tasks + if ($BuildInfo.containsKey('ModuleBuildTasks')) + { + foreach ($Module in $BuildInfo['ModuleBuildTasks'].Keys) + { + try + { + Write-Host -ForegroundColor DarkGray -Verbose "Importing tasks from module $Module" + $LoadedModule = Import-Module $Module -PassThru -ErrorAction Stop + foreach ($TaskToExport in $BuildInfo['ModuleBuildTasks'].($Module)) + { + $LoadedModule.ExportedAliases.GetEnumerator().Where{ + # using -like to support wildcard + Write-Host -ForegroundColor DarkGray "`t Loading $($_.Key)..." + $_.Key -like $TaskToExport + }.ForEach{ + # Dot sourcing the Tasks via their exported aliases + . (Get-Alias $_.Key) + } + } + } + catch + { + Write-Host -ForegroundColor Red -Object "Could not load tasks for module $Module." + Write-Error $_ + } + } + } + + # Loading Build Tasks defined in the .build/ folder (will override the ones imported above if same task name) + Get-ChildItem -Path ".build/" -Recurse -Include *.ps1 -ErrorAction Ignore | ForEach-Object { + "Importing file $($_.BaseName)" | Write-Verbose + . $_.FullName + } + + # Synopsis: Empty task, useful to test the bootstrap process + task noop { } + + # Define default task sequence ("."), can be overridden in the $BuildInfo + task . { + Write-Build Yellow "No sequence currently defined for the default task" + } + + # Load Invoke-Build task sequences/workflows from $BuildInfo + Write-Host -ForegroundColor DarkGray "Adding Workflow from configuration:" + foreach ($Workflow in $BuildInfo.BuildWorkflow.keys) + { + Write-Verbose "Creating Build Workflow '$Workflow' with tasks $($BuildInfo.BuildWorkflow.($Workflow) -join ', ')" + $WorkflowItem = $BuildInfo.BuildWorkflow.($Workflow) + if ($WorkflowItem.Trim() -match '^\{(?[\w\W]*)\}$') + { + $WorkflowItem = [ScriptBlock]::Create($Matches['sb']) + } + Write-Host -ForegroundColor DarkGray " +-> $Workflow" + task $Workflow $WorkflowItem + } + + Write-Host -ForeGroundColor magenta "[build] Executing requested workflow: $($Tasks -join ', ')" + + } + finally + { + Pop-Location -StackName BeforeBuild + } +} + +Begin +{ + # Find build config if not specified + if (-not $BuildConfig) + { + $config = Get-ChildItem -Path "$PSScriptRoot\*" -Include 'build.y*ml', 'build.psd1', 'build.json*' -ErrorAction:Ignore + if (-not $config -or ($config -is [array] -and $config.Length -le 0)) + { + throw "No build configuration found. Specify path via -BuildConfig" + } + elseif ($config -is [array]) + { + if ($config.Length -gt 1) + { + throw "More than one build configuration found. Specify which one to use via -BuildConfig" + } + $BuildConfig = $config[0] + } + else + { + $BuildConfig = $config + } + } + # Bootstrapping the environment before using Invoke-Build as task runner + + if ($MyInvocation.ScriptName -notLike '*Invoke-Build.ps1') + { + Write-Host -foregroundColor Green "[pre-build] Starting Build Init" + Push-Location $PSScriptRoot -StackName BuildModule + } + + if ($RequiredModulesDirectory -in @('CurrentUser', 'AllUsers')) + { + # Installing modules instead of saving them + Write-Host -foregroundColor Green "[pre-build] Required Modules will be installed for $RequiredModulesDirectory, not saved." + # Tell Resolve-Dependency to use provided scope as the -PSDependTarget if not overridden in Build.psd1 + $PSDependTarget = $RequiredModulesDirectory + } + else + { + if (-Not (Split-Path -IsAbsolute -Path $OutputDirectory)) + { + $OutputDirectory = Join-Path -Path $PSScriptRoot -ChildPath $OutputDirectory + } + + # Resolving the absolute path to save the required modules to + if (-Not (Split-Path -IsAbsolute -Path $RequiredModulesDirectory)) + { + $RequiredModulesDirectory = Join-Path -Path $PSScriptRoot -ChildPath $RequiredModulesDirectory + } + + # Create the output/modules folder if not exists, or resolve the Absolute path otherwise + if (Resolve-Path $RequiredModulesDirectory -ErrorAction SilentlyContinue) + { + Write-Debug "[pre-build] Required Modules path already exist at $RequiredModulesDirectory" + $RequiredModulesPath = Convert-Path $RequiredModulesDirectory + } + else + { + Write-Host -foregroundColor Green "[pre-build] Creating required modules directory $RequiredModulesDirectory." + $RequiredModulesPath = (New-Item -ItemType Directory -Force -Path $RequiredModulesDirectory).FullName + } + + # Prepending $RequiredModulesPath folder to PSModulePath to resolve from this folder FIRST + if ($RequiredModulesDirectory -notIn @('CurrentUser', 'AllUsers') -and + (($Env:PSModulePath -split [io.path]::PathSeparator) -notContains $RequiredModulesDirectory)) + { + Write-Host -foregroundColor Green "[pre-build] Prepending '$RequiredModulesDirectory' folder to PSModulePath" + $Env:PSModulePath = $RequiredModulesDirectory + [io.path]::PathSeparator + $Env:PSModulePath + } + + # Checking if the user should -ResolveDependency + if ((!(Get-Module -ListAvailable powershell-yaml) -or !(Get-Module -ListAvailable InvokeBuild) -or !(Get-Module -ListAvailable PSDepend)) -and !$ResolveDependency) + { + if ($AutoRestore -or !$PSBoundParameters.ContainsKey('Tasks') -or $Tasks -contains 'build') + { + Write-Host -ForegroundColor Yellow "[pre-build] Dependency missing, running './build.ps1 -ResolveDependency -Tasks noop' for you `r`n" + $ResolveDependency = $true + } + else + { + Write-Warning "Some required Modules are missing, make sure you first run with the '-ResolveDependency' parameter." + Write-Warning "Running 'build.ps1 -ResolveDependency -Tasks noop' will pull required modules without running the build task." + } + } + + if ($BuiltModuleSubdirectory) + { + if (-Not (Split-Path -IsAbsolute $BuiltModuleSubdirectory)) + { + $BuildModuleOutput = Join-Path $OutputDirectory $BuiltModuleSubdirectory + } + else + { + $BuildModuleOutput = $BuiltModuleSubdirectory + } + } + else + { + $BuildModuleOutput = $OutputDirectory + } + + # Prepending $BuildModuleOutput folder to PSModulePath to resolve built module from this folder + if (($Env:PSModulePath -split [io.path]::PathSeparator) -notContains $BuildModuleOutput) + { + Write-Host -foregroundColor Green "[pre-build] Prepending '$BuildModuleOutput' folder to PSModulePath" + $Env:PSModulePath = $BuildModuleOutput + [io.path]::PathSeparator + $Env:PSModulePath + } + + # Tell Resolve-Dependency to use $RequiredModulesPath as -PSDependTarget if not overridden in Build.psd1 + $PSDependTarget = $RequiredModulesPath + } + + if ($ResolveDependency) + { + Write-Host -Object "[pre-build] Resolving dependencies." -foregroundColor Green + $ResolveDependencyParams = @{ } + + # If BuildConfig is a Yaml file, bootstrap powershell-yaml via ResolveDependency + if ($BuildConfig -match '\.[yaml|yml]$') + { + $ResolveDependencyParams.add('WithYaml', $True) + } + + $ResolveDependencyAvailableParams = (Get-Command -Name '.\Resolve-Dependency.ps1').parameters.keys + foreach ($CmdParameter in $ResolveDependencyAvailableParams) + { + + # The parameter has been explicitly used for calling the .build.ps1 + if ($MyInvocation.BoundParameters.ContainsKey($CmdParameter)) + { + $ParamValue = $MyInvocation.BoundParameters.ContainsKey($CmdParameter) + Write-Debug " adding $CmdParameter :: $ParamValue [from user-provided parameters to Build.ps1]" + $ResolveDependencyParams.Add($CmdParameter, $ParamValue) + } + # Use defaults parameter value from Build.ps1, if any + else + { + if ($ParamValue = Get-Variable -Name $CmdParameter -ValueOnly -ErrorAction Ignore) + { + Write-Debug " adding $CmdParameter :: $ParamValue [from default Build.ps1 variable]" + $ResolveDependencyParams.add($CmdParameter, $ParamValue) + } + } + } + + Write-Host -foregroundColor Green "[pre-build] Starting bootstrap process." + .\Resolve-Dependency.ps1 @ResolveDependencyParams + } + + if ($MyInvocation.ScriptName -notLike '*Invoke-Build.ps1') + { + Write-Verbose "Bootstrap completed. Handing back to InvokeBuild." + if ($PSBoundParameters.ContainsKey('ResolveDependency')) + { + Write-Verbose "Dependency already resolved. Removing task" + $null = $PSBoundParameters.Remove('ResolveDependency') + } + Write-Host -foregroundColor Green "[build] Starting build with InvokeBuild." + Invoke-Build @PSBoundParameters -Task $Tasks -File $MyInvocation.MyCommand.Path + Pop-Location -StackName BuildModule + return + } +} diff --git a/build.yaml b/build.yaml new file mode 100644 index 0000000..a7b5ad8 --- /dev/null +++ b/build.yaml @@ -0,0 +1,106 @@ +--- +#################################################### +# ModuleBuilder Configuration # +#################################################### +CopyDirectories: + - en-US + - DSCResources + - Modules +Encoding: UTF8 +VersionedOutputDirectory: true + +#################################################### +# ModuleBuilder Dependent Modules Configuration # +#################################################### + +NestedModule: + DscResource.Common: + CopyOnly: true + Path: ./output/RequiredModules/DscResource.Common + AddToManifest: false + Exclude: PSGetModuleInfo.xml + +#################################################### +# Sampler Pipeline Configuration # +#################################################### +BuildWorkflow: + '.': + - build + - test + + build: + - Clean + - Build_Module_ModuleBuilder + - Build_NestedModules_ModuleBuilder + - Create_changelog_release_output + - Generate_Conceptual_Help + + pack: + - build + - package_module_nupkg + + hqrmtest: + - DscResource_Tests_Stop_On_Fail + + test: + - Pester_Tests_Stop_On_Fail + - Pester_if_Code_Coverage_Under_Threshold + + publish: + - Publish_release_to_GitHub + - publish_module_to_gallery + + +#################################################### +# PESTER Configuration # +#################################################### + +Pester: + OutputFormat: NUnitXML + ExcludeFromCodeCoverage: + - Modules/DscResource.Common + Script: + - tests/Unit + ExcludeTag: + Tag: + CodeCoverageThreshold: 83 + CodeCoverageOutputFile: JaCoCo_coverage.xml + CodeCoverageOutputFileEncoding: ascii + +DscTest: + ExcludeTag: + - "Common Tests - New Error-Level Script Analyzer Rules" + Tag: + ExcludeSourceFile: + - output + ExcludeModuleFile: + - Modules/DscResource.Common + +Resolve-Dependency: + Gallery: '' + AllowPrerelease: false + Verbose: false + +ModuleBuildTasks: + Sampler: + - '*.build.Sampler.ib.tasks' + DscResource.DocGenerator: + - 'Task.*' + +TaskHeader: | + param($Path) + "" + "=" * 79 + Write-Build Cyan "`t`t`t$($Task.Name.replace("_"," ").ToUpper())" + Write-Build DarkGray "$(Get-BuildSynopsis $Task)" + "-" * 79 + Write-Build DarkGray " $Path" + Write-Build DarkGray " $($Task.InvocationInfo.ScriptName):$($Task.InvocationInfo.ScriptLineNumber)" + "" + +GitHubConfig: + GitHubFilesToAdd: + - 'CHANGELOG.md' + GitHubConfigUserName: dscbot + GitHubConfigUserEmail: dsccommunity@outlook.com + UpdateChangelogOnPrerelease: false diff --git a/.codecov.yml b/codecov.yml similarity index 70% rename from .codecov.yml rename to codecov.yml index 29a05dd..9ac402c 100644 --- a/.codecov.yml +++ b/codecov.yml @@ -1,9 +1,10 @@ codecov: - notify: - require_ci_to_pass: no + require_ci_to_pass: no + # master should be the baseline for reporting + branch: master comment: - layout: "reach, diff" + layout: 'reach, diff' behavior: default coverage: @@ -22,3 +23,6 @@ coverage: # and let codecov.io set the goal for the code changed in the patch. target: auto threshold: 5 + +fixes: + - '\d+\.\d+\.\d+\/::source/' # move path "X.Y.Z/" => "source/" diff --git a/DSCResources/MSFT_xVHD/MSFT_xVHD.psm1 b/source/DSCResources/MSFT_xVHD/MSFT_xVHD.psm1 similarity index 85% rename from DSCResources/MSFT_xVHD/MSFT_xVHD.psm1 rename to source/DSCResources/MSFT_xVHD/MSFT_xVHD.psm1 index f1e769c..eb7243e 100644 --- a/DSCResources/MSFT_xVHD/MSFT_xVHD.psm1 +++ b/source/DSCResources/MSFT_xVHD/MSFT_xVHD.psm1 @@ -1,3 +1,9 @@ +$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. @@ -18,23 +24,23 @@ function Get-TargetResource param ( [Parameter(Mandatory = $true)] - [String] + [System.String] $Name, [Parameter(Mandatory = $true)] - [String] + [System.String] $Path, [Parameter()] - [ValidateSet("Vhd","Vhdx")] - [String] - $Generation = "Vhd" + [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' + throw 'Please ensure that Hyper-V role is installed with its PowerShell module' } # Construct the full path for the vhdFile @@ -95,34 +101,34 @@ function Set-TargetResource param ( [Parameter(Mandatory = $true)] - [String] + [System.String] $Name, [Parameter(Mandatory = $true)] - [String] + [System.String] $Path, [Parameter()] - [String] + [System.String] $ParentPath, [Parameter()] - [Uint64] + [System.UInt64] $MaximumSizeBytes, [Parameter()] [ValidateSet('Dynamic', 'Fixed', 'Differencing')] - [String] + [System.String] $Type = 'Dynamic', [Parameter()] [ValidateSet('Vhd', 'Vhdx')] - [String] + [System.String] $Generation = 'Vhd', [Parameter()] [ValidateSet('Present', 'Absent')] - [String] + [System.String] $Ensure = 'Present' ) @@ -204,9 +210,9 @@ function Set-TargetResource else { $params = @{ - Path = $vhdFilePath + Path = $vhdFilePath SizeBytes = $MaximumSizeBytes - $Type = $True + $Type = $True } $null = New-VHD @params } @@ -248,76 +254,76 @@ function Test-TargetResource param ( [Parameter(Mandatory = $true)] - [String] + [System.String] $Name, [Parameter(Mandatory = $true)] - [String] + [System.String] $Path, [Parameter()] - [String] + [System.String] $ParentPath, [Parameter()] - [Uint64] + [System.UInt64] $MaximumSizeBytes, [Parameter()] [ValidateSet('Vhd', 'Vhdx')] - [String] + [System.String] $Generation = 'Vhd', [Parameter()] [ValidateSet('Dynamic', 'Fixed', 'Differencing')] - [String] + [System.String] $Type = 'Dynamic', [Parameter()] [ValidateSet('Present', 'Absent')] - [String] + [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" + 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.' + throw 'Specify MaximumSizeBytes property for Fixed and Dynamic VHDs.' } if ($ParentPath -and $Type -ne 'Differencing') { - Throw 'Parent path is only supported for Differencing disks' + throw 'Parent path is only supported for Differencing disks' } if (-not $ParentPath -and $Type -eq 'Differencing') { - Throw 'Differencing requires a parent path' + throw 'Differencing requires a parent path' } if ($ParentPath) { if (!(Test-Path -Path $ParentPath)) { - Throw "$ParentPath does not exists" + 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])" + throw "Generation $Generation should match ParentPath extension $($ParentPath.Split('.')[-1])" } } if (!(Test-Path -Path $Path)) { - Throw "$Path does not exists" + throw "$Path does not exists" } # Construct the full path for the vhdFile @@ -328,7 +334,7 @@ function Test-TargetResource # 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")) + return ($result -and ($Ensure -eq 'Present')) } <# @@ -346,15 +352,15 @@ function GetNameWithExtension param ( [Parameter(Mandatory = $true)] - [String] + [System.String] $Name, [Parameter(Mandatory = $true)] - [String] + [System.String] $Generation = 'Vhd' ) - # If the name ends with vhd or vhdx don't append the generation to the vhdname. + # 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] diff --git a/DSCResources/MSFT_xVHD/MSFT_xVHD.schema.mof b/source/DSCResources/MSFT_xVHD/MSFT_xVHD.schema.mof similarity index 100% rename from DSCResources/MSFT_xVHD/MSFT_xVHD.schema.mof rename to source/DSCResources/MSFT_xVHD/MSFT_xVHD.schema.mof diff --git a/source/DSCResources/MSFT_xVHD/en-US/MSFT_xVHD.strings.psd1 b/source/DSCResources/MSFT_xVHD/en-US/MSFT_xVHD.strings.psd1 new file mode 100644 index 0000000..3b35d66 --- /dev/null +++ b/source/DSCResources/MSFT_xVHD/en-US/MSFT_xVHD.strings.psd1 @@ -0,0 +1,2 @@ +ConvertFrom-StringData @' +'@ diff --git a/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.psm1 b/source/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.psm1 similarity index 64% rename from DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.psm1 rename to source/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.psm1 index fd7e010..8eea531 100644 --- a/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.psm1 +++ b/source/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.psm1 @@ -1,25 +1,10 @@ -#region localizeddata -if (Test-Path "${PSScriptRoot}\${PSUICulture}") -{ - Import-LocalizedData ` - -BindingVariable LocalizedData ` - -Filename MSFT_xVMDvdDrive.strings.psd1 ` - -BaseDirectory "${PSScriptRoot}\${PSUICulture}" -} -else -{ - #fallback to en-US - Import-LocalizedData ` - -BindingVariable LocalizedData ` - -Filename MSFT_xVMDvdDrive.strings.psd1 ` - -BaseDirectory "${PSScriptRoot}\en-US" -} -#endregion - -# Import the common HyperV functions -Import-Module -Name ( Join-Path ` - -Path (Split-Path -Path $PSScriptRoot -Parent) ` - -ChildPath '\HyperVCommon\HyperVCommon.psm1' ) +$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 @@ -40,23 +25,23 @@ function Get-TargetResource [OutputType([System.Collections.Hashtable])] param ( - [parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $VMName, - [parameter(Mandatory = $true)] - [System.Uint32] + [Parameter(Mandatory = $true)] + [System.UInt32] $ControllerNumber, - [parameter(Mandatory = $true)] - [System.Uint32] + [Parameter(Mandatory = $true)] + [System.UInt32] $ControllerLocation ) Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($LocalizedData.GettingVMDVDDriveMessage ` - -f $VMName,$ControllerNumber,$ControllerLocation) + $($script:localizedData.GettingVMDVDDriveMessage ` + -f $VMName, $ControllerNumber, $ControllerLocation) ) -join '' ) Test-ParameterValid @PSBoundParameters @@ -112,30 +97,32 @@ function Set-TargetResource [CmdletBinding()] param ( - [parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $VMName, - [parameter(Mandatory = $true)] - [System.Uint32] + [Parameter(Mandatory = $true)] + [System.UInt32] $ControllerLocation, - [parameter(Mandatory = $true)] - [System.Uint32] + [Parameter(Mandatory = $true)] + [System.UInt32] $ControllerNumber, + [Parameter()] [System.String] $Path, - [ValidateSet("Present","Absent")] + [Parameter()] + [ValidateSet('Present', 'Absent')] [System.String] $Ensure = 'Present' ) Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($LocalizedData.SettingVMDVDDriveMessage ` - -f $VMName,$ControllerNumber,$ControllerLocation) + $($script:localizedData.SettingVMDVDDriveMessage ` + -f $VMName, $ControllerNumber, $ControllerLocation) ) -join '' ) $null = $PSBoundParameters.Remove('Path') @@ -150,14 +137,14 @@ function Set-TargetResource if ($dvdDrive.Ensure -eq 'Present') { # The DVD Drive already exists - if (-not [String]::IsNullOrWhiteSpace($Path) ` - -and ($Path -ne $dvdDrive.Path)) + 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): " - $($LocalizedData.VMDVDDriveChangePathMessage) ` - -f $VMName,$ControllerNumber,$ControllerLocation,$Path ` + "$($MyInvocation.MyCommand): " + $($script:localizedData.VMDVDDriveChangePathMessage) ` + -f $VMName, $ControllerNumber, $ControllerLocation, $Path ` ) -join '' ) Set-VMDvdDrive @PSBoundParameters -Path $Path @@ -167,13 +154,14 @@ function Set-TargetResource { # The DVD Drive does not exist but should. Change required. Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.VMDVDDriveAddMessage) ` - -f $VMName,$ControllerNumber,$ControllerLocation,$Path ` + "$($MyInvocation.MyCommand): " + $($script:localizedData.VMDVDDriveAddMessage) ` + -f $VMName, $ControllerNumber, $ControllerLocation, $Path ` ) -join '' ) - if (-not [String]::IsNullOrWhiteSpace($Path)) { - $PSBoundParameters.Add('Path',$Path) + if (-not [System.String]::IsNullOrWhiteSpace($Path)) + { + $PSBoundParameters.Add('Path', $Path) } # if Add-VMDvdDrive @PSBoundParameters @@ -186,9 +174,9 @@ function Set-TargetResource { # The DVD Drive does exist, but should not. Change required. Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.VMDVDDriveRemoveMessage) ` - -f $VMName,$ControllerNumber,$ControllerLocation ` + "$($MyInvocation.MyCommand): " + $($script:localizedData.VMDVDDriveRemoveMessage) ` + -f $VMName, $ControllerNumber, $ControllerLocation ` ) -join '' ) Remove-VMDvdDrive @PSBoundParameters @@ -222,30 +210,32 @@ function Test-TargetResource [OutputType([System.Boolean])] param ( - [parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $VMName, - [parameter(Mandatory = $true)] - [System.Uint32] + [Parameter(Mandatory = $true)] + [System.UInt32] $ControllerLocation, - [parameter(Mandatory = $true)] - [System.Uint32] + [Parameter(Mandatory = $true)] + [System.UInt32] $ControllerNumber, + [Parameter()] [System.String] $Path, - [ValidateSet("Present","Absent")] + [Parameter()] + [ValidateSet('Present', 'Absent')] [System.String] $Ensure = 'Present' ) Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($LocalizedData.TestingVMDVDDriveMessage ` - -f $VMName,$ControllerNumber,$ControllerLocation) + $($script:localizedData.TestingVMDVDDriveMessage ` + -f $VMName, $ControllerNumber, $ControllerLocation) ) -join '' ) $null = $PSBoundParameters.Remove('Path') @@ -255,7 +245,7 @@ function Test-TargetResource $dvdDrive = Get-TargetResource @PSBoundParameters # Flag to signal whether settings are correct - [Boolean] $desiredConfigurationMatch = $true + [System.Boolean] $desiredConfigurationMatch = $true if ($Ensure -eq 'Present') { @@ -263,14 +253,14 @@ function Test-TargetResource if ($dvdDrive.Ensure -eq 'Present') { # The DVD Drive already exists - if (-not [String]::IsNullOrWhiteSpace($Path) ` - -and ($Path -ne $dvdDrive.Path)) + 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): " - $($LocalizedData.VMDVDDriveExistsAndShouldPathMismatchMessage) ` - -f $VMName,$ControllerNumber,$ControllerLocation,$Path,$dvdDrive.Path ` + "$($MyInvocation.MyCommand): " + $($script:localizedData.VMDVDDriveExistsAndShouldPathMismatchMessage) ` + -f $VMName, $ControllerNumber, $ControllerLocation, $Path, $dvdDrive.Path ` ) -join '' ) $desiredConfigurationMatch = $false @@ -279,9 +269,9 @@ function Test-TargetResource { # The DVD drive exists and should. Change not required. Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.VMDVDDriveExistsAndShouldMessage) ` - -f $VMName,$ControllerNumber,$ControllerLocation,$Path ` + "$($MyInvocation.MyCommand): " + $($script:localizedData.VMDVDDriveExistsAndShouldMessage) ` + -f $VMName, $ControllerNumber, $ControllerLocation, $Path ` ) -join '' ) } # if } @@ -289,9 +279,9 @@ function Test-TargetResource { # The DVD Drive does not exist but should. Change required. Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.VMDVDDriveDoesNotExistButShouldMessage) ` - -f $VMName,$ControllerNumber,$ControllerLocation ` + "$($MyInvocation.MyCommand): " + $($script:localizedData.VMDVDDriveDoesNotExistButShouldMessage) ` + -f $VMName, $ControllerNumber, $ControllerLocation ` ) -join '' ) $desiredConfigurationMatch = $false @@ -304,9 +294,9 @@ function Test-TargetResource { # The DVD Drive does exist, but should not. Change required. Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.VMDVDDriveDoesExistButShouldNotMessage) ` - -f $VMName,$ControllerNumber,$ControllerLocation ` + "$($MyInvocation.MyCommand): " + $($script:localizedData.VMDVDDriveDoesExistButShouldNotMessage) ` + -f $VMName, $ControllerNumber, $ControllerLocation ` ) -join '' ) $desiredConfigurationMatch = $false @@ -315,9 +305,9 @@ function Test-TargetResource { # The DVD Drive does not exist and should not. Change not required. Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($LocalizedData.VMDVDDriveDoesNotExistAndShouldNotMessage) ` - -f $VMName,$ControllerNumber,$ControllerLocation ` + "$($MyInvocation.MyCommand): " + $($script:localizedData.VMDVDDriveDoesNotExistAndShouldNotMessage) ` + -f $VMName, $ControllerNumber, $ControllerLocation ` ) -join '' ) } # if } # if @@ -356,36 +346,37 @@ function Test-TargetResource function Test-ParameterValid { [CmdletBinding()] - [OutputType([Boolean])] + [OutputType([System.Boolean])] param ( - [parameter(Mandatory = $true)] + [Parameter(Mandatory = $true)] [System.String] $VMName, - [parameter(Mandatory = $true)] - [System.Uint32] + [Parameter(Mandatory = $true)] + [System.UInt32] $ControllerLocation, - [parameter(Mandatory = $true)] - [System.Uint32] + [Parameter(Mandatory = $true)] + [System.UInt32] $ControllerNumber, + [Parameter()] [System.String] $Path, - [ValidateSet("Present","Absent")] + [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)) + if (-not (Get-Module -ListAvailable -Name Hyper-V)) { - New-InvalidArgumentError ` - -ErrorId 'RoleMissingError' ` - -ErrorMessage ($LocalizedData.RoleMissingError -f ` - 'Hyper-V') + $errorMessage = $script:localizedData.RoleMissingError -f 'Hyper-V' + + New-ObjectNotFoundException -Message $errorMessage } # if # Does the VM exist? @@ -393,40 +384,37 @@ function Test-ParameterValid # Does the controller exist? if (-not (Get-VMScsiController -VMName $VMName -ControllerNumber $ControllerNumber) ` - -and -not (Get-VMIdeController -VMName $VMName -ControllerNumber $ControllerNumber)) + -and -not (Get-VMIdeController -VMName $VMName -ControllerNumber $ControllerNumber)) { # No it does not - New-InvalidArgumentError ` - -ErrorId 'VMControllerDoesNotExistError' ` - -ErrorMessage ($LocalizedData.VMControllerDoesNotExistError -f ` - $VMName,$ControllerNumber) + $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) + -VMName $VMName ` + -ControllerLocation $ControllerLocation ` + -ControllerNumber $ControllerNumber) { # Yes, so don't even try and touch this - New-InvalidArgumentError ` - -ErrorId 'ControllerConflictError' ` - -ErrorMessage ($LocalizedData.ControllerConflictError -f ` - $VMName,$ControllerNumber,$ControllerLocation) + $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 ([String]::IsNullOrWhiteSpace($Path))) + if (-not ([System.String]::IsNullOrWhiteSpace($Path))) { if (-not (Test-Path -Path $Path)) { # Path does not exist - New-InvalidArgumentError ` - -ErrorId 'PathDoesNotExistError' ` - -ErrorMessage ($LocalizedData.PathDoesNotExistError -f ` - $Path) + $errorMessage = $script:localizedData.PathDoesNotExistError -f $Path + + New-ObjectNotFoundException -Message $errorMessage } # if } # if } # if diff --git a/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.schema.mof b/source/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.schema.mof similarity index 100% rename from DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.schema.mof rename to source/DSCResources/MSFT_xVMDvdDrive/MSFT_xVMDvdDrive.schema.mof diff --git a/DSCResources/MSFT_xVMDvdDrive/en-us/MSFT_xVMDvdDrive.strings.psd1 b/source/DSCResources/MSFT_xVMDvdDrive/en-US/MSFT_xVMDvdDrive.strings.psd1 similarity index 100% rename from DSCResources/MSFT_xVMDvdDrive/en-us/MSFT_xVMDvdDrive.strings.psd1 rename to source/DSCResources/MSFT_xVMDvdDrive/en-US/MSFT_xVMDvdDrive.strings.psd1 diff --git a/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.psm1 b/source/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.psm1 similarity index 75% rename from DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.psm1 rename to source/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.psm1 index b5db636..85f4322 100644 --- a/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.psm1 +++ b/source/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.psm1 @@ -1,25 +1,10 @@ -#region localizeddata -if (Test-Path "${PSScriptRoot}\${PSUICulture}") -{ - Import-LocalizedData ` - -BindingVariable LocalizedData ` - -Filename MSFT_xVMHardDiskDrive.strings.psd1 ` - -BaseDirectory "${PSScriptRoot}\${PSUICulture}" -} -else -{ - # fallback to en-US - Import-LocalizedData ` - -BindingVariable LocalizedData ` - -Filename MSFT_xVMHardDiskDrive.strings.psd1 ` - -BaseDirectory "${PSScriptRoot}\en-US" -} -#endregion +$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 -# Import the common HyperV functions -Import-Module -Name ( Join-Path ` - -Path (Split-Path -Path $PSScriptRoot -Parent) ` - -ChildPath '\HyperVCommon\HyperVCommon.psm1' ) +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' <# .SYNOPSIS @@ -44,19 +29,19 @@ function Get-TargetResource $Path ) - Assert-Module -Name 'Hyper-V' + Assert-Module -ModuleName 'Hyper-V' $hardDiskDrive = Get-VMHardDiskDrive -VMName $VMName -ErrorAction Stop | - Where-Object -FilterScript { $_.Path -eq $Path } + Where-Object -FilterScript { $_.Path -eq $Path } if ($null -eq $hardDiskDrive) { - Write-Verbose -Message ($localizedData.DiskNotFound -f $Path, $VMName) + Write-Verbose -Message ($script:localizedData.DiskNotFound -f $Path, $VMName) $ensure = 'Absent' } else { - Write-Verbose -Message ($localizedData.DiskFound -f $Path, $VMName) + Write-Verbose -Message ($script:localizedData.DiskFound -f $Path, $VMName) $ensure = 'Present' } @@ -126,11 +111,12 @@ function Test-TargetResource $resource = Get-TargetResource -VMName $VMName -Path $Path - # Throw exception when the ControllerNumber or ControllerLocation are out of bounds for IDE + # 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 = $localizedData.IdeLocationError -f $ControllerNumber, $ControllerLocation - New-InvalidOperationError -ErrorId 'InvalidLocation' -ErrorMessage $errorMessage + $errorMessage = $script:localizedData.IdeLocationError -f $ControllerNumber, $ControllerLocation + + New-InvalidArgumentException -ArgumentName 'ControllerType' -Message $errorMessage } $isCompliant = $true @@ -139,9 +125,9 @@ function Test-TargetResource # Only check passed parameter values if ($resource.ContainsKey($key)) { - Write-Verbose -Message ($localizedData.ComparingParameter -f $key, - $PSBoundParameters[$key], - $resource[$key]) + Write-Verbose -Message ($script:localizedData.ComparingParameter -f $key, + $PSBoundParameters[$key], + $resource[$key]) $isCompliant = $isCompliant -and ($PSBoundParameters[$key] -eq $resource[$key]) } } @@ -201,19 +187,19 @@ function Set-TargetResource $Ensure = 'Present' ) - Assert-Module -Name 'Hyper-V' + Assert-Module -ModuleName 'Hyper-V' $hardDiskDrive = Get-VMHardDiskDrive -VMName $VMName | - Where-Object -FilterScript { $_.Path -eq $Path } + Where-Object -FilterScript { $_.Path -eq $Path } if ($Ensure -eq 'Present') { $null = $PSBoundParameters.Remove('Ensure') - Write-Verbose -Message ($localizedData.CheckingDiskIsAttached) + Write-Verbose -Message ($script:localizedData.CheckingDiskIsAttached) if ($hardDiskDrive) { - Write-Verbose -Message ($localizedData.DiskFound -f $Path, $VMName) + 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 @@ -236,22 +222,25 @@ function Set-TargetResource } else { - Write-Verbose -Message ($localizedData.CheckingExistingDiskLocation) + Write-Verbose -Message ($script:localizedData.CheckingExistingDiskLocation) + $getVMHardDiskDriveParams = @{ VMName = $VMName ControllerType = $ControllerType ControllerNumber = $ControllerNumber ControllerLocation = $ControllerLocation } + $existingHardDiskDrive = Get-VMHardDiskDrive @getVMHardDiskDriveParams + if ($null -ne $existingHardDiskDrive) { - $errorMessage = $localizedData.DiskPresentError -f $ControllerNumber, ` - $ControllerLocation - New-InvalidOperationError -ErrorId 'ControllerNotEmpty' -ErrorMessage $errorMessage + $errorMessage = $script:localizedData.DiskPresentError -f $ControllerNumber, $ControllerLocation + + New-InvalidResultException -Message $errorMessage } - Write-Verbose -Message ($localizedData.AddingDisk -f $Path, $VMName) + Write-Verbose -Message ($script:localizedData.AddingDisk -f $Path, $VMName) $null = Add-VMHardDiskDrive @PSBoundParameters } } @@ -260,12 +249,12 @@ function Set-TargetResource # We must ensure that the disk is absent if ($hardDiskDrive) { - Write-Verbose -Message ($localizedData.RemovingDisk -f $Path, $VMName) + Write-Verbose -Message ($script:localizedData.RemovingDisk -f $Path, $VMName) $null = $hardDiskDrive | Remove-VMHardDiskDrive } else { - Write-Warning -Message ($localizedData.DiskNotFound -f $Path, $VMName) + Write-Warning -Message ($script:localizedData.DiskNotFound -f $Path, $VMName) } } } diff --git a/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.schema.mof b/source/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.schema.mof similarity index 100% rename from DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.schema.mof rename to source/DSCResources/MSFT_xVMHardDiskDrive/MSFT_xVMHardDiskDrive.schema.mof diff --git a/DSCResources/MSFT_xVMHardDiskDrive/en-US/MSFT_xVMHardDiskDrive.strings.psd1 b/source/DSCResources/MSFT_xVMHardDiskDrive/en-US/MSFT_xVMHardDiskDrive.strings.psd1 similarity index 92% rename from DSCResources/MSFT_xVMHardDiskDrive/en-US/MSFT_xVMHardDiskDrive.strings.psd1 rename to source/DSCResources/MSFT_xVMHardDiskDrive/en-US/MSFT_xVMHardDiskDrive.strings.psd1 index 50a9aa4..5864aac 100644 --- a/DSCResources/MSFT_xVMHardDiskDrive/en-US/MSFT_xVMHardDiskDrive.strings.psd1 +++ b/source/DSCResources/MSFT_xVMHardDiskDrive/en-US/MSFT_xVMHardDiskDrive.strings.psd1 @@ -5,7 +5,7 @@ ConvertFrom-StringData @' CheckingExistingDiskLocation = Checking if there is an existing disk in the specified location. AddingDisk = Adding the disk '{0}' to VM '{1}'. RemovingDisk = Removing disk '{0}' from VM '{1}'. - ComparingParameter = Comparing '{0}'; expected '{1}', actual '{2}'. + ComparingParameter = Comparing '{0}'. Expected '{1}', actual '{2}'. DiskPresentError = There is already a disk present in controller '{0}', location '{1}'. IdeLocationError = ControllerNumber '{0}' or ControllerLocation '{1}' are not valid for IDE controller. diff --git a/DSCResources/MSFT_xVMHost/MSFT_xVMHost.psm1 b/source/DSCResources/MSFT_xVMHost/MSFT_xVMHost.psm1 similarity index 91% rename from DSCResources/MSFT_xVMHost/MSFT_xVMHost.psm1 rename to source/DSCResources/MSFT_xVMHost/MSFT_xVMHost.psm1 index b4c0bb3..476f935 100644 --- a/DSCResources/MSFT_xVMHost/MSFT_xVMHost.psm1 +++ b/source/DSCResources/MSFT_xVMHost/MSFT_xVMHost.psm1 @@ -1,21 +1,10 @@ -#region localizeddata -if (Test-Path "${PSScriptRoot}\${PSUICulture}") -{ - Import-LocalizedData -BindingVariable localizedData -Filename MSFT_xVMHost.psd1 ` - -BaseDirectory "${PSScriptRoot}\${PSUICulture}" -} -else -{ - # fallback to en-US - Import-LocalizedData -BindingVariable localizedData -Filename MSFT_xVMHost.psd1 ` - -BaseDirectory "${PSScriptRoot}\en-US" -} -#endregion +$script:dscResourceCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/DscResource.Common' +$script:hyperVDscCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/HyperVDsc.Common' -# Import the common HyperV functions -Import-Module -Name ( Join-Path ` - -Path (Split-Path -Path $PSScriptRoot -Parent) ` - -ChildPath '\HyperVCommon\HyperVCommon.psm1' ) +Import-Module -Name $script:dscResourceCommonModulePath +Import-Module -Name $script:hyperVDscCommonModulePath + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' <# .SYNOPSIS @@ -36,9 +25,9 @@ function Get-TargetResource $IsSingleInstance ) - Assert-Module -Name 'Hyper-V' + Assert-Module -ModuleName 'Hyper-V' - Write-Verbose -Message $localizedData.QueryingVMHost + Write-Verbose -Message $script:localizedData.QueryingVMHost $vmHost = Get-VMHost # Convert the current TimeSpan into minutes @@ -222,7 +211,7 @@ function Test-TargetResource $VirtualMachineMigrationEnabled ) - Assert-Module -Name 'Hyper-V' + Assert-Module -ModuleName 'Hyper-V' $targetResource = Get-TargetResource -IsSingleInstance $IsSingleInstance $isTargetResourceCompliant = $true @@ -233,18 +222,18 @@ function Test-TargetResource ($parameter.Value -ne $targetResource[$parameter.Key])) { $isTargetResourceCompliant = $false - Write-Verbose -Message ($localizedData.PropertyMismatch -f $parameter.Key, + Write-Verbose -Message ($script:localizedData.PropertyMismatch -f $parameter.Key, $parameter.Value, $targetResource[$parameter.Key]) } } if ($isTargetResourceCompliant) { - Write-Verbose -Message $localizedData.VMHostInDesiredState + Write-Verbose -Message $script:localizedData.VMHostInDesiredState } else { - Write-Verbose -Message $localizedData.VMHostNotInDesiredState + Write-Verbose -Message $script:localizedData.VMHostNotInDesiredState } return $isTargetResourceCompliant @@ -400,7 +389,7 @@ function Set-TargetResource $VirtualMachineMigrationEnabled ) - Assert-Module -Name 'Hyper-V' + Assert-Module -ModuleName 'Hyper-V' $null = $PSBoundParameters.Remove('IsSingleInstance') @@ -426,17 +415,21 @@ function Set-TargetResource { if ((Get-CimInstance -ClassName Win32_ComputerSystem).PartOfDomain) { - Write-Verbose -Message $localizedData.EnableLiveMigration + Write-Verbose -Message $script:localizedData.EnableLiveMigration + Enable-VMMigration } else { - New-InvalidOperationError -ErrorId InvalidState -ErrorMessage $localizedData.LiveMigrationDomainOnly + $errorMessage = $script:localizedData.LiveMigrationDomainOnly + + New-InvalidOperationException -Message $errorMessage } } else { - Write-Verbose -Message $localizedData.DisableLiveMigration + Write-Verbose -Message $script:localizedData.DisableLiveMigration + Disable-VMMigration } } @@ -450,8 +443,8 @@ function Set-TargetResource if ($vmHostParams.Count -ne 0) { - Write-Verbose -Message $localizedData.UpdatingVMHostProperties + Write-Verbose -Message $script:localizedData.UpdatingVMHostProperties Set-VMHost @PSBoundParameters - Write-Verbose -Message $localizedData.VMHostPropertiesUpdated + Write-Verbose -Message $script:localizedData.VMHostPropertiesUpdated } } #end function diff --git a/DSCResources/MSFT_xVMHost/MSFT_xVMHost.schema.mof b/source/DSCResources/MSFT_xVMHost/MSFT_xVMHost.schema.mof similarity index 100% rename from DSCResources/MSFT_xVMHost/MSFT_xVMHost.schema.mof rename to source/DSCResources/MSFT_xVMHost/MSFT_xVMHost.schema.mof diff --git a/DSCResources/MSFT_xVMHost/en-US/MSFT_xVMHost.psd1 b/source/DSCResources/MSFT_xVMHost/en-US/MSFT_xVMHost.strings.psd1 similarity index 90% rename from DSCResources/MSFT_xVMHost/en-US/MSFT_xVMHost.psd1 rename to source/DSCResources/MSFT_xVMHost/en-US/MSFT_xVMHost.strings.psd1 index 3e25077..75ee7b7 100644 --- a/DSCResources/MSFT_xVMHost/en-US/MSFT_xVMHost.psd1 +++ b/source/DSCResources/MSFT_xVMHost/en-US/MSFT_xVMHost.strings.psd1 @@ -1,6 +1,6 @@ ConvertFrom-StringData @' QueryingVMHost = Querying VM host configuration. - PropertyMismatch = Property '{0}' mismatch; expected value '{1}', but was '{2}'. + PropertyMismatch = Property '{0}' mismatch. Expected value '{1}', but was '{2}'. VMHostInDesiredState = VM host in desired state. VMHostNotInDesiredState = VM host not in desired state. UpdatingVMHostProperties = Updating VM host properties. diff --git a/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.psm1 b/source/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.psm1 similarity index 73% rename from DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.psm1 rename to source/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.psm1 index 2b32f64..112942f 100644 --- a/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.psm1 +++ b/source/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.psm1 @@ -1,21 +1,10 @@ -#region localizeddata -if (Test-Path "${PSScriptRoot}\${PSUICulture}") -{ - Import-LocalizedData -BindingVariable localizedData -Filename MSFT_xVMHyperV.psd1 ` - -BaseDirectory "${PSScriptRoot}\${PSUICulture}" -} -else -{ - # fallback to en-US - Import-LocalizedData -BindingVariable localizedData -Filename MSFT_xVMHyperV.psd1 ` - -BaseDirectory "${PSScriptRoot}\en-US" -} -#endregion +$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 -# Import the common HyperV functions -Import-Module -Name ( Join-Path ` - -Path (Split-Path -Path $PSScriptRoot -Parent) ` - -ChildPath '\HyperVCommon\HyperVCommon.psm1' ) +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' function Get-TargetResource { @@ -32,12 +21,12 @@ function Get-TargetResource $VhdPath ) - Write-Verbose -Message ($localizedData.QueryingVM -f $Name) + 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 ($localizedData.RoleMissingError -f 'Hyper-V') + throw ($script:localizedData.RoleMissingError -f 'Hyper-V') } $vmobj = Get-VM -Name $Name -ErrorAction SilentlyContinue @@ -45,7 +34,7 @@ function Get-TargetResource # Check if 1 or 0 VM with name = $name exist if ($vmobj.count -gt 1) { - Throw ($localizedData.MoreThanOneVMExistsError -f $Name) + throw ($script:localizedData.MoreThanOneVMExistsError -f $Name) } <# @@ -74,7 +63,7 @@ function Get-TargetResource { $macAddress += $networkAdapter.MacAddress - if (-Not ([string]::IsNullOrEmpty($networkAdapter.SwitchName))) + if (-Not ([System.String]::IsNullOrEmpty($networkAdapter.SwitchName))) { $switchName += $networkAdapter.SwitchName } @@ -86,29 +75,43 @@ function Get-TargetResource } @{ - Name = $Name + 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 + 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 } } @@ -120,78 +123,78 @@ function Set-TargetResource ( # Name of the VM [Parameter(Mandatory = $true)] - [String] + [System.String] $Name, # VHD associated with the VM [Parameter(Mandatory = $true)] - [String] + [System.String] $VhdPath, # Virtual switch associated with the VM [Parameter()] - [String[]] + [System.String[]] $SwitchName, # State of the VM [Parameter()] [ValidateSet('Running', 'Paused', 'Off')] - [String] + [System.String] $State, # Folder where the VM data will be stored [Parameter()] - [String] + [System.String] $Path, # Virtual machine generation [Parameter()] [ValidateRange(1, 2)] - [UInt32] + [System.UInt32] $Generation = 1, # Startup RAM for the VM [Parameter()] [ValidateRange(32MB, 65536MB)] - [UInt64] + [System.UInt64] $StartupMemory, # Minimum RAM for the VM. This enables dynamic memory [Parameter()] [ValidateRange(32MB, 65536MB)] - [UInt64] + [System.UInt64] $MinimumMemory, # Maximum RAM for the VM. This enables dynamic memory [Parameter()] [ValidateRange(32MB, 1048576MB)] - [UInt64] + [System.UInt64] $MaximumMemory, # MAC address of the VM [Parameter()] - [String[]] + [System.String[]] $MACAddress, # Processor count for the VM [Parameter()] - [UInt32] + [System.UInt32] $ProcessorCount, # Waits for VM to get valid IP address [Parameter()] - [Boolean] + [System.Boolean] $WaitForIP, # If specified, shutdowns and restarts the VM as needed for property changes [Parameter()] - [Boolean] + [System.Boolean] $RestartIfNeeded, # Should the VM be created or deleted [Parameter()] [ValidateSet('Present', 'Absent')] - [String] + [System.String] $Ensure = 'Present', [Parameter()] @@ -200,24 +203,24 @@ function Set-TargetResource # Enable secure boot for Generation 2 VMs [Parameter()] - [Boolean] + [System.Boolean] $SecureBoot = $true, # Enable Guest Services [Parameter()] - [Boolean] + [System.Boolean] $EnableGuestService = $false, # Enable AutomaticCheckpoints [Parameter()] - [Boolean] + [System.Boolean] $AutomaticCheckpointsEnabled ) # Check if Hyper-V module is present for Hyper-V cmdlets if (!(Get-Module -ListAvailable -Name Hyper-V)) { - Throw ($localizedData.RoleMissingError -f 'Hyper-V') + throw ($script:localizedData.RoleMissingError -f 'Hyper-V') } # Check if AutomaticCheckpointsEnabled is set in configuration @@ -229,24 +232,24 @@ function Set-TargetResource #> if (-Not (Get-Command -Name Set-VM -Module Hyper-V).Parameters.ContainsKey('AutomaticCheckpointsEnabled')) { - Throw ($localizedData.AutomaticCheckpointsUnsupported) + throw ($script:localizedData.AutomaticCheckpointsUnsupported) } } - Write-Verbose -Message ($localizedData.CheckingVMExists -f $Name) + Write-Verbose -Message ($script:localizedData.CheckingVMExists -f $Name) $vmObj = Get-VM -Name $Name -ErrorAction SilentlyContinue # VM already exists if ($vmObj) { - Write-Verbose -Message ($localizedData.VMExists -f $Name) + 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 ($localizedData.VMPropertyShouldBe -f 'Ensure', $Ensure, 'Present') + 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 ($localizedData.VMPropertySet -f 'Ensure', $Ensure) + Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'Ensure', $Ensure) } <# @@ -258,26 +261,26 @@ function Set-TargetResource # 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 ($localizedData.VMPropertyShouldBe -f 'State', $State, $vmObj.State) + Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'State', $State, $vmObj.State) Set-VMState -Name $Name -State $State -WaitForIP $WaitForIP - Write-Verbose -Message ($localizedData.VMPropertySet -f 'State', $State) + Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'State', $State) } - $changeProperty = @{} + $changeProperty = @{ } # If the VM does not have the right startup memory if ($PSBoundParameters.ContainsKey('StartupMemory') -and ($vmObj.MemoryStartup -ne $StartupMemory)) { - Write-Verbose -Message ($localizedData.VMPropertyShouldBe -f 'MemoryStartup', $StartupMemory, $vmObj.MemoryStartup) + 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 ($localizedData.AdjustingLessThanMemoryWarning -f 'StartupMemory', $vmObj.MemoryStartup, 'MinimumMemory', $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 ($localizedData.AdjustingGreaterThanMemoryWarning -f 'StartupMemory', $vmObj.MemoryStartup, 'MaximumMemory', $MaximumMemory) + Write-Verbose -Message ($script:localizedData.AdjustingGreaterThanMemoryWarning -f 'StartupMemory', $vmObj.MemoryStartup, 'MaximumMemory', $MaximumMemory) $changeProperty['MemoryStartup'] = $MaximumMemory } @@ -289,12 +292,12 @@ function Set-TargetResource if ($PSBoundParameters.ContainsKey('MinimumMemory') -and ($vmObj.Memoryminimum -ne $MinimumMemory)) { - Write-Verbose -Message ($localizedData.VMPropertyShouldBe -f 'MinimumMemory', $MinimumMemory, $vmObj.MemoryMinimum) + 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 ($localizedData.VMPropertyShouldBe -f 'MaximumMemory', $MaximumMemory, $vmObj.MemoryMaximum) + Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'MaximumMemory', $MaximumMemory, $vmObj.MemoryMaximum) $changeProperty['MemoryMaximum'] = $MaximumMemory } } @@ -302,7 +305,7 @@ function Set-TargetResource # 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 ($localizedData.VMPropertyShouldBe -f 'ProcessorCount', $ProcessorCount, $vmObj.ProcessorCount) + Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'ProcessorCount', $ProcessorCount, $vmObj.ProcessorCount) $changeProperty['ProcessorCount'] = $ProcessorCount } @@ -310,7 +313,7 @@ function Set-TargetResource if ($changeProperty.Count -gt 0) { Set-VMProperty -Name $Name -VMCommand 'Set-VM' -ChangeProperty $changeProperty -WaitForIP $WaitForIP -RestartIfNeeded $RestartIfNeeded - Write-Verbose -Message ($localizedData.VMPropertiesUpdated -f $Name) + Write-Verbose -Message ($script:localizedData.VMPropertiesUpdated -f $Name) } <# @@ -332,19 +335,19 @@ function Set-TargetResource $vmObj = Get-VM -Name $Name -ErrorAction SilentlyContinue if ($vmObj.DynamicMemoryEnabled) { - Write-Verbose -Message ($localizedData.VMPropertyShouldBe -f 'DynamicMemoryEnabled', $false, $vmObj.DynamicMemoryEnabled) + Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'DynamicMemoryEnabled', $false, $vmObj.DynamicMemoryEnabled) $setVMPropertyParams = @{ - VMName = $Name - VMCommand = 'Set-VM' - ChangeProperty = @{ - StaticMemory = $true + VMName = $Name + VMCommand = 'Set-VM' + ChangeProperty = @{ + StaticMemory = $true DynamicMemory = $false } - WaitForIP = $WaitForIP + WaitForIP = $WaitForIP RestartIfNeeded = $RestartIfNeeded } Set-VMProperty @setVMPropertyParams - Write-Verbose -Message ($localizedData.VMPropertiesUpdated -f $Name) + Write-Verbose -Message ($script:localizedData.VMPropertiesUpdated -f $Name) } } @@ -358,23 +361,23 @@ function Set-TargetResource # We cannot change the MAC address whilst the VM is running.. This is changed later if ($nic.SwitchName -ne $switch) { - Write-Verbose -Message ($localizedData.VMPropertyShouldBe -f 'NIC', $switch, $nic.SwitchName) + Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'NIC', $switch, $nic.SwitchName) $nic | Connect-VMNetworkAdapter -SwitchName $switch - Write-Verbose -Message ($localizedData.VMPropertySet -f 'NIC', $switch) + Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'NIC', $switch) } } else { - Write-Verbose -Message ($localizedData.VMPropertyShouldBe -f 'NIC', $switch, '') + 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 ($localizedData.VMPropertySet -f 'NIC', $switch) + Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'NIC', $switch) } else { Add-VMNetworkAdapter -VMName $Name -SwitchName $switch - Write-Verbose -Message ($localizedData.VMPropertySet -f 'NIC', $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 @@ -388,7 +391,7 @@ function Set-TargetResource $nic = $vmObj.NetworkAdapters[$i] if ($nic.MacAddress -ne $address) { - Write-Verbose -Message ($localizedData.VMPropertyShouldBe -f 'MACAddress', $address, $nic.MacAddress) + Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'MACAddress', $address, $nic.MacAddress) Set-VMMACAddress -Name $Name -NICIndex $i -MACAddress $address -WaitForIP $WaitForIP -RestartIfNeeded $RestartIfNeeded } } @@ -399,7 +402,7 @@ function Set-TargetResource $vmSecureBoot = Test-VMSecureBoot -Name $Name if ($SecureBoot -ne $vmSecureBoot) { - Write-Verbose -Message ($localizedData.VMPropertyShouldBe -f 'SecureBoot', $SecureBoot, $vmSecureBoot) + Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'SecureBoot', $SecureBoot, $vmSecureBoot) if (-not $SecureBoot) { @@ -412,13 +415,15 @@ function Set-TargetResource # Cannot change the secure boot state whilst the VM is powered on. $setVMPropertyParams = @{ - VMName = $Name - VMCommand = 'Set-VMFirmware' - ChangeProperty = @{ EnableSecureBoot = $enableSecureBoot } + VMName = $Name + VMCommand = 'Set-VMFirmware' + ChangeProperty = @{ + EnableSecureBoot = $enableSecureBoot + } RestartIfNeeded = $RestartIfNeeded } Set-VMProperty @setVMPropertyParams - Write-Verbose -Message ($localizedData.VMPropertySet -f 'SecureBoot', $SecureBoot) + Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'SecureBoot', $SecureBoot) } } @@ -434,18 +439,18 @@ function Set-TargetResource # 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} + $guestService = $vmObj | Get-VMIntegrationService | Where-Object -FilterScript { $_.Id -eq $guestServiceId } if ($guestService.Enabled -eq $false -and $EnableGuestService) { - Write-Verbose -Message ($localizedData.VMPropertyShouldBe -f 'EnableGuestService', $EnableGuestService, $guestService.Enabled) + Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'EnableGuestService', $EnableGuestService, $guestService.Enabled) $guestService | Enable-VMIntegrationService - Write-Verbose -Message ($localizedData.VMPropertySet -f 'EnableGuestService', $EnableGuestService) + Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'EnableGuestService', $EnableGuestService) } elseif ($guestService.Enabled -and -not $EnableGuestService) { - Write-Verbose -Message ($localizedData.VMPropertyShouldBe -f 'EnableGuestService', $EnableGuestService, $guestService.Enabled) + Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'EnableGuestService', $EnableGuestService, $guestService.Enabled) $guestService | Disable-VMIntegrationService - Write-Verbose -Message ($localizedData.VMPropertySet -f 'EnableGuestService', $EnableGuestService) + Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'EnableGuestService', $EnableGuestService) } # If AutomaticCheckpointsEnabled is set in configuration @@ -462,12 +467,12 @@ function Set-TargetResource # VM is not present, create one else { - Write-Verbose -Message ($localizedData.VMDoesNotExist -f $Name) + Write-Verbose -Message ($script:localizedData.VMDoesNotExist -f $Name) if ($Ensure -eq 'Present') { - Write-Verbose -Message ($localizedData.CreatingVM -f $Name) + Write-Verbose -Message ($script:localizedData.CreatingVM -f $Name) - $parameters = @{} + $parameters = @{ } $parameters['Name'] = $Name $parameters['VHDPath'] = $VhdPath $parameters['Generation'] = $Generation @@ -496,7 +501,7 @@ function Set-TargetResource } $null = New-VM @parameters - $parameters = @{} + $parameters = @{ } $parameters['Name'] = $Name $parameters['StaticMemory'] = $true $parameters['DynamicMemory'] = $false @@ -550,7 +555,7 @@ function Set-TargetResource for ($i = 1; $i -lt $SwitchName.Count; $i++) { $addVMNetworkAdapterParams = @{ - VMName = $Name + VMName = $Name SwitchName = $SwitchName[$i] } if ($MACAddress -and (-not [System.String]::IsNullOrEmpty($MACAddress[$i]))) @@ -558,7 +563,7 @@ function Set-TargetResource $addVMNetworkAdapterParams['StaticMacAddress'] = $MACAddress[$i] } Add-VMNetworkAdapter @addVMNetworkAdapterParams - Write-Verbose -Message ($localizedData.VMPropertySet -f 'NIC', $SwitchName[$i]) + Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'NIC', $SwitchName[$i]) } if ($Generation -eq 2) @@ -576,15 +581,15 @@ function Set-TargetResource 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 + Get-VMIntegrationService -VMName $Name | Where-Object -FilterScript { $_.Id -eq $guestServiceId } | Enable-VMIntegrationService } - Write-Verbose -Message ($localizedData.VMCreated -f $Name) + Write-Verbose -Message ($script:localizedData.VMCreated -f $Name) if ($State) { Set-VMState -Name $Name -State $State -WaitForIP $WaitForIP - Write-Verbose -Message ($localizedData.VMPropertySet -f 'State', $State) + Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'State', $State) } } @@ -599,78 +604,78 @@ function Test-TargetResource ( # Name of the VM [Parameter(Mandatory = $true)] - [String] + [System.String] $Name, # VHD associated with the VM [Parameter(Mandatory = $true)] - [String] + [System.String] $VhdPath, # Virtual switch associated with the VM [Parameter()] - [String[]] + [System.String[]] $SwitchName, # State of the VM [Parameter()] [ValidateSet('Running', 'Paused', 'Off')] - [String] + [System.String] $State, # Folder where the VM data will be stored [Parameter()] - [String] + [System.String] $Path, # Virtual machine generation [Parameter()] [ValidateRange(1, 2)] - [UInt32] + [System.UInt32] $Generation = 1, # Startup RAM for the VM [Parameter()] [ValidateRange(32MB, 65536MB)] - [UInt64] + [System.UInt64] $StartupMemory, # Minimum RAM for the VM. This enables dynamic memory [Parameter()] [ValidateRange(32MB, 65536MB)] - [UInt64] + [System.UInt64] $MinimumMemory, # Maximum RAM for the VM. This enables dynamic memory [Parameter()] [ValidateRange(32MB, 1048576MB)] - [UInt64] + [System.UInt64] $MaximumMemory, # MAC address of the VM [Parameter()] - [String[]] + [System.String[]] $MACAddress, # Processor count for the VM [Parameter()] - [UInt32] + [System.UInt32] $ProcessorCount, # Waits for VM to get valid IP address [Parameter()] - [Boolean] + [System.Boolean] $WaitForIP, # If specified, shutdowns and restarts the VM as needed for property changes [Parameter()] - [Boolean] + [System.Boolean] $RestartIfNeeded, # Should the VM be created or deleted [Parameter()] [ValidateSet('Present', 'Absent')] - [String] + [System.String] $Ensure = 'Present', [Parameter()] @@ -679,29 +684,29 @@ function Test-TargetResource # Enable secure boot for Generation 2 VMs [Parameter()] - [Boolean] + [System.Boolean] $SecureBoot = $true, [Parameter()] - [Boolean] + [System.Boolean] $EnableGuestService = $false, # Enable AutomaticCheckpoints [Parameter()] - [Boolean] + [System.Boolean] $AutomaticCheckpointsEnabled ) # Check if Hyper-V module is present for Hyper-V cmdlets if (!(Get-Module -ListAvailable -Name Hyper-V)) { - Throw ($localizedData.RoleMissingError -f '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 ($localizedData.MoreThanOneVMExistsError -f $Name) + throw ($script:localizedData.MoreThanOneVMExistsError -f $Name) } # Check if AutomaticCheckpointsEnabled is set in configuration @@ -713,7 +718,7 @@ function Test-TargetResource #> if (-Not (Get-Command -Name Set-VM -Module Hyper-V).Parameters.ContainsKey('AutomaticCheckpointsEnabled')) { - Throw ($localizedData.AutomaticCheckpointsUnsupported) + throw ($script:localizedData.AutomaticCheckpointsUnsupported) } } @@ -725,7 +730,7 @@ function Test-TargetResource # Check if $VhdPath exist if (!(Test-Path $VhdPath)) { - Throw ($localizedData.VhdPathDoesNotExistError -f $VhdPath) + throw ($script:localizedData.VhdPathDoesNotExistError -f $VhdPath) } # Check if Minimum memory is less than StartUpmemory @@ -733,7 +738,7 @@ function Test-TargetResource $PSBoundParameters.ContainsKey('MinimumMemory') -and ($MinimumMemory -gt $StartupMemory)) { - Throw ($localizedData.MinMemGreaterThanStartupMemError -f $MinimumMemory, $StartupMemory) + throw ($script:localizedData.MinMemGreaterThanStartupMemError -f $MinimumMemory, $StartupMemory) } # Check if Minimum memory is greater than Maximummemory @@ -741,7 +746,7 @@ function Test-TargetResource $PSBoundParameters.ContainsKey('MinimumMemory') -and ($MinimumMemory -gt $MaximumMemory)) { - Throw ($localizedData.MinMemGreaterThanMaxMemError -f $MinimumMemory, $MaximumMemory) + throw ($script:localizedData.MinMemGreaterThanMaxMemError -f $MinimumMemory, $MaximumMemory) } # Check if Startup memory is greater than Maximummemory @@ -749,7 +754,7 @@ function Test-TargetResource $PSBoundParameters.ContainsKey('StartupMemory') -and ($StartupMemory -gt $MaximumMemory)) { - Throw ($localizedData.StartUpMemGreaterThanMaxMemError -f $StartupMemory, $MaximumMemory) + throw ($script:localizedData.StartUpMemGreaterThanMaxMemError -f $StartupMemory, $MaximumMemory) } <# @@ -758,19 +763,19 @@ function Test-TargetResource #> if (($Generation -eq 2) -and ($VhdPath.Split('.')[-1] -eq 'vhd')) { - Throw ($localizedData.VhdUnsupportedOnGen2VMError) + throw ($script:localizedData.VhdUnsupportedOnGen2VMError) } # Check if $Path exist if ($Path -and !(Test-Path -Path $Path)) { - Throw ($localizedData.PathDoesNotExistError -f $Path) + throw ($script:localizedData.PathDoesNotExistError -f $Path) } $vhdChain = @(Get-VhdHierarchy -VhdPath ($vmObj.HardDrives[0].Path)) if ($vhdChain -notcontains $VhdPath) { - Write-Verbose -Message ($localizedData.VMPropertyShouldBe -f 'VhdPath', $VhdPath, ($vhdChain -join ',')) + Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'VhdPath', $VhdPath, ($vhdChain -join ',')) return $false } @@ -826,7 +831,7 @@ function Test-TargetResource { if ($vmObj.NetworkAdapters[$i].SwitchName -ne $SwitchName[$i]) { - Write-Verbose -Message ($localizedData.VMPropertyShouldBe -f 'SwitchName', $SwitchName[$i], $vmObj.NetworkAdapters[$i].SwitchName) + Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'SwitchName', $SwitchName[$i], $vmObj.NetworkAdapters[$i].SwitchName) return $false } } @@ -835,7 +840,7 @@ function Test-TargetResource { if ($vmObj.NetworkAdapters[$i].MACAddress -ne $MACAddress[$i]) { - Write-Verbose -Message ($localizedData.VMPropertyShouldBe -f 'MACAddress', $MACAddress[$i], $vmObj.NetworkAdapters[$i].MACAddress) + Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'MACAddress', $MACAddress[$i], $vmObj.NetworkAdapters[$i].MACAddress) return $false } } @@ -856,16 +861,16 @@ function Test-TargetResource $vmSecureBoot = Test-VMSecureBoot -Name $Name if ($SecureBoot -ne $vmSecureBoot) { - Write-Verbose -Message ($localizedData.VMPropertyShouldBe -f 'SecureBoot', $SecureBoot, $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} + $guestService = $vmObj | Get-VMIntegrationService | Where-Object -FilterScript { $_.Id -eq $guestServiceId } if ($guestService.Enabled -ne $EnableGuestService) { - Write-Verbose -Message ($localizedData.VMPropertyShouldBe -f 'EnableGuestService', $EnableGuestService, $guestService.Enabled) + Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'EnableGuestService', $EnableGuestService, $guestService.Enabled) return $false } @@ -874,7 +879,7 @@ function Test-TargetResource { if ($vmObj.AutomaticCheckpointsEnabled -ne $AutomaticCheckpointsEnabled) { - Write-Verbose -Message ($localizedData.VMPropertyShouldBe -f 'AutomaticCheckpointsEnabled', $AutomaticCheckpointsEnabled, $vmObj.AutomaticCheckpointsEnabled) + Write-Verbose -Message ($script:localizedData.VMPropertyShouldBe -f 'AutomaticCheckpointsEnabled', $AutomaticCheckpointsEnabled, $vmObj.AutomaticCheckpointsEnabled) return $false } } @@ -922,11 +927,11 @@ function Set-VMMACAddress param ( [Parameter(Mandatory = $true)] - [String] + [System.String] $Name, [Parameter(Mandatory = $true)] - [String] + [System.String] $MACAddress, [Parameter(Mandatory = $true)] @@ -934,11 +939,11 @@ function Set-VMMACAddress $NICIndex, [Parameter()] - [Boolean] + [System.Boolean] $WaitForIP, [Parameter()] - [Boolean] + [System.Boolean] $RestartIfNeeded ) $vmObj = Get-VM -Name $Name @@ -957,17 +962,17 @@ function Set-VMMACAddress # Cannot make a paused VM to go back to Paused state after turning Off if ($originalState -eq 'Paused') { - Write-Warning -Message ($localizedData.VMStateWillBeOffWarning -f $Name) + Write-Warning -Message ($script:localizedData.VMStateWillBeOffWarning -f $Name) } } elseif ($originalState -eq 'Off') { $vmObj.NetworkAdapters[$NICIndex] | Set-VMNetworkAdapter -StaticMacAddress $MACAddress - Write-Verbose -Message ($localizedData.VMPropertySet -f 'MACAddress', $MACAddress) + Write-Verbose -Message ($script:localizedData.VMPropertySet -f 'MACAddress', $MACAddress) } else { - Write-Error -Message ($localizedData.CannotUpdatePropertiesOnlineError -f $Name, $vmObj.State) + Write-Error -Message ($script:localizedData.CannotUpdatePropertiesOnlineError -f $Name, $vmObj.State) } } @@ -976,7 +981,7 @@ function Test-VMSecureBoot param ( [Parameter(Mandatory = $true)] - [string] + [System.String] $Name ) $vm = Get-VM -Name $Name diff --git a/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.schema.mof b/source/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.schema.mof similarity index 100% rename from DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.schema.mof rename to source/DSCResources/MSFT_xVMHyperV/MSFT_xVMHyperV.schema.mof diff --git a/DSCResources/MSFT_xVMHyperV/en-US/MSFT_xVMHyperV.psd1 b/source/DSCResources/MSFT_xVMHyperV/en-US/MSFT_xVMHyperV.strings.psd1 similarity index 95% rename from DSCResources/MSFT_xVMHyperV/en-US/MSFT_xVMHyperV.psd1 rename to source/DSCResources/MSFT_xVMHyperV/en-US/MSFT_xVMHyperV.strings.psd1 index 67d0b3d..11ea1ee 100644 --- a/DSCResources/MSFT_xVMHyperV/en-US/MSFT_xVMHyperV.psd1 +++ b/source/DSCResources/MSFT_xVMHyperV/en-US/MSFT_xVMHyperV.strings.psd1 @@ -9,11 +9,9 @@ ConvertFrom-StringData @' VhdUnsupportedOnGen2VMError = Generation 2 virtual machines do not support the .VHD virtual disk extension. CannotUpdatePropertiesOnlineError = Can not change properties for VM '{0}' in '{1}' state unless 'RestartIfNeeded' is set to true. AutomaticCheckpointsUnsupported = AutomaticCheckpoints are not supported on this host. - AdjustingGreaterThanMemoryWarning = VM {0} '{1}' is greater than {2} '{3}'. Adjusting {0} to be '{3}'. AdjustingLessThanMemoryWarning = VM {0} '{1}' is less than {2} '{3}'. Adjusting {0} to be '{3}'. VMStateWillBeOffWarning = VM '{0}' state will be 'OFF' and not 'Paused'. - CheckingVMExists = Checking if VM '{0}' exists ... VMExists = VM '{0}' exists. VMDoesNotExist = VM '{0}' does not exist. @@ -22,7 +20,5 @@ ConvertFrom-StringData @' VMPropertyShouldBe = VM property '{0}' should be '{1}', actual '{2}'. VMPropertySet = VM property '{0}' is '{1}'. VMPropertiesUpdated = VM '{0}' properties have been updated. - WaitingForVMIPAddress = Waiting for IP Address for VM '{0}' ... - QueryingVM = Querying VM '{0}'. '@ diff --git a/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 b/source/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 similarity index 67% rename from DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 rename to source/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 index 65ec9b5..d1ed7ae 100644 --- a/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 +++ b/source/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 @@ -1,16 +1,8 @@ -#region localizeddata -if (Test-Path "${PSScriptRoot}\${PSUICulture}") -{ - Import-LocalizedData -BindingVariable LocalizedData -filename MSFT_xVMNetworkAdapter.psd1 ` - -BaseDirectory "${PSScriptRoot}\${PSUICulture}" -} -else -{ - #fallback to en-US - Import-LocalizedData -BindingVariable LocalizedData -filename MSFT_xVMNetworkAdapter.psd1 ` - -BaseDirectory "${PSScriptRoot}\en-US" -} -#endregion +$script:dscResourceCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/DscResource.Common' + +Import-Module -Name $script:dscResourceCommonModulePath + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' <# .SYNOPSIS @@ -32,29 +24,34 @@ else .PARAMETER IpAddress Specifies the IpAddress information for the network adapter. #> -Function Get-TargetResource +function Get-TargetResource { [CmdletBinding()] [OutputType([System.Collections.Hashtable])] - Param ( - [Parameter(Mandatory)] - [String] $Id, - - [Parameter(Mandatory)] - [String] $Name, - - [Parameter(Mandatory)] - [String] $SwitchName, - - [Parameter(Mandatory)] - [String] $VMName + 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 + Id = $Id + Name = $Name SwitchName = $SwitchName - VMName = $VMName + VMName = $VMName } $arguments = @{ @@ -63,7 +60,7 @@ Function Get-TargetResource if ($VMName -ne 'ManagementOS') { - $arguments.Add('VMName',$VMName) + $arguments.Add('VMName', $VMName) } else { @@ -71,12 +68,12 @@ Function Get-TargetResource $arguments.Add('SwitchName', $SwitchName) } - Write-Verbose -Message $localizedData.GetVMNetAdapter + Write-Verbose -Message $script:localizedData.GetVMNetAdapter $netAdapter = Get-VMNetworkAdapter @arguments -ErrorAction SilentlyContinue if ($netAdapter) { - Write-Verbose -Message $localizedData.FoundVMNetAdapter + Write-Verbose -Message $script:localizedData.FoundVMNetAdapter if ($VMName -eq 'ManagementOS') { $configuration.Add('MacAddress', $netAdapter.MacAddress) @@ -89,15 +86,15 @@ Function Get-TargetResource } $networkInfo = Get-NetworkInformation -VMName $VMName -Name $Name - if($networkInfo) + if ($networkInfo) { $item = New-CimInstance -ClassName MSFT_xNetworkSettings -Property $networkInfo -Namespace root/microsoft/windows/desiredstateconfiguration -ClientOnly $configuration.Add('NetworkSetting', $item) } - $configuration.Add('Ensure','Present') + $configuration.Add('Ensure', 'Present') - Write-Verbose -Message $localizedData.GetVMNetAdapterVlan + Write-Verbose -Message $script:localizedData.GetVMNetAdapterVlan $netAdapterVlan = Get-VMNetworkAdapterVlan -VMNetworkAdapter $netAdapter if ($netAdapterVlan.OperationMode -ne 'Untagged') { @@ -106,8 +103,8 @@ Function Get-TargetResource } else { - Write-Verbose -Message $localizedData.NoVMNetAdapterFound - $configuration.Add('Ensure','Absent') + Write-Verbose -Message $script:localizedData.NoVMNetAdapterFound + $configuration.Add('Ensure', 'Absent') } return $configuration @@ -143,35 +140,43 @@ Function Get-TargetResource .PARAMETER Ensure Specifies if the network adapter should be Present or Absent. #> -Function Set-TargetResource +function Set-TargetResource { [CmdletBinding()] - Param ( - [Parameter(Mandatory)] - [String] $Id, + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Id, - [Parameter(Mandatory)] - [String] $Name, + [Parameter(Mandatory = $true)] + [System.String] + $Name, - [Parameter(Mandatory)] - [String] $SwitchName, + [Parameter(Mandatory = $true)] + [System.String] + $SwitchName, - [Parameter(Mandatory)] - [String] $VMName, + [Parameter(Mandatory = $true)] + [System.String] + $VMName, [Parameter()] - [String] $MacAddress, + [System.String] + $MacAddress, [Parameter()] [Microsoft.Management.Infrastructure.CimInstance] $NetworkSetting, [Parameter()] - [String] $VlanId, + [System.String] + $VlanId, [Parameter()] - [ValidateSet('Present','Absent')] - [String] $Ensure='Present' + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present' ) $arguments = @{ @@ -180,7 +185,7 @@ Function Set-TargetResource if ($VMName -ne 'ManagementOS') { - $arguments.Add('VMName',$VMName) + $arguments.Add('VMName', $VMName) } else { @@ -188,26 +193,26 @@ Function Set-TargetResource $arguments.Add('SwitchName', $SwitchName) } - Write-Verbose -Message $localizedData.GetVMNetAdapter + Write-Verbose -Message $script:localizedData.GetVMNetAdapter $netAdapterExists = Get-VMNetworkAdapter @arguments -ErrorAction SilentlyContinue if ($Ensure -eq 'Present') { if ($netAdapterExists) { - Write-Verbose -Message $localizedData.FoundVMNetAdapter + Write-Verbose -Message $script:localizedData.FoundVMNetAdapter if (($VMName -ne 'ManagementOS')) { if ($MacAddress) { if ($netAdapterExists.DynamicMacAddressEnabled) { - Write-Verbose -Message $localizedData.EnableStaticMacAddress + Write-Verbose -Message $script:localizedData.EnableStaticMacAddress $updateMacAddress = $true } elseif ($MacAddress -ne $netAdapterExists.StaicMacAddress) { - Write-Verbose -Message $localizedData.EnableStaticMacAddress + Write-Verbose -Message $script:localizedData.EnableStaticMacAddress $updateMacAddress = $true } } @@ -215,26 +220,26 @@ Function Set-TargetResource { if (-not $netAdapterExists.DynamicMacAddressEnabled) { - Write-Verbose -Message $localizedData.EnableDynamicMacAddress + Write-Verbose -Message $script:localizedData.EnableDynamicMacAddress $updateMacAddress = $true } } if ($netAdapterExists.SwitchName -ne $SwitchName) { - Write-Verbose -Message $localizedData.PerformSwitchConnect + Write-Verbose -Message $script:localizedData.PerformSwitchConnect Connect-VMNetworkAdapter -VMNetworkAdapter $netAdapterExists -SwitchName $SwitchName -ErrorAction Stop -Verbose } if (($updateMacAddress)) { - Write-Verbose -Message $localizedData.PerformVMNetModify + Write-Verbose -Message $script:localizedData.PerformVMNetModify $setArguments = @{ } - $setArguments.Add('VMNetworkAdapter',$netAdapterExists) + $setArguments.Add('VMNetworkAdapter', $netAdapterExists) if ($MacAddress) { - $setArguments.Add('StaticMacAddress',$MacAddress) + $setArguments.Add('StaticMacAddress', $MacAddress) } else { @@ -250,15 +255,15 @@ Function Set-TargetResource { if (-not $MacAddress) { - $arguments.Add('DynamicMacAddress',$true) + $arguments.Add('DynamicMacAddress', $true) } else { - $arguments.Add('StaticMacAddress',$MacAddress) + $arguments.Add('StaticMacAddress', $MacAddress) } - $arguments.Add('SwitchName',$SwitchName) + $arguments.Add('SwitchName', $SwitchName) } - Write-Verbose -Message $localizedData.AddVMNetAdapter + Write-Verbose -Message $script:localizedData.AddVMNetAdapter $netAdapterExists = Add-VMNetworkAdapter @arguments -Passthru -ErrorAction Stop } @@ -267,36 +272,36 @@ Function Set-TargetResource $networkInfo = Get-NetworkInformation -VMName $VMName -Name $Name if (-not $NetworkSetting) { - if($networkInfo) + if ($networkInfo) { - Write-Verbose -Message $localizedData.EnableDhcp + Write-Verbose -Message $script:localizedData.EnableDhcp Set-NetworkInformation -VMName $VMName -Name $Name -Dhcp } } else { - $parameters = @{} - if ($ipAddress = $NetworkSetting.CimInstanceProperties["IpAddress"].Value) + $parameters = @{ } + if ($ipAddress = $NetworkSetting.CimInstanceProperties['IpAddress'].Value) { if (-not $ipAddress) { - throw $localizedData.MissingIPAndSubnet + throw $script:localizedData.MissingIPAndSubnet } $parameters.Add('IPAddress', $ipAddress) } - if ($subnet = $NetworkSetting.CimInstanceProperties["Subnet"].Value) + if ($subnet = $NetworkSetting.CimInstanceProperties['Subnet'].Value) { if (-not $subnet) { - throw $localizedData.MissingIPAndSubnet + throw $script:localizedData.MissingIPAndSubnet } $parameters.Add('Subnet', $subnet) } - if ($defaultGateway = $NetworkSetting.CimInstanceProperties["DefaultGateway"].Value) + if ($defaultGateway = $NetworkSetting.CimInstanceProperties['DefaultGateway'].Value) { $parameters.Add('DefaultGateway', $defaultGateway) } - if ($dnsServer = $NetworkSetting.CimInstanceProperties["DnsServer"].Value) + if ($dnsServer = $NetworkSetting.CimInstanceProperties['DnsServer'].Value) { $parameters.Add('DnsServer', $dnsServer) } @@ -304,7 +309,7 @@ Function Set-TargetResource Set-NetworkInformation -VMName $VMName -Name $Name @parameters } - Write-Verbose -Message $localizedData.GetVMNetAdapterVlan + Write-Verbose -Message $script:localizedData.GetVMNetAdapterVlan $netAdapterVlan = Get-VMNetworkAdapterVlan -VMNetworkAdapter $netAdapterExists if ($netAdapterVlan) { @@ -314,7 +319,7 @@ Function Set-TargetResource } else { - Write-Verbose -Message $localizedData.RemovingVlanTag + Write-Verbose -Message $script:localizedData.RemovingVlanTag Set-VMNetworkAdapterVlan -VMNetworkAdapter $netAdapterExists -Untagged } } @@ -325,14 +330,14 @@ Function Set-TargetResource if ($setVlan) { - Write-Verbose -Message $localizedData.SettingVlan + Write-Verbose -Message $script:localizedData.SettingVlan Set-VMNetworkAdapterVlan -VMNetworkAdapter $netAdapterExists -Access -VlanId $VlanId } } } else { - Write-Verbose -Message $localizedData.RemoveVMNetAdapter + Write-Verbose -Message $script:localizedData.RemoveVMNetAdapter Remove-VMNetworkAdapter @arguments -ErrorAction Stop } } @@ -367,36 +372,44 @@ Function Set-TargetResource .PARAMETER Ensure Specifies if the network adapter should be Present or Absent. #> -Function Test-TargetResource +function Test-TargetResource { [CmdletBinding()] [OutputType([System.Boolean])] - Param ( - [Parameter(Mandatory)] - [String] $Id, + param + ( + [Parameter(Mandatory = $true)] + [System.String] + $Id, - [Parameter(Mandatory)] - [String] $Name, + [Parameter(Mandatory = $true)] + [System.String] + $Name, - [Parameter(Mandatory)] - [String] $SwitchName, + [Parameter(Mandatory = $true)] + [System.String] + $SwitchName, - [Parameter(Mandatory)] - [String] $VMName, + [Parameter(Mandatory = $true)] + [System.String] + $VMName, [Parameter()] - [String] $MacAddress, + [System.String] + $MacAddress, [Parameter()] [Microsoft.Management.Infrastructure.CimInstance] $NetworkSetting, [Parameter()] - [String] $VlanId, + [System.String] + $VlanId, [Parameter()] - [ValidateSet('Present','Absent')] - [String] $Ensure='Present' + [ValidateSet('Present', 'Absent')] + [System.String] + $Ensure = 'Present' ) $arguments = @{ @@ -405,7 +418,7 @@ Function Test-TargetResource if ($VMName -ne 'ManagementOS') { - $arguments.Add('VMName',$VMName) + $arguments.Add('VMName', $VMName) } else { @@ -413,7 +426,7 @@ Function Test-TargetResource $arguments.Add('SwitchName', $SwitchName) } - Write-Verbose -Message $localizedData.GetVMNetAdapter + Write-Verbose -Message $script:localizedData.GetVMNetAdapter $netAdapterExists = Get-VMNetworkAdapter @arguments -ErrorAction SilentlyContinue if ($Ensure -eq 'Present') @@ -426,12 +439,12 @@ Function Test-TargetResource { if ($netAdapterExists.DynamicMacAddressEnabled) { - Write-Verbose -Message $localizedData.EnableStaticMacAddress + Write-Verbose -Message $script:localizedData.EnableStaticMacAddress return $false } elseif ($netAdapterExists.MacAddress -ne $MacAddress) { - Write-Verbose -Message $localizedData.StaticAddressDoesNotMatch + Write-Verbose -Message $script:localizedData.StaticAddressDoesNotMatch return $false } } @@ -439,7 +452,7 @@ Function Test-TargetResource { if (-not $netAdapterExists.DynamicMacAddressEnabled) { - Write-Verbose -Message $localizedData.EnableDynamicMacAddress + Write-Verbose -Message $script:localizedData.EnableDynamicMacAddress return $false } } @@ -447,9 +460,9 @@ Function Test-TargetResource $networkInfo = Get-NetworkInformation -VMName $VMName -Name $Name if (-not $NetworkSetting) { - if($networkInfo) + if ($networkInfo) { - Write-Verbose -Message $localizedData.NotDhcp + Write-Verbose -Message $script:localizedData.NotDhcp return $false } } @@ -457,42 +470,42 @@ Function Test-TargetResource { if (-not $networkInfo) { - Write-Verbose -Message $localizedData.Dhcp + 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 + $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 $localizedData.MissingIPAndSubnet + throw $script:localizedData.MissingIPAndSubnet } if ($ipAddress -and -not $networkInfo.IPAddress.Split(',').Contains($ipAddress)) { - Write-Verbose -Message $localizedData.IPAddressNotConfigured + Write-Verbose -Message $script:localizedData.IPAddressNotConfigured return $false } if ($defaultGateway -and -not $networkInfo.DefaultGateway.Split(',').Contains($defaultGateway)) { - Write-Verbose -Message $localizedData.GatewayNotConfigured + Write-Verbose -Message $script:localizedData.GatewayNotConfigured return $false } if ($dnsServer -and -not $networkInfo.DNSServer.Split(',').Contains($dnsServer)) { - Write-Verbose -Message $localizedData.DNSServerNotConfigured + Write-Verbose -Message $script:localizedData.DNSServerNotConfigured return $false } } } - Write-Verbose -Message $localizedData.GetVMNetAdapterVlan + Write-Verbose -Message $script:localizedData.GetVMNetAdapterVlan $netAdapterVlan = Get-VMNetworkAdapterVlan -VMNetworkAdapter $netAdapterExists if ($netAdapterVlan) { @@ -500,7 +513,7 @@ Function Test-TargetResource { if ($VlanId) { - Write-Verbose -Message $localizedData.VlanNotUntagged + Write-Verbose -Message $script:localizedData.VlanNotUntagged return $false } } @@ -510,44 +523,44 @@ Function Test-TargetResource { if ($netAdapterVlan.AccessVlanId -ne $VlanId) { - Write-Verbose -Message $localizedData.VlanDoesNotMatch + Write-Verbose -Message $script:localizedData.VlanDoesNotMatch return $false } } else { - Write-Verbose -Message $localizedData.VlanShouldntBeTagged + Write-Verbose -Message $script:localizedData.VlanShouldntBeTagged return $false } } } elseif ($VlanId) { - Write-Verbose -Message $localizedData.VlanNotUntagged + Write-Verbose -Message $script:localizedData.VlanNotUntagged return $false } if ($netAdapterExists.SwitchName -ne $SwitchName) { - Write-Verbose -Message $localizedData.SwitchIsDifferent + Write-Verbose -Message $script:localizedData.SwitchIsDifferent return $false } else { - Write-Verbose -Message $localizedData.VMNetAdapterExistsNoActionNeeded + Write-Verbose -Message $script:localizedData.VMNetAdapterExistsNoActionNeeded return $true } } else { - Write-Verbose -Message $localizedData.VMNetAdapterExistsNoActionNeeded + Write-Verbose -Message $script:localizedData.VMNetAdapterExistsNoActionNeeded return $true } } else { - Write-Verbose -Message $localizedData.VMNetAdapterDoesNotExistShouldAdd + Write-Verbose -Message $script:localizedData.VMNetAdapterDoesNotExistShouldAdd return $false } } @@ -555,12 +568,12 @@ Function Test-TargetResource { if ($netAdapterExists) { - Write-Verbose -Message $localizedData.VMNetAdapterExistsShouldRemove + Write-Verbose -Message $script:localizedData.VMNetAdapterExistsShouldRemove return $false } else { - Write-Verbose -Message $localizedData.VMNetAdapterDoesNotExistNoActionNeeded + Write-Verbose -Message $script:localizedData.VMNetAdapterDoesNotExistNoActionNeeded return $true } } @@ -570,18 +583,21 @@ function Get-NetworkInformation { [CmdletBinding()] [OutputType([System.Collections.Hashtable])] - Param ( - [Parameter(Mandatory)] - [String] $VMName, - - [Parameter(Mandatory)] - [String] $Name + 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") + $networkSettings = $vmNetAdapter.GetRelated('Msvm_GuestNetworkAdapterConfiguration') if ($networkSettings.DHCPEnabled) { @@ -590,10 +606,10 @@ function Get-NetworkInformation else { return @{ - IpAddress = $networkSettings.IPAddresses -join ',' - Subnet = $networkSettings.Subnets -join ',' + IpAddress = $networkSettings.IPAddresses -join ',' + Subnet = $networkSettings.Subnets -join ',' DefaultGateway = $networkSettings.DefaultGateways -join ',' - DnsServer = $networkSettings.DNSServers -join ',' + DnsServer = $networkSettings.DNSServers -join ',' } } @@ -602,33 +618,41 @@ function Get-NetworkInformation function Set-NetworkInformation { [CmdletBinding()] - Param ( - [Parameter(Mandatory)] - [String] $VMName, - - [Parameter(Mandatory)] - [String] $Name, - - [Parameter(ParameterSetName='Dhcp')] - [switch] $Dhcp, - - [Parameter(Mandatory, ParameterSetName='Static')] - [String] $IPAddress, - - [Parameter(Mandatory, ParameterSetName='Static')] - [String] $Subnet, - - [Parameter(ParameterSetName='Static')] - [String] $DefaultGateway, - - [Parameter(ParameterSetName='Static')] - [String] $DnsServer + 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 + $networkSettings = $vmNetAdapter.GetRelated('Msvm_GuestNetworkAdapterConfiguration') | Select-Object -First 1 switch ($PSCmdlet.ParameterSetName) { @@ -640,6 +664,7 @@ function Set-NetworkInformation $networkSettings.DefaultGateways = @() $networkSettings.DNSServers = @() } + 'Static' { $networkSettings.IPAddresses = $IPAddress @@ -649,16 +674,19 @@ function Set-NetworkInformation { $networkSettings.DefaultGateways = $DefaultGateway } + if ($DnsServer) { $networkSettings.DNSServers = $DNSServer } + $networkSettings.DHCPEnabled = $false } } + $networkSettings.ProtocolIFType = 4096 - $service = Get-WmiObject -Class "Msvm_VirtualSystemManagementService" -Namespace "root\virtualization\v2" + $service = Get-WmiObject -Class 'Msvm_VirtualSystemManagementService' -Namespace 'root\virtualization\v2' $setIP = $service.SetGuestNetworkAdapterConfiguration($vm, $networkSettings.GetText(1)) if ($setIP.ReturnValue -eq 4096) @@ -671,7 +699,7 @@ function Set-NetworkInformation $job = [WMI]$setIP.job } - if($job.JobState -ne 7) + if ($job.JobState -ne 7) { throw $job.GetError().Error } diff --git a/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof b/source/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof similarity index 100% rename from DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof rename to source/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.schema.mof diff --git a/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.psd1 b/source/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.strings.psd1 similarity index 76% rename from DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.psd1 rename to source/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.strings.psd1 index b5e1676..d142c76 100644 --- a/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.psd1 +++ b/source/DSCResources/MSFT_xVMNetworkAdapter/en-US/MSFT_xVMNetworkAdapter.strings.psd1 @@ -1,6 +1,4 @@ ConvertFrom-StringData @' - VMNameAndManagementTogether=VMName cannot be provided when ManagementOS is set to True. - MustProvideVMName=Must provide VMName parameter when ManagementOS is set to False. GetVMNetAdapter=Getting VM Network Adapter information. GetVMNetAdapterVlan=Getting VM Network Adapter VLAN information. VlanShouldntBeTagged=VM Network Adapter should not have a Vlan tag. @@ -8,7 +6,6 @@ ConvertFrom-StringData @' VlanDoesNotMatch=VlanId does not match. RemovingVlanTag=Removing Vlan tagging on Network Adapter. SettingVlan=Setting VlanId on network adapter. - IpAddressIsNotSet=Ip Address is not set. NotDhcp=Ethernet Adapter is not configured for Dhcp. Dhcp=Ethernet Adapter is configured for Dhcp. EnableDhcp=Enabling DHCP. @@ -18,20 +15,16 @@ ConvertFrom-StringData @' MissingIPAndSubnet=Missing IPAddress or Subnet. FoundVMNetAdapter=Found VM Network Adapter. NoVMNetAdapterFound=No VM Network Adapter found. - StaticMacAddressChosen=Static MAC Address has been specified. StaticAddressDoesNotMatch=Staic MAC address on the VM Network Adapter does not match. - ModifyVMNetAdapter=VM Network Adapter exists with different configuration. This will be modified. EnableDynamicMacAddress=VM Network Adapter exists but without Dynamic MAC address setting. EnableStaticMacAddress=VM Network Adapter exists but without static MAC address setting. PerformVMNetModify=Performing VM Network Adapter configuration changes. - CannotChangeHostAdapterMacAddress=VM Network adapter in configuration is a host adapter. Its configuration cannot be modified. AddVMNetAdapter=Adding VM Network Adapter. RemoveVMNetAdapter=Removing VM Network Adapter. VMNetAdapterExistsNoActionNeeded=VM Network Adapter exists with requested configuration. No action needed. VMNetAdapterDoesNotExistShouldAdd=VM Network Adapter does not exist. It will be added. VMNetAdapterExistsShouldRemove=VM Network Adapter Exists. It will be removed. VMNetAdapterDoesNotExistNoActionNeeded=VM Network adapter does not exist. No action needed. - StaticMacExists=StaicMacAddress configuration exists as desired. SwitchIsDifferent=Net Adapter is not connected to the requested switch. PerformSwitchConnect=Connecting VM Net adapter to the right switch. '@ diff --git a/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.psm1 b/source/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.psm1 similarity index 80% rename from DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.psm1 rename to source/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.psm1 index 79cd09c..23620a5 100644 --- a/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.psm1 +++ b/source/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.psm1 @@ -1,21 +1,10 @@ -#region localizeddata -if (Test-Path "${PSScriptRoot}\${PSUICulture}") -{ - Import-LocalizedData -BindingVariable localizedData -Filename MSFT_xVMProcessor.psd1 ` - -BaseDirectory "${PSScriptRoot}\${PSUICulture}" -} -else -{ - # fallback to en-US - Import-LocalizedData -BindingVariable localizedData -Filename MSFT_xVMProcessor.psd1 ` - -BaseDirectory "${PSScriptRoot}\en-US" -} -#endregion +$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 -# Import the common HyperV functions -Import-Module -Name ( Join-Path ` - -Path (Split-Path -Path $PSScriptRoot -Parent) ` - -ChildPath '\HyperVCommon\HyperVCommon.psm1' ) +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' <# .SYNOPSIS @@ -35,23 +24,23 @@ function Get-TargetResource $VMName ) - Assert-Module -Name 'Hyper-V' - Write-Verbose -Message ($localizedData.QueryingVMProcessor -f $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 + 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 + RestartIfNeeded = $false } return $configuration } @@ -134,7 +123,7 @@ function Test-TargetResource $HwThreadCountPerCore, [Parameter()] - [ValidateRange(0,100)] + [ValidateRange(0, 100)] [System.UInt64] $Maximum, @@ -147,12 +136,12 @@ function Test-TargetResource $MaximumCountPerNumaSocket, [Parameter()] - [ValidateRange(0,10000)] + [ValidateRange(0, 10000)] [System.UInt32] $RelativeWeight, [Parameter()] - [ValidateRange(0,100)] + [ValidateRange(0, 100)] [System.UInt64] $Reserve, @@ -173,7 +162,7 @@ function Test-TargetResource $RestartIfNeeded ) - Assert-Module -Name 'Hyper-V' + Assert-Module -ModuleName 'Hyper-V' Assert-TargetResourceParameter @PSBoundParameters $targetResource = Get-TargetResource -VMName $VMName @@ -187,18 +176,18 @@ function Test-TargetResource ($parameter.Value -ne $targetResource[$parameter.Key])) { $isTargetResourceCompliant = $false - Write-Verbose -Message ($localizedData.PropertyMismatch -f $parameter.Key, - $parameter.Value, $targetResource[$parameter.Key]) + Write-Verbose -Message ($script:localizedData.PropertyMismatch -f $parameter.Key, + $parameter.Value, $targetResource[$parameter.Key]) } } if ($isTargetResourceCompliant) { - Write-Verbose -Message ($localizedData.VMProcessorInDesiredState -f $VMName) + Write-Verbose -Message ($script:localizedData.VMProcessorInDesiredState -f $VMName) } else { - Write-Verbose -Message ($localizedData.VMProcessorNotInDesiredState -f $VMName) + Write-Verbose -Message ($script:localizedData.VMProcessorNotInDesiredState -f $VMName) } return $isTargetResourceCompliant @@ -281,7 +270,7 @@ function Set-TargetResource $HwThreadCountPerCore, [Parameter()] - [ValidateRange(0,100)] + [ValidateRange(0, 100)] [System.UInt64] $Maximum, @@ -294,12 +283,12 @@ function Set-TargetResource $MaximumCountPerNumaSocket, [Parameter()] - [ValidateRange(0,10000)] + [ValidateRange(0, 10000)] [System.UInt32] $RelativeWeight, [Parameter()] - [ValidateRange(0,100)] + [ValidateRange(0, 100)] [System.UInt64] $Reserve, @@ -320,7 +309,7 @@ function Set-TargetResource $RestartIfNeeded ) - Assert-Module -Name 'Hyper-V' + Assert-Module -ModuleName 'Hyper-V' Assert-TargetResourceParameter @PSBoundParameters # Parameters requiring shutdown. @@ -346,7 +335,8 @@ function Set-TargetResource if (-not $RestartIfNeeded) { $errorMessage = $localized.CannotUpdateVmOnlineError -f $parameterName - New-InvalidOperationError -ErrorId InvalidState -ErrorMessage $errorMessage + + New-InvalidOperationException -Message $errorMessage } else { @@ -362,19 +352,19 @@ function Set-TargetResource if (-not $isRestartRequired) { # No parameter specified that requires a restart, so disable the restart flag - Write-Verbose -Message ($localizedData.UpdatingVMProperties -f $VMName) + Write-Verbose -Message ($script:localizedData.UpdatingVMProperties -f $VMName) Set-VMProcessor -VMName $VMName @PSBoundParameters - Write-Verbose -Message ($localizedData.VMPropertiesUpdated -f $VMName) + 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 + VMName = $VMName + VMCommand = 'Set-VMProcessor' + ChangeProperty = $PSBoundParameters RestartIfNeeded = $true - Verbose = $Verbose + Verbose = $Verbose } Set-VMProperty @setVMPropertyParameters } @@ -434,8 +424,8 @@ function Assert-TargetResourceParameter { if (($PSBoundParameters.ContainsKey($parameterName)) -and ($osBuildNumber -lt 14393)) { - $errorMessage = $localizedData.UnsupportedSystemError -f $parameterName, 14393 - New-InvalidArgumentError -ErrorId SystemUnsupported -ErrorMessage $errorMessage + $errorMessage = $script:localizedData.UnsupportedSystemError -f $parameterName, 14393 + New-InvalidOperationException -Message $errorMessage } } } #end function diff --git a/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.schema.mof b/source/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.schema.mof similarity index 100% rename from DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.schema.mof rename to source/DSCResources/MSFT_xVMProcessor/MSFT_xVMProcessor.schema.mof diff --git a/DSCResources/MSFT_xVMProcessor/en-US/MSFT_xVMProcessor.psd1 b/source/DSCResources/MSFT_xVMProcessor/en-US/MSFT_xVMProcessor.strings.psd1 similarity index 69% rename from DSCResources/MSFT_xVMProcessor/en-US/MSFT_xVMProcessor.psd1 rename to source/DSCResources/MSFT_xVMProcessor/en-US/MSFT_xVMProcessor.strings.psd1 index fa6eab6..3ba3e34 100644 --- a/DSCResources/MSFT_xVMProcessor/en-US/MSFT_xVMProcessor.psd1 +++ b/source/DSCResources/MSFT_xVMProcessor/en-US/MSFT_xVMProcessor.strings.psd1 @@ -1,12 +1,9 @@ ConvertFrom-StringData @' QueryingVMProcessor = Querying VM '{0}' processor(s). - PropertyMismatch = Property '{0}' mismatch; expected value '{1}', but was '{2}'. + PropertyMismatch = Property '{0}' mismatch. Expected value '{1}', but was '{2}'. VMProcessorInDesiredState = VM '{0}' processor(s) in desired state. VMProcessorNotInDesiredState = VM '{0}' processor(s) not in desired state. UpdatingVMProperties = Updating VM '{0}' properties. VMPropertiesUpdated = VM '{0}' properties have been updated. - - VMNotFoundError = VM '{0}' was not found. UnsupportedSystemError = Parameter '{0}' is not supported on operating system builds earlier than '{1}'. - CannotUpdateVmOnlineError = Cannot change online property '{0}' unless 'RestartIfNeeded' is set to true. '@ diff --git a/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.psm1 b/source/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.psm1 similarity index 67% rename from DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.psm1 rename to source/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.psm1 index 6f7fd14..bf23d58 100644 --- a/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.psm1 +++ b/source/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.psm1 @@ -1,25 +1,10 @@ -#region localizeddata -if (Test-Path "${PSScriptRoot}\${PSUICulture}") -{ - Import-LocalizedData ` - -BindingVariable LocalizedData ` - -Filename MSFT_xVMScsiController.strings.psd1 ` - -BaseDirectory "${PSScriptRoot}\${PSUICulture}" -} -else -{ - # fallback to en-US - Import-LocalizedData ` - -BindingVariable LocalizedData ` - -Filename MSFT_xVMScsiController.strings.psd1 ` - -BaseDirectory "${PSScriptRoot}\en-US" -} -#endregion +$script:dscResourceCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/DscResource.Common' +$script:hyperVDscCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../../Modules/HyperVDsc.Common' -# Import the common HyperV functions -Import-Module -Name ( Join-Path ` - -Path (Split-Path -Path $PSScriptRoot -Parent) ` - -ChildPath '\HyperVCommon\HyperVCommon.psm1' ) +Import-Module -Name $script:dscResourceCommonModulePath +Import-Module -Name $script:hyperVDscCommonModulePath + +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' <# .SYNOPSIS @@ -48,17 +33,17 @@ function Get-TargetResource $ControllerNumber ) - Assert-Module -Name 'Hyper-V' + Assert-Module -ModuleName 'Hyper-V' $controller = Get-VMScsiController -VMName $VMName -ControllerNumber $ControllerNumber if ($null -eq $controller) { - Write-Verbose -Message ($localizedData.ControllerNotFound -f $ControllerNumber, $VMName) + Write-Verbose -Message ($script:localizedData.ControllerNotFound -f $ControllerNumber, $VMName) $ensure = 'Absent' } else { - Write-Verbose -Message ($localizedData.ControllerFound -f $ControllerNumber, $VMName) + Write-Verbose -Message ($script:localizedData.ControllerFound -f $ControllerNumber, $VMName) $ensure = 'Present' } @@ -118,9 +103,9 @@ function Test-TargetResource $isCompliant = $true foreach ($key in $resource.Keys) { - Write-Verbose -Message ($localizedData.ComparingParameter -f $key, - $PSBoundParameters[$key], - $resource[$key]) + Write-Verbose -Message ($script:localizedData.ComparingParameter -f $key, + $PSBoundParameters[$key], + $resource[$key]) $isCompliant = $isCompliant -and ($PSBoundParameters[$key] -eq $resource[$key]) } @@ -168,15 +153,16 @@ function Set-TargetResource $Ensure = 'Present' ) - Assert-Module -Name 'Hyper-V' + 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 = $localizedData.CannotUpdateVmOnlineError -f $VMName - New-InvalidOperationError -ErrorId InvalidState -ErrorMessage $errorMessage + $errorMessage = $script:localizedData.CannotUpdateVmOnlineError -f $VMName + + New-InvalidOperationException -Message $errorMessage } [System.Int32] $scsiControllerCount = @(Get-VMScsiController -VMName $VMName).Count @@ -185,22 +171,23 @@ function Set-TargetResource 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. + 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 = $localizedData.CannotAddScsiControllerError -f $ControllerNumber - New-InvalidArgumentError -ErrorId InvalidController -ErrorMessage $errorMessage + $errorMessage = $script:localizedData.CannotAddScsiControllerError -f $ControllerNumber + + New-InvalidOperationException -Message $errorMessage } Set-VMState -Name $VMName -State 'Off' - Write-Verbose -Message ($localizedData.AddingController -f $scsiControllerCount) + Write-Verbose -Message ($script:localizedData.AddingController -f $scsiControllerCount) Add-VMScsiController -VMName $VMName } else { - if ($scsiControllerCount -ne ($ControllerNumber +1)) + if ($scsiControllerCount -ne ($ControllerNumber + 1)) { <# All intermediate controllers should be present on the system. Whilst we can remove @@ -208,22 +195,23 @@ function Set-TargetResource reordered. For example, if we remove controller at position #1, then a controller that was at position #2 will become controller number #1. #> - $errorMessage = $localizedData.CannotRemoveScsiControllerError -f $ControllerNumber - New-InvalidArgumentError -ErrorId InvalidController -ErrorMessage $errorMessage + $errorMessage = $script:localizedData.CannotRemoveScsiControllerError -f $ControllerNumber + + New-InvalidOperationException -Message $errorMessage } Set-VMState -Name $VMName -State 'Off' - Write-Verbose -Message ($localizedData.CheckingExistingDisks -f $ControllerNumber) + Write-Verbose -Message ($script:localizedData.CheckingExistingDisks -f $ControllerNumber) $controller = Get-VMScsiController -VMName $VmName -ControllerNumber $ControllerNumber foreach ($drive in $controller.Drives) { - $warningMessage = $localizedData.RemovingDiskWarning -f $drive.Path, $ControllerNumber + $warningMessage = $script:localizedData.RemovingDiskWarning -f $drive.Path, $ControllerNumber Write-Warning -Message $warningMessage Remove-VMHardDiskDrive -VMHardDiskDrive $drive } - Write-Verbose -Message ($localizedData.RemovingController -f $ControllerNumber, $VMName) + Write-Verbose -Message ($script:localizedData.RemovingController -f $ControllerNumber, $VMName) Remove-VMScsiController -VMScsiController $controller } diff --git a/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.schema.mof b/source/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.schema.mof similarity index 100% rename from DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.schema.mof rename to source/DSCResources/MSFT_xVMScsiController/MSFT_xVMScsiController.schema.mof diff --git a/DSCResources/MSFT_xVMScsiController/en-US/MSFT_xVMScsiController.strings.psd1 b/source/DSCResources/MSFT_xVMScsiController/en-US/MSFT_xVMScsiController.strings.psd1 similarity index 93% rename from DSCResources/MSFT_xVMScsiController/en-US/MSFT_xVMScsiController.strings.psd1 rename to source/DSCResources/MSFT_xVMScsiController/en-US/MSFT_xVMScsiController.strings.psd1 index 1587659..4ccc530 100644 --- a/DSCResources/MSFT_xVMScsiController/en-US/MSFT_xVMScsiController.strings.psd1 +++ b/source/DSCResources/MSFT_xVMScsiController/en-US/MSFT_xVMScsiController.strings.psd1 @@ -1,7 +1,7 @@ ConvertFrom-StringData @' ControllerFound = Found controller '{0}' attached to VM '{1}'. ControllerNotFound = Controller '{0}' missing from VM '{1}' - ComparingParameter = Comparing '{0}'; expected '{1}', actual '{2}'. + ComparingParameter = Comparing '{0}'. Expected '{1}', actual '{2}'. AddingController = Adding controller number '{0}'. CheckingExistingDisks = Checking for existing disks on controller '{0}'. RemovingController = Removing controller '{0}' from VM '{1}'. diff --git a/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.psm1 b/source/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.psm1 similarity index 56% rename from DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.psm1 rename to source/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.psm1 index 397e464..e23bc07 100644 --- a/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.psm1 +++ b/source/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.psm1 @@ -1,25 +1,10 @@ -#region localizeddata -if (Test-Path "${PSScriptRoot}\${PSUICulture}") -{ - Import-LocalizedData ` - -BindingVariable LocalizedData ` - -Filename MSFT_xVMSwitch.strings.psd1 ` - -BaseDirectory "${PSScriptRoot}\${PSUICulture}" -} -else -{ - #fallback to en-US - Import-LocalizedData ` - -BindingVariable LocalizedData ` - -Filename MSFT_xVMSwitch.strings.psd1 ` - -BaseDirectory "${PSScriptRoot}\en-US" -} -#endregion +$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 -# Import the common HyperV functions -Import-Module -Name ( Join-Path ` - -Path (Split-Path -Path $PSScriptRoot -Parent) ` - -ChildPath '\HyperVCommon\HyperVCommon.psm1' ) +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' <# .SYNOPSIS @@ -38,12 +23,12 @@ function Get-TargetResource param ( [Parameter(Mandatory = $true)] - [String] + [System.String] $Name, [Parameter(Mandatory = $true)] - [ValidateSet("External","Internal","Private")] - [String] + [ValidateSet('External', 'Internal', 'Private')] + [System.String] $Type ) @@ -52,9 +37,9 @@ function Get-TargetResource # Check if Hyper-V module is present for Hyper-V cmdlets if (!(Get-Module -ListAvailable -Name Hyper-V)) { - New-InvalidOperationError ` - -ErrorId 'HyperVNotInstalledError' ` - -ErrorMessage $LocalizedData.HyperVNotInstalledError + $errorMessage = $script:localizedData.HyperVNotInstalledError + + New-ObjectNotFoundException -Message $errorMessage } $switch = Get-VMSwitch -Name $Name -SwitchType $Type -ErrorAction SilentlyContinue @@ -91,14 +76,14 @@ function Get-TargetResource } $returnValue = @{ - Name = $switch.Name - Type = $switch.SwitchType - NetAdapterName = [string[]]$netAdapterName - AllowManagementOS = $switch.AllowManagementOS - EnableEmbeddedTeaming = $switch.EmbeddedTeamingEnabled - LoadBalancingAlgorithm = $loadBalancingAlgorithm - Ensure = $ensure - Id = $switch.Id + 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 } @@ -151,77 +136,89 @@ function Set-TargetResource param ( [Parameter(Mandatory = $true)] - [String] + [System.String] $Name, [Parameter(Mandatory = $true)] - [ValidateSet("External","Internal","Private")] - [String] + [ValidateSet('External', 'Internal', 'Private')] + [System.String] $Type, [Parameter()] [ValidateNotNullOrEmpty()] - [String[]] + [System.String[]] $NetAdapterName, [Parameter()] - [Boolean] + [System.Boolean] $AllowManagementOS = $false, [Parameter()] - [Boolean] + [System.Boolean] $EnableEmbeddedTeaming = $false, [Parameter()] - [ValidateSet("Default","Weight","Absolute","None","NA")] - [String] - $BandwidthReservationMode = "NA", + [ValidateSet('Default', 'Weight', 'Absolute', 'None', 'NA')] + [System.String] + $BandwidthReservationMode = 'NA', [Parameter()] - [ValidateSet('Dynamic','HyperVPort')] - [String] + [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!'}})] - [String] + [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")] - [String] - $Ensure = "Present" + [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)) { - New-InvalidOperationError ` - -ErrorId 'HyperVNotInstalledError' ` - -ErrorMessage $LocalizedData.HyperVNotInstalledError + $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')) + elseif (($BandwidthReservationMode -ne 'NA') -and ((Get-OSVersion) -lt [version]'6.2.0')) { - New-InvalidArgumentError ` - -ErrorId 'BandwidthReservationModeError' ` - -ErrorMessage $LocalizedData.BandwidthReservationModeError + $errorMessage = $script:localizedData.BandwidthReservationModeError + + New-InvalidOperationException -Message $errorMessage } if ($EnableEmbeddedTeaming -eq $true -and (Get-OSVersion).Major -lt 10) { - New-InvalidArgumentError ` - -ErrorId 'SETServer2016Error' ` - -ErrorMessage $LocalizedData.SETServer2016Error + $errorMessage = $script:localizedData.SETServer2016Error + + New-InvalidOperationException -Message $errorMessage } if (($PSBoundParameters.ContainsKey('Id')) -and (Get-OSVersion).Major -lt 10) { - New-InvalidArgumentError ` - -ErrorId 'VMSwitchIDServer2016Error' ` - -ErrorMessage $LocalizedData.VMSwitchIDServer2016Error + $errorMessage = $script:localizedData.VMSwitchIDServer2016Error + + New-InvalidOperationException -Message $errorMessage } if ($Ensure -eq 'Present') @@ -233,12 +230,12 @@ function Set-TargetResource { $removeReaddSwitch = $false - Write-Verbose -Message ($LocalizedData.CheckingSwitchMessage -f $Name) + 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 ($LocalizedData.NetAdapterInterfaceIncorrectMessage -f $Name) + Write-Verbose -Message ($script:localizedData.NetAdapterInterfaceIncorrectMessage -f $Name) $removeReaddSwitch = $true } } @@ -247,63 +244,63 @@ function Set-TargetResource $adapters = (Get-NetAdapter -InterfaceDescription $switch.NetAdapterInterfaceDescriptions -ErrorAction SilentlyContinue).Name if ($null -ne (Compare-Object -ReferenceObject $adapters -DifferenceObject $NetAdapterName)) { - Write-Verbose -Message ($LocalizedData.SwitchIncorrectNetworkAdapters -f $Name) + Write-Verbose -Message ($script:localizedData.SwitchIncorrectNetworkAdapters -f $Name) $removeReaddSwitch = $true } } - if (($BandwidthReservationMode -ne "NA") -and ($switch.BandwidthReservationMode -ne $BandwidthReservationMode)) + if (($BandwidthReservationMode -ne 'NA') -and ($switch.BandwidthReservationMode -ne $BandwidthReservationMode)) { - Write-Verbose -Message ($LocalizedData.BandwidthReservationModeIncorrect -f $Name) + Write-Verbose -Message ($script:localizedData.BandwidthReservationModeIncorrect -f $Name) $removeReaddSwitch = $true } if ($null -ne $switch.EmbeddedTeamingEnabled -and $switch.EmbeddedTeamingEnabled -ne $EnableEmbeddedTeaming) { - Write-Verbose -Message ($LocalizedData.EnableEmbeddedTeamingIncorrect -f $Name) + Write-Verbose -Message ($script:localizedData.EnableEmbeddedTeamingIncorrect -f $Name) $removeReaddSwitch = $true } if ($null -ne $switch.EmbeddedTeamingEnabled -and $switch.EmbeddedTeamingEnabled -ne $EnableEmbeddedTeaming) { - Write-Verbose -Message ($LocalizedData.EnableEmbeddedTeamingIncorrect -f $Name) + Write-Verbose -Message ($script:localizedData.EnableEmbeddedTeamingIncorrect -f $Name) $removeReaddSwitch = $true } if ($PSBoundParameters.ContainsKey('Id') -and $switch.Id -ne $Id) { - Write-Verbose -Message ($LocalizedData.IdIncorrect -f $Name) + Write-Verbose -Message ($script:localizedData.IdIncorrect -f $Name) $removeReaddSwitch = $true } if ($removeReaddSwitch) { - Write-Verbose -Message ($LocalizedData.RemoveAndReaddSwitchMessage -f $Name) + Write-Verbose -Message ($script:localizedData.RemoveAndReaddSwitchMessage -f $Name) $switch | Remove-VMSwitch -Force - $parameters = @{} - $parameters["Name"] = $Name - $parameters["NetAdapterName"] = $NetAdapterName + $parameters = @{ } + $parameters['Name'] = $Name + $parameters['NetAdapterName'] = $NetAdapterName - if ($BandwidthReservationMode -ne "NA") + if ($BandwidthReservationMode -ne 'NA') { - $parameters["MinimumBandwidthMode"] = $BandwidthReservationMode + $parameters['MinimumBandwidthMode'] = $BandwidthReservationMode } - if ($PSBoundParameters.ContainsKey("AllowManagementOS")) + if ($PSBoundParameters.ContainsKey('AllowManagementOS')) { - $parameters["AllowManagementOS"] = $AllowManagementOS + $parameters['AllowManagementOS'] = $AllowManagementOS } - if ($PSBoundParameters.ContainsKey("EnableEmbeddedTeaming")) + if ($PSBoundParameters.ContainsKey('EnableEmbeddedTeaming')) { - $parameters["EnableEmbeddedTeaming"] = $EnableEmbeddedTeaming + $parameters['EnableEmbeddedTeaming'] = $EnableEmbeddedTeaming } if ($PSBoundParameters.ContainsKey('Id')) { - $parameters["Id"] = $Id.ToString() + $parameters['Id'] = $Id.ToString() } $null = New-VMSwitch @parameters @@ -312,70 +309,70 @@ function Set-TargetResource } else { - Write-Verbose -Message ($LocalizedData.SwitchCorrectNetAdapterAndBandwidthMode -f $Name, ($NetAdapterName -join ','), $BandwidthReservationMode) + Write-Verbose -Message ($script:localizedData.SwitchCorrectNetAdapterAndBandwidthMode -f $Name, ($NetAdapterName -join ','), $BandwidthReservationMode) } - Write-Verbose -Message ($LocalizedData.CheckAllowManagementOS -f $Name) - if ($PSBoundParameters.ContainsKey("AllowManagementOS") -and ($switch.AllowManagementOS -ne $AllowManagementOS)) + Write-Verbose -Message ($script:localizedData.CheckAllowManagementOS -f $Name) + if ($PSBoundParameters.ContainsKey('AllowManagementOS') -and ($switch.AllowManagementOS -ne $AllowManagementOS)) { - Write-Verbose -Message ($LocalizedData.AllowManagementOSIncorrect -f $Name) + Write-Verbose -Message ($script:localizedData.AllowManagementOSIncorrect -f $Name) $switch | Set-VMSwitch -AllowManagementOS $AllowManagementOS - Write-Verbose -Message ($LocalizedData.AllowManagementOSUpdated -f $Name, $AllowManagementOS) + Write-Verbose -Message ($script:localizedData.AllowManagementOSUpdated -f $Name, $AllowManagementOS) } else { - Write-Verbose -Message ($LocalizedData.AllowManagementOSCorrect -f $Name) + Write-Verbose -Message ($script:localizedData.AllowManagementOSCorrect -f $Name) } } # If the switch is not present, create one else { - Write-Verbose -Message ($LocalizedData.PresentNotCorrect -f $Name, $Ensure) - Write-Verbose -Message $LocalizedData.CreatingSwitch - $parameters = @{} - $parameters["Name"] = $Name + Write-Verbose -Message ($script:localizedData.PresentNotCorrect -f $Name, $Ensure) + Write-Verbose -Message $script:localizedData.CreatingSwitch + $parameters = @{ } + $parameters['Name'] = $Name - if ($BandwidthReservationMode -ne "NA") + if ($BandwidthReservationMode -ne 'NA') { - $parameters["MinimumBandwidthMode"] = $BandwidthReservationMode + $parameters['MinimumBandwidthMode'] = $BandwidthReservationMode } if ($NetAdapterName) { - $parameters["NetAdapterName"] = $NetAdapterName - if ($PSBoundParameters.ContainsKey("AllowManagementOS")) + $parameters['NetAdapterName'] = $NetAdapterName + if ($PSBoundParameters.ContainsKey('AllowManagementOS')) { - $parameters["AllowManagementOS"] = $AllowManagementOS + $parameters['AllowManagementOS'] = $AllowManagementOS } } else { - $parameters["SwitchType"] = $Type + $parameters['SwitchType'] = $Type } - if ($PSBoundParameters.ContainsKey("EnableEmbeddedTeaming")) + if ($PSBoundParameters.ContainsKey('EnableEmbeddedTeaming')) { - $parameters["EnableEmbeddedTeaming"] = $EnableEmbeddedTeaming + $parameters['EnableEmbeddedTeaming'] = $EnableEmbeddedTeaming } if ($PSBoundParameters.ContainsKey('Id')) { - $parameters["Id"] = $Id + $parameters['Id'] = $Id } $switch = New-VMSwitch @parameters - Write-Verbose -Message ($LocalizedData.PresentCorrect -f $Name, $Ensure) + 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')) + if ($EnableEmbeddedTeaming -eq $true -and $PSBoundParameters.ContainsKey('LoadBalancingAlgorithm')) { - Write-Verbose -Message ($LocalizedData.SetLoadBalancingAlgorithmMessage -f $Name, $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 + # Ensure is set to 'Absent', remove the switch else { Get-VMSwitch $Name -ErrorAction SilentlyContinue | Remove-VMSwitch -Force @@ -420,104 +417,116 @@ function Test-TargetResource param ( [Parameter(Mandatory = $true)] - [String] + [System.String] $Name, [Parameter(Mandatory = $true)] - [ValidateSet("External","Internal","Private")] - [String] + [ValidateSet('External', 'Internal', 'Private')] + [System.String] $Type, [Parameter()] [ValidateNotNullOrEmpty()] - [String[]] + [System.String[]] $NetAdapterName, [Parameter()] - [Boolean] + [System.Boolean] $AllowManagementOS = $false, [Parameter()] - [Boolean] + [System.Boolean] $EnableEmbeddedTeaming = $false, [Parameter()] - [ValidateSet("Default","Weight","Absolute","None","NA")] - [String] - $BandwidthReservationMode = "NA", + [ValidateSet('Default', 'Weight', 'Absolute', 'None', 'NA')] + [System.String] + $BandwidthReservationMode = 'NA', [Parameter()] - [ValidateSet('Dynamic','HyperVPort')] - [String] + [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!'}})] - [String] + [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")] - [String] - $Ensure = "Present" + [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)) { - New-InvalidOperationError ` - -ErrorId 'HyperVNotInstalledError' ` - -ErrorMessage $LocalizedData.HyperVNotInstalledError + $errorMessage = $script:localizedData.HyperVNotInstalledError + New-ObjectNotFoundException -Message $errorMessage } #region input validation if ($Type -eq 'External' -and !($NetAdapterName)) { - New-InvalidArgumentError ` - -ErrorId 'NetAdapterNameRequiredError' ` - -ErrorMessage $LocalizedData.NetAdapterNameRequiredError + $errorMessage = $script:localizedData.NetAdapterNameRequiredError + + New-InvalidArgumentException -ArgumentName 'Type' -Message $errorMessage } if ($Type -ne 'External' -and $NetAdapterName) { - New-InvalidArgumentError ` - -ErrorId 'NetAdapterNameNotRequiredError' ` - -ErrorMessage $LocalizedData.NetAdapterNameNotRequiredError + $errorMessage = $script:localizedData.NetAdapterNameNotRequiredError + + New-InvalidArgumentException -ArgumentName 'Type' -Message $errorMessage } - if (($BandwidthReservationMode -ne "NA") -and ((Get-OSVersion) -lt [version]'6.2.0')) + if (($BandwidthReservationMode -ne 'NA') -and ((Get-OSVersion) -lt [version]'6.2.0')) { - New-InvalidArgumentError ` - -ErrorId 'BandwidthReservationModeError' ` - -ErrorMessage $LocalizedData.BandwidthReservationModeError + $errorMessage = $script:localizedData.BandwidthReservationModeError + + New-InvalidArgumentException -ArgumentName 'BandwidthReservationMode' -Message $errorMessage } if ($EnableEmbeddedTeaming -eq $true -and (Get-OSVersion).Major -lt 10) { - New-InvalidArgumentError ` - -ErrorId 'SETServer2016Error' ` - -ErrorMessage $LocalizedData.SETServer2016Error + $errorMessage = $script:localizedData.SETServer2016Error + + New-InvalidArgumentException -ArgumentName 'EnableEmbeddedTeaming' -Message $errorMessage } if (($PSBoundParameters.ContainsKey('Id')) -and (Get-OSVersion).Major -lt 10) { - New-InvalidArgumentError ` - -ErrorId 'VMSwitchIDServer2016Error' ` - -ErrorMessage $LocalizedData.VMSwitchIDServer2016Error + $errorMessage = $script:localizedData.VMSwitchIDServer2016Error + + New-InvalidOperationException -Message $errorMessage } #endregion try { # Check if switch exists - Write-Verbose -Message ($LocalizedData.PresentChecking -f $Name, $Ensure) + 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 ($LocalizedData.SwitchPresent -f $Name) + Write-Verbose -Message ($script:localizedData.SwitchPresent -f $Name) # If switch should be present, check the switch type if ($Ensure -eq 'Present') { @@ -525,14 +534,14 @@ function Test-TargetResource 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 ($LocalizedData.CheckingBandwidthReservationMode -f $Name) + Write-Verbose -Message ($script:localizedData.CheckingBandwidthReservationMode -f $Name) if ($switch.BandwidthReservationMode -eq $BandwidthReservationMode -or $null -eq $switch.BandwidthReservationMode) { - Write-Verbose -Message ($LocalizedData.BandwidthReservationModeCorrect -f $Name) + Write-Verbose -Message ($script:localizedData.BandwidthReservationModeCorrect -f $Name) } else { - Write-Verbose -Message ($LocalizedData.BandwidthReservationModeIncorrect -f $Name) + Write-Verbose -Message ($script:localizedData.BandwidthReservationModeIncorrect -f $Name) return $false } } @@ -542,7 +551,7 @@ function Test-TargetResource { if ($EnableEmbeddedTeaming -eq $false) { - Write-Verbose -Message ($LocalizedData.CheckingNetAdapterInterface -f $Name) + Write-Verbose -Message ($script:localizedData.CheckingNetAdapterInterface -f $Name) $adapter = $null try { @@ -554,7 +563,7 @@ function Test-TargetResource # 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 $LocalizedData.NetAdapterNotFound + Write-Verbose -Message $script:localizedData.NetAdapterNotFound } if ($adapter.InterfaceDescription -ne $switch.NetAdapterInterfaceDescription) @@ -563,86 +572,86 @@ function Test-TargetResource } else { - Write-Verbose -Message ($LocalizedData.NetAdapterInterfaceCorrect -f $Name) + Write-Verbose -Message ($script:localizedData.NetAdapterInterfaceCorrect -f $Name) } } else { - Write-Verbose -Message ($LocalizedData.CheckingNetAdapterInterfaces -f $Name) + 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 ($LocalizedData.IncorrectNetAdapterInterfaces -f $Name) + Write-Verbose -Message ($script:localizedData.IncorrectNetAdapterInterfaces -f $Name) return $false } else { - Write-Verbose -Message ($LocalizedData.CorrectNetAdapterInterfaces -f $Name) + Write-Verbose -Message ($script:localizedData.CorrectNetAdapterInterfaces -f $Name) } } else { - Write-Verbose -Message ($LocalizedData.IncorrectNetAdapterInterfaces -f $Name) + Write-Verbose -Message ($script:localizedData.IncorrectNetAdapterInterfaces -f $Name) return $false } } - if ($PSBoundParameters.ContainsKey("AllowManagementOS")) + if ($PSBoundParameters.ContainsKey('AllowManagementOS')) { - Write-Verbose -Message ($LocalizedData.CheckAllowManagementOS -f $Name) + Write-Verbose -Message ($script:localizedData.CheckAllowManagementOS -f $Name) if (($switch.AllowManagementOS -ne $AllowManagementOS)) { return $false } else { - Write-Verbose -Message ($LocalizedData.AllowManagementOSCorrect -f $Name) + Write-Verbose -Message ($script:localizedData.AllowManagementOSCorrect -f $Name) } } - if($PSBoundParameters.ContainsKey('LoadBalancingAlgorithm')) + if ($PSBoundParameters.ContainsKey('LoadBalancingAlgorithm')) { - Write-Verbose -Message ($LocalizedData.CheckingLoadBalancingAlgorithm -f $Name) + Write-Verbose -Message ($script:localizedData.CheckingLoadBalancingAlgorithm -f $Name) $loadBalancingAlgorithm = ($switch | Get-VMSwitchTeam).LoadBalancingAlgorithm.toString() - if($loadBalancingAlgorithm -ne $LoadBalancingAlgorithm) + if ($loadBalancingAlgorithm -ne $LoadBalancingAlgorithm) { return $false } else { - Write-Verbose -Message ($LocalizedData.LoadBalancingAlgorithmCorrect -f $Name) + Write-Verbose -Message ($script:localizedData.LoadBalancingAlgorithmCorrect -f $Name) } } } # Only check embedded teaming if specified - if ($PSBoundParameters.ContainsKey("EnableEmbeddedTeaming") -eq $true) + if ($PSBoundParameters.ContainsKey('EnableEmbeddedTeaming') -eq $true) { - Write-Verbose -Message ($LocalizedData.CheckEnableEmbeddedTeaming -f $Name) + Write-Verbose -Message ($script:localizedData.CheckEnableEmbeddedTeaming -f $Name) if ($switch.EmbeddedTeamingEnabled -eq $EnableEmbeddedTeaming -or $null -eq $switch.EmbeddedTeamingEnabled) { - Write-Verbose -Message ($LocalizedData.EnableEmbeddedTeamingCorrect -f $Name) + Write-Verbose -Message ($script:localizedData.EnableEmbeddedTeamingCorrect -f $Name) } else { - Write-Verbose -Message ($LocalizedData.EnableEmbeddedTeamingIncorrect -f $Name) + Write-Verbose -Message ($script:localizedData.EnableEmbeddedTeamingIncorrect -f $Name) return $false } } # Check if the Switch has the desired ID - if ($PSBoundParameters.ContainsKey("Id") -eq $true) + if ($PSBoundParameters.ContainsKey('Id') -eq $true) { - Write-Verbose -Message ($LocalizedData.CheckID -f $Name) + Write-Verbose -Message ($script:localizedData.CheckID -f $Name) if ($switch.Id.Guid -eq $Id) { - Write-Verbose -Message ($LocalizedData.IdCorrect -f $Name) + Write-Verbose -Message ($script:localizedData.IdCorrect -f $Name) } else { - Write-Verbose -Message ($LocalizedData.IdIncorrect -f $Name) + Write-Verbose -Message ($script:localizedData.IdIncorrect -f $Name) return $false } } @@ -655,12 +664,23 @@ function Test-TargetResource 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 ($LocalizedData.SwitchNotPresent -f $Name) + Write-Verbose -Message ($script:localizedData.SwitchNotPresent -f $Name) return ($Ensure -eq 'Absent') } } diff --git a/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.schema.mof b/source/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.schema.mof similarity index 100% rename from DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.schema.mof rename to source/DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.schema.mof diff --git a/DSCResources/MSFT_xVMSwitch/en-us/MSFT_xVMSwitch.strings.psd1 b/source/DSCResources/MSFT_xVMSwitch/en-US/MSFT_xVMSwitch.strings.psd1 similarity index 100% rename from DSCResources/MSFT_xVMSwitch/en-us/MSFT_xVMSwitch.strings.psd1 rename to source/DSCResources/MSFT_xVMSwitch/en-US/MSFT_xVMSwitch.strings.psd1 diff --git a/DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.psm1 b/source/DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.psm1 similarity index 54% rename from DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.psm1 rename to source/DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.psm1 index 218d243..e05f600 100644 --- a/DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.psm1 +++ b/source/DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.psm1 @@ -1,4 +1,10 @@ +$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. @@ -18,29 +24,40 @@ function Get-TargetResource $FileDirectory, [Parameter()] - [ValidateSet('ModifiedDate','SHA-1','SHA-256','SHA-512')] + [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 + $item = New-CimInstance -ClassName MSFT_FileDirectoryConfiguration -Property @{ + DestinationPath = $VhdPath + Ensure = 'Absent' + } -Namespace 'root/microsoft/windows/desiredstateconfiguration' -ClientOnly - Return @{ - VhdPath = $VhdPath + return @{ + VhdPath = $VhdPath FileDirectory = $item - } + } } # Mount VHD. $mountVHD = EnsureVHDState -Mounted -vhdPath $vhdPath - $itemsFound = foreach($Item in $FileDirectory) + $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) + ":\" + + $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 @@ -51,21 +68,27 @@ function Get-TargetResource if (Test-Path $finalPath) { - New-CimInstance -ClassName MSFT_FileDirectoryConfiguration -Property @{DestinationPath = $finalPath; Ensure = "Present"} -Namespace root/microsoft/windows/desiredstateconfiguration -ClientOnly + 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 + 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 + return @{ + VhdPath = $VhdPath + FileDirectory = $itemsFound } } @@ -85,67 +108,68 @@ function Set-TargetResource $FileDirectory, [Parameter()] - [ValidateSet('ModifiedDate','SHA-1','SHA-256','SHA-512')] + [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!"} + 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 + # show the drive letters. + Get-PSDrive | Write-Verbose - $mountedDrive = $mountedVHD | Get-Disk | Get-Partition | Where-Object -FilterScript {$_.Type -ne 'Recovery'} | Get-Volume + $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 + 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 the destination should be removed + if (-not($itemToCopy.Ensure)) + { + if (Test-Path $finalDestinationPath) { - if (Test-Path $finalDestinationPath) - { - SetVHDFile -destinationPath $finalDestinationPath -ensure:$false -recurse:($itemToCopy.Recurse) - } + SetVHDFile -destinationPath $finalDestinationPath -ensure:$false -recurse:($itemToCopy.Recurse) } - else + } + else + { + # Copy Scenario + if ($itemToCopy.SourcePath) + { + SetVHDFile -sourcePath $itemToCopy.SourcePath -destinationPath $finalDestinationPath -recurse:($itemToCopy.Recurse) -force:($itemToCopy.Force) + } + elseif ($itemToCopy.Content) { - # Copy Scenario - if ($itemToCopy.SourcePath) + # if the type is not specified assume it is a file. + if (-not ($itemToCopy.Type)) { - SetVHDFile -sourcePath $itemToCopy.SourcePath -destinationPath $finalDestinationPath -recurse:($itemToCopy.Recurse) -force:($itemToCopy.Force) + $itemToCopy.Type = 'File' } - elseif ($itemToCopy.Content) - { - "Writing a content to a file" - # 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) - } + # 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 { @@ -169,7 +193,7 @@ function Test-TargetResource $FileDirectory, [Parameter()] - [ValidateSet('ModifiedDate','SHA-1','SHA-256','SHA-512')] + [ValidateSet('ModifiedDate', 'SHA-1', 'SHA-256', 'SHA-512')] [System.String] $CheckSum = 'ModifiedDate' ) @@ -188,8 +212,8 @@ function Test-TargetResource # 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) + ":\" + $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. @@ -198,55 +222,55 @@ function Test-TargetResource foreach ($item in $FileDirectory) { $itemToCopy = GetItemToCopy -item $item - $destination = $itemToCopy.DestinationPath + $destination = $itemToCopy.DestinationPath Write-Verbose ("Testing the file with relative VHD destination $destination") - $destination = $itemToCopy.DestinationPath + $destination = $itemToCopy.DestinationPath $finalDestinationPath = $letterDrive $finalDestinationPath = Join-Path $letterDrive $destination if (Test-Path $finalDestinationPath) { - if( -not ($itemToCopy.Ensure)) - { + 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) - } + 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)) + if (($itemToCopy.Type -eq 'Directory') -and ($itemToCopy.Recurse)) + { + $result = $result -and -not(ItemHasChanged -sourcePath $itemToCopy.SourcePath -destinationPath $finalDestinationPath -CheckSum $CheckSum) + + if (-not ($result)) { - $result = $result -and -not(ItemHasChanged -sourcePath $itemToCopy.SourcePath -destinationPath $finalDestinationPath -CheckSum $CheckSum) - - if (-not ($result)) - { - break; - } - } - } + break + } + } + } } else { # If Ensure is specified as Present or if Ensure is not specified at all. - if(($itemToCopy.Ensure)) + if (($itemToCopy.Ensure)) { $result = $false - break; + break } } @@ -256,7 +280,7 @@ function Test-TargetResource $currentAttribute = @(Get-ItemProperty -Path $finalDestinationPath | ForEach-Object -MemberName Attributes) $result = $currentAttribute.Contains($itemToCopy.Attributes) } - } + } } finally { @@ -264,79 +288,84 @@ function Test-TargetResource } - Write-Verbose "Test returned $result" - return $result; + Write-Verbose "Test returned $result" + return $result } # Assert the state of the VHD. function EnsureVHDState { - [CmdletBinding(DefaultParametersetName="Mounted")] - param( - - [Parameter(ParameterSetName = "Mounted")] + [CmdletBinding(DefaultParameterSetName = 'Mounted')] + param + ( + [Parameter(ParameterSetName = 'Mounted')] [switch]$Mounted, - [Parameter(ParameterSetName = "Dismounted")] + + [Parameter(ParameterSetName = 'Dismounted')] [switch]$Dismounted, - [Parameter(Mandatory=$true)] + + [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 (-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 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 + if ($PSCmdlet.ParameterSetName -eq 'Mounted') + { + # Try mounting the VHD. + $mountedVHD = Mount-VHD -Path $vhdPath -Passthru -ErrorAction SilentlyContinue -ErrorVariable var - return $mountedVHD - } - else - { - return $mountedVHD - } + # 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 { - Dismount-VHD $vhdPath -ea SilentlyContinue - + 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( + param + ( [Parameter()] - [Microsoft.Management.Infrastructure.CimInstance] $item - ) + [Microsoft.Management.Infrastructure.CimInstance] + $item + ) #Initialize Return Object - $returnValue = @{} + $returnValue = @{ } #Define Default Values $DesiredProperties = [ordered]@{ - 'SourcePath' = $null + 'SourcePath' = $null 'DestinationPath' = $null - 'Ensure' = 'Present' - 'Recurse' = 'True' - 'Force' = 'True' - 'Content' = $null - 'Attributes' = $null - 'Type' = 'Directory' + 'Ensure' = 'Present' + 'Recurse' = 'True' + 'Force' = 'True' + 'Content' = $null + 'Attributes' = $null + 'Type' = 'Directory' } - [string[]]($DesiredProperties.Keys) | Foreach-Object -Process { + [System.String[]] ($DesiredProperties.Keys) | Foreach-Object -Process { #Get Property Value $thisItem = $item.CimInstanceProperties[$_].Value @@ -353,6 +382,7 @@ function GetItemToCopy $DefaultValues.Type = 'File' } } + $returnValue[$_] = $DefaultValues[$_] } else @@ -375,9 +405,9 @@ function GetItemToCopy } - $returnValue.Keys | ForEach-Object -Process { + $returnValue.Keys | ForEach-Object -Process { Write-Verbose "$_ => $($returnValue[$_])" - } + } return $returnValue } @@ -386,25 +416,36 @@ function GetItemToCopy # 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")] + [CmdletBinding(DefaultParameterSetName = 'Copy')] + param + ( + [Parameter(Mandatory = $true, ParameterSetName = 'Copy')] $sourcePath, + [Parameter()] - [switch]$recurse, + [switch] + $recurse, + [Parameter()] - [switch]$force, - [Parameter(ParameterSetName = "New")] + [switch] + $force, + + [Parameter(ParameterSetName = 'New')] $type, - [Parameter(ParameterSetName = "New")] + + [Parameter(ParameterSetName = 'New')] $content, - [Parameter(Mandatory=$true)] + + [Parameter(Mandatory = $true)] $destinationPath, - [Parameter(Mandatory=$true,ParameterSetName = "Set")] + + [Parameter(Mandatory = $true, ParameterSetName = 'Set')] $attribute, - [Parameter(Mandatory=$true,ParameterSetName = "Delete")] - [switch]$ensure - ) + + [Parameter(Mandatory = $true, ParameterSetName = 'Delete')] + [switch] + $ensure + ) Write-Verbose "Setting the VHD file $($PSCmdlet.ParameterSetName)" if ($PSCmdlet.ParameterSetName -eq 'Copy') @@ -414,7 +455,7 @@ function SetVHDFile } elseif ($PSCmdlet.ParameterSetName -eq 'New') { - If ($type -eq 'Directory') + if ($type -eq 'Directory') { New-Item -Path $destinationPath -ItemType $type } @@ -439,21 +480,24 @@ function SetVHDFile # 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' + 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; + $sourceItems = $null + $destinationItems = $null if ($itemIsFolder) { @@ -468,9 +512,9 @@ function ItemHasChanged } - if ( -not ($destinationItems)) + if (-not ($destinationItems)) { - return $true; + return $true } # Compute the difference using the algorithem specified. @@ -482,23 +526,26 @@ function ItemHasChanged { $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/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.schema.mof b/source/DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.schema.mof similarity index 100% rename from DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.schema.mof rename to source/DSCResources/MSFT_xVhdFileDirectory/MSFT_xVhdFileDirectory.schema.mof diff --git a/source/DSCResources/MSFT_xVhdFileDirectory/en-US/MSFT_xVhdFileDirectory.strings.psd1 b/source/DSCResources/MSFT_xVhdFileDirectory/en-US/MSFT_xVhdFileDirectory.strings.psd1 new file mode 100644 index 0000000..3b35d66 --- /dev/null +++ b/source/DSCResources/MSFT_xVhdFileDirectory/en-US/MSFT_xVhdFileDirectory.strings.psd1 @@ -0,0 +1,2 @@ +ConvertFrom-StringData @' +'@ diff --git a/source/Examples/Sample_EndToEndXHyperV_RunningVM.ps1 b/source/Examples/Sample_EndToEndXHyperV_RunningVM.ps1 new file mode 100644 index 0000000..0e7db60 --- /dev/null +++ b/source/Examples/Sample_EndToEndXHyperV_RunningVM.ps1 @@ -0,0 +1,62 @@ +# End to end sample for x-Hyper-v +Configuration Sample_EndToEndXHyperV_RunningVM +{ + param + ( + [Parameter()] + $vhdPath = 'C:\temp\disk.vhdx', + + [Parameter()] + $Name = 'Disk1', + + [Parameter()] + $unattendedFilePathToCopy = 'C:\Media\unattended.xml' + ) + + Import-DscResource -ModuleName 'xHyper-V' + + # Create a switch to be used by the VM + xVMSwitch switch + { + Name = 'Test-Switch' + Ensure = 'Present' + Type = 'Internal' + } + + # Create new VHD file. + xVHD NewVHD1 + { + + Ensure = 'Present' + Name = $name + Path = (Split-Path $vhdPath) + Generation = 'vhd' + ParentPath = $vhdPath + } + + # Customize VHD by copying a folders/files to the VHD before a VM can be created + # Example below shows copying unattended.xml before a VM can be created + xVhdFile CopyUnattendxml + { + VhdPath = $vhdPath + FileDirectory = MSFT_xFileDirectory + { + SourcePath = $unattendedFilePathToCopy + DestinationPath = 'unattended.xml' + } + } + + # create the testVM out of the vhd. + xVMHyperV testvm + { + Name = "$($name)_vm" + SwitchName = 'Test-Switch' + VhdPath = Join-path (Split-Path $vhdPath) "$name.vhd" + ProcessorCount = 2 + MaximumMemory = 1GB + MinimumMemory = 512MB + RestartIfNeeded = $true + DependsOn = '[xVHD]NewVHD1', '[xVMSwitch]switch', '[xVhdFile]CopyUnattendxml' + State = 'Running' + } +} diff --git a/Examples/Sample_xVMHardDiskDrive_VMWith4AdditionalDisks.ps1 b/source/Examples/Sample_xVMHardDiskDrive_VMWith4AdditionalDisks.ps1 similarity index 94% rename from Examples/Sample_xVMHardDiskDrive_VMWith4AdditionalDisks.ps1 rename to source/Examples/Sample_xVMHardDiskDrive_VMWith4AdditionalDisks.ps1 index 7cf165b..69f889c 100644 --- a/Examples/Sample_xVMHardDiskDrive_VMWith4AdditionalDisks.ps1 +++ b/source/Examples/Sample_xVMHardDiskDrive_VMWith4AdditionalDisks.ps1 @@ -1,17 +1,17 @@ -configuration Sample_xVMHardDiskDrive +configuration Sample_xVMHardDiskDrive_VMWith4AdditionalDisks { param ( [Parameter()] - [string[]] + [System.String[]] $NodeName = 'localhost', [Parameter(Mandatory = $true)] - [string] + [System.String] $VMName, [Parameter(Mandatory = $true)] - [string] + [System.String] $VhdPath ) diff --git a/Examples/Sample_xVMHardDiskDrive_VMWithExtraDisk.ps1 b/source/Examples/Sample_xVMHardDiskDrive_VMWithExtraDisk.ps1 similarity index 97% rename from Examples/Sample_xVMHardDiskDrive_VMWithExtraDisk.ps1 rename to source/Examples/Sample_xVMHardDiskDrive_VMWithExtraDisk.ps1 index 0b01fbc..c04da8f 100644 --- a/Examples/Sample_xVMHardDiskDrive_VMWithExtraDisk.ps1 +++ b/source/Examples/Sample_xVMHardDiskDrive_VMWithExtraDisk.ps1 @@ -1,4 +1,4 @@ -configuration Sample_xVMHardDiskDrive +configuration Sample_xVMHardDiskDrive_VMWithExtraDisk { param ( diff --git a/source/Examples/Sample_xVMHost_Paths.ps1 b/source/Examples/Sample_xVMHost_Paths.ps1 new file mode 100644 index 0000000..ddde243 --- /dev/null +++ b/source/Examples/Sample_xVMHost_Paths.ps1 @@ -0,0 +1,20 @@ +Configuration Sample_xVMHost_Paths +{ + param + ( + [Parameter()] + $VirtualHardDiskPath = 'C:\VMDisks', + + [Parameter()] + $VirtualMachinePath = 'C:\VMs' + ) + + Import-DscResource -ModuleName 'xHyper-V' + + xVMHost HyperVHostPaths + { + IsSingleInstance = 'Yes' + VirtualHardDiskPath = $VirtualHardDiskPath + VirtualMachinePath = $VirtualMachinePath + } +} diff --git a/Examples/Sample_xVMHyperV_Complete.ps1 b/source/Examples/Sample_xVMHyperV_Complete.ps1 similarity index 71% rename from Examples/Sample_xVMHyperV_Complete.ps1 rename to source/Examples/Sample_xVMHyperV_Complete.ps1 index 6ec87db..1f94de4 100644 --- a/Examples/Sample_xVMHyperV_Complete.ps1 +++ b/source/Examples/Sample_xVMHyperV_Complete.ps1 @@ -2,41 +2,53 @@ configuration Sample_xVMHyperV_Complete { param ( - [string[]]$NodeName = 'localhost', + [System.String[]] + $NodeName = 'localhost', - [Parameter(Mandatory)] - [string]$VMName, + [Parameter(Mandatory = $true)] + [System.String] + $VMName, - [Parameter(Mandatory)] - [uint64]$VhdSizeBytes, + [Parameter(Mandatory = $true)] + [System.UInt64] + $VhdSizeBytes, - [Parameter(Mandatory)] - [Uint64]$StartupMemory, + [Parameter(Mandatory = $true)] + [System.UInt64] + $StartupMemory, - [Parameter(Mandatory)] - [Uint64]$MinimumMemory, + [Parameter(Mandatory = $true)] + [System.UInt64] + $MinimumMemory, - [Parameter(Mandatory)] - [Uint64]$MaximumMemory, + [Parameter(Mandatory = $true)] + [System.UInt64] + $MaximumMemory, - [Parameter(Mandatory)] - [String]$SwitchName, + [Parameter(Mandatory = $true)] + [System.String] + $SwitchName, - [Parameter(Mandatory)] - [String]$Path, + [Parameter(Mandatory = $true)] + [System.String] + $Path, - [Parameter(Mandatory)] - [Uint32]$ProcessorCount, + [Parameter(Mandatory = $true)] + [System.UInt32] + $ProcessorCount, [ValidateSet('Off','Paused','Running')] - [String]$State = 'Off', + [System.String] + $State = 'Off', - [Switch]$WaitForIP, + [Switch] + $WaitForIP, - [bool]$AutomaticCheckpointsEnabled + [System.Boolean] + $AutomaticCheckpointsEnabled ) - Import-DscResource -module xHyper-V + Import-DscResource -ModuleName 'xHyper-V' Node $NodeName { diff --git a/Examples/Sample_xVMHyperV_DynamicMemory.ps1 b/source/Examples/Sample_xVMHyperV_DynamicMemory.ps1 similarity index 57% rename from Examples/Sample_xVMHyperV_DynamicMemory.ps1 rename to source/Examples/Sample_xVMHyperV_DynamicMemory.ps1 index 4f260cd..9465f88 100644 --- a/Examples/Sample_xVMHyperV_DynamicMemory.ps1 +++ b/source/Examples/Sample_xVMHyperV_DynamicMemory.ps1 @@ -2,25 +2,31 @@ configuration Sample_xVMHyperV_DynamicMemory { param ( - [string[]]$NodeName = 'localhost', + [System.String[]] + $NodeName = 'localhost', - [Parameter(Mandatory)] - [string]$VMName, - - [Parameter(Mandatory)] - [string]$VhdPath, + [Parameter(Mandatory = $true)] + [System.String] + $VMName, - [Parameter(Mandatory)] - [Uint64]$StartupMemory, + [Parameter(Mandatory = $true)] + [System.String] + $VhdPath, - [Parameter(Mandatory)] - [Uint64]$MinimumMemory, + [Parameter(Mandatory = $true)] + [System.UInt64] + $StartupMemory, - [Parameter(Mandatory)] - [Uint64]$MaximumMemory + [Parameter(Mandatory = $true)] + [System.UInt64] + $MinimumMemory, + + [Parameter(Mandatory = $true)] + [System.UInt64] + $MaximumMemory ) - Import-DscResource -module xHyper-V + Import-DscResource -ModuleName 'xHyper-V' Node $NodeName { diff --git a/Examples/Sample_xVMHyperV_MultipleNICs.ps1 b/source/Examples/Sample_xVMHyperV_MultipleNICs.ps1 similarity index 76% rename from Examples/Sample_xVMHyperV_MultipleNICs.ps1 rename to source/Examples/Sample_xVMHyperV_MultipleNICs.ps1 index 09adbae..d4ce83b 100644 --- a/Examples/Sample_xVMHyperV_MultipleNICs.ps1 +++ b/source/Examples/Sample_xVMHyperV_MultipleNICs.ps1 @@ -2,22 +2,28 @@ Configuration Sample_xVMHyperV_MultipleNICs { param ( - [string[]]$NodeName = 'localhost', + [Parameter()] + [System.String[]] + $NodeName = 'localhost', - [Parameter(Mandatory)] - [string]$VMName, + [Parameter()] + [System.String] + $VMName = 'TestVM', - [Parameter(Mandatory)] - [string]$VhdPath, + [Parameter()] + [System.String] + $VhdPath = 'C:\temp\disk.vhdx', - [Parameter(Mandatory)] - [string[]]$SwitchName, + [Parameter()] + [System.String[]] + $SwitchName = @('MySwitch'), [Parameter()] - [string[]]$MACAddress + [System.String[]] + $MACAddress = '0000000' ) - Import-DscResource -module xHyper-V + Import-DscResource -ModuleName 'xHyper-V' Node $NodeName { @@ -44,7 +50,7 @@ Configuration Sample_xVMHyperV_MultipleNICs # Remove spaces and hyphens from the identifier $vmSwitchName = $vmSwitch -replace ' ','' -replace '-','' # Add the virtual switch dependency - $xVMHyperVDependsOn += "[xVMHyperV]$vmSwitchName" + $xVMHyperVDependsOn += "[xVMSwitch]$vmSwitchName" xVMSwitch $vmSwitchName { @@ -68,5 +74,3 @@ Configuration Sample_xVMHyperV_MultipleNICs } } } - -Sample_xVMHyperV_MultipleNICs -VMName 'MultiNICVM' -VhdPath 'C:\VMs\MultiNICVM.vhdx' -SwitchName 'Switch 1','Switch-2' diff --git a/Examples/Sample_xVMHyperV_Simple.ps1 b/source/Examples/Sample_xVMHyperV_Simple.ps1 similarity index 67% rename from Examples/Sample_xVMHyperV_Simple.ps1 rename to source/Examples/Sample_xVMHyperV_Simple.ps1 index a191a88..f502249 100644 --- a/Examples/Sample_xVMHyperV_Simple.ps1 +++ b/source/Examples/Sample_xVMHyperV_Simple.ps1 @@ -2,16 +2,19 @@ configuration Sample_xVMHyperV_Simple { param ( - [string[]]$NodeName = 'localhost', + [System.String[]] + $NodeName = 'localhost', - [Parameter(Mandatory)] - [string]$VMName, - - [Parameter(Mandatory)] - [string]$VhdPath + [Parameter(Mandatory = $true)] + [System.String] + $VMName, + + [Parameter(Mandatory = $true)] + [System.String] + $VhdPath ) - Import-DscResource -module xHyper-V + Import-DscResource -ModuleName 'xHyper-V' Node $NodeName { diff --git a/Examples/Sample_xVMHyperV_SimpleWithDVDDrive.ps1 b/source/Examples/Sample_xVMHyperV_SimpleWithDVDDrive.ps1 similarity index 71% rename from Examples/Sample_xVMHyperV_SimpleWithDVDDrive.ps1 rename to source/Examples/Sample_xVMHyperV_SimpleWithDVDDrive.ps1 index 2299b79..0dafeae 100644 --- a/Examples/Sample_xVMHyperV_SimpleWithDVDDrive.ps1 +++ b/source/Examples/Sample_xVMHyperV_SimpleWithDVDDrive.ps1 @@ -2,18 +2,22 @@ configuration Sample_xVMHyperV_SimpleWithDvdDrive { param ( - [string[]]$NodeName = 'localhost', + [System.String[]] + $NodeName = 'localhost', - [Parameter(Mandatory)] - [string]$VMName, + [Parameter(Mandatory = $true)] + [System.String] + $VMName, - [Parameter(Mandatory)] - [string]$VhdPath, + [Parameter(Mandatory = $true)] + [System.String] + $VhdPath, - [string]$ISOPath + [System.String] + $ISOPath ) - Import-DscResource -module xHyper-V + Import-DscResource -ModuleName 'xHyper-V' Node $NodeName { @@ -38,7 +42,7 @@ configuration Sample_xVMHyperV_SimpleWithDvdDrive xVMDvdDrive NewVMDvdDriveISO { Ensure = 'Present' - Name = $VMName + VMName = $VMName ControllerNumber = 0 ControllerLocation = 0 Path = $ISOPath diff --git a/Examples/Sample_xVMHyperV_SimpleWithNestedVirtualization.ps1 b/source/Examples/Sample_xVMHyperV_SimpleWithNestedVirtualization.ps1 similarity index 89% rename from Examples/Sample_xVMHyperV_SimpleWithNestedVirtualization.ps1 rename to source/Examples/Sample_xVMHyperV_SimpleWithNestedVirtualization.ps1 index 6837639..41475dc 100644 --- a/Examples/Sample_xVMHyperV_SimpleWithNestedVirtualization.ps1 +++ b/source/Examples/Sample_xVMHyperV_SimpleWithNestedVirtualization.ps1 @@ -3,23 +3,23 @@ configuration Sample_xVMHyperV_SimpleWithNestedVirtualization param ( [Parameter()] - [string[]] + [System.String[]] $NodeName = 'localhost', [Parameter(Mandatory = $true)] - [string] + [System.String] $VMName, [Parameter(Mandatory = $true)] - [string] + [System.String] $VhdPath, [Parameter(Mandatory = $true)] - [Uint64] + [System.UInt64] $Memory ) - Import-DscResource -module xHyper-V + Import-DscResource -ModuleName 'xHyper-V' Node $NodeName { diff --git a/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 b/source/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 similarity index 68% rename from Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 rename to source/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 index 7be0ae5..b567156 100644 --- a/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 +++ b/source/Examples/Sample_xVMNetworkAdapter_ManagementOS.ps1 @@ -1,6 +1,6 @@ -Configuration HostOSAdapter +Configuration Sample_xVMNetworkAdapter_ManagementOS { - Import-DscResource -ModuleName xHyper-V -Name xVMNetworkAdapter + Import-DscResource -ModuleName 'xHyper-V' -Name xVMNetworkAdapter Import-DscResource -ModuleName PSDesiredStateConfiguration xVMNetworkAdapter HostOSAdapter { diff --git a/Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 b/source/Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 similarity index 78% rename from Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 rename to source/Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 index a0cd100..84bfd44 100644 --- a/Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 +++ b/source/Examples/Sample_xVMNetworkAdapter_MultipleManagementOS.ps1 @@ -1,6 +1,6 @@ -Configuration HostOSAdapter +Configuration Sample_xVMNetworkAdapter_MultipleManagementOS { - Import-DscResource -ModuleName xHyper-V -Name xVMNetworkAdapter + Import-DscResource -ModuleName 'xHyper-V' -Name xVMNetworkAdapter Import-DscResource -ModuleName PSDesiredStateConfiguration xVMNetworkAdapter ManagementAdapter { diff --git a/Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1 b/source/Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1 similarity index 83% rename from Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1 rename to source/Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1 index 56d0a55..8a4bc78 100644 --- a/Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1 +++ b/source/Examples/Sample_xVMNetworkAdapter_MultipleVM.ps1 @@ -1,6 +1,6 @@ -Configuration VMAdapter +Configuration Sample_xVMNetworkAdapter_MultipleVM { - Import-DscResource -ModuleName xHyper-V -Name xVMNetworkAdapter + Import-DscResource -ModuleName 'xHyper-V' -Name xVMNetworkAdapter Import-DscResource -ModuleName PSDesiredStateConfiguration xVMNetworkAdapter MyVM01NIC { diff --git a/Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 b/source/Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 similarity index 67% rename from Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 rename to source/Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 index 80f0ead..af48d1d 100644 --- a/Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 +++ b/source/Examples/Sample_xVMNetworkAdapter_MultipleVMMACAddress.ps1 @@ -1,13 +1,13 @@ -Configuration VMAdapter +Configuration Sample_xVMNetworkAdapter_MultipleVMMACAddress { - Import-DscResource -ModuleName xHyper-V -Name xVMNetworkAdapter + Import-DscResource -ModuleName 'xHyper-V' -Name xVMNetworkAdapter Import-DscResource -ModuleName PSDesiredStateConfiguration xVMNetworkAdapter MyVM01NIC { Id = 'MyVM01-NIC' Name = 'MyVM01-NIC' SwitchName = 'SETSwitch' - MacAddress = '001523be0c' + MacAddress = '001523be0c00' VMName = 'MyVM01' Ensure = 'Present' } @@ -16,7 +16,7 @@ Id = 'MyVM02-NIC' Name = 'MyVM02-NIC' SwitchName = 'SETSwitch' - MacAddress = '001523be0d' + MacAddress = '001523be0c00' VMName = 'MyVM02' Ensure = 'Present' } diff --git a/source/Examples/Sample_xVMNetworkAdapter_VMStaticNetworkSettings.ps1 b/source/Examples/Sample_xVMNetworkAdapter_VMStaticNetworkSettings.ps1 new file mode 100644 index 0000000..b9321c3 --- /dev/null +++ b/source/Examples/Sample_xVMNetworkAdapter_VMStaticNetworkSettings.ps1 @@ -0,0 +1,21 @@ +Configuration Sample_xVMNetworkAdapter_VMStaticNetworkSettings +{ + Import-DscResource -ModuleName 'xHyper-V' + + xVMNetworkAdapter MyVM01NIC + { + Ensure = 'Present' + Id = 'MyVM01-NIC' + Name = 'MyVM01-NIC' + SwitchName = 'SETSwitch' + MacAddress = '001523be0c00' + VMName = 'MyVM01' + NetworkSetting = xNetworkSettings + { + IpAddress = '192.168.0.100' + Subnet = '255.255.255.255' + DefaultGateway = '192.168.0.1' + DnsServer = '192.168.0.1' + } + } +} diff --git a/Examples/Sample_xVMNetworkAdapter_VMVlanTagging.ps1 b/source/Examples/Sample_xVMNetworkAdapter_VMVlanTagging.ps1 similarity index 62% rename from Examples/Sample_xVMNetworkAdapter_VMVlanTagging.ps1 rename to source/Examples/Sample_xVMNetworkAdapter_VMVlanTagging.ps1 index 0c17245..e667364 100644 --- a/Examples/Sample_xVMNetworkAdapter_VMVlanTagging.ps1 +++ b/source/Examples/Sample_xVMNetworkAdapter_VMVlanTagging.ps1 @@ -1,13 +1,13 @@ -Configuration VMAdapter +Configuration Sample_xVMNetworkAdapter_VMVlanTagging { - Import-DscResource -ModuleName xHyper-V -Name xVMNetworkAdapter + Import-DscResource -ModuleName 'xHyper-V' -Name xVMNetworkAdapter Import-DscResource -ModuleName PSDesiredStateConfiguration xVMNetworkAdapter MyVM01NIC { Id = 'MyVM01-NIC' Name = 'MyVM01-NIC' SwitchName = 'SETSwitch' - MacAddress = '001523be0c' + MacAddress = '001523be0c00' VMName = 'MyVM01' VlanId = '1' Ensure = 'Present' diff --git a/Examples/Sample_xVMScsiController_AddControllers.ps1 b/source/Examples/Sample_xVMScsiController_AddControllers.ps1 similarity index 86% rename from Examples/Sample_xVMScsiController_AddControllers.ps1 rename to source/Examples/Sample_xVMScsiController_AddControllers.ps1 index 9ef5a72..b22a54f 100644 --- a/Examples/Sample_xVMScsiController_AddControllers.ps1 +++ b/source/Examples/Sample_xVMScsiController_AddControllers.ps1 @@ -1,4 +1,4 @@ -configuration Sample_xVMScsiController +configuration Sample_xVMScsiController_AddControllers { param ( @@ -61,8 +61,3 @@ configuration Sample_xVMScsiController } } - -$mofPath = "C:\temp\Sample_xVMScsiController" - -Sample_xVMScsiController -VMName "test1" -VhdPath "C:\temp\Tests" -OutputPath $mofPath -Start-DscConfiguration -Path $mofPath -Verbose -Wait -Force diff --git a/Examples/Sample_xVMSwitch_External.ps1 b/source/Examples/Sample_xVMSwitch_External.ps1 similarity index 63% rename from Examples/Sample_xVMSwitch_External.ps1 rename to source/Examples/Sample_xVMSwitch_External.ps1 index 48e2e94..7a5929b 100644 --- a/Examples/Sample_xVMSwitch_External.ps1 +++ b/source/Examples/Sample_xVMSwitch_External.ps1 @@ -2,16 +2,19 @@ configuration Sample_xVMSwitch_External { param ( - [string[]]$NodeName = 'localhost', + [System.String[]] + $NodeName = 'localhost', - [Parameter(Mandatory)] - [string]$SwitchName, - - [Parameter(Mandatory)] - [string]$NetAdapterName + [Parameter(Mandatory = $true)] + [System.String] + $SwitchName, + + [Parameter(Mandatory = $true)] + [System.String] + $NetAdapterName ) - Import-DscResource -module xHyper-V + Import-DscResource -ModuleName 'xHyper-V' Node $NodeName { @@ -28,7 +31,7 @@ configuration Sample_xVMSwitch_External Ensure = 'Present' Name = $SwitchName Type = 'External' - NetAdapterName = $NetAdapterName + NetAdapterName = $NetAdapterName DependsOn = '[WindowsFeature]HyperV' } } diff --git a/Examples/Sample_xVMSwitch_ExternalSET.ps1 b/source/Examples/Sample_xVMSwitch_ExternalSET.ps1 similarity index 85% rename from Examples/Sample_xVMSwitch_ExternalSET.ps1 rename to source/Examples/Sample_xVMSwitch_ExternalSET.ps1 index 24c888d..b03c485 100644 --- a/Examples/Sample_xVMSwitch_ExternalSET.ps1 +++ b/source/Examples/Sample_xVMSwitch_ExternalSET.ps1 @@ -1,21 +1,21 @@ -Configuration Sample_xVMSwitch_External +Configuration Sample_xVMSwitch_ExternalSET { param ( [Parameter()] - [string[]] + [System.String[]] $NodeName = 'localhost', [Parameter(Mandatory = $true)] - [string] + [System.String] $SwitchName, [Parameter(Mandatory = $true)] - [string[]] + [System.String[]] $NetAdapterNames ) - Import-DscResource -module xHyper-V + Import-DscResource -ModuleName 'xHyper-V' Node $NodeName { diff --git a/Examples/Sample_xVMSwitch_ExternalSET_LBMode.ps1 b/source/Examples/Sample_xVMSwitch_ExternalSET_LBMode.ps1 similarity index 81% rename from Examples/Sample_xVMSwitch_ExternalSET_LBMode.ps1 rename to source/Examples/Sample_xVMSwitch_ExternalSET_LBMode.ps1 index 102ea56..b50ae89 100644 --- a/Examples/Sample_xVMSwitch_ExternalSET_LBMode.ps1 +++ b/source/Examples/Sample_xVMSwitch_ExternalSET_LBMode.ps1 @@ -1,21 +1,21 @@ -Configuration Sample_xVMSwitch_External +Configuration Sample_xVMSwitch_ExternalSET_LBMode { param ( [Parameter()] - [string[]] + [System.String[]] $NodeName = 'localhost', [Parameter(Mandatory = $true)] - [string] + [System.String] $SwitchName, [Parameter(Mandatory = $true)] - [string[]] + [System.String[]] $NetAdapterNames ) - Import-DscResource -module xHyper-V + Import-DscResource -ModuleName 'xHyper-V' Node $NodeName { @@ -33,7 +33,7 @@ Configuration Sample_xVMSwitch_External DependsOn = '[WindowsFeature]HyperV' } - # Ensures a VM with Load Balancing Algorithm "Hyper-V Port" + # Ensures a VM with Load Balancing Algorithm 'Hyper-V Port" xVMSwitch ExternalSwitch { Ensure = 'Present' diff --git a/Examples/Sample_xVMSwitch_Internal.ps1 b/source/Examples/Sample_xVMSwitch_Internal.ps1 similarity index 74% rename from Examples/Sample_xVMSwitch_Internal.ps1 rename to source/Examples/Sample_xVMSwitch_Internal.ps1 index cc1c189..8f8de1d 100644 --- a/Examples/Sample_xVMSwitch_Internal.ps1 +++ b/source/Examples/Sample_xVMSwitch_Internal.ps1 @@ -2,13 +2,15 @@ configuration Sample_xVMSwitch_Internal { param ( - [string[]]$NodeName = 'localhost', + [System.String[]] + $NodeName = 'localhost', - [Parameter(Mandatory)] - [string]$SwitchName + [Parameter(Mandatory = $true)] + [System.String] + $SwitchName ) - Import-DscResource -module xHyper-V + Import-DscResource -ModuleName 'xHyper-V' Node $NodeName { diff --git a/Examples/Sample_xVHD_AdditionalPropertyVHD.ps1 b/source/Examples/Sample_xVhd_AdditionalPropertyVHD.ps1 similarity index 81% rename from Examples/Sample_xVHD_AdditionalPropertyVHD.ps1 rename to source/Examples/Sample_xVhd_AdditionalPropertyVHD.ps1 index c552cbe..47e744f 100644 --- a/Examples/Sample_xVHD_AdditionalPropertyVHD.ps1 +++ b/source/Examples/Sample_xVhd_AdditionalPropertyVHD.ps1 @@ -3,33 +3,33 @@ configuration Sample_xVHD_AdditionalPropertyVHD param ( [Parameter(Mandatory = $true)] - [string] + [System.String] $Name, [Parameter(Mandatory = $true)] - [string] + [System.String] $Path, [Parameter(Mandatory = $true)] - [string] + [System.String] $ParentPath, [Parameter(Mandatory = $true)] - [string] + [System.String] $MaximumSizeBytes, [Parameter()] [ValidateSet('Vhd', 'Vhdx')] - [string] + [System.String] $Generation = 'Vhd', [Parameter()] [ValidateSet('Present', 'Absent')] - [string] + [System.String] $Ensure = 'Present' ) - Import-DscResource -ModuleName xHyper-V + Import-DscResource -ModuleName 'xHyper-V' Node localhost { diff --git a/source/Examples/Sample_xVhd_ChangeAttribute.ps1 b/source/Examples/Sample_xVhd_ChangeAttribute.ps1 new file mode 100644 index 0000000..eb9d87a --- /dev/null +++ b/source/Examples/Sample_xVhd_ChangeAttribute.ps1 @@ -0,0 +1,28 @@ +Configuration Sample_xVhd_ChangeAttribute +{ + param + ( + [Parameter(Mandatory = $true, Position = 0)] + $vhdPath = 'C:\temp\disk.vhdx', + + [Parameter(Mandatory = $true)] + $relativeDestinationPath = 'Temp', + + [Parameter()] + [ValidateSet ('Archive', 'Hidden', 'ReadOnly', 'System' )] + $attribute = 'Archive' + ) + + Import-DscResource -ModuleName 'xHyper-V' + + xVhdFile Change-Attribute + { + VhdPath = $vhdPath + FileDirectory = MSFT_xFileDirectory + { + DestinationPath = $relativeDestinationPath + Attributes = $attribute + } + + } +} diff --git a/source/Examples/Sample_xVhd_CopyFileOrFolder.ps1 b/source/Examples/Sample_xVhd_CopyFileOrFolder.ps1 new file mode 100644 index 0000000..64f7da1 --- /dev/null +++ b/source/Examples/Sample_xVhd_CopyFileOrFolder.ps1 @@ -0,0 +1,26 @@ +Configuration Sample_xVhd_CopyFileOrFolder +{ + param + ( + [Parameter()] + $vhdPath = 'C:\temp\disk.vhdx', + + [Parameter()] + $itemToCopy = 'C:\Temp', + + [Parameter()] + $relativeDestinationPath = 'Temp' + ) + + Import-DscResource -ModuleName 'xHyper-V' + + xVhdFile FileCopy + { + VhdPath = $vhdPath + FileDirectory = MSFT_xFileDirectory + { + SourcePath = $itemToCopy + DestinationPath = $relativeDestinationPath + } + } +} diff --git a/Examples/Sample_xVHD_DiffVHD.ps1 b/source/Examples/Sample_xVhd_DiffVHD.ps1 similarity index 83% rename from Examples/Sample_xVHD_DiffVHD.ps1 rename to source/Examples/Sample_xVhd_DiffVHD.ps1 index 303544a..053fea3 100644 --- a/Examples/Sample_xVHD_DiffVHD.ps1 +++ b/source/Examples/Sample_xVhd_DiffVHD.ps1 @@ -3,37 +3,37 @@ configuration Sample_xVhd_DiffVhd param ( [Parameter()] - [string[]] + [System.String[]] $NodeName = 'localhost', [Parameter(Mandatory = $true)] - [string] + [System.String] $Name, [Parameter(Mandatory = $true)] - [string] + [System.String] $Path, [Parameter(Mandatory = $true)] - [string] + [System.String] $ParentPath, [Parameter()] [ValidateSet('Vhd', 'Vhdx')] - [string] + [System.String] $Generation = 'Vhd', [Parameter()] [ValidateSet('Dynamic', 'Fixed', 'Differencing')] - [string]$Type = 'Differencing', + [System.String]$Type = 'Differencing', [Parameter()] [ValidateSet('Present', 'Absent')] - [string] + [System.String] $Ensure = 'Present' ) - Import-DscResource -ModuleName xHyper-V + Import-DscResource -ModuleName 'xHyper-V' Node $NodeName { diff --git a/Examples/Sample_xVHD_FixedVHD.ps1 b/source/Examples/Sample_xVhd_FixedVHD.ps1 similarity index 85% rename from Examples/Sample_xVHD_FixedVHD.ps1 rename to source/Examples/Sample_xVhd_FixedVHD.ps1 index 94777a1..bb62a86 100644 --- a/Examples/Sample_xVHD_FixedVHD.ps1 +++ b/source/Examples/Sample_xVhd_FixedVHD.ps1 @@ -3,34 +3,34 @@ configuration Sample_xVhd_FixedVhd param ( [Parameter()] - [string[]] + [System.String[]] $NodeName = 'localhost', [Parameter(Mandatory = $true)] - [string] + [System.String] $Name, [Parameter(Mandatory = $true)] - [string] + [System.String] $Path, [Parameter()] [ValidateSet('Vhd', 'Vhdx')] - [string] + [System.String] $Generation = 'Vhd', [Parameter()] [ValidateSet('Dynamic', 'Fixed', 'Differencing')] - [string] + [System.String] $Type = 'Fixed', [Parameter()] [ValidateSet('Present', 'Absent')] - [string] + [System.String] $Ensure = 'Present' ) - Import-DscResource -ModuleName xHyper-V + Import-DscResource -ModuleName 'xHyper-V' Node $NodeName { diff --git a/Examples/Sample_xVHD_MissingPropertyVHD.ps1 b/source/Examples/Sample_xVhd_MissingPropertyVHD.ps1 similarity index 80% rename from Examples/Sample_xVHD_MissingPropertyVHD.ps1 rename to source/Examples/Sample_xVhd_MissingPropertyVHD.ps1 index baa7037..ab6be7c 100644 --- a/Examples/Sample_xVHD_MissingPropertyVHD.ps1 +++ b/source/Examples/Sample_xVhd_MissingPropertyVHD.ps1 @@ -3,25 +3,25 @@ configuration Sample_xVHD_MissingPropertyVHD param ( [Parameter(Mandatory = $true)] - [string] + [System.String] $Name, [Parameter(Mandatory = $true)] - [string] + [System.String] $Path, [Parameter()] [ValidateSet('Vhd', 'Vhdx')] - [string] + [System.String] $Generation = 'Vhd', [Parameter()] [ValidateSet('Present', 'Absent')] - [string] + [System.String] $Ensure = 'Present' ) - Import-DscResource -module xHyper-V + Import-DscResource -ModuleName 'xHyper-V' Node localhost { diff --git a/Examples/Sample_xVHD_NewVHD.ps1 b/source/Examples/Sample_xVhd_NewVHD.ps1 similarity index 84% rename from Examples/Sample_xVHD_NewVHD.ps1 rename to source/Examples/Sample_xVhd_NewVHD.ps1 index f607afb..5ebc0f8 100644 --- a/Examples/Sample_xVHD_NewVHD.ps1 +++ b/source/Examples/Sample_xVhd_NewVHD.ps1 @@ -3,32 +3,32 @@ configuration Sample_xVHD_NewVhd param ( [Parameter()] - [string[]] + [System.String[]] $NodeName = 'localhost', [Parameter(Mandatory = $true)] - [string] + [System.String] $Name, [Parameter(Mandatory = $true)] - [string] + [System.String] $Path, [Parameter(Mandatory = $true)] - [Uint64] + [System.UInt64] $MaximumSizeBytes, [Parameter()] [ValidateSet('Vhd', 'Vhdx')] - [string]$Generation = 'Vhd', + [System.String]$Generation = 'Vhd', [Parameter()] [ValidateSet('Present', 'Absent')] - [string] + [System.String] $Ensure = 'Present' ) - Import-DscResource -ModuleName xHyper-V + Import-DscResource -ModuleName 'xHyper-V' Node $NodeName { diff --git a/source/Examples/Sample_xVhd_RemoveFileOrFolderFromVHD.ps1 b/source/Examples/Sample_xVhd_RemoveFileOrFolderFromVHD.ps1 new file mode 100644 index 0000000..9046359 --- /dev/null +++ b/source/Examples/Sample_xVhd_RemoveFileOrFolderFromVHD.ps1 @@ -0,0 +1,26 @@ +Configuration Sample_xVhd_RemoveFileOrFolderFromVHD +{ + param + ( + [Parameter()] + $vhdPath = 'C:\temp\disk.vhdx', + + [Parameter()] + $relativeDestinationPath = 'Temp', + + [Parameter()] + $Ensure = 'Absent' + ) + + Import-DscResource -ModuleName 'xHyper-V' + + xVhdFile RemoveFile + { + VhdPath = $vhdPath + FileDirectory = MSFT_xFileDirectory + { + DestinationPath = $relativeDestinationPath + Ensure = $Ensure + } + } +} diff --git a/source/Modules/HyperVDsc.Common/HyperVDsc.Common.psd1 b/source/Modules/HyperVDsc.Common/HyperVDsc.Common.psd1 new file mode 100644 index 0000000..83cc2a7 --- /dev/null +++ b/source/Modules/HyperVDsc.Common/HyperVDsc.Common.psd1 @@ -0,0 +1,57 @@ +# +# 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/HyperVCommon/HyperVCommon.psm1 b/source/Modules/HyperVDsc.Common/HyperVDsc.Common.psm1 similarity index 65% rename from DSCResources/HyperVCommon/HyperVCommon.psm1 rename to source/Modules/HyperVDsc.Common/HyperVDsc.Common.psm1 index 25ad1d5..6795cf4 100644 --- a/DSCResources/HyperVCommon/HyperVCommon.psm1 +++ b/source/Modules/HyperVDsc.Common/HyperVDsc.Common.psm1 @@ -1,84 +1,8 @@ -#region localizeddata -if (Test-Path "${PSScriptRoot}\${PSUICulture}") -{ - Import-LocalizedData ` - -BindingVariable LocalizedData ` - -Filename HyperVCommon.strings.psd1 ` - -BaseDirectory "${PSScriptRoot}\${PSUICulture}" -} -else -{ - # fallback to en-US - Import-LocalizedData ` - -BindingVariable LocalizedData ` - -Filename HyperVCommon.strings.psd1 ` - -BaseDirectory "${PSScriptRoot}\en-US" -} -#endregion +$script:dscResourceCommonModulePath = Join-Path -Path $PSScriptRoot -ChildPath '../DscResource.Common' -<# - .SYNOPSIS - Throws an InvalidOperation custom exception. +Import-Module -Name $script:dscResourceCommonModulePath - .PARAMETER ErrorId - The error Id of the exception. - - .PARAMETER ErrorMessage - The error message text to set in the exception. -#> -function New-InvalidOperationError -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $ErrorId, - - [Parameter(Mandatory = $true)] - [System.String] - $ErrorMessage - ) - - $exception = New-Object -TypeName System.InvalidOperationException ` - -ArgumentList $ErrorMessage - $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidOperation - $errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord ` - -ArgumentList $exception, $ErrorId, $errorCategory, $null - throw $errorRecord -} # end function New-InvalidOperationError - -<# - .SYNOPSIS - Throws an InvalidArgument custom exception. - - .PARAMETER ErrorId - The error Id of the exception. - - .PARAMETER ErrorMessage - The error message text to set in the exception. -#> -function New-InvalidArgumentError -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String] - $ErrorId, - - [Parameter(Mandatory = $true)] - [System.String] - $ErrorMessage - ) - - $exception = New-Object -TypeName System.ArgumentException ` - -ArgumentList $ErrorMessage - $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument - $errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord ` - -ArgumentList $exception, $ErrorId, $errorCategory, $null - throw $errorRecord -} # end function New-InvalidArgumentError +$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US' <# .SYNOPSIS @@ -140,7 +64,9 @@ function Set-VMProperty $ChangeProperty['VMName'] = $VMName # Set the common parameters for splatting against Get-VM and Set-VMState - $vmCommonProperty = @{ Name = $VMName; } + $vmCommonProperty = @{ + Name = $VMName + } # Ensure that the name parameter is set for verbose messages $Name = $VMName @@ -151,7 +77,9 @@ function Set-VMProperty $ChangeProperty['Name'] = $Name # Set the common parameters for splatting against Get-VM and Set-VMState - $vmCommonProperty = @{ Name = $Name; } + $vmCommonProperty = @{ + Name = $Name + } } $vmObject = Get-VM @vmCommonProperty @@ -162,7 +90,7 @@ function Set-VMProperty # Turn the vm off to make changes Set-VMState @vmCommonProperty -State Off - Write-Verbose -Message ($localizedData.UpdatingVMProperties -f $Name) + Write-Verbose -Message ($script:localizedData.UpdatingVMProperties -f $Name) # Make changes using the passed hashtable & $VMCommand @ChangeProperty @@ -172,24 +100,24 @@ function Set-VMProperty Set-VMState @vmCommonProperty -State Running -WaitForIP $WaitForIP } - Write-Verbose -Message ($localizedData.VMPropertiesUpdated -f $Name) + Write-Verbose -Message ($script:localizedData.VMPropertiesUpdated -f $Name) # Cannot restore a vm to a paused state if ($vmOriginalState -eq 'Paused') { - Write-Warning -Message ($localizedData.VMStateWillBeOffWarning -f $Name) + Write-Warning -Message ($script:localizedData.VMStateWillBeOffWarning -f $Name) } } elseif ($vmOriginalState -eq 'Off') { - Write-Verbose -Message ($localizedData.UpdatingVMProperties -f $Name) + Write-Verbose -Message ($script:localizedData.UpdatingVMProperties -f $Name) & $VMCommand @ChangeProperty - Write-Verbose -Message ($localizedData.VMPropertiesUpdated -f $Name) + Write-Verbose -Message ($script:localizedData.VMPropertiesUpdated -f $Name) } else { - $errorMessage = $localizedData.CannotUpdatePropertiesOnlineError -f $Name, $vmOriginalState - New-InvalidOperationError -ErrorId RestartRequired -ErrorMessage $errorMessage + $errorMessage = $script:localizedData.CannotUpdatePropertiesOnlineError -f $Name, $vmOriginalState + New-InvalidOperationException -Message $errorMessage } } #end function @@ -238,13 +166,13 @@ function Set-VMState if ($vmCurrentState -eq 'Paused') { # If VM is in paused state, use resume-vm to make it running - Write-Verbose -Message ($localizedData.ResumingVM -f $Name) + 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 ($localizedData.StartingVM -f $Name) + Write-Verbose -Message ($script:localizedData.StartingVM -f $Name) Start-VM -Name $Name } @@ -256,14 +184,14 @@ function Set-VMState 'Paused' { if ($vmCurrentState -ne 'Off') { - Write-Verbose -Message ($localizedData.SuspendingVM -f $Name) + Write-Verbose -Message ($script:localizedData.SuspendingVM -f $Name) Suspend-VM -Name $Name } } 'Off' { if ($vmCurrentState -ne 'Off') { - Write-Verbose -Message ($localizedData.StoppingVM -f $Name) + Write-Verbose -Message ($script:localizedData.StoppingVM -f $Name) Stop-VM -Name $Name -Force -WarningAction SilentlyContinue } } @@ -298,39 +226,16 @@ function Wait-VMIPAddress [System.Int32] $elapsedSeconds = 0 while ((Get-VMNetworkAdapter -VMName $Name).IpAddresses.Count -lt 2) { - Write-Verbose -Message ($localizedData.WaitingForVMIPAddress -f $Name) - Start-Sleep -Seconds 3; + Write-Verbose -Message ($script:localizedData.WaitingForVMIPAddress -f $Name) + Start-Sleep -Seconds 3 $elapsedSeconds += 3 if ($elapsedSeconds -gt $Timeout) { - $errorMessage = $localizedData.WaitForVMIPAddressTimeoutError -f $Name, $Timeout - New-InvalidOperationError -ErrorId 'WaitVmTimeout' -ErrorMessage $errorMessage - } - } -} #end function - -<# - .SYNOPSIS - Ensures that the specified PowerShell module(s) are installed. + $errorMessage = $script:localizedData.WaitForVMIPAddressTimeoutError -f $Name, $Timeout - .PARAMETER Name - Name of the PowerShell module to check is installed. -#> -function Assert-Module -{ - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [System.String[]] - $Name - ) - - if (-not (Get-Module -Name $Name -ListAvailable )) - { - $errorMessage = $localizedData.RoleMissingError -f $Name - New-InvalidOperationError -ErrorId MissingRole -ErrorMessage $errorMessage + New-ObjectNotFoundException -Message $errorMessage + } } } #end function @@ -428,8 +333,8 @@ function Get-VMHyperV # Check if 1 or 0 VM with name = $name exist if ($vm.count -gt 1) { - $errorMessage = $localizedData.MoreThanOneVMExistsError -f $VMName - New-InvalidArgumentError -ErrorId 'MultipleVMsFound' -ErrorMessage $errorMessage + $errorMessage = $script:localizedData.MoreThanOneVMExistsError -f $VMName + New-InvalidResultException -Message $errorMessage } return $vm diff --git a/DSCResources/HyperVCommon/en-us/HyperVCommon.strings.psd1 b/source/Modules/HyperVDsc.Common/en-US/HyperVDsc.Common.strings.psd1 similarity index 88% rename from DSCResources/HyperVCommon/en-us/HyperVCommon.strings.psd1 rename to source/Modules/HyperVDsc.Common/en-US/HyperVDsc.Common.strings.psd1 index ae731d3..bcfab65 100644 --- a/DSCResources/HyperVCommon/en-us/HyperVCommon.strings.psd1 +++ b/source/Modules/HyperVDsc.Common/en-US/HyperVDsc.Common.strings.psd1 @@ -6,11 +6,8 @@ ConvertFrom-StringData @' 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. - RoleMissingError = Please ensure that '{0}' role is installed with its PowerShell module. MoreThanOneVMExistsError = More than one VM with the name '{0}' exists. '@ diff --git a/source/build.psd1 b/source/build.psd1 new file mode 100644 index 0000000..cc73d6e --- /dev/null +++ b/source/build.psd1 @@ -0,0 +1,6 @@ +@{ + Path = 'xHyper-V.psd1' #or build breaks on Linux +} +# Waiting for ModuleBuilder to do away with this file +# when all parameters are provided to the function + diff --git a/source/en-US/about_xHyper-V.help.txt b/source/en-US/about_xHyper-V.help.txt new file mode 100644 index 0000000..d0cf781 --- /dev/null +++ b/source/en-US/about_xHyper-V.help.txt @@ -0,0 +1,25 @@ +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/source/xHyper-V.psd1 b/source/xHyper-V.psd1 new file mode 100644 index 0000000..aa42cc1 --- /dev/null +++ b/source/xHyper-V.psd1 @@ -0,0 +1,89 @@ +@{ + # Version number of this module. + moduleVersion = '0.0.1' + + # 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 = '' + } # End of PSData hashtable + } # End of PrivateData hashtable +} + + + + + + + + + + + + + + + + diff --git a/Tests/Integration/IntegrationTestsCommon.psm1 b/tests/Integration/IntegrationTestsCommon.psm1 similarity index 64% rename from Tests/Integration/IntegrationTestsCommon.psm1 rename to tests/Integration/IntegrationTestsCommon.psm1 index f407d69..2fda2fa 100644 --- a/Tests/Integration/IntegrationTestsCommon.psm1 +++ b/tests/Integration/IntegrationTestsCommon.psm1 @@ -8,10 +8,8 @@ function Test-HyperVInstalled { [CmdletBinding()] - [OutputType([String])] - param - ( - ) + [OutputType([System.String])] + param () # Ensure that the tests can be performed on this computer if ($PSVersionTable.PSEdition -eq 'Core') @@ -23,16 +21,18 @@ function Test-HyperVInstalled { $ProductType = (Get-CimInstance Win32_OperatingSystem).ProductType } # if - switch ($ProductType) { + + switch ($ProductType) + { 1 { # Desktop OS or Nano Server $HyperVInstalled = (((Get-WindowsOptionalFeature ` - -FeatureName Microsoft-Hyper-V ` - -Online).State -eq 'Enabled') -and ` + -FeatureName Microsoft-Hyper-V ` + -Online).State -eq 'Enabled') -and ` ((Get-WindowsOptionalFeature ` - -FeatureName Microsoft-Hyper-V-Management-PowerShell ` - -Online).State -eq 'Enabled')) + -FeatureName Microsoft-Hyper-V-Management-PowerShell ` + -Online).State -eq 'Enabled')) Break } 3 @@ -45,15 +45,17 @@ function Test-HyperVInstalled default { # Unsupported OS type for testing - Write-Verbose -Message "Integration tests cannot be run on this operating system." -Verbose + Write-Verbose -Message 'Integration tests cannot be run on this operating system.' -Verbose Break } } if ($HyperVInstalled -eq $false) { - Write-Verbose -Message "Integration tests cannot be run because Hyper-V Components not installed." -Verbose - Return $false + Write-Warning -Message 'Integration tests cannot be run because Hyper-V Components not installed.' -Verbose + + return $false } - Return $True + + return $True } # end function Test-HyperVInstalled diff --git a/Tests/Integration/MSFT_xVMDvdDrive.Integration.Tests.ps1 b/tests/Integration/MSFT_xVMDvdDrive.Integration.Tests.ps1 similarity index 70% rename from Tests/Integration/MSFT_xVMDvdDrive.Integration.Tests.ps1 rename to tests/Integration/MSFT_xVMDvdDrive.Integration.Tests.ps1 index 50813a0..595eda2 100644 --- a/Tests/Integration/MSFT_xVMDvdDrive.Integration.Tests.ps1 +++ b/tests/Integration/MSFT_xVMDvdDrive.Integration.Tests.ps1 @@ -1,31 +1,30 @@ -$script:DSCModuleName = 'xHyper-V' -$script:DSCResourceName = 'MSFT_xVMDvdDrive' - -#region HEADER -# Integration Test Template Version: 1.1.1 -[String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +$script:dscModuleName = 'xHyper-V' +$script:dscResourceName = 'MSFT_xVMDvdDrive' + +try +{ + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' +} +catch [System.IO.FileNotFoundException] { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' } -Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceName ` - -TestType Integration -#endregion +$script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Integration' # Import the common integration test functions Import-Module -Name ( Join-Path ` - -Path $PSScriptRoot ` - -ChildPath 'IntegrationTestsCommon.psm1' ) + -Path $PSScriptRoot ` + -ChildPath 'IntegrationTestsCommon.psm1' ) # Ensure that the tests can be performed on this computer if (-not (Test-HyperVInstalled)) { - Return + return } # if # Using try/finally to always cleanup even if something awful happens. @@ -83,11 +82,11 @@ try $current = Get-DscConfiguration | Where-Object { $_.ConfigurationName -eq "$($script:DSCResourceName)_Add_Config" } - $current.VMName | Should Be $VMName - $current.ControllerNumber | Should Be 0 + $current.VMName | Should Be $VMName + $current.ControllerNumber | Should Be 0 $current.ControllerLocation | Should Be 0 - $current.Path | Should BeNullOrEmpty - $current.Ensure | Should Be 'Present' + $current.Path | Should BeNullOrEmpty + $current.Ensure | Should Be 'Present' } } } @@ -118,24 +117,22 @@ try $current = Get-DscConfiguration | Where-Object { $_.ConfigurationName -eq "$($script:DSCResourceName)_Remove_Config" } - $current.VMName | Should Be $VMName - $current.ControllerNumber | Should Be 0 + $current.VMName | Should Be $VMName + $current.ControllerNumber | Should Be 0 $current.ControllerLocation | Should Be 0 - $current.Path | Should BeNullOrEmpty - $current.Ensure | Should Be 'Absent' + $current.Path | Should BeNullOrEmpty + $current.Ensure | Should Be 'Absent' } } } } finally { - #region FOOTER # Make sure the test VM has been removed if (Get-VM -Name $VMName -ErrorAction SilentlyContinue) { $null = Remove-VM -Name $VMName -Force } # if - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } diff --git a/Tests/Integration/MSFT_xVMDvdDrive_add.config.ps1 b/tests/Integration/MSFT_xVMDvdDrive_add.config.ps1 similarity index 88% rename from Tests/Integration/MSFT_xVMDvdDrive_add.config.ps1 rename to tests/Integration/MSFT_xVMDvdDrive_add.config.ps1 index defc5f3..9cc5a1d 100644 --- a/Tests/Integration/MSFT_xVMDvdDrive_add.config.ps1 +++ b/tests/Integration/MSFT_xVMDvdDrive_add.config.ps1 @@ -1,6 +1,6 @@ configuration MSFT_xVMDvdDrive_Add_Config { - Import-DscResource -ModuleName xHyper-V + Import-DscResource -ModuleName 'xHyper-V' node localhost { xVMDvdDrive Integration_Test { diff --git a/Tests/Integration/MSFT_xVMDvdDrive_remove.config.ps1 b/tests/Integration/MSFT_xVMDvdDrive_remove.config.ps1 similarity index 89% rename from Tests/Integration/MSFT_xVMDvdDrive_remove.config.ps1 rename to tests/Integration/MSFT_xVMDvdDrive_remove.config.ps1 index fb9ea13..0086c60 100644 --- a/Tests/Integration/MSFT_xVMDvdDrive_remove.config.ps1 +++ b/tests/Integration/MSFT_xVMDvdDrive_remove.config.ps1 @@ -1,6 +1,6 @@ configuration MSFT_xVMDvdDrive_Remove_Config { - Import-DscResource -ModuleName xHyper-V + Import-DscResource -ModuleName 'xHyper-V' node localhost { xVMDvdDrive Integration_Test { diff --git a/Tests/Integration/MSFT_xVMHost.Integration.Tests.ps1 b/tests/Integration/MSFT_xVMHost.Integration.Tests.ps1 similarity index 59% rename from Tests/Integration/MSFT_xVMHost.Integration.Tests.ps1 rename to tests/Integration/MSFT_xVMHost.Integration.Tests.ps1 index 1a18764..f68c31b 100644 --- a/Tests/Integration/MSFT_xVMHost.Integration.Tests.ps1 +++ b/tests/Integration/MSFT_xVMHost.Integration.Tests.ps1 @@ -1,31 +1,30 @@ -$script:DSCModuleName = 'xHyper-V' -$script:DSCResourceName = 'MSFT_xVMHost' +$script:dscModuleName = 'xHyper-V' +$script:dscResourceName = 'MSFT_xVMHost' -#region HEADER -# Integration Test Template Version: 1.1.1 -[String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +try +{ + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' +} +catch [System.IO.FileNotFoundException] { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' } -Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceName ` - -TestType Integration -#endregion +$script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Integration' # Import the common integration test functions Import-Module -Name ( Join-Path ` - -Path $PSScriptRoot ` - -ChildPath 'IntegrationTestsCommon.psm1' ) + -Path $PSScriptRoot ` + -ChildPath 'IntegrationTestsCommon.psm1' ) # Ensure that the tests can be performed on this computer if (-not (Test-HyperVInstalled)) { - Return + return } # if $currentVmHost = Get-VMHost @@ -53,11 +52,11 @@ try -EnableEnhancedSessionMode (-not $currentEnableEnhancedSessionMode) $startDscConfigurationParams = @{ - Path = $TestDrive; - ComputerName = 'localhost'; - Wait = $true; - Verbose = $true; - Force = $true; + Path = $TestDrive + ComputerName = 'localhost' + Wait = $true + Verbose = $true + Force = $true } Start-DscConfiguration @startDscConfigurationParams @@ -75,20 +74,17 @@ try } $current.VirtualHardDiskPath | Should Be $TestDrive.FullName - $current.VirtualMachinePath | Should Be $TestDrive.FullName + $current.VirtualMachinePath | Should Be $TestDrive.FullName $current.EnableEnhancedSessionMode | Should Be (-not $currentEnableEnhancedSessionMode) } } } finally { - #region FOOTER - # Restore current host settings Set-VMHost -VirtualHardDiskPath $currentVirtualHardDiskPath ` - -VirtualMachinePath $currentVirtualMachinePath ` - -EnableEnhancedSessionMode $currentEnableEnhancedSessionMode -Verbose + -VirtualMachinePath $currentVirtualMachinePath ` + -EnableEnhancedSessionMode $currentEnableEnhancedSessionMode -Verbose - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } diff --git a/Tests/Integration/MSFT_xVMHost_set.config.ps1 b/tests/Integration/MSFT_xVMHost_set.config.ps1 similarity index 87% rename from Tests/Integration/MSFT_xVMHost_set.config.ps1 rename to tests/Integration/MSFT_xVMHost_set.config.ps1 index 14c43bc..b94392b 100644 --- a/Tests/Integration/MSFT_xVMHost_set.config.ps1 +++ b/tests/Integration/MSFT_xVMHost_set.config.ps1 @@ -1,4 +1,4 @@ -configuration MSFT_xVMHost_Set_Config +configuration MSFT_xVMHost_Set_Config { param ( @@ -15,7 +15,7 @@ configuration MSFT_xVMHost_Set_Config $EnableEnhancedSessionMode ) - Import-DscResource -ModuleName xHyper-V + Import-DscResource -ModuleName 'xHyper-V' node localhost { xVMHost Integration_Test { diff --git a/Tests/Integration/MSFT_xVMProcessor.Integration.Tests.ps1 b/tests/Integration/MSFT_xVMProcessor.Integration.Tests.ps1 similarity index 71% rename from Tests/Integration/MSFT_xVMProcessor.Integration.Tests.ps1 rename to tests/Integration/MSFT_xVMProcessor.Integration.Tests.ps1 index a5751f5..2fe3a3a 100644 --- a/Tests/Integration/MSFT_xVMProcessor.Integration.Tests.ps1 +++ b/tests/Integration/MSFT_xVMProcessor.Integration.Tests.ps1 @@ -1,31 +1,30 @@ -$script:DSCModuleName = 'xHyper-V' -$script:DSCResourceName = 'MSFT_xVMProcessor' +$script:dscModuleName = 'xHyper-V' +$script:dscResourceName = 'MSFT_xVMProcessor' -#region HEADER -# Integration Test Template Version: 1.1.1 -[String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +try +{ + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' +} +catch [System.IO.FileNotFoundException] { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' } -Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceName ` - -TestType Integration -#endregion +$script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Integration' # Import the common integration test functions Import-Module -Name ( Join-Path ` - -Path $PSScriptRoot ` - -ChildPath 'IntegrationTestsCommon.psm1' ) + -Path $PSScriptRoot ` + -ChildPath 'IntegrationTestsCommon.psm1' ) # Ensure that the tests can be performed on this computer if (-not (Test-HyperVInstalled)) { - Return + return } # if # Using try/finally to always cleanup even if something awful happens. @@ -91,13 +90,11 @@ try } finally { - #region FOOTER # Make sure the test VM has been removed if (Get-VM -Name $VMName -ErrorAction SilentlyContinue) { $null = Remove-VM -Name $VMName -Force } # if - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } diff --git a/Tests/Integration/MSFT_xVMProcessor_set.config.ps1 b/tests/Integration/MSFT_xVMProcessor_set.config.ps1 similarity index 89% rename from Tests/Integration/MSFT_xVMProcessor_set.config.ps1 rename to tests/Integration/MSFT_xVMProcessor_set.config.ps1 index ee46073..16ffdf5 100644 --- a/Tests/Integration/MSFT_xVMProcessor_set.config.ps1 +++ b/tests/Integration/MSFT_xVMProcessor_set.config.ps1 @@ -1,6 +1,6 @@ configuration MSFT_xVMProcessor_Set_Config { - Import-DscResource -ModuleName xHyper-V + Import-DscResource -ModuleName 'xHyper-V' node localhost { xVMProcessor Integration_Test { diff --git a/tests/Unit/HyperVDsc.Common.Tests.ps1 b/tests/Unit/HyperVDsc.Common.Tests.ps1 new file mode 100644 index 0000000..69a8d01 --- /dev/null +++ b/tests/Unit/HyperVDsc.Common.Tests.ps1 @@ -0,0 +1,315 @@ +#region HEADER +$script:projectPath = "$PSScriptRoot\..\.." | Convert-Path +$script:projectName = (Get-ChildItem -Path "$script:projectPath\*\*.psd1" | Where-Object -FilterScript { + ($_.Directory.Name -match 'source|src' -or $_.Directory.Name -eq $_.BaseName) -and + $(try + { + Test-ModuleManifest -Path $_.FullName -ErrorAction Stop + } + catch + { + $false + }) + }).BaseName + +$script:parentModule = Get-Module -Name $script:projectName -ListAvailable | Select-Object -First 1 +$script:subModulesFolder = Join-Path -Path $script:parentModule.ModuleBase -ChildPath 'Modules' +Remove-Module -Name $script:parentModule -Force -ErrorAction 'SilentlyContinue' + +$script:subModuleName = (Split-Path -Path $PSCommandPath -Leaf) -replace '\.Tests.ps1' +$script:subModuleFile = Join-Path -Path $script:subModulesFolder -ChildPath "$($script:subModuleName)" + +Import-Module $script:subModuleFile -Force -ErrorAction 'Stop' +#endregion HEADER + +# Import the stub functions. +#Get-Module -Name 'Hyper-V' -All | Remove-Module -Force +Import-Module -Name "$PSScriptRoot/Stubs/Hyper-V.stubs.psm1" -Force + +InModuleScope $script:subModuleName { + Describe 'HyperVDsc.Common\Set-VMProperty' { + It "Should throw if VM is running and 'RestartIfNeeded' is False" { + $mockVMName = 'Test' + + Mock -CommandName Get-VM -MockWith { + return @{ + State = 'Running' + } + } + + $setVMPropertyParams = @{ + VMName = $mockVMName + VMCommand = 'Set-VMProcessor' + ChangeProperty = @{ + ResourcePoolName = 'Dummy' + } + } + + { Set-VMProperty @setVMPropertyParams } | Should -Throw ( + $script:localizedData.CannotUpdatePropertiesOnlineError -f $mockVMName, 'Running' + ) + } + + It "Should stop and restart VM when running and 'RestartIfNeeded' is True" { + Mock -CommandName Stop-VM + Mock -CommandName Set-VMProcessor + Mock -CommandName Set-VMState + Mock -CommandName Get-VM -MockWith { + return @{ + State = 'Running' + } + } + + $setVMPropertyParams = @{ + VMName = 'Test' + VMCommand = 'Set-VMProcessor' + ChangeProperty = @{ + ResourcePoolName = 'Dummy' + } + RestartIfNeeded = $true + } + Set-VMProperty @setVMPropertyParams + + Assert-MockCalled -CommandName Set-VMState -ParameterFilter { + $State -eq 'Off' + } -Scope It + + Assert-MockCalled -CommandName Set-VMState -ParameterFilter { + $State -eq 'Running' + } -Scope It + } + + } + + Describe 'HyperVDsc.Common\Set-VMState' { + It 'Should resume VM when current "State" is "Paused" and target state is "Running"' { + Mock -CommandName Resume-VM + Mock -CommandName Wait-VMIPAddress + Mock -CommandName Get-VM -MockWith { + return @{ + State = 'Paused' + } + } + + Set-VMState -Name 'TestVM' -State 'Running' + + Assert-MockCalled -CommandName Resume-VM -Scope It + Assert-MockCalled -CommandName Wait-VMIPAddress -Scope It -Exactly 0 + } + + It 'Should resume VM and wait when current "State" is "Paused" and target state is "Running"' { + Mock -CommandName Resume-VM + Mock -CommandName Wait-VMIPAddress + Mock -CommandName Get-VM -MockWith { + return @{ + State = 'Paused' + } + } + + Set-VMState -Name 'TestVM' -State 'Running' -WaitForIP $true + + Assert-MockCalled -CommandName Resume-VM -Scope It + Assert-MockCalled -CommandName Wait-VMIPAddress -Scope It + } + + It 'Should start VM when current "State" is "Off" and target state is "Running"' { + Mock -CommandName Start-VM + Mock -CommandName Wait-VMIPAddress + Mock -CommandName Get-VM -MockWith { + return @{ + State = 'Off' + } + } + + Set-VMState -Name 'TestVM' -State 'Running' + + Assert-MockCalled -CommandName Start-VM -Scope It + Assert-MockCalled -CommandName Wait-VMIPAddress -Scope It -Exactly 0 + } + + It 'Should start VM and wait when current "State" is "Off" and target state is "Running"' { + Mock -CommandName Start-VM + Mock -CommandName Wait-VMIPAddress + Mock -CommandName Get-VM -MockWith { + return @{ + State = 'Off' + } + } + + Set-VMState -Name 'TestVM' -State 'Running' -WaitForIP $true + + Assert-MockCalled -CommandName Start-VM -Scope It + Assert-MockCalled -CommandName Wait-VMIPAddress -Scope It + } + + It 'Should suspend VM when current "State" is "Running" and target state is "Paused"' { + Mock -CommandName Suspend-VM + Mock -CommandName Get-VM -MockWith { + return @{ + State = 'Running' + } + } + + Set-VMState -Name 'TestVM' -State 'Paused' + + Assert-MockCalled -CommandName Suspend-VM -Scope It + } + + It 'Should stop VM when current "State" is "Running" and target state is "Off"' { + Mock -CommandName Stop-VM + Mock -CommandName Get-VM -MockWith { + return @{ + State = 'Running' + } + } + + Set-VMState -Name 'TestVM' -State 'Off' + + Assert-MockCalled -CommandName Stop-VM -Scope It + } + + It 'Should stop VM when current "State" is "Paused" and target state is "Off"' { + Mock -CommandName Stop-VM + Mock -CommandName Get-VM -MockWith { + return @{ + State = 'Paused' + } + } + + Set-VMState -Name 'TestVM' -State 'Off' + + Assert-MockCalled -CommandName Stop-VM -Scope It + } + } # describe HyperVDsc.Common\Set-VMState +} + +Describe 'HyperVDsc.Common\Wait-VMIPAddress' { + Context 'When VM network adapter reports 2 IP addresses'{ + BeforeAll { + Mock -CommandName Get-VMNetworkAdapter -ModuleName 'HyperVDsc.Common' -MockWith { + return @{ + IpAddresses = @('192.168.0.1', '172.16.0.1') + } + } + } + + It 'Should return without throwing an exception' { + $result = Wait-VMIPAddress -Name 'Test' -Verbose + + $result | Should -BeNullOrEmpty + } + } + + Context 'When VM network adapter reports 2 IP addresses'{ + BeforeAll { + Mock -CommandName Start-Sleep -ModuleName 'HyperVDsc.Common' + Mock -CommandName Get-VMNetworkAdapter -ModuleName 'HyperVDsc.Common' -MockWith { + return $null + } + } + + It 'Should throw the correct exception' { + { Wait-VMIPAddress -Name 'Test' -Timeout 2 -Verbose } | Should -Throw ( + $script:localizedData.WaitForVMIPAddressTimeoutError -f 'Test', '2' + ) + } + } +} # describe HyperVDsc.Common\WaitVMIPAddress + +Describe 'HyperVDsc.Common\ConvertTo-TimeSpan' { + It 'Should convert 60 seconds to "System.TimeSpan" of 1 minute' { + $testSeconds = 60 + + $result = ConvertTo-TimeSpan -TimeInterval $testSeconds -TimeIntervalType Seconds + + $result.TotalMinutes | Should -Be 1 + } + + It 'Should convert 60 minutes to "System.TimeSpan" of 60 minutes' { + $testMinutes = 60 + + $result = ConvertTo-TimeSpan -TimeInterval $testMinutes -TimeIntervalType Minutes + + $result.TotalHours | Should -Be 1 + } + + It 'Should convert 48 hours to "System.TimeSpan" of 2 days' { + $testHours = 48 + + $result = ConvertTo-TimeSpan -TimeInterval $testHours -TimeIntervalType Hours + + $result.TotalDays | Should -Be 2 + } + +} # describe HyperVDsc.Common\ConvertTo-TimeSpan + +Describe 'HyperVDsc.Common\ConvertFrom-TimeSpan' { + It 'Should convert a "System.TimeSpan" of 1 minute to 60 seconds' { + $testTimeSpan = New-TimeSpan -Minutes 1 + + $result = ConvertFrom-TimeSpan -TimeSpan $testTimeSpan -TimeSpanType Seconds + + $result | Should -Be 60 + } + + It 'Should convert a "System.TimeSpan" of 1 hour to 60 minutes' { + $testTimeSpan = New-TimeSpan -Hours 1 + + $result = ConvertFrom-TimeSpan -TimeSpan $testTimeSpan -TimeSpanType Minutes + + $result | Should -Be 60 + } + + It 'Should convert a "System.TimeSpan" of 2 dayes to 48 hours' { + $testTimeSpan = New-TimeSpan -Days 2 + + $result = ConvertFrom-TimeSpan -TimeSpan $testTimeSpan -TimeSpanType Hours + + $result | Should -Be 48 + } + +} # describe HyperVDsc.Common\ConvertFrom-TimeSpan + +Describe 'HyperVDsc.Common\Get-VMHyperV' { + BeforeAll { + $mockVMName = 'TestVM' + } + + # Guard mocks + It 'Should not throw when no VM is found' { + Mock -CommandName Get-VM -ModuleName 'HyperVDsc.Common' + + $result = Get-VMHyperV -VMName $mockVMName + + $result | Should -BeNullOrEmpty + } + + It 'Should not throw when one VM is found' { + Mock -CommandName Get-VM -ModuleName 'HyperVDsc.Common' -MockWith { + [PSCustomObject] @{ + Name = $VMName + } + } + + $result = Get-VMHyperV -VMName $mockVMName + + $result.Name | Should -Be $mockVMName + } + + It 'Should throw when more than one VM is found' { + Mock -CommandName Get-VM -ModuleName 'HyperVDsc.Common' -MockWith { + @( + [PSCustomObject] @{ + Name = $VMName + }, + [PSCustomObject] @{ + Name = $VMName + } + ) + } + + { Get-VMHyperV -VMName $mockVMName } | Should -Throw ( + $script:localizedData.MoreThanOneVMExistsError -f $mockVMName + ) + } +} # describe HyperVDsc.Common\Get-VMHyperV diff --git a/Tests/Unit/MSFT_xVHD.tests.ps1 b/tests/Unit/MSFT_xVHD.Tests.ps1 similarity index 76% rename from Tests/Unit/MSFT_xVHD.tests.ps1 rename to tests/Unit/MSFT_xVHD.Tests.ps1 index 83d779c..3a276b2 100644 --- a/Tests/Unit/MSFT_xVHD.tests.ps1 +++ b/tests/Unit/MSFT_xVHD.Tests.ps1 @@ -1,45 +1,38 @@ -#region HEADER - -# Unit Test Template Version: 1.2.0 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'xHyper-V' ` - -DSCResourceName 'MSFT_xVHD' ` - -TestType Unit - -#endregion HEADER +$script:dscModuleName = 'xHyper-V' +$script:dscResourceName = 'MSFT_xVhd' function Invoke-TestSetup { + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + # Import the stub functions. + Import-Module -Name "$PSScriptRoot/Stubs/Hyper-V.stubs.psm1" -Force } function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } -# Begin Testing +Invoke-TestSetup + try { - Invoke-TestSetup - - InModuleScope 'MSFT_xVHD' { + InModuleScope $script:dscResourceName { Describe 'MSFT_xVHD\Get-TargetResource' { - # Create an empty function to be able to mock the missing Hyper-V cmdlet - function Get-VHD - { - - } - Context 'Should stop when Hyper-V module is missing' { Mock -CommandName Get-Module -ParameterFilter { ($Name -eq 'Hyper-V') -and ($ListAvailable -eq $true) } -MockWith { return $false @@ -47,7 +40,7 @@ try It 'Should throw when the module is missing' { { Test-TargetResource -Name 'server.vhdx' -Path 'C:\VMs' -Type 'Fixed' -MaximumSizeBytes 1GB } | - Should Throw 'Please ensure that Hyper-V role is installed with its PowerShell module' + Should -Throw 'Please ensure that Hyper-V role is installed with its PowerShell module' } } @@ -67,8 +60,8 @@ try } $getTargetResult = Get-TargetResource -Name 'server' -Path 'c:\boguspath' -Generation 'vhdx' - $getTargetResult.Ensure | Should Be 'Present' - $getTargetResult | Should BeOfType hashtable + $getTargetResult.Ensure | Should -Be 'Present' + $getTargetResult | Should -BeOfType hashtable } } @@ -77,8 +70,8 @@ try Mock -CommandName Get-VHD $getTargetResult = Get-TargetResource -Name 'server' -Path 'c:\boguspath' -Generation 'vhdx' - $getTargetResult.Ensure | Should Be 'Absent' - $getTargetResult | Should BeOfType hashtable + $getTargetResult.Ensure | Should -Be 'Absent' + $getTargetResult | Should -BeOfType hashtable } } } @@ -87,29 +80,29 @@ try Context 'Name does not have extension' { It 'Should return server.vhdx with generation vhdx' { GetNameWithExtension -Name 'server' -Generation 'vhdx' | - Should Be 'server.vhdx' + Should -Be 'server.vhdx' } It 'Should return server.vhd with generation vhd' { GetNameWithExtension -Name 'server' -Generation 'vhd' | - Should Be 'server.vhd' + Should -Be 'server.vhd' } It 'Should not throw' { { GetNameWithExtension -Name 'server' -Generation 'vhd' } | - Should Not Throw + Should -Not -throw } } Context 'Name has extension' { It 'Should return server.vhdx with Name server.vhdx and generation vhdx' { GetNameWithExtension -Name 'server.vhd' -Generation 'vhd' | - Should Be 'server.vhd' + Should -Be 'server.vhd' } It 'Should throw with mismatch with extension from name and generation' { { GetNameWithExtension -Name 'server.vhdx' -Generation 'vhd' } | - Should Throw 'the extension vhdx on the name does not match the generation vhd' + Should -Throw 'the extension vhdx on the name does not match the generation vhd' } } } @@ -128,7 +121,7 @@ try It 'Should throw when the module is missing' { { Test-TargetResource -Name 'server.vhdx' -Path 'C:\VMs' -Type 'Fixed' -MaximumSizeBytes 1GB } | - Should Throw 'Please ensure that Hyper-V role is installed with its PowerShell module' + Should -Throw 'Please ensure that Hyper-V role is installed with its PowerShell module' } } @@ -140,17 +133,17 @@ try Context 'Parameter validation' { It 'Fixed and Dynamic VHDs need MaximumSizeBytes specified' { { Test-TargetResource -Name 'server' -Path 'C:\VMs' -Type 'Dynamic' } | - Should Throw 'Specify MaximumSizeBytes property for Fixed and Dynamic VHDs.' + Should -Throw 'Specify MaximumSizeBytes property for Fixed and Dynamic VHDs.' } It 'Parent Path is passed for a non Differencing disk' { { Test-TargetResource -Name 'server' -Path 'C:\VMs' -ParentPath 'C:\VMs\Parent' -Type 'Fixed' -MaximumSizeBytes 1GB } | - Should Throw 'Parent path is only supported for Differencing disks' + Should -Throw 'Parent path is only supported for Differencing disks' } It 'Differencing disk needs a Parent Path' { { Test-TargetResource -Name 'server' -Path 'C:\VMs' -Type 'Differencing' } | - Should Throw 'Differencing requires a parent path' + Should -Throw 'Differencing requires a parent path' } } @@ -159,7 +152,7 @@ try Mock -CommandName Test-Path -MockWith { $false } { Test-TargetResource -Name 'server' -Path 'C:\VMs' -Type 'Differencing' -ParentPath 'c:\boguspath' } | - Should Throw 'c:\boguspath does not exists' + Should -Throw 'c:\boguspath does not exists' } # "Generation $Generation should match ParentPath extension $($ParentPath.Split('.')[-1])" @@ -167,7 +160,7 @@ try Mock -CommandName Test-Path -MockWith { $true } { Test-TargetResource -Name 'server' -Path 'C:\VMs' -Type 'Differencing' -ParentPath 'c:\boguspath.vhd' -Generation 'Vhdx' } | - Should Throw 'Generation Vhdx should match ParentPath extension vhd' + Should -Throw 'Generation Vhdx should match ParentPath extension vhd' } } @@ -176,7 +169,7 @@ try Mock -CommandName Test-Path -MockWith { $false } { Test-TargetResource -Name 'server.vhdx' -Path 'C:\VMs' -Type 'Fixed' -MaximumSizeBytes 1GB } | - Should Throw 'C:\VMs does not exists' + Should -Throw 'C:\VMs does not exists' } } @@ -189,13 +182,13 @@ try It 'Should not throw' { { Test-TargetResource -Name 'server.vhdx' -Path 'C:\VMs' -Type 'Fixed' -MaximumSizeBytes 1GB } | - Should not Throw + Should -not -throw } It 'Should return a boolean and it should be true' { $testResult = Test-TargetResource -Name 'server.vhdx' -Path 'C:\VMs' -Type 'Fixed' -MaximumSizeBytes 1GB - $testResult | Should BeOfType bool - $testResult -eq $true | Should Be $true + $testResult | Should -BeOfType bool + $testResult -eq $true | Should -Be $true } } @@ -208,39 +201,18 @@ try It 'Should not throw' { { Test-TargetResource -Name 'server.vhdx' -Path 'C:\VMs' -Type 'Fixed' -MaximumSizeBytes 1GB } | - Should not Throw + Should -not -throw } It 'Should return a boolean and it should be false' { $testResult = Test-TargetResource -Name 'server.vhdx' -Path 'C:\VMs' -Type 'Fixed' -MaximumSizeBytes 1GB - $testResult | Should BeOfType bool - $testResult -eq $true | Should Be $false + $testResult | Should -BeOfType bool + $testResult -eq $true | Should -Be $false } } } Describe 'MSFT_xVHD\Set-TargetResource' { - # Create an empty function to be able to mock the missing Hyper-V cmdlet - function Get-VHD - { - - } - - function Set-VHD - { - - } - - function Resize-VHD - { - - } - - function New-VHD - { - - } - Context 'Ensure is Absent' { Mock -CommandName Test-Path -MockWith { $true } Mock -CommandName Remove-Item @@ -266,7 +238,7 @@ try Mock -CommandName Set-VHD Mock -CommandName Resize-VHD Mock -CommandName GetNameWithExtension -MockWith { 'server.vhdx' } - Mock -CommandName New-VHD -MockWith { } + Mock -CommandName New-VHD } It 'Should Create a VHD when Ensure is present and no VHD exists yet for non Differencing disk' { diff --git a/Tests/Unit/MSFT_xVMDvdDrive.tests.ps1 b/tests/Unit/MSFT_xVMDvdDrive.Tests.ps1 similarity index 77% rename from Tests/Unit/MSFT_xVMDvdDrive.tests.ps1 rename to tests/Unit/MSFT_xVMDvdDrive.Tests.ps1 index a194462..a6be1a2 100644 --- a/Tests/Unit/MSFT_xVMDvdDrive.tests.ps1 +++ b/tests/Unit/MSFT_xVMDvdDrive.Tests.ps1 @@ -1,52 +1,37 @@ -$script:DSCModuleName = 'xHyper-V' -$script:DSCResourceName = 'MSFT_xVMDvdDrive' - -#region HEADER -# Unit Test Template Version: 1.1.0 -[String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +$script:dscModuleName = 'xHyper-V' +$script:dscResourceName = 'MSFT_xVMDvdDrive' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import the stub functions. + Import-Module -Name "$PSScriptRoot/Stubs/Hyper-V.stubs.psm1" -Force +} + +function Invoke-TestCleanup { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } -Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceName ` - -TestType Unit -#endregion HEADER +Invoke-TestSetup -# Begin Testing try { - #region Pester Tests - InModuleScope $script:DSCResourceName { - # Function to create a exception object for testing output exceptions - function Get-InvalidArgumentError - { - [CmdletBinding()] - param - ( - [Parameter(Mandatory)] - [ValidateNotNullOrEmpty()] - [System.String] - $ErrorId, - - [Parameter(Mandatory)] - [ValidateNotNullOrEmpty()] - [System.String] - $ErrorMessage - ) - - $exception = New-Object -TypeName System.ArgumentException ` - -ArgumentList $ErrorMessage - $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument - $errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord ` - -ArgumentList $exception, $ErrorId, $errorCategory, $null - return $errorRecord - } # end function Get-InvalidArgumentError - + InModuleScope $script:dscResourceName { #region Pester Test Initialization $script:VMName = 'HyperVUnitTestsVM' @@ -115,62 +100,8 @@ try } #endregion - #region Function Get-TargetResource + #region function Get-TargetResource Describe 'MSFT_xVMDvdDrive\Get-TargetResource' { - #region VM Functions - function Get-VM { - Param - ( - [String] - $Name - ) - } - - function Get-VMScsiController { - Param - ( - [String] - $VMName, - - [Uint32] - $ControllerNumber - ) - } - - function Get-VMIdeController { - Param - ( - [String] - $VMName, - - [Uint32] - $ControllerNumber - ) - } - - function Get-VMHardDiskDrive { - Param - ( - [String] - $VMName, - - [Uint32] - $ControllerNumber, - - [Uint32] - $ControllerLocation - ) - } - - function Get-VMDvdDrive { - Param - ( - [String] - $VMName - ) - } - #endregion - Context 'DVD Drive does not exist' { # Verifiable (should be called) mocks Mock ` @@ -186,15 +117,15 @@ try It 'should not throw exception' { { $script:resource = Get-TargetResource @script:splatGetDvdDrive - } | Should Not Throw + } | Should -Not -throw } It 'should return expected values' { - $script:resource.VMName | Should Be $script:splatGetDvdDrive.VMName - $script:resource.ControllerNumber | Should Be $script:splatGetDvdDrive.ControllerNumber - $script:resource.ControllerLocation | Should Be $script:splatGetDvdDrive.ControllerLocation - $script:resource.Path | Should BeNullOrEmpty - $script:resource.Ensure | Should Be 'Absent' + $script:resource.VMName | Should -Be $script:splatGetDvdDrive.VMName + $script:resource.ControllerNumber | Should -Be $script:splatGetDvdDrive.ControllerNumber + $script:resource.ControllerLocation | Should -Be $script:splatGetDvdDrive.ControllerLocation + $script:resource.Path | Should -BeNullOrEmpty + $script:resource.Ensure | Should -Be 'Absent' } It 'all the get mocks should be called' { @@ -220,15 +151,15 @@ try It 'should not throw exception' { { $script:resource = Get-TargetResource @script:splatGetDvdDrive - } | Should Not Throw + } | Should -Not -throw } It 'should return expected values' { - $script:resource.VMName | Should Be $script:splatGetDvdDrive.VMName - $script:resource.ControllerNumber | Should Be $script:splatGetDvdDrive.ControllerNumber - $script:resource.ControllerLocation | Should Be $script:splatGetDvdDrive.ControllerLocation - $script:resource.Path | Should BeNullOrEmpty - $script:resource.Ensure | Should Be 'Present' + $script:resource.VMName | Should -Be $script:splatGetDvdDrive.VMName + $script:resource.ControllerNumber | Should -Be $script:splatGetDvdDrive.ControllerNumber + $script:resource.ControllerLocation | Should -Be $script:splatGetDvdDrive.ControllerLocation + $script:resource.Path | Should -BeNullOrEmpty + $script:resource.Ensure | Should -Be 'Present' } It 'all the get mocks should be called' { @@ -254,15 +185,15 @@ try It 'should not throw exception' { { $script:resource = Get-TargetResource @script:splatGetDvdDrive - } | Should Not Throw + } | Should -Not -throw } It 'should return expected values' { - $script:resource.VMName | Should Be $script:splatGetDvdDrive.VMName - $script:resource.ControllerNumber | Should Be $script:splatGetDvdDrive.ControllerNumber - $script:resource.ControllerLocation | Should Be $script:splatGetDvdDrive.ControllerLocation - $script:resource.Path | Should Be $script:TestISOPath - $script:resource.Ensure | Should Be 'Present' + $script:resource.VMName | Should -Be $script:splatGetDvdDrive.VMName + $script:resource.ControllerNumber | Should -Be $script:splatGetDvdDrive.ControllerNumber + $script:resource.ControllerLocation | Should -Be $script:splatGetDvdDrive.ControllerLocation + $script:resource.Path | Should -Be $script:TestISOPath + $script:resource.Ensure | Should -Be 'Present' } It 'all the get mocks should be called' { @@ -275,58 +206,8 @@ try } #endregion - #region Function Set-TargetResource + #region function Set-TargetResource Describe 'MSFT_xVMDvdDrive\Set-TargetResource' { - #region VM Functions - function Add-VMDvdDrive { - Param - ( - [String] - $VMName, - - [Uint32] - $ControllerNumber, - - [Uint32] - $ControllerLocation, - - [String] - $Path - ) - } - - function Set-VMDvdDrive { - Param - ( - [String] - $VMName, - - [Uint32] - $ControllerNumber, - - [Uint32] - $ControllerLocation, - - [String] - $Path - ) - } - - function Remove-VMDvdDrive { - Param - ( - [String] - $VMName, - - [Uint32] - $ControllerNumber, - - [Uint32] - $ControllerLocation - ) - } - #endregion - Context 'DVD Drive does not exist but should' { # Verifiable (should be called) mocks Mock ` @@ -344,7 +225,7 @@ try Mock -CommandName Remove-VMDvdDrive It 'should not throw exception' { - { Set-TargetResource @script:splatAddDvdDriveNoPath } | Should Not Throw + { Set-TargetResource @script:splatAddDvdDriveNoPath } | Should -Not -throw } It 'all the get mocks should be called' { @@ -370,7 +251,7 @@ try Mock -CommandName Remove-VMDvdDrive It 'should not throw exception' { - { Set-TargetResource @script:splatAddDvdDrive } | Should Not Throw + { Set-TargetResource @script:splatAddDvdDrive } | Should -Not -throw } It 'all the get mocks should be called' { @@ -399,7 +280,7 @@ try Mock -CommandName Remove-VMDvdDrive It 'should not throw exception' { - { Set-TargetResource @script:splatAddDvdDrive } | Should Not Throw + { Set-TargetResource @script:splatAddDvdDrive } | Should -Not -throw } It 'all the get mocks should be called' { @@ -429,7 +310,7 @@ try Mock -CommandName Set-VMDvdDrive It 'should not throw exception' { - { Set-TargetResource @script:splatRemoveDvdDrive } | Should Not Throw + { Set-TargetResource @script:splatRemoveDvdDrive } | Should -Not -throw } It 'all the get mocks should be called' { @@ -455,7 +336,7 @@ try Mock -CommandName Remove-VMDvdDrive It 'should not throw exception' { - { Set-TargetResource @script:splatRemoveDvdDrive } | Should Not Throw + { Set-TargetResource @script:splatRemoveDvdDrive } | Should -Not -throw } It 'all the get mocks should be called' { @@ -469,7 +350,7 @@ try } #endregion - #region Function Test-TargetResource + #region function Test-TargetResource Describe 'MSFT_xVMDvdDrive\Test-TargetResource' { Context 'DVD Drive does not exist but should' { # Verifiable (should be called) mocks @@ -479,7 +360,7 @@ try -Verifiable It 'should return false' { - Test-TargetResource @script:splatAddDvdDriveNoPath | Should Be $False + Test-TargetResource @script:splatAddDvdDriveNoPath | Should -Be $False } It 'all the get mocks should be called' { @@ -496,7 +377,7 @@ try -Verifiable It 'should return true' { - Test-TargetResource @script:splatAddDvdDrive | Should Be $True + Test-TargetResource @script:splatAddDvdDrive | Should -Be $True } It 'all the get mocks should be called' { @@ -513,7 +394,7 @@ try -Verifiable It 'should return false' { - Test-TargetResource @script:splatAddDvdDrive | Should Be $False + Test-TargetResource @script:splatAddDvdDrive | Should -Be $False } It 'all the get mocks should be called' { @@ -530,7 +411,7 @@ try -Verifiable It 'should return false' { - Test-TargetResource @script:splatRemoveDvdDrive | Should Be $False + Test-TargetResource @script:splatRemoveDvdDrive | Should -Be $False } It 'all the get mocks should be called' { @@ -547,7 +428,7 @@ try -Verifiable It 'should return true' { - Test-TargetResource @script:splatRemoveDvdDrive | Should Be $True + Test-TargetResource @script:splatRemoveDvdDrive | Should -Be $True } It 'all the get mocks should be called' { @@ -558,62 +439,8 @@ try } #endregion - #region Function Test-ParameterValid + #region function Test-ParameterValid Describe 'MSFT_xVMDvdDrive\Test-ParameterValid' { - #region VM Functions - function Get-VM { - Param - ( - [String] - $Name - ) - } - - function Get-VMScsiController { - Param - ( - [String] - $VMName, - - [Uint32] - $ControllerNumber - ) - } - - function Get-VMIdeController { - Param - ( - [String] - $VMName, - - [Uint32] - $ControllerNumber - ) - } - - function Get-VMHardDiskDrive { - Param - ( - [String] - $VMName, - - [Uint32] - $ControllerNumber, - - [Uint32] - $ControllerLocation - ) - } - - function Get-VMDvdDrive { - Param - ( - [String] - $VMName - ) - } - #endregion - Context 'Hyper-V Module is not available' { # Verifiable (should be called) mocks Mock ` @@ -627,12 +454,9 @@ try Mock -CommandName Get-VMHardDiskDrive It 'should throw exception' { - $errorRecord = Get-InvalidArgumentError ` - -ErrorId 'RoleMissingError' ` - -ErrorMessage ($LocalizedData.RoleMissingError -f ` - 'Hyper-V') + $errorMessage = $script:localizedData.RoleMissingError -f 'Hyper-V' - { Test-ParameterValid @script:splatAddDvdDriveNoPath } | Should Throw $errorRecord + { Test-ParameterValid @script:splatAddDvdDriveNoPath } | Should -Throw $errorMessage } It 'all the get mocks should be called' { @@ -650,7 +474,7 @@ try Mock ` -CommandName Get-VM ` - -MockWith { Throw } ` + -MockWith { throw } ` -ParameterFilter { $VMName -eq $script:splatAddDvdDriveNoPath.VMName } ` -Verifiable @@ -660,7 +484,7 @@ try Mock -CommandName Get-VMHardDiskDrive It 'should throw exception' { - { Test-ParameterValid @script:splatAddDvdDriveNoPath } | Should Throw + { Test-ParameterValid @script:splatAddDvdDriveNoPath } | Should -Throw } It 'all the get mocks should be called' { @@ -698,12 +522,9 @@ try Mock -CommandName Get-VMHardDiskDrive It 'should throw exception' { - $errorRecord = Get-InvalidArgumentError ` - -ErrorId 'VMControllerDoesNotExistError' ` - -ErrorMessage ($LocalizedData.VMControllerDoesNotExistError -f ` - $script:VMName,0) + $errorMessage = $script:localizedData.VMControllerDoesNotExistError -f $script:VMName, 0 - { Test-ParameterValid @script:splatAddDvdDriveNoPath } | Should Throw $errorRecord + { Test-ParameterValid @script:splatAddDvdDriveNoPath } | Should -Throw $errorMessage } It 'all the get mocks should be called' { @@ -718,7 +539,7 @@ try } } - Context 'VM exists, SCSI contrller exists, HD assigned' { + Context 'VM exists, SCSI controller exists, HD assigned' { # Verifiable (should be called) mocks Mock ` -CommandName Get-Module ` @@ -747,12 +568,9 @@ try Mock -CommandName Get-VMIdeController It 'should throw exception' { - $errorRecord = Get-InvalidArgumentError ` - -ErrorId 'ControllerConflictError' ` - -ErrorMessage ($LocalizedData.ControllerConflictError -f ` - $script:VMName,0,1) + $errorMessage = $script:localizedData.ControllerConflictError -f $script:VMName, 0, 1 - { Test-ParameterValid @script:splatAddDvdDriveNoPath } | Should Throw $errorRecord + { Test-ParameterValid @script:splatAddDvdDriveNoPath } | Should -Throw $errorMessage } It 'all the get mocks should be called' { @@ -767,7 +585,7 @@ try } } - Context 'VM exists, SCSI contrller exists, HD not assigned, Path invalid' { + Context 'VM exists, SCSI controller exists, HD not assigned, Path invalid' { # Verifiable (should be called) mocks Mock ` -CommandName Get-Module ` @@ -800,12 +618,9 @@ try Mock -CommandName Get-VMIdeController It 'should throw exception' { - $errorRecord = Get-InvalidArgumentError ` - -ErrorId 'PathDoesNotExistError' ` - -ErrorMessage ($LocalizedData.PathDoesNotExistError -f ` - $script:TestISOPath) + $errorMessage = $script:localizedData.PathDoesNotExistError -f $script:TestISOPath - { Test-ParameterValid @script:splatAddDvdDrive } | Should Throw $errorRecord + { Test-ParameterValid @script:splatAddDvdDrive } | Should -Throw $errorMessage } It 'all the get mocks should be called' { @@ -854,7 +669,7 @@ try Mock -CommandName Get-VMIdeController It 'should not throw exception' { - Test-ParameterValid @script:splatAddDvdDrive | Should Be $True + Test-ParameterValid @script:splatAddDvdDrive | Should -Be $True } It 'all the get mocks should be called' { @@ -875,7 +690,5 @@ try } finally { - #region FOOTER - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion + Invoke-TestCleanup } diff --git a/Tests/Unit/MSFT_xVMHardDiskDrive.Tests.ps1 b/tests/Unit/MSFT_xVMHardDiskDrive.Tests.ps1 similarity index 50% rename from Tests/Unit/MSFT_xVMHardDiskDrive.Tests.ps1 rename to tests/Unit/MSFT_xVMHardDiskDrive.Tests.ps1 index 9ebefdb..1eaea79 100644 --- a/Tests/Unit/MSFT_xVMHardDiskDrive.Tests.ps1 +++ b/tests/Unit/MSFT_xVMHardDiskDrive.Tests.ps1 @@ -1,46 +1,44 @@ -$script:DSCModuleName = 'xHyper-V' -$script:DSCResourceName = 'MSFT_xVMHardDiskDrive' +$script:dscModuleName = 'xHyper-V' +$script:dscResourceName = 'MSFT_xVMHardDiskDrive' -#region HEADER - -# Unit Test Template Version: 1.2.0 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +function Invoke-TestSetup { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import the stub functions. + Import-Module -Name "$PSScriptRoot/Stubs/Hyper-V.stubs.psm1" -Force } -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceName ` - -TestType Unit - -#endregion HEADER - -function Invoke-TestSetup { - +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } -function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment -} +Invoke-TestSetup -# Begin Testing try { - Invoke-TestSetup - - InModuleScope $script:DSCResourceName { + InModuleScope $script:dscResourceName { $testVMName = 'UnitTestVM' $testHardDiskPath = 'TestDrive:\{0}.vhdx' -f $testVMName Describe 'MSFT_xVMHardDiskDrive\Get-TargetResource' { - $stubHardDiskDrive = @{ + $stubHardDiskDrive = [PSCustomObject] @{ VMName = $testVMName Path = $testHardDiskPath ControllerLocation = 0 @@ -49,64 +47,46 @@ try } # Guard mocks - Mock Assert-Module { } - - function Get-VMHardDiskDrive { - [CmdletBinding()] - param - ( - [System.String] - $VMName - ) - } + Mock -CommandName Assert-Module It 'Should return a [System.Collections.Hashtable] object type' { - Mock Get-VMHardDiskDrive { return $stubHardDiskDrive } + Mock -CommandName Get-VMHardDiskDrive { return $stubHardDiskDrive } $result = Get-TargetResource -VMName $testVMName -Path $testhardDiskPath - $result -is [System.Collections.Hashtable] | Should Be $true + $result -is [System.Collections.Hashtable] | Should -Be $true } It 'Should return "Present" when hard disk is attached' { - Mock Get-VMHardDiskDrive { return $stubHardDiskDrive } + Mock -CommandName Get-VMHardDiskDrive { return $stubHardDiskDrive } $result = Get-TargetResource -VMName $testVMName -Path $testhardDiskPath - $result.Ensure | Should Be 'Present' + $result.Ensure | Should -Be 'Present' } It 'Should return "Absent" when hard disk is not attached' { - Mock Get-VMHardDiskDrive { } + Mock -CommandName Get-VMHardDiskDrive $result = Get-TargetResource -VMName $testVMName -Path $testhardDiskPath - $result.Ensure | Should Be 'Absent' + $result.Ensure | Should -Be 'Absent' } It 'Should assert Hyper-V module is installed' { - Mock Assert-Module { } - Mock Get-VMHardDiskDrive { return $stubHardDiskDrive } + Mock -CommandName Assert-Module + Mock -CommandName Get-VMHardDiskDrive { return $stubHardDiskDrive } $null = Get-TargetResource -VMName $testVMName -Path $testhardDiskPath - Assert-MockCalled Assert-Module -ParameterFilter { $Name -eq 'Hyper-V' } -Scope It + Assert-MockCalled -CommandName Assert-Module -ParameterFilter { $ModuleName -eq 'Hyper-V' } -Scope It } } # descrive Get-TargetResource Describe 'MSFT_xVMHardDiskDrive\Test-TargetResource' { # Guard mocks - Mock Assert-Module { } - - function Get-VMHardDiskDrive { - [CmdletBinding()] - param - ( - [System.String] - $VMName - ) - } + Mock -CommandName Assert-Module $stubTargetResource = @{ VMName = $testVMName @@ -118,11 +98,11 @@ try } It 'Should return a [System.Boolean] object type' { - Mock Get-TargetResource { return $stubTargetResource } + Mock -CommandName Get-TargetResource { return $stubTargetResource } $result = Test-TargetResource -VMName $testVMName -Path $testHardDiskPath - $result -is [System.Boolean] | Should Be $true + $result -is [System.Boolean] | Should -Be $true } $parameterNames = @( @@ -144,7 +124,7 @@ try $result = Test-TargetResource @testTargetResourceParams - $result | Should Be $true + $result | Should -Be $true } It "Should fail when parameter '$parameterName' is incorrect" { @@ -153,7 +133,7 @@ try $result = Test-TargetResource @testTargetResourceParams - $result | Should Be $false + $result | Should -Be $false } } @@ -166,7 +146,7 @@ try $result = Test-TargetResource @testTargetResourceParams - $result | Should Be $true + $result | Should -Be $true } It "Should fail when parameter 'ControllerType' is incorrect" { @@ -178,7 +158,7 @@ try $result = Test-TargetResource @testTargetResourceParams - $result | Should Be $false + $result | Should -Be $false } It "Should pass when parameter 'Ensure' is correct" { @@ -190,7 +170,7 @@ try $result = Test-TargetResource @testTargetResourceParams - $result | Should Be $true + $result | Should -Be $true } It "Should fail when parameter 'Ensure' is incorrect" { @@ -202,7 +182,7 @@ try $result = Test-TargetResource @testTargetResourceParams - $result | Should Be $false + $result | Should -Be $false } It 'Should throw when IDE controller number 2 is specified' { @@ -213,7 +193,7 @@ try ControllerNumber = 2 } - { Test-TargetResource @testTargetResourceParams } | Should Throw 'not valid' + { Test-TargetResource @testTargetResourceParams } | Should -Throw 'not valid' } It 'Should throw when IDE controller location 2 is specified' { @@ -224,153 +204,68 @@ try ControllerLocation = 2 } - { Test-TargetResource @testTargetResourceParams } | Should Throw 'not valid' + { Test-TargetResource @testTargetResourceParams } | Should -Throw 'not valid' } } # describe Test-TargetResource Describe 'MSFT_xVMHardDiskDrive\Set-TargetResource' { - - function Get-VMHardDiskDrive { - [CmdletBinding()] - param - ( - [Parameter(ValueFromPipeline)] - [System.String] - $VMName, - - [System.String] - $Path, - - [System.String] - $ControllerType, - - [System.Int32] - $ControllerNumber, - - [System.Int32] - $ControllerLocation - ) - } - - function Set-VMHardDiskDrive { - [CmdletBinding()] - param - ( - [Parameter(ValueFromPipeline)] - [System.String] - $VMName, - - [System.String] - $Path, - - [System.String] - $ControllerType, - - [System.Int32] - $ControllerNumber, - - [System.Int32] - $ControllerLocation - ) - } - - function Add-VMHardDiskDrive { - [CmdletBinding()] - param - ( - [Parameter(ValueFromPipeline)] - [System.String] - $VMName, - - [System.String] - $Path, - - [System.String] - $ControllerType, - - [System.Int32] - $ControllerNumber, - - [System.Int32] - $ControllerLocation - ) - } - - function Remove-VMHardDiskDrive { - [CmdletBinding()] - param - ( - [Parameter(ValueFromPipeline)] - [System.String] - $VMName, - - [System.String] - $Path, - - [System.String] - $ControllerType, - - [System.Int32] - $ControllerNumber, - - [System.Int32] - $ControllerLocation - ) - } - # Guard mocks - Mock Assert-Module { } - Mock Get-VMHardDiskDrive { } - Mock Set-VMHardDiskDrive { } - Mock Add-VMHardDiskDrive { } - Mock Remove-VMHardDiskDrive { } - - $stubHardDiskDrive = @{ - VMName = $testVMName - Path = $testHardDiskPath - ControllerLocation = 0 - ControllerNumber = 0 - ControllerType = 'SCSI' - } + Mock -CommandName Assert-Module + Mock -CommandName Get-VMHardDiskDrive + Mock -CommandName Set-VMHardDiskDrive + Mock -CommandName Add-VMHardDiskDrive + Mock -CommandName Remove-VMHardDiskDrive + + <# + Create a mock of a the class HardDiskDrive to support piping to + the cmdlet Set-VMHardDiskDrive. + #> + $stubHardDiskDrive = [Microsoft.HyperV.PowerShell.HardDiskDrive]::CreateTypeInstance() + $stubHardDiskDrive.CimSession = New-MockObject -Type CimSession + $stubHardDiskDrive.VMName = $testVMName + $stubHardDiskDrive.Path = $testHardDiskPath + $stubHardDiskDrive.ControllerLocation = 0 + $stubHardDiskDrive.ControllerNumber = 0 + $stubHardDiskDrive.ControllerType = 'SCSI' It 'Should assert Hyper-V module is installed' { - Mock Get-VMHardDiskDrive { return $stubHardDiskDrive } + Mock -CommandName Get-VMHardDiskDrive { return $stubHardDiskDrive } $null = Set-TargetResource -VMName $testVMName -Path $testHardDiskPath - Assert-MockCalled Assert-Module -ParameterFilter { $Name -eq 'Hyper-V' } -Scope It + Assert-MockCalled -CommandName Assert-Module -ParameterFilter { $ModuleName -eq 'Hyper-V' } -Scope It } It 'Should update existing hard disk' { - Mock Get-VMHardDiskDrive { return $stubHardDiskDrive } + Mock -CommandName Get-VMHardDiskDrive { return $stubHardDiskDrive } $null = Set-TargetResource -VMName $testVMName -Path $testHardDiskPath - Assert-MockCalled Set-VMHardDiskDrive -Scope It + Assert-MockCalled -CommandName Set-VMHardDiskDrive -Scope It } It 'Should add hard disk when is not attached' { - Mock Get-VMHardDiskDrive { } - Mock Get-VMHardDiskDrive -ParameterFilter { $PSBoundParameters.ContainsKey('ControllerType') } + Mock -CommandName Get-VMHardDiskDrive + Mock -CommandName Get-VMHardDiskDrive -ParameterFilter { $PSBoundParameters.ContainsKey('ControllerType') } $null = Set-TargetResource -VMName $testVMName -Path $testHardDiskPath - Assert-MockCalled Add-VMHardDiskDrive -Scope It + Assert-MockCalled -CommandName Add-VMHardDiskDrive -Scope It } It 'Should throw when an existing disk is attached to controller/location' { - Mock Get-VMHardDiskDrive { } - Mock Get-VMHardDiskDrive -ParameterFilter { $PSBoundParameters.ContainsKey('ControllerType') } { return $stubHardDiskDrive } + Mock -CommandName Get-VMHardDiskDrive + Mock -CommandName Get-VMHardDiskDrive -ParameterFilter { $PSBoundParameters.ContainsKey('ControllerType') } { return $stubHardDiskDrive } - { Set-TargetResource -VMName $testVMName -Path $testHardDiskPath } | Should Throw 'disk present' + { Set-TargetResource -VMName $testVMName -Path $testHardDiskPath } | Should -Throw 'disk present' } It 'Should remove attached hard disk when Ensure is "Absent"' { - Mock Get-VMHardDiskDrive { return $stubHardDiskDrive } + Mock -CommandName Get-VMHardDiskDrive { return $stubHardDiskDrive } $null = Set-TargetResource -VMName $testVMName -Path $testHardDiskPath -Ensure 'Absent' - Assert-MockCalled Remove-VMHardDiskDrive -Scope It + Assert-MockCalled -CommandName Remove-VMHardDiskDrive -Scope It } } # describe Set-TargetResource } # InModuleScope diff --git a/Tests/Unit/MSFT_xVMHost.tests.ps1 b/tests/Unit/MSFT_xVMHost.Tests.ps1 similarity index 59% rename from Tests/Unit/MSFT_xVMHost.tests.ps1 rename to tests/Unit/MSFT_xVMHost.Tests.ps1 index 7396683..2191aa5 100644 --- a/Tests/Unit/MSFT_xVMHost.tests.ps1 +++ b/tests/Unit/MSFT_xVMHost.Tests.ps1 @@ -1,68 +1,61 @@ -$script:DSCModuleName = 'xHyper-V' -$script:DSCResourceName = 'MSFT_xVMHost' +$script:dscModuleName = 'xHyper-V' +$script:dscResourceName = 'MSFT_xVMHost' -#region HEADER - -# Unit Test Template Version: 1.2.0 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +function Invoke-TestSetup { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import the stub functions. + Import-Module -Name "$PSScriptRoot/Stubs/Hyper-V.stubs.psm1" -Force } -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceName ` - -TestType Unit - -#endregion HEADER - -function Invoke-TestSetup { - +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } -function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment -} +Invoke-TestSetup -# Begin Testing try { - Invoke-TestSetup - - InModuleScope $script:DSCResourceName { + InModuleScope $script:dscResourceName { $testVMName = 'UnitTestVM' Describe 'MSFT_xVMHost\Get-TargetResource' { - $fakeVMHost = @{ - ResourceMeteringSaveInterval = 60; + ResourceMeteringSaveInterval = 60 } - # Guard mocks - - function Get-VMHost { } - It 'Should return a [System.Collections.Hashtable] object type' { - Mock Assert-Module { } - Mock Get-VMHost { return $fakeVMHost } + Mock -CommandName Assert-Module + Mock -CommandName Get-VMHost { return $fakeVMHost } $result = Get-TargetResource -IsSingleInstance 'Yes' - $result -is [System.Collections.Hashtable] | Should Be $true + $result -is [System.Collections.Hashtable] | Should -Be $true } It 'Should assert Hyper-V module is installed' { - Mock Assert-Module { } - Mock Get-VMHost { return $fakeVMHost } + Mock -CommandName Assert-Module + Mock -CommandName Get-VMHost { return $fakeVMHost } $result = Get-TargetResource -IsSingleInstance 'Yes' - Assert-MockCalled Assert-Module -ParameterFilter { $Name -eq 'Hyper-V' } -Scope It + Assert-MockCalled -CommandName Assert-Module -ParameterFilter { $ModuleName -eq 'Hyper-V' } -Scope It } } # describe Get-TargetResource @@ -70,53 +63,51 @@ try Describe 'MSFT_xVMHost\Test-TargetResource' { # Guard mocks - Mock Assert-Module { } - - function Get-VMHost { } + Mock -CommandName Assert-Module $fakeTargetResource = @{ - IsSingleInstance = 'Yes'; - EnableEnhancedSessionMode = $true; - FibreChannelWwnn = 'C003FF0000FFFF00'; - FibreChannelWwpnMaximum = 'C003FFFBEAE1FFFF'; - FibreChannelWwpnMinimum = 'C003FFFBEAE10000'; - MacAddressMinimum = '00155D327500'; - MacAddressMaximum = '00155D3275FF'; - MaximumStorageMigrations = 2; - MaximumVirtualMachineMigrations = 2; - NumaSpanningEnabled = $true; - ResourceMeteringSaveIntervalMinute = 60; - UseAnyNetworkForMigration = $false; - VirtualMachinePath ='C:\ProgramData\Microsoft\Windows\Hyper-V'; - VirtualMachineMigrationAuthenticationType = 'CredSSP'; - VirtualMachineMigrationPerformanceOption = 'TCPIP'; - VirtualHardDiskPath = 'C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks'; + IsSingleInstance = 'Yes' + EnableEnhancedSessionMode = $true + FibreChannelWwnn = 'C003FF0000FFFF00' + FibreChannelWwpnMaximum = 'C003FFFBEAE1FFFF' + FibreChannelWwpnMinimum = 'C003FFFBEAE10000' + MacAddressMinimum = '00155D327500' + MacAddressMaximum = '00155D3275FF' + MaximumStorageMigrations = 2 + MaximumVirtualMachineMigrations = 2 + NumaSpanningEnabled = $true + ResourceMeteringSaveIntervalMinute = 60 + UseAnyNetworkForMigration = $false + VirtualMachinePath ='C:\ProgramData\Microsoft\Windows\Hyper-V' + VirtualMachineMigrationAuthenticationType = 'CredSSP' + VirtualMachineMigrationPerformanceOption = 'TCPIP' + VirtualHardDiskPath = 'C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks' VirtualMachineMigrationEnabled = $true } It 'Should return a [System.Boolean] object type' { - Mock Get-TargetResource { return $fakeTargetResource } + Mock -CommandName Get-TargetResource { return $fakeTargetResource } $testTargetResourceParams = @{ - IsSingleInstance = 'Yes'; - EnableEnhancedSessionMode = $fakeTargetResource.EnableEnhancedSessionMode; + IsSingleInstance = 'Yes' + EnableEnhancedSessionMode = $fakeTargetResource.EnableEnhancedSessionMode VirtualMachineMigrationEnabled = $fakeTargetResource.VirtualMachineMigrationEnabled } $result = Test-TargetResource @testTargetResourceParams - $result -is [System.Boolean] | Should Be $true + $result -is [System.Boolean] | Should -Be $true } It 'Should assert Hyper-V module is installed' { - Mock Get-TargetResource { return $fakeTargetResource } + Mock -CommandName Get-TargetResource { return $fakeTargetResource } $testTargetResourceParams = @{ - IsSingleInstance = 'Yes'; - EnableEnhancedSessionMode = $fakeTargetResource.EnableEnhancedSessionMode; + IsSingleInstance = 'Yes' + EnableEnhancedSessionMode = $fakeTargetResource.EnableEnhancedSessionMode } $result = Test-TargetResource @testTargetResourceParams - Assert-MockCalled Assert-Module -ParameterFilter { $Name -eq 'Hyper-V' } -Scope It + Assert-MockCalled -CommandName Assert-Module -ParameterFilter { $ModuleName -eq 'Hyper-V' } -Scope It } $parameterNames = @( @@ -139,133 +130,157 @@ try # Test each individual parameter value separately foreach ($parameterName in $parameterNames) { - $parameterValue = $fakeTargetResource[$parameterName]; + $parameterValue = $fakeTargetResource[$parameterName] $testTargetResourceParams = @{ - IsSingleInstance = 'Yes'; + IsSingleInstance = 'Yes' } # Pass value verbatim so it should always pass first It "Should pass when parameter '$parameterName' is correct" { $testTargetResourceParams[$parameterName] = $parameterValue - $result = Test-TargetResource @testTargetResourceParams; + $result = Test-TargetResource @testTargetResourceParams - $result | Should Be $true; + $result | Should -Be $true } - if ($parameterValue -is [System.Boolean]) { - + if ($parameterValue -is [System.Boolean]) + { # Invert parameter value to cause a test failure $testTargetResourceParams[$parameterName] = -not $parameterValue } - elseif ($parameterValue -is [System.String]) { - + elseif ($parameterValue -is [System.String]) + { # Repeat string to cause a test failure $testTargetResourceParams[$parameterName] = "$parameterValue$parameterValue" } - elseif ($parameterValue -is [System.Int32] -or $parameterValue -is [System.Int64]) { - + elseif ($parameterValue -is [System.Int32] -or $parameterValue -is [System.Int64]) + { # Add one to cause a test failure $testTargetResourceParams[$parameterName] = $parameterValue + 1 } It "Should fail when parameter '$parameterName' is incorrect" { - $result = Test-TargetResource @testTargetResourceParams; + $result = Test-TargetResource @testTargetResourceParams - $result | Should Be $false; + $result | Should -Be $false } } It "Should pass when parameter is correct" -TestCases @( - @{ Parameter = 'VirtualMachineMigrationAuthenticationType'; - Value = $fakeTargetResource.VirtualMachineMigrationAuthenticationType; - Expected = $true; } - @{ Parameter = 'VirtualMachineMigrationPerformanceOption'; - Value = $fakeTargetResource.VirtualMachineMigrationPerformanceOption; - Expected = $true; } - @{ Parameter = 'VirtualMachineMigrationEnabled'; - Value = $fakeTargetResource.VirtualMachineMigrationEnabled; - Expected = $true; } + @{ + Parameter = 'VirtualMachineMigrationAuthenticationType' + Value = $fakeTargetResource.VirtualMachineMigrationAuthenticationType + Expected = $true + } + @{ + Parameter = 'VirtualMachineMigrationPerformanceOption' + Value = $fakeTargetResource.VirtualMachineMigrationPerformanceOption + Expected = $true + } + @{ + Parameter = 'VirtualMachineMigrationEnabled' + Value = $fakeTargetResource.VirtualMachineMigrationEnabled + Expected = $true + } ) -Test { - param ( - [System.String] $Parameter, - [System.Object] $Value, - [System.Boolean] $Expected + param + ( + [Parameter()] + [System.String] + $Parameter, + + [Parameter()] + [System.Object] + $Value, + + [Parameter()] + [System.Boolean] + $Expected ) $testTargetResourceParams = @{ - IsSingleInstance = 'Yes'; - $Parameter = $Value; + IsSingleInstance = 'Yes' + $Parameter = $Value } - $result = Test-TargetResource @testTargetResourceParams | Should Be $Expected; + + $result = Test-TargetResource @testTargetResourceParams | Should -Be $Expected } It "Should fail when parameter is incorrect" -TestCases @( - @{ Parameter = 'VirtualMachineMigrationAuthenticationType'; - Value = 'Kerberos'; - Expected = $false; } - @{ Parameter = 'VirtualMachineMigrationPerformanceOption'; - Value = 'Compression'; - Expected = $false; } - @{ Parameter = 'VirtualMachineMigrationEnabled'; - Value = $true; - Expected = $true; } + @{ + Parameter = 'VirtualMachineMigrationAuthenticationType' + Value = 'Kerberos' + Expected = $false + } + @{ + Parameter = 'VirtualMachineMigrationPerformanceOption' + Value = 'Compression' + Expected = $false + } + @{ + Parameter = 'VirtualMachineMigrationEnabled' + Value = $true + Expected = $true + } ) -Test { - param - ( - [System.String] $Parameter, - [System.Object] $Value, - [System.Boolean] $Expected - ) - - $testTargetResourceParams = @{ - IsSingleInstance = 'Yes'; - $Parameter = $Value; - } - $result = Test-TargetResource @testTargetResourceParams | Should Be $Expected; + param + ( + [Parameter()] + [System.String] + $Parameter, + + [Parameter()] + [System.Object] + $Value, + + [Parameter()] + [System.Boolean] + $Expected + ) + + $testTargetResourceParams = @{ + IsSingleInstance = 'Yes' + $Parameter = $Value } + $result = Test-TargetResource @testTargetResourceParams | Should -Be $Expected + } + } # describe Test-TargetResource Describe 'MSFT_xVMHost\Set-TargetResource' { - - function Get-VMHost { } - function Set-VMHost { param ($ResourceMeteringSaveInterval) } - - function Enable-VMMigration { } - - function Disable-VMMigration { } - # Guard mocks - Mock Assert-Module { } - Mock Get-VMHost { } - Mock Set-VMHost { } - Mock Enable-VMMigration { } - Mock Disable-VMMigration { } + Mock -CommandName Assert-Module + Mock -CommandName Get-VMHost + Mock -CommandName Set-VMHost + Mock -CommandName Enable-VMMigration + Mock -CommandName Disable-VMMigration It 'Should assert Hyper-V module is installed' { $setTargetResourceParams = @{ - IsSingleInstance = 'Yes'; + IsSingleInstance = 'Yes' } $result = Set-TargetResource @setTargetResourceParams - Assert-MockCalled Assert-Module -ParameterFilter { $Name -eq 'Hyper-V' } -Scope It + Assert-MockCalled -CommandName Assert-Module -ParameterFilter { $ModuleName -eq 'Hyper-V' } -Scope It } It 'Should call "Set-VMHost" with [System.TimeSpan] object when "ResourceMeteringSaveIntervalMinute" specified' { $setTargetResourceParams = @{ - IsSingleInstance = 'Yes'; - ResourceMeteringSaveIntervalMinute = 60; + IsSingleInstance = 'Yes' + ResourceMeteringSaveIntervalMinute = 60 } + $result = Set-TargetResource @setTargetResourceParams - Assert-MockCalled Set-VMHost -ParameterFilter { $ResourceMeteringSaveInterval -is [System.TimeSpan] } + Assert-MockCalled -CommandName Set-VMHost -ParameterFilter { $ResourceMeteringSaveInterval -is [System.TimeSpan] } } It 'Should call "Enable-VMMigration" when "VirtualMachineMigrationEnabled" is set to true and computer is domain joined' { Mock -CommandName 'Get-CimInstance' -MockWith { - [pscustomobject]@{ + [pscustomobject] @{ PartOfDomain = $true } } @@ -285,7 +300,7 @@ try It 'Should not call "Enable-VMMigration" and should throw when "VirtualMachineMigrationEnabled" is set to true and computer is not domain joined' { Mock -CommandName 'Get-CimInstance' -MockWith { - [pscustomobject]@{ + [pscustomobject] @{ PartOfDomain = $false } } diff --git a/tests/Unit/MSFT_xVMHyperV.Tests.ps1 b/tests/Unit/MSFT_xVMHyperV.Tests.ps1 new file mode 100644 index 0000000..13c06bf --- /dev/null +++ b/tests/Unit/MSFT_xVMHyperV.Tests.ps1 @@ -0,0 +1,964 @@ +$script:dscModuleName = 'xHyper-V' +$script:dscResourceName = 'MSFT_xVMHyperV' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import the stub functions. + Import-Module -Name "$PSScriptRoot/Stubs/Hyper-V.stubs.psm1" -Force +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +try +{ + InModuleScope $script:dscResourceName { + Describe 'xVMHyper-V' { + $null = New-Item -Path 'TestDrive:\TestVM.vhdx' -ItemType File + $null = New-Item -Path 'TestDrive:\TestVM.vhd' -ItemType File + + $stubVhdxDisk = [Microsoft.HyperV.PowerShell.HardDiskDrive]::CreateTypeInstance() + $stubVhdxDisk.Path = 'TestDrive:\TestVM.vhdx' + + $stubVhdDisk = [Microsoft.HyperV.PowerShell.HardDiskDrive]::CreateTypeInstance() + $stubVhdDisk.Path = 'TestDrive:\TestVM.vhd' + + $studVhdxDiskSnapshot = New-Item -Path "TestDrive:\TestVM_D0145678-1576-4435-AB18-9F000C1C17D0.avhdx" -ItemType File + $StubVMConfig = New-Item -Path 'TestDrive:\TestVM.xml' -ItemType File + + # Mock the class VMNetworkAdapter to support piping to cmdlet Connect-VMNetworkAdapter + $stubNIC1 = [Microsoft.HyperV.PowerShell.VMNetworkAdapter]::CreateTypeInstance() + $stubNIC1.SwitchName = 'Test Switch 1' + $stubNIC1.MacAddress = 'AA-BB-CC-DD-EE-FF' + $stubNIC1.IpAddresses = @('192.168.0.1', '10.0.0.1') + + # Mock the class VMNetworkAdapter to support piping to cmdlet Connect-VMNetworkAdapter + $stubNIC2 = [Microsoft.HyperV.PowerShell.VMNetworkAdapter]::CreateTypeInstance() + $stubNIC2.SwitchName = 'Test Switch 2' + $stubNIC2.MacAddress = 'AA-BB-CC-DD-EE-FE' + $stubNIC2.IpAddresses = @('192.168.1.1') + + $mockVmGuid = [System.Guid]::NewGuid().ToString() + + Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'RunningVM' } -MockWith { + $stubVM = [Microsoft.HyperV.PowerShell.VirtualMachine]::CreateTypeInstance() + $stubVM.Name = 'RunningVM' + $stubVM.HardDrives = @( + $stubVhdxDisk, + $stubVhdDisk + ) + $stubVM.Path = $StubVMConfig.FullPath + $stubVM.Generation = 1 + $stubVM.MemoryStartup = 512MB + $stubVM.MemoryMinimum = 128MB + $stubVM.MemoryMaximum = 4096MB + $stubVM.ProcessorCount = 1 + $stubVM.ID = $mockVmGuid + $stubVM.CPUUsage = 10 + $stubVM.MemoryAssigned = 512MB + $stubVM.Uptime = New-TimeSpan -Hours 12 + $stubVM.CreationTime = (Get-Date).AddHours(-12) + $stubVM.DynamicMemoryEnabled = $true + $stubVM.Notes = '' + $stubVM.State = 'Running' + $stubVM.NetworkAdapters = @( + $stubNIC1, + $stubNIC2 + ) + + return $stubVM + } + + Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'StoppedVM' } -MockWith { + $stubVM = [Microsoft.HyperV.PowerShell.VirtualMachine]::CreateTypeInstance() + $stubVM.Name = 'StoppedVM' + $stubVM.HardDrives = @( + $stubVhdxDisk, + $stubVhdDisk + ) + $stubVM.Path = $StubVMConfig.FullPath + $stubVM.Generation = 1 + $stubVM.MemoryStartup = 512MB + $stubVM.MemoryMinimum = 128MB + $stubVM.MemoryMaximum = 4096MB + $stubVM.ProcessorCount = 1 + $stubVM.ID = $mockVmGuid + $stubVM.CPUUsage = 10 + $stubVM.MemoryAssigned = 512MB + $stubVM.Uptime = New-TimeSpan -Hours 12 + $stubVM.CreationTime = (Get-Date).AddHours(-12) + $stubVM.DynamicMemoryEnabled = $true + $stubVM.Notes = '' + $stubVM.State = 'Off' + $stubVM.NetworkAdapters = @( + $stubNIC1, + $stubNIC2 + ) + + return $stubVM + } + + Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'PausedVM' } -MockWith { + $stubVM = [Microsoft.HyperV.PowerShell.VirtualMachine]::CreateTypeInstance() + $stubVM.Name = 'PausedVM' + $stubVM.HardDrives = @( + $stubVhdxDisk, + $stubVhdDisk + ) + $stubVM.Path = $StubVMConfig.FullPath + $stubVM.Generation = 1 + $stubVM.MemoryStartup = 512MB + $stubVM.MemoryMinimum = 128MB + $stubVM.MemoryMaximum = 4096MB + $stubVM.ProcessorCount = 1 + $stubVM.ID = $mockVmGuid + $stubVM.CPUUsage = 10 + $stubVM.MemoryAssigned = 512MB + $stubVM.Uptime = New-TimeSpan -Hours 12 + $stubVM.CreationTime = (Get-Date).AddHours(-12) + $stubVM.DynamicMemoryEnabled = $true + $stubVM.Notes = '' + $stubVM.State = 'Paused' + $stubVM.NetworkAdapters = @( + $stubNIC1, + $stubNIC2 + ) + + return $stubVM + } + + Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'NonexistentVM' } -MockWith { + Write-Error 'VM not found.' + } + + Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'DuplicateVM' } -MockWith { + $stubVM1 = [Microsoft.HyperV.PowerShell.VirtualMachine]::CreateTypeInstance() + $stubVM1.Name = 'DuplicateVM' + $stubVM1.HardDrives = @( + $stubVhdxDisk, + $stubVhdDisk + ) + $stubVM1.Path = $StubVMConfig.FullPath + $stubVM1.Generation = 1 + $stubVM1.MemoryStartup = 512MB + $stubVM1.MemoryMinimum = 128MB + $stubVM1.MemoryMaximum = 4096MB + $stubVM1.ProcessorCount = 1 + $stubVM1.ID = $mockVmGuid + $stubVM1.CPUUsage = 10 + $stubVM1.MemoryAssigned = 512MB + $stubVM1.Uptime = New-TimeSpan -Hours 12 + $stubVM1.CreationTime = (Get-Date).AddHours(-12) + $stubVM1.DynamicMemoryEnabled = $true + $stubVM1.Notes = '' + $stubVM1.State = 'Off' + $stubVM1.NetworkAdapters = @( + $stubNIC1, + $stubNIC2 + ) + + $stubVM2 = [Microsoft.HyperV.PowerShell.VirtualMachine]::CreateTypeInstance() + $stubVM2.Name = 'DuplicateVM' + $stubVM2.HardDrives = @( + $stubVhdxDisk, + $stubVhdDisk + ) + $stubVM2.Path = $StubVMConfig.FullPath + $stubVM2.Generation = 1 + $stubVM2.MemoryStartup = 512MB + $stubVM2.MemoryMinimum = 128MB + $stubVM2.MemoryMaximum = 4096MB + $stubVM2.ProcessorCount = 1 + $stubVM2.ID = $mockVmGuid + $stubVM2.CPUUsage = 10 + $stubVM2.MemoryAssigned = 512MB + $stubVM2.Uptime = New-TimeSpan -Hours 12 + $stubVM2.CreationTime = (Get-Date).AddHours(-12) + $stubVM2.DynamicMemoryEnabled = $true + $stubVM2.Notes = '' + $stubVM2.State = 'Off' + $stubVM2.NetworkAdapters = @( + $stubNIC1, + $stubNIC2 + ) + + return @( + $stubVM1, + $stubVM2 + ) + } + + Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'Generation1Vhd' } -MockWith { + $stubVM = [Microsoft.HyperV.PowerShell.VirtualMachine]::CreateTypeInstance() + $stubVM.Name = 'Generation1Vhd' + $stubVM.HardDrives = @( + $stubVhdDisk + ) + $stubVM.Path = $StubVMConfig.FullPath + $stubVM.Generation = 1 + $stubVM.MemoryStartup = 512MB + $stubVM.MemoryMinimum = 128MB + $stubVM.MemoryMaximum = 4096MB + $stubVM.ProcessorCount = 1 + $stubVM.ID = $mockVmGuid + $stubVM.CPUUsage = 10 + $stubVM.MemoryAssigned = 512MB + $stubVM.Uptime = New-TimeSpan -Hours 12 + $stubVM.CreationTime = (Get-Date).AddHours(-12) + $stubVM.DynamicMemoryEnabled = $true + $stubVM.Notes = '' + $stubVM.State = 'Running' + $stubVM.NetworkAdapters = @( + $stubNIC1, + $stubNIC2 + ) + + return $stubVM + } + + Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'Generation2VM' } -MockWith { + $stubVM = [Microsoft.HyperV.PowerShell.VirtualMachine]::CreateTypeInstance() + $stubVM.Name = 'Generation2VM' + $stubVM.HardDrives = @( + $stubVhdxDisk + ) + $stubVM.Path = $StubVMConfig.FullPath + $stubVM.Generation = 2 + $stubVM.MemoryStartup = 512MB + $stubVM.MemoryMinimum = 128MB + $stubVM.MemoryMaximum = 4096MB + $stubVM.ProcessorCount = 1 + $stubVM.ID = $mockVmGuid + $stubVM.CPUUsage = 10 + $stubVM.MemoryAssigned = 512MB + $stubVM.Uptime = New-TimeSpan -Hours 12 + $stubVM.CreationTime = (Get-Date).AddHours(-12) + $stubVM.DynamicMemoryEnabled = $true + $stubVM.Notes = '' + $stubVM.State = 'Running' + $stubVM.NetworkAdapters = @( + $stubNIC1, + $stubNIC2 + ) + + return $stubVM + } + + Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'VMWithAutomaticCheckpoints' } -MockWith { + $stubVM = [Microsoft.HyperV.PowerShell.VirtualMachine]::CreateTypeInstance() + $stubVM.Name = 'VMWithAutomaticCheckpoints' + $stubVM.HardDrives = @( + $stubVhdxDisk + ) + $stubVM.Path = $StubVMConfig.FullPath + $stubVM.Generation = 2 + $stubVM.MemoryStartup = 512MB + $stubVM.MemoryMinimum = 128MB + $stubVM.MemoryMaximum = 4096MB + $stubVM.ProcessorCount = 1 + $stubVM.ID = $mockVmGuid + $stubVM.CPUUsage = 10 + $stubVM.MemoryAssigned = 512MB + $stubVM.Uptime = New-TimeSpan -Hours 12 + $stubVM.CreationTime = (Get-Date).AddHours(-12) + $stubVM.DynamicMemoryEnabled = $true + $stubVM.Notes = '' + $stubVM.State = 'Running' + $stubVM.AutomaticCheckpointsEnabled = $true + $stubVM.NetworkAdapters = @( + $stubNIC1, + $stubNIC2 + ) + + return $stubVM + } + + Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'VMWithoutAutomaticCheckpoints' } -MockWith { + $stubVM = [Microsoft.HyperV.PowerShell.VirtualMachine]::CreateTypeInstance() + $stubVM.Name = 'VMWithoutAutomaticCheckpoints' + $stubVM.HardDrives = @( + $stubVhdxDisk + ) + $stubVM.Path = $StubVMConfig.FullPath + $stubVM.Generation = 2 + $stubVM.MemoryStartup = 512MB + $stubVM.MemoryMinimum = 128MB + $stubVM.MemoryMaximum = 4096MB + $stubVM.ProcessorCount = 1 + $stubVM.ID = $mockVmGuid + $stubVM.CPUUsage = 10 + $stubVM.MemoryAssigned = 512MB + $stubVM.Uptime = New-TimeSpan -Hours 12 + $stubVM.CreationTime = (Get-Date).AddHours(-12) + $stubVM.DynamicMemoryEnabled = $true + $stubVM.Notes = '' + $stubVM.State = 'Running' + $stubVM.AutomaticCheckpointsEnabled = $false + $stubVM.NetworkAdapters = @( + $stubNIC1, + $stubNIC2 + ) + + return $stubVM + } + + Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'VMAutomaticCheckpointsUnsupported' } -MockWith { + $stubVM = [Microsoft.HyperV.PowerShell.VirtualMachine]::CreateTypeInstance() + $stubVM.Name = 'VMAutomaticCheckpointsUnsupported' + $stubVM.HardDrives = @( + $stubVhdxDisk + ) + $stubVM.Path = $StubVMConfig.FullPath + $stubVM.Generation = 2 + $stubVM.MemoryStartup = 512MB + $stubVM.MemoryMinimum = 128MB + $stubVM.MemoryMaximum = 4096MB + $stubVM.ProcessorCount = 1 + $stubVM.ID = $mockVmGuid + $stubVM.CPUUsage = 10 + $stubVM.MemoryAssigned = 512MB + $stubVM.Uptime = New-TimeSpan -Hours 12 + $stubVM.CreationTime = (Get-Date).AddHours(-12) + $stubVM.DynamicMemoryEnabled = $true + $stubVM.Notes = '' + $stubVM.State = 'Running' + $stubVM.NetworkAdapters = @( + $stubNIC1, + $stubNIC2 + ) + + return $stubVM + } + + $stubGuestServiceInterfaceId = 'Microsoft:{0}\6C09BB55-D683-4DA0-8931-C9BF705F6480' -f $mockVmGuid + + Mock -CommandName Get-VMIntegrationService -MockWith { + $guestServiceInterface = [Microsoft.HyperV.PowerShell.VMIntegrationComponent]::CreateTypeInstance() + $guestServiceInterface.Enabled = $false + $guestServiceInterface.Id = $stubGuestServiceInterfaceId + + return $guestServiceInterface + } + + Mock -CommandName Get-Module -ParameterFilter { ($Name -eq 'Hyper-V') -and ($ListAvailable -eq $true) } -MockWith { return $true } + Mock -CommandName Get-VhdHierarchy -ParameterFilter { $VhdPath.EndsWith('.vhd') } -MockWith { + # Return single Vhd chain for .vhds + return @($stubVhdDisk.Path) + } + Mock -CommandName Get-VhdHierarchy -ParameterFilter { $VhdPath.EndsWith('.vhdx') } -MockWith { + # Return snapshot hierarchy for .vhdxs + return @($stubVhdxDiskSnapshot.FullName, $stubVhdxDisk.Path) + } + Context 'Validates Get-TargetResource Method' { + + It 'Returns a hashtable' { + $targetResource = Get-TargetResource -Name 'RunningVM' -VhdPath $stubVhdxDisk.Path + $targetResource -is [System.Collections.Hashtable] | Should -Be $true + } + + It 'throws when multiple VMs are present' { + { Get-TargetResource -Name 'DuplicateVM' -VhdPath $stubVhdxDisk.Path } | Should -Throw + } + + It 'Does not call Get-VMFirmware if a generation 1 VM' { + Mock -CommandName Get-VMFirmware -MockWith { throw } + $null = Get-TargetResource -Name 'RunningVM' -VhdPath $stubVhdxDisk.Path + Assert-MockCalled -CommandName Get-VMFirmware -Scope It -Exactly 0 + } + + It 'Calls Get-VMFirmware if a generation 2 VM' { + Mock -CommandName Get-VMFirmware -MockWith { return $true } + $null = Get-TargetResource -Name 'Generation2VM' -VhdPath $stubVhdxDisk.Path + Assert-MockCalled -CommandName Get-VMFirmware -Scope It -Exactly 1 + } + + It 'Hash table contains key EnableGuestService' { + $targetResource = Get-TargetResource -Name 'RunningVM' -VhdPath $stubVhdxDisk.Path + $targetResource.ContainsKey('EnableGuestService') | Should -Be $true + } + It 'Hash table contains key AutomaticCheckpointEnabled' { + $targetResource = Get-TargetResource -Name 'VMWithAutomaticCheckpoints' -VhdPath $stubVhdxDisk.Path + $targetResource.ContainsKey('AutomaticCheckpointsEnabled') | Should -Be $true + } + It 'throws when Hyper-V Tools are not installed' { + # This test needs to be the last in the Context otherwise all subsequent Get-Module checks will fail + Mock -CommandName Get-Module -ParameterFilter { ($Name -eq 'Hyper-V') -and ($ListAvailable -eq $true) } + { Get-TargetResource -Name 'RunningVM' @testParams } | Should -Throw + } + } #end context Validates Get-TargetResource Method + + Context 'Validates Test-TargetResource Method' { + $testParams = @{ + VhdPath = $stubVhdxDisk.Path + } + + It 'Returns a boolean' { + $targetResource = Test-TargetResource -Name 'RunningVM' @testParams + $targetResource -is [System.Boolean] | Should -Be $true + } + + It 'Returns $true when VM is present and "Ensure" = "Present"' { + Test-TargetResource -Name 'RunningVM' @testParams | Should -Be $true + } + + It 'Returns $false when VM is not present and "Ensure" = "Present"' { + Test-TargetResource -Name 'NonexistentVM' @testParams | Should -Be $false + } + + It 'Returns $true when VM is not present and "Ensure" = "Absent"' { + Test-TargetResource -Name 'NonexistentVM' -Ensure Absent @testParams | Should -Be $true + } + + It 'Returns $false when VM is present and "Ensure" = "Absent"' { + Test-TargetResource -Name 'RunningVM' -Ensure Absent @testParams | Should -Be $false + } + + It 'Returns $true when VM is in the "Running" state and no state is explicitly specified' { + Test-TargetResource -Name 'RunningVM' @testParams | Should -Be $true + } + + It 'Returns $true when VM is in the "Stopped" state and no state is explicitly specified' { + Test-TargetResource -Name 'StoppedVM' @testParams | Should -Be $true + } + + It 'Returns $true when VM is in the "Paused" state and no state is explicitly specified' { + Test-TargetResource -Name 'PausedVM' @testParams | Should -Be $true + } + + It 'Returns $true when VM is in the "Running" state and requested "State" = "Running"' { + Test-TargetResource -Name 'RunningVM' @testParams | Should -Be $true + } + + It 'Returns $true when VM is in the "Off" state and requested "State" = "Off"' { + Test-TargetResource -Name 'StoppedVM' -State Off @testParams | Should -Be $true + } + + It 'Returns $true when VM is in the "Paused" state and requested "State" = Paused"' { + Test-TargetResource -Name 'PausedVM' -State Paused @testParams | Should -Be $true + } + + It 'Returns $false when VM is in the "Running" state and requested "State" = "Off"' { + Test-TargetResource -Name 'RunningVM' -State Off @testParams | Should -Be $false + } + + It 'Returns $false when VM is in the "Off" state and requested "State" = "Runnning"' { + Test-TargetResource -Name 'StoppedVM' -State Running @testParams | Should -Be $false + } + + It 'Returns $true when VM .vhd file is specified with a generation 1 VM' { + Test-TargetResource -Name 'Generation1Vhd' -VhdPath $stubVhdDisk.Path -Generation 1 -Verbose | Should -Be $true + } + + It 'Returns $true when VM .vhdx file is specified with a generation 1 VM' { + Test-TargetResource -Name 'StoppedVM' -VhdPath $stubVhdxDisk.Path -Generation 1 | Should -Be $true + } + + It 'Returns $true when VM .vhdx file is specified with a generation 2 VM' { + Mock -CommandName Test-VMSecureBoot -MockWith { return $true } + Test-TargetResource -Name 'Generation2VM' -Generation 2 @testParams | Should -Be $true + } + + It 'throws when a VM .vhd file is specified with a generation 2 VM' { + { Test-TargetResource -Name 'Gen2VM' -VhdPath $stubVhdDisk.Path -Generation 2 } | Should -Throw + } + + It 'Returns $true when multiple NICs are assigned in the correct order' { + Test-TargetResource -Name 'RunningVM' @testParams -SwitchName @($stubNIC1.SwitchName, $stubNIC2.SwitchName) | Should -Be $true + } + + It 'Returns $false when multiple NICs are not assigned/assigned in the wrong order' { + Test-TargetResource -Name 'RunningVM' @testParams -SwitchName @($stubNIC2.SwitchName, $stubNIC1.SwitchName) | Should -Be $false + } + + It 'Returns $true when multiple MAC addresses are assigned in the correct order' { + Test-TargetResource -Name 'RunningVM' @testParams -MACAddress @($stubNIC1.MACAddress, $stubNIC2.MACAddress) | Should -Be $true + } + + It 'Returns $false when multiple MAC addresses not assigned/assigned in the wrong order' { + Test-TargetResource -Name 'RunningVM' @testParams -MACAddress @($stubNIC1.MACAddress, $stubNIC2.MACAddress) | Should -Be $true + } + + It 'Returns $true regardless of "SecureBoot" setting on a generation 1 VM' { + Test-TargetResource -Name 'RunningVM' -SecureBoot $true @testParams | Should -Be $true + Test-TargetResource -Name 'RunningVM' -SecureBoot $false @testParams | Should -Be $true + } + + It 'Returns $true when SecureBoot is On and requested "SecureBoot" = "$true"' { + Mock -CommandName Test-VMSecureBoot -MockWith { return $true } + Test-TargetResource -Name 'Generation2VM' -Generation 2 @testParams | Should -Be $true + } + + It 'Returns $false when SecureBoot is On and requested "SecureBoot" = "$false"' { + Mock -CommandName Test-VMSecureBoot -MockWith { return $true } + Test-TargetResource -Name 'Generation2VM' -SecureBoot $false -Generation 2 @testParams | Should -Be $false + } + + It 'Returns $true when VM has snapshot chain' { + Mock -CommandName Get-VhdHierarchy -MockWith { + return @($studVhdxDiskSnapshot, $stubVhdxDisk) + } + Test-TargetResource -Name 'Generation2VM' -VhdPath $stubVhdxDisk.Path -Verbose | Should -Be $true + } + + It 'Returns $false when EnableGuestService is off and requested "EnableGuestService" = "$true"' { + Test-TargetResource -Name 'RunningVM' -EnableGuestService $true @testParams | Should -Be $false + } + + It 'Returns $true when EnableGuestService is off and "EnableGuestService" is not requested"' { + Test-TargetResource -Name 'RunningVM' @testParams | Should -Be $true + } + + Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'Set-VM' -and $Module -eq 'Hyper-V' } -MockWith { + [pscustomobject]@{ + parameters = @{ + # Does not contains parameter AutomaticCheckpointsEnabled + } + } + } + It 'throws when AutomaticCheckpointsEnabled is configured but not supported' { + { Test-TargetResource -Name 'VMAutomaticCheckpoinstUnsupported' -AutomaticCheckpointsEnabled $true @testParams } | Should -Throw + } + + Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'Set-VM' -and $Module -eq 'Hyper-V' } -MockWith { + [pscustomobject]@{ + parameters = @{ + 'AutomaticCheckpointsEnabled' = '' + } + } + } + It 'Returns $true when AutomaticCheckpointsEnabled is on and requested "AutomaticCheckpointsEnabled" is not requested' { + Test-TargetResource -Name 'VMWithAutomaticCheckpoints' @testParams | Should -Be $true + } + It 'Returns $true when AutomaticCheckpointsEnabled is on and requested "AutomaticCheckpointsEnabled" = "$true"' { + Test-TargetResource -Name 'VMWithAutomaticCheckpoints' -AutomaticCheckpointsEnabled $true @testParams | Should -Be $true + } + It 'Returns $true when AutomaticCheckpointsEnabled is off and requested "AutomaticCheckpointsEnabled" = "$false"' { + Test-TargetResource -Name 'VMWithoutAutomaticCheckpoints' -AutomaticCheckpointsEnabled $false @testParams | Should -Be $true + } + It 'Returns $false when AutomaticCheckpointsEnabled is off and requested "AutomaticCheckpointsEnabled" = "$true"' { + Test-TargetResource -Name 'VMWithoutAutomaticCheckpoints' -AutomaticCheckpointsEnabled $true @testParams | Should -Be $false + } + It 'Returns $false when AutomaticCheckpointsEnabled is on and requested "AutomaticCheckpointsEnabled" = "$false"' { + Test-TargetResource -Name 'VMWithAutomaticCheckpoints' -AutomaticCheckpointsEnabled $false @testParams | Should -Be $false + } + + It 'Returns $true when EnableGuestService is on and requested "EnableGuestService" = "$true"' { + Mock -CommandName Get-VMIntegrationService -MockWith { + $guestServiceInterface = [Microsoft.HyperV.PowerShell.VMIntegrationComponent]::CreateTypeInstance() + $guestServiceInterface.Enabled = $true + $guestServiceInterface.Id = $stubGuestServiceInterfaceId + + return $guestServiceInterface + } + + Test-TargetResource -Name 'RunningVM' -EnableGuestService $true @testParams | Should -Be $true + } + + It 'throws when Hyper-V Tools are not installed' { + # This test needs to be the last in the Context otherwise all subsequent Get-Module checks will fail + Mock -CommandName Get-Module -ParameterFilter { ($Name -eq 'Hyper-V') -and ($ListAvailable -eq $true) } + { Test-TargetResource -Name 'RunningVM' @testParams } | Should -Throw + } + + } #end context Validates Test-TargetResource Method + + Context 'Validates Set-TargetResource Method' { + $testParams = @{ + VhdPath = $stubVhdxDisk.Path + } + + Mock -CommandName Get-VM -ParameterFilter { $Name -eq 'NewVM' } + Mock -CommandName New-VM -MockWith { + $stubVM = [Microsoft.HyperV.PowerShell.VirtualMachine]::CreateTypeInstance() + $stubVM.Name = 'NewVM' + $stubVM.Path = $StubVMConfig.FullPath + $stubVM.Generation = $Generation + $stubVM.ID = $mockVmGuid + $stubVM.State = 'Off' + + return $stubVM + } + + Mock -CommandName Set-VM -MockWith { return $true } + Mock -CommandName Stop-VM -MockWith { return $true } # requires output to be able to pipe something into Remove-VM + Mock -CommandName Remove-VM -MockWith { return $true } + Mock -CommandName Set-VMNetworkAdapter -MockWith { return $true } + Mock -CommandName Get-VMNetworkAdapter -MockWith { return $stubVM.NetworkAdapters.IpAddresses } + Mock -CommandName Set-VMState -MockWith { return $true } + Mock -CommandName Set-VMMemory + + It 'Removes an existing VM when "Ensure" = "Absent"' { + Set-TargetResource -Name 'RunningVM' -Ensure Absent @testParams + Assert-MockCalled -CommandName Remove-VM -Scope It + } + + It 'Creates and starts a VM VM with disabled dynamic memory that does not exist when "Ensure" = "Present" and "State" = "Running"' { + Set-TargetResource -Name 'NewVM' -State Running @testParams + Assert-MockCalled -CommandName New-VM -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-VM -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-VMState -Exactly -Times 1 -Scope It + } + + It 'Creates but does not start a VM with disabled dynamic memory that does not exist when "Ensure" = "Present"' { + Set-TargetResource -Name 'NewVM' @testParams + Assert-MockCalled -CommandName New-VM -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-VM -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-VMState -Exactly -Times 0 -Scope It + } + + It 'Creates but does not start a VM with disabled dynamic memory when only StartupMemory is specified' { + Set-TargetResource -Name 'NewVM' @testParams -StartupMemory 4GB + Assert-MockCalled -CommandName New-VM -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-VM -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-VMState -Exactly -Times 0 -Scope It + } + + It 'Creates but does not start a VM with disabled dynamic memory when identical values for startup, minimum and maximum memory are specified' { + Set-TargetResource -Name 'NewVM' @testParams -StartupMemory 4GB -MinimumMemory 4GB -MaximumMemory 4GB + Assert-MockCalled -CommandName New-VM -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-VM -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-VMMemory -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-VMState -Exactly -Times 0 -Scope It + } + + It 'Creates but does not start a VM with enabled dynamic memory because a MinimumMemory value is specified' { + Set-TargetResource -Name 'NewVM' @testParams -MinimumMemory 512MB + Assert-MockCalled -CommandName New-VM -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-VM -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-VMMemory -Exactly -Times 0 -Scope It + Assert-MockCalled -CommandName Set-VMState -Exactly -Times 0 -Scope It + } + + It 'Creates but does not start a VM with enabled dynamic memory because a MaximumMemory value is specified' { + Set-TargetResource -Name 'NewVM' @testParams -MaximumMemory 16GB + Assert-MockCalled -CommandName New-VM -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-VM -Exactly -Times 1 -Scope It + Assert-MockCalled -CommandName Set-VMMemory -Exactly -Times 0 -Scope It + Assert-MockCalled -CommandName Set-VMState -Exactly -Times 0 -Scope It + } + + It 'Does not change VM state when VM "State" = "Running" and requested "State" = "Running"' { + Set-TargetResource -Name 'RunningVM' -State Running @testParams + Assert-MockCalled -CommandName Set-VMState -Exactly -Times 0 -Scope It + } + + It 'Does not change VM state when VM "State" = "Off" and requested "State" = "Off"' { + Set-TargetResource -Name 'StoppedVM' -State Off @testParams + Assert-MockCalled -CommandName Set-VMState -Exactly -Times 0 -Scope It + } + + It 'Changes VM state when existing VM "State" = "Off" and requested "State" = "Running"' { + Set-TargetResource -Name 'StoppedVM' -State Running @testParams + Assert-MockCalled -CommandName Set-VMState -Exactly -Times 1 -Scope It + } + + It 'Changes VM state when existing VM "State" = "Running" and requested "State" = "Off"' { + Set-TargetResource -Name 'RunningVM' -State Off @testParams + Assert-MockCalled -CommandName Set-VMState -Exactly -Times 1 -Scope It + } + + It 'Creates a generation 1 VM by default/when not explicitly specified' { + Set-TargetResource -Name 'NewVM' @testParams + Assert-MockCalled -CommandName New-VM -ParameterFilter { $Generation -eq 1 } -Scope It + } + + It 'Creates a generation 1 VM when explicitly specified' { + Set-TargetResource -Name 'NewVM' -Generation 1 @testParams + Assert-MockCalled -CommandName New-VM -ParameterFilter { $Generation -eq 1 } -Scope It + } + + It 'Creates a generation 2 VM when explicitly specified' { + Set-TargetResource -Name 'NewVM' -Generation 2 @testParams + Assert-MockCalled -CommandName New-VM -ParameterFilter { $Generation -eq 2 } -Scope It + } + + It 'Calls "Add-VMNetworkAdapter" for each NIC when creating a new VM' { + Mock -CommandName Add-VMNetworkAdapter + Set-TargetResource -Name 'NewVM' @testParams -SwitchName 'Switch1', 'Switch2' + # The first NIC is assigned during the VM creation + Assert-MockCalled -CommandName Add-VMNetworkAdapter -Exactly 1 -Scope It + } + + It 'Calls "Connect-VMNetworkAdapter" for each existing NIC when updating an existing VM' { + Mock -CommandName Connect-VMNetworkAdapter + Set-TargetResource -Name 'StoppedVM' @testParams -SwitchName 'Switch1', 'Switch2' + # The first NIC is assigned during the VM creation + Assert-MockCalled -CommandName Connect-VMNetworkAdapter -Exactly 2 -Scope It + } + + It 'Calls "Add-VMNetworkAdapter" for each missing NIC when updating an existing VM' { + Mock -CommandName Connect-VMNetworkAdapter + Mock -CommandName Add-VMNetworkAdapter + Set-TargetResource -Name 'StoppedVM' @testParams -SwitchName 'Switch1', 'Switch2', 'Switch3' + # The first NIC is assigned during the VM creation + Assert-MockCalled -CommandName Connect-VMNetworkAdapter -Exactly 2 -Scope It + Assert-MockCalled -CommandName Add-VMNetworkAdapter -Exactly 1 -Scope It + } + + It 'Does not change switch assignments if no switch assignments are specified' { + Mock -CommandName Connect-VMNetworkAdapter + Set-TargetResource -Name 'StoppedVM' @testParams + Assert-MockCalled -CommandName Connect-VMNetworkAdapter -Exactly 0 -Scope It + } + + It 'Does not change NIC assignments if the switch assisgnments are correct' { + Mock -CommandName Set-VMNetworkAdapter + Set-TargetResource -Name 'StoppedVM' @testParams -SwitchName $stubNIC1.SwitchName, $stubNIC2.SwitchName + Assert-MockCalled -CommandName Set-VMNetworkAdapter -Exactly 0 -Scope It + } + + It 'Errors when updating MAC addresses on a running VM and "RestartIfNeeded" = "$false"' { + { Set-TargetResource -Name 'RunningVM' @testParams -MACAddress 'AABBCCDDEEFE', 'AABBCCDDEEFF' -ErrorAction Stop } | Should -Throw + } + + It 'Does not change MAC addresses if no MAC addresses assignments are specified' { + Mock -CommandName Set-VMNetworkAdapter -ParameterFilter { $StaticMacAddress -ne $null } + Set-TargetResource -Name 'StoppedVM' @testParams + Assert-MockCalled -CommandName Set-VMNetworkAdapter -ParameterFilter { $StaticMacAddress -ne $null } -Exactly 0 -Scope It + } + + It 'Calls "Set-VMNetworkAdapter" for each MAC address on a stopped VM' { + Mock -CommandName Set-VMNetworkAdapter + Set-TargetResource -Name 'StoppedVM' @testParams -MACAddress 'AABBCCDDEEFE', 'AABBCCDDEEFF' + # The first NIC is assigned during the VM creation + Assert-MockCalled -CommandName Set-VMNetworkAdapter -Exactly 2 -Scope It + } + + It 'Does not change Secure Boot call "Set-VMProperty" when creating a generation 1 VM' { + Mock -CommandName Set-VMProperty + Set-TargetResource -Name 'RunningVM' @testParams + Assert-MockCalled -CommandName Set-VMProperty -ParameterFilter { $VMCommand -eq 'Set-VMFirmware' } -Exactly 0 -Scope It + } + + It 'Does call "Set-VMProperty" when creating a generation 2 VM' { + Mock -CommandName Test-VMSecureBoot -MockWith { return $true } + Mock -CommandName Set-VMProperty + Set-TargetResource -Name 'RunningVM' -Generation 2 -SecureBoot $false @testParams + Assert-MockCalled -CommandName Set-VMProperty -ParameterFilter { $VMCommand -eq 'Set-VMFirmware' } -Exactly 1 -Scope It + } + + It 'Does not change Secure Boot for generation 1 VM' { + Mock -CommandName Test-VMSecureBoot -MockWith { return $true } + Mock -CommandName Set-VMProperty + Set-TargetResource -Name 'StoppedVM' -SecureBoot $true @testParams + Set-TargetResource -Name 'StoppedVM' -SecureBoot $false @testParams + Assert-MockCalled -CommandName Set-VMProperty -ParameterFilter { $VMCommand -eq 'Set-VMFirmware' } -Exactly 0 -Scope It + } + + It 'Does not change Secure Boot for generation 2 VM with VM "SecureBoot" match' { + Mock -CommandName Test-VMSecureBoot -MockWith { return $true } + Mock -CommandName Set-VMProperty + Set-TargetResource -Name 'StoppedVM' -SecureBoot $true -Generation 2 @testParams + Assert-MockCalled -CommandName Set-VMProperty -ParameterFilter { $VMCommand -eq 'Set-VMFirmware' } -Exactly 0 -Scope It + } + + It 'Does change Secure Boot for generation 2 VM with VM "SecureBoot" mismatch' { + Mock -CommandName Test-VMSecureBoot -MockWith { return $false } + Mock -CommandName Set-VMProperty + Set-TargetResource -Name 'StoppedVM' -SecureBoot $true -Generation 2 @testParams + Assert-MockCalled -CommandName Set-VMProperty -ParameterFilter { $VMCommand -eq 'Set-VMFirmware' } -Exactly 1 -Scope It + } + + It 'Does call "Enable-VMIntegrationService" when "EnableGuestService" = "$true"' { + Mock -CommandName Enable-VMIntegrationService + Set-TargetResource -Name 'RunningVM' -EnableGuestService $true @testParams + Assert-MockCalled -CommandName Enable-VMIntegrationService -Exactly -Times 1 -Scope It + } + + It 'Does call "Disable-VMIntegrationService" when "Guest Service Interface" = "Enabled" and "EnableGuestService" = "$false" specified' { + Mock -CommandName Disable-VMIntegrationService + Mock -CommandName Get-VMIntegrationService -MockWith { + $guestServiceInterface = [Microsoft.HyperV.PowerShell.VMIntegrationComponent]::CreateTypeInstance() + $guestServiceInterface.Enabled = $true + $guestServiceInterface.Id = $stubGuestServiceInterfaceId + + return $guestServiceInterface + } + + Set-TargetResource -Name 'RunningVM' -EnableGuestService $false @testParams + Assert-MockCalled -CommandName Disable-VMIntegrationService -Exactly -Times 1 -Scope It + } + + Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'Set-VM' -and $Module -eq 'Hyper-V' } -MockWith { + [pscustomobject]@{ + parameters = @{ + # Does not contain parameter AutomaticCheckpointsEnabled + } + } + } + It 'throws when AutomaticCheckpointsEnabled is configured but not supported' { + { Set-TargetResource -Name 'VMAutomaticCheckpointsUnsupported' -AutomaticCheckpointsEnabled $true @testParams } | Should -Throw + } + It 'Does not call "Set-VM" when "AutomaticCheckpointsEnabled" is unsupported and unspecified' { + Set-TargetResource -Name 'VMAutomaticCheckpointsUnsupported' @testParams + Assert-MockCalled -CommandName Set-VM -Exactly -Times 0 -Scope It + } + + Mock -CommandName Get-Command -ParameterFilter { $Name -eq 'Set-VM' -and $Module -eq 'Hyper-V' } -MockWith { + [pscustomobject]@{ + parameters = @{ + 'AutomaticCheckpointsEnabled' = '' + } + } + } + $AutomaticCheckpointsEnabledTestCases = @( + @{ + VMName = 'VMWithAutomaticCheckpoints' + SetAutomaticCheckpointsEnabled = $true + Assert = 'Does not call "Set-VM"' + Times = 0 + }, + @{ + VMName = 'VMWithoutAutomaticCheckpoints' + SetAutomaticCheckpointsEnabled = $false + Assert = 'Does not call "Set-VM"' + Times = 0 + }, + @{ + VMName = 'VMWithAutomaticCheckpoints' + SetAutomaticCheckpointsEnabled = $false + Assert = 'Does call "Set-VM"' + Times = 1 + }, + @{ + VMName = 'VMWithoutAutomaticCheckpoints' + SetAutomaticCheckpointsEnabled = $true + Assert = 'Does call "Set-VM"' + Times = 1 + } + ) + It ' on VM when "AutomaticCheckpointsEnabled" is set to ""' -TestCases $AutomaticCheckpointsEnabledTestCases { + param + ( + $VMName, + $SetAutomaticCheckpointsEnabled, + $Times + ) + + Set-TargetResource -Name $VMName -AutomaticCheckpointsEnabled $SetAutomaticCheckpointsEnabled @testParams + Assert-MockCalled -CommandName Set-VM -ParameterFilter { $Name -eq $VMName -and $AutomaticCheckpointsEnabled -eq $SetAutomaticCheckpointsEnabled } -Exactly -Times $Times -Scope It + } + It 'Disables dynamic memory of RuningVM if only StartupMemory specified' { + Mock -CommandName Set-VMProperty + Set-TargetResource -Name 'RunningVM' -StartupMemory 4GB @testParams + Assert-MockCalled -CommandName Set-VMProperty -ParameterFilter { + $VMCommand -eq 'Set-VM' -and + ($ChangeProperty.StaticMemory -eq $true) -and + ($ChangeProperty.DynamicMemory -eq $false) + } -Exactly -Times 1 -Scope It + } + + It 'Disables dynamic memory of RunningVM if StartupMemory, MinimumMemory and MaximumMemory are specified with the same values' { + Mock -CommandName Set-VMProperty + Set-TargetResource -Name 'RunningVM' -StartupMemory 4GB -MinimumMemory 4GB -MaximumMemory 4GB @testParams + Assert-MockCalled -CommandName Set-VMProperty -ParameterFilter { + $VMCommand -eq 'Set-VM' -and + ($ChangeProperty.StaticMemory -eq $true) -and + ($ChangeProperty.DynamicMemory -eq $false) + } -Exactly -Times 1 -Scope It + } + + It 'Enables dynamic memory of RuningVM if MinimumMemory is specified ' { + Mock -CommandName Set-VMProperty + Set-TargetResource -Name 'RunningVM' -MinimumMemory 4GB @testParams + Assert-MockCalled -CommandName Set-VMProperty -ParameterFilter { + $VMCommand -eq 'Set-VM' -and + ($ChangeProperty.StaticMemory -eq $false) -and + ($ChangeProperty.DynamicMemory -eq $true) + } -Exactly -Times 1 -Scope It + } + + It 'Enables dynamic memory of RuningVM if MaximumMemory is specified ' { + Mock -CommandName Set-VMProperty + Set-TargetResource -Name 'RunningVM' -MaximumMemory 4GB @testParams + Assert-MockCalled -CommandName Set-VMProperty -ParameterFilter { + $VMCommand -eq 'Set-VM' -and + ($ChangeProperty.StaticMemory -eq $false) -and + ($ChangeProperty.DynamicMemory -eq $true) + } -Exactly -Times 1 -Scope It + } + + It 'throws when Hyper-V Tools are not installed' { + Mock -CommandName Get-Module -ParameterFilter { ($Name -eq 'Hyper-V') -and ($ListAvailable -eq $true) } + { Set-TargetResource -Name 'RunningVM' @testParams } | Should -Throw + } + } #end context Validates Set-TargetResource Method + + Context 'Validates Test-VMSecureBoot Method' { + BeforeAll { + Mock -CommandName Get-VM -MockWith { + $stubVM = [Microsoft.HyperV.PowerShell.VirtualMachine]::CreateTypeInstance() + $stubVM.Name = 'NewVM' + $stubVM.Path = $StubVMConfig.FullPath + $stubVM.Generation = $Generation + $stubVM.ID = $mockVmGuid + $stubVM.State = 'Off' + + return $stubVM + } + } + + It 'Returns $true when "SecureBoot" = "On"' { + Mock -CommandName Get-VMFirmware -MockWith { + return [PSCustomObject] @{ + SecureBoot = 'On' + } + } + + Test-VMSecureBoot -Name 'TestVM' | Should -Be $true + } + + It 'Returns $false when "SecureBoot" = "Off"' { + Mock -CommandName Get-VMFirmware -MockWith { + return [PSCustomObject] @{ + SecureBoot = 'Off' + } + } + + Test-VMSecureBoot -Name 'TestVM' | Should -Be $false + } + + } #end context Validates Test-VMSecureBoot Method + + Context 'Validates Get-VhdHierarchy Method' { + It 'Does not throw with null parent path (#52)' { + # Must use a different file extension to ensure existing mocks Get-VhdHierarchy or not called + $fakeVhdPath = 'BaseVhd.avhdx' + + Mock -CommandName Get-VHD -ParameterFilter { $Path -eq $fakeVhdPath } -MockWith { + return [PSCustomObject] @{ + Path = $fakeVhdPath + ParentPath = $null + } + } + + { Get-VhdHierarchy -VhdPath $fakeVhdPath } | Should -Not -throw + } + + } #end context validates Get-VhdHierarchy + } #end describe xVMHyper-V + } #end inmodulescope +} +finally +{ + Invoke-TestCleanup +} diff --git a/Tests/Unit/MSFT_xVMNetworkAdapter.Tests.ps1 b/tests/Unit/MSFT_xVMNetworkAdapter.Tests.ps1 similarity index 55% rename from Tests/Unit/MSFT_xVMNetworkAdapter.Tests.ps1 rename to tests/Unit/MSFT_xVMNetworkAdapter.Tests.ps1 index cd65429..c21cf58 100644 --- a/Tests/Unit/MSFT_xVMNetworkAdapter.Tests.ps1 +++ b/tests/Unit/MSFT_xVMNetworkAdapter.Tests.ps1 @@ -1,57 +1,65 @@ -$Global:DSCModuleName = 'xHyper-V' -$Global:DSCResourceName = 'MSFT_xVMNetworkAdapter' +$script:dscModuleName = 'xHyper-V' +$script:dscResourceName = 'MSFT_xVMNetworkAdapter' -#region HEADER -if ( (-not (Test-Path -Path '.\DSCResource.Tests\')) -or ` - (-not (Test-Path -Path '.\DSCResource.Tests\TestHelper.psm1')) ) +function Invoke-TestSetup { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git') + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import the stub functions. + Import-Module -Name "$PSScriptRoot/Stubs/Hyper-V.stubs.psm1" -Force } -else + +function Invoke-TestCleanup { - & git @('-C',(Join-Path -Path (Get-Location) -ChildPath '\DSCResource.Tests\'),'pull') + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } -Import-Module .\DSCResource.Tests\TestHelper.psm1 -Force -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $Global:DSCModuleName ` - -DSCResourceName $Global:DSCResourceName ` - -TestType Unit -#endregion - -# Begin Testing + +Invoke-TestSetup + try { - #region Pester Tests - InModuleScope $Global:DSCResourceName { - - # Create the Mock Objects that will be used for running tests + InModuleScope $script:dscResourceName { + # Create the Mock -CommandName Objects that will be used for running tests $MockHostAdapter = [PSCustomObject] @{ - Id = 'HostManagement1' - Name = 'Management' - SwitchName = 'HostSwitch' - VMName = 'ManagementOS' + Id = 'HostManagement1' + Name = 'Management' + SwitchName = 'HostSwitch' + VMName = 'ManagementOS' } $propertiesStatic = @{ IpAddress = "192.168.0.1" - Subnet = "255.255.255.0" + Subnet = "255.255.255.0" } $networkSettingsStatic = New-CimInstance -ClassName xNetworkSettings -Property $properties -Namespace root/microsoft/windows/desiredstateconfiguration -ClientOnly $TestAdapter = [PSObject]@{ - Id = $MockHostAdapter.Id - Name = $MockHostAdapter.Name - SwitchName = $MockHostAdapter.SwitchName - VMName = $MockHostAdapter.VMName + Id = $MockHostAdapter.Id + Name = $MockHostAdapter.Name + SwitchName = $MockHostAdapter.SwitchName + VMName = $MockHostAdapter.VMName } - $MockAdapter = [PSObject]@{ - Name = $TestAdapter.Name - SwitchName = $MockHostAdapter.SwitchName - IsManagementOs = $True - MacAddress = '14FEB5C6CE98' - } + $MockAdapter = [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase]::CreateTypeInstance() + $MockAdapter.Name = $MockHostAdapter.Name + $MockAdapter.SwitchName = $MockHostAdapter.SwitchName + $MockAdapter.VMName = $MockHostAdapter.VMName + $MockAdapter.IsManagementOs = $true + $MockAdapter.MacAddress = '14FEB5C6CE98' $MockAdapterVlanUntagged = [PSObject]@{ OperationMode = 'Untagged' @@ -59,24 +67,17 @@ try $MockAdapterVlanTagged = [PSObject]@{ OperationMode = 'Access' - AccessVlanId = '1' + AccessVlanId = '1' } - Describe "$($Global:DSCResourceName)\Get-TargetResource" { - #Function placeholders - function Get-VMNetworkAdapter { } - function Set-VMNetworkAdapter { } - function Remove-VMNetworkAdapter { } - function Get-VMNetworkAdapterVlan { } - function Add-VMNetworkAdapter { } - function Get-NetworkInformation { } + Describe 'MSFT_xVMNetworkAdapter\Get-TargetResource' { Context 'NetAdapter does not exist' { - Mock Get-VMNetworkAdapter - Mock Get-VMNetworkAdapterVlan + Mock -CommandName Get-VMNetworkAdapter + Mock -CommandName Get-VMNetworkAdapterVlan It 'should return ensure as absent' { $Result = Get-TargetResource ` @TestAdapter - $Result.Ensure | Should Be 'Absent' + $Result.Ensure | Should -Be 'Absent' } It 'should call the expected mocks' { Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 @@ -84,31 +85,32 @@ try } } - Context 'NetAdapter exists' { + Context 'NetAdapter with untagged VLAN exists' { Mock -CommandName Get-VMNetworkAdapter -MockWith { $MockAdapter } + Mock -CommandName Get-VMNetworkAdapterVlan -MockWith { $MockAdapterVlanUntagged } Mock -CommandName Get-NetworkInformation -MockWith { return @{ - IpAddress = '10.10.10.10' - Subnet = '255.255.255.0' + IpAddress = '10.10.10.10' + Subnet = '255.255.255.0' DefaultGateway = '10.10.10.1' - DnsServer = '10.10.10.1' + DnsServer = '10.10.10.1' } } It 'should return adapter properties' { $Result = Get-TargetResource @TestAdapter - $Result.Ensure | Should Be 'Present' - $Result.Name | Should Be $TestAdapter.Name - $Result.SwitchName | Should Be $TestAdapter.SwitchName - $Result.VMName | Should Be 'ManagementOS' - $Result.Id | Should Be $TestAdapter.Id - $Result.VlanId | Should -BeNullOrEmpty - $Result.NetworkSetting | Should -Not -BeNullOrEmpty + $Result.Ensure | Should -Be 'Present' + $Result.Name | Should -Be $TestAdapter.Name + $Result.SwitchName | Should -Be $TestAdapter.SwitchName + $Result.VMName | Should -Be 'ManagementOS' + $Result.Id | Should -Be $TestAdapter.Id + $Result.VlanId | Should -BeNullOrEmpty + $Result.NetworkSetting | Should -Not -BeNullOrEmpty } It 'should call the expected mocks' { Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 @@ -116,22 +118,32 @@ try } } - Context 'NetAdapter exists' { + Context 'NetAdapter with tagged VLAN exists' { Mock -CommandName Get-VMNetworkAdapter -MockWith { $MockAdapter } + Mock -CommandName Get-VMNetworkAdapterVlan -MockWith { $MockAdapterVlanTagged } + Mock -CommandName Get-NetworkInformation -MockWith { + return @{ + IpAddress = '10.10.10.10' + Subnet = '255.255.255.0' + DefaultGateway = '10.10.10.1' + DnsServer = '10.10.10.1' + } + } + It 'should return adapter properties' { $Result = Get-TargetResource @TestAdapter - $Result.Ensure | Should Be 'Present' - $Result.Name | Should Be $TestAdapter.Name - $Result.SwitchName | Should Be $TestAdapter.SwitchName - $Result.VMName | Should Be 'ManagementOS' - $Result.Id | Should Be $TestAdapter.Id - $Result.VlanId | Should Be '1' + $Result.Ensure | Should -Be 'Present' + $Result.Name | Should -Be $TestAdapter.Name + $Result.SwitchName | Should -Be $TestAdapter.SwitchName + $Result.VMName | Should -Be 'ManagementOS' + $Result.Id | Should -Be $TestAdapter.Id + $Result.VlanId | Should -Be '1' } It 'should call the expected mocks' { Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 @@ -140,61 +152,55 @@ try } } - Describe "$($Global:DSCResourceName)\Set-TargetResource" { - #Function placeholders - function Get-VMNetworkAdapter { } - function Get-VMNetworkAdapterVlan { } - function Set-VMNetworkAdapter { } - function Set-VMNetworkAdapterVlan { } - function Remove-VMNetworkAdapter { } - function Add-VMNetworkAdapter { } - function Get-NetworkInformation { } - function Set-NetworkInformation { } - + Describe 'MSFT_xVMNetworkAdapter\Set-TargetResource' { $newAdapter = [PSObject]@{ - Id = 'UniqueString' - Name = $TestAdapter.Name - SwitchName = $TestAdapter.SwitchName - VMName = 'VMName' - NetworkSetting = $networkSettingsStatic - Ensure = 'Present' + Id = 'UniqueString' + Name = $TestAdapter.Name + SwitchName = $TestAdapter.SwitchName + VMName = 'VMName' + NetworkSetting = $networkSettingsStatic + Ensure = 'Present' } Context 'Adapter does not exist but should' { - - Mock Get-VMNetworkAdapter - Mock Get-VMNetworkAdapterVlan - Mock Add-VMNetworkAdapter - Mock Remove-VMNetworkAdapter - Mock Set-VMNetworkAdapterVlan - Mock Set-NetworkInformation + Mock -CommandName Get-VMNetworkAdapter + Mock -CommandName Get-VMNetworkAdapterVlan + Mock -CommandName Add-VMNetworkAdapter -MockWith { + $MockAdapter + } + Mock -CommandName Remove-VMNetworkAdapter + Mock -CommandName Set-VMNetworkAdapterVlan + Mock -CommandName Get-NetworkInformation + Mock -CommandName Set-NetworkInformation It 'should not throw error' { { Set-TargetResource @newAdapter - } | Should Not Throw + } | Should -Not -throw } + It 'should call expected Mocks' { Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 Assert-MockCalled -CommandName Set-VMNetworkAdapterVlan -Exactly 0 Assert-MockCalled -commandName Add-VMNetworkAdapter -Exactly 1 Assert-MockCalled -commandName Remove-VMNetworkAdapter -Exactly 0 + Assert-MockCalled -CommandName Get-NetworkInformation -Exactly 1 Assert-MockCalled -CommandName Set-NetworkInformation -Exactly 1 } } Context 'Adapter exists but should not exist' { - Mock Get-VMNetworkAdapter - Mock Add-VMNetworkAdapter - Mock Remove-VMNetworkAdapter - Mock Set-VMNetworkAdapterVlan + Mock -CommandName Get-VMNetworkAdapter + Mock -CommandName Add-VMNetworkAdapter + Mock -CommandName Remove-VMNetworkAdapter + Mock -CommandName Set-VMNetworkAdapterVlan It 'should not throw error' { { $updateAdapter = $newAdapter.Clone() $updateAdapter.Ensure = 'Absent' Set-TargetResource @updateAdapter - } | Should Not Throw + } | Should -Not -throw } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 @@ -205,29 +211,21 @@ try } } - Describe "$($Global:DSCResourceName)\Test-TargetResource" { - #Function placeholders - function Get-VMNetworkAdapter { } - function Get-VMNetworkAdapterVlan { } - function Set-VMNetworkAdapter { } - function Remove-VMNetworkAdapter { } - function Add-VMNetworkAdapter { } - function Get-NetworkInformation { } - + Describe 'MSFT_xVMNetworkAdapter\Test-TargetResource' { $newAdapter = [PSObject]@{ - Id = 'UniqueString' - Name = $TestAdapter.Name - SwitchName = $TestAdapter.SwitchName - VMName = 'ManagementOS' - Ensure = 'Present' + Id = 'UniqueString' + Name = $TestAdapter.Name + SwitchName = $TestAdapter.SwitchName + VMName = 'ManagementOS' + Ensure = 'Present' } Context 'Adapter does not exist but should' { - Mock Get-VMNetworkAdapter - Mock Get-VMNetworkAdapterVlan + Mock -CommandName Get-VMNetworkAdapter + Mock -CommandName Get-VMNetworkAdapterVlan It 'should return false' { - Test-TargetResource @newAdapter | Should be $false + Test-TargetResource @newAdapter | Should -Be $false } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 @@ -235,12 +233,12 @@ try } Context 'Adapter exists but should not exist' { - Mock Get-VMNetworkAdapter -MockWith { $MockAdapter } + Mock -CommandName Get-VMNetworkAdapter -MockWith { $MockAdapter } It 'should return $false' { $updateAdapter = $newAdapter.Clone() $updateAdapter.Ensure = 'Absent' - Test-TargetResource @updateAdapter | Should Be $false + Test-TargetResource @updateAdapter | Should -Be $false } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 @@ -248,11 +246,11 @@ try } Context 'Adapter exists and no action needed without Vlan tag' { - Mock Get-VMNetworkAdapter -MockWith { $MockAdapter } + Mock -CommandName Get-VMNetworkAdapter -MockWith { $MockAdapter } It 'should return true' { $updateAdapter = $newAdapter.Clone() - Test-TargetResource @updateAdapter | Should Be $true + Test-TargetResource @updateAdapter | Should -Be $true } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 @@ -260,16 +258,16 @@ try } Context 'Adapter exists and no action needed with Vlan tag' { - Mock Get-VMNetworkAdapter -MockWith { $MockAdapter } - Mock Get-VMNetworkAdapterVlan -MockWith { $MockAdapterVlanTagged } + Mock -CommandName Get-VMNetworkAdapter -MockWith { $MockAdapter } + Mock -CommandName Get-VMNetworkAdapterVlan -MockWith { $MockAdapterVlanTagged } Mock -CommandName Get-NetworkInformation It 'should return true' { $updateAdapter = $newAdapter.Clone() - $updateAdapter.VMName = "VMName" + $updateAdapter.VMName = "VMName" $updateAdapter.MacAddress = '14FEB5C6CE98' - $updateAdapter.VlanId = '1' - Test-TargetResource @updateAdapter | Should Be $true + $updateAdapter.VlanId = '1' + Test-TargetResource @updateAdapter | Should -Be $true } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 @@ -278,16 +276,16 @@ try } Context 'Adapter exists but Vlan is not tagged' { - Mock Get-VMNetworkAdapter -MockWith { $MockAdapter } - Mock Get-VMNetworkAdapterVlan + Mock -CommandName Get-VMNetworkAdapter -MockWith { $MockAdapter } + Mock -CommandName Get-VMNetworkAdapterVlan Mock -CommandName Get-NetworkInformation It 'should return false' { $updateAdapter = $newAdapter.Clone() - $updateAdapter.VMName = "VMName" + $updateAdapter.VMName = "VMName" $updateAdapter.MacAddress = '14FEB5C6CE98' $updateAdapter.VlanId = '1' - Test-TargetResource @updateAdapter | Should Be $false + Test-TargetResource @updateAdapter | Should -Be $false } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 @@ -296,16 +294,16 @@ try } Context 'Adapter exists but Vlan tag is wrong' { - Mock Get-VMNetworkAdapter -MockWith { $MockAdapter } - Mock Get-VMNetworkAdapterVlan -MockWith { $MockAdapterVlanTagged } + Mock -CommandName Get-VMNetworkAdapter -MockWith { $MockAdapter } + Mock -CommandName Get-VMNetworkAdapterVlan -MockWith { $MockAdapterVlanTagged } Mock -CommandName Get-NetworkInformation It 'should return false' { $updateAdapter = $newAdapter.Clone() - $updateAdapter.VMName = "VMName" + $updateAdapter.VMName = "VMName" $updateAdapter.MacAddress = '14FEB5C6CE98' $updateAdapter.VlanId = '2' - Test-TargetResource @updateAdapter | Should Be $false + Test-TargetResource @updateAdapter | Should -Be $false } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 @@ -314,12 +312,12 @@ try } Context 'Adapter does not exist and no action needed' { - Mock Get-VMNetworkAdapter + Mock -CommandName Get-VMNetworkAdapter It 'should return true' { $updateAdapter = $newAdapter.Clone() $updateAdapter.Ensure = 'Absent' - Test-TargetResource @updateAdapter | Should Be $true + Test-TargetResource @updateAdapter | Should -Be $true } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 @@ -327,17 +325,17 @@ try } Context 'Adapter exists but network settings are not correct' { - Mock Get-VMNetworkAdapter -MockWith { $MockAdapter } - Mock Get-VMNetworkAdapterVlan -MockWith { $MockAdapterVlanTagged } + Mock -CommandName Get-VMNetworkAdapter -MockWith { $MockAdapter } + Mock -CommandName Get-VMNetworkAdapterVlan -MockWith { $MockAdapterVlanTagged } Mock -CommandName Get-NetworkInformation -MockWith { @{ Dhcp = $false } } It 'should return false' { $updateAdapter = $newAdapter.Clone() - $updateAdapter.VMName = "VMName" + $updateAdapter.VMName = "VMName" $updateAdapter.MacAddress = '14FEB5C6CE98' - Test-TargetResource @updateAdapter | Should Be $false + Test-TargetResource @updateAdapter | Should -Be $false } It 'should call expected Mocks' { Assert-MockCalled -commandName Get-VMNetworkAdapter -Exactly 1 @@ -351,7 +349,5 @@ try } finally { - #region FOOTER - Restore-TestEnvironment -TestEnvironment $TestEnvironment - #endregion + Invoke-TestCleanup } diff --git a/Tests/Unit/MSFT_xVMProcessor.Tests.ps1 b/tests/Unit/MSFT_xVMProcessor.Tests.ps1 similarity index 56% rename from Tests/Unit/MSFT_xVMProcessor.Tests.ps1 rename to tests/Unit/MSFT_xVMProcessor.Tests.ps1 index 88b37d7..44834f8 100644 --- a/Tests/Unit/MSFT_xVMProcessor.Tests.ps1 +++ b/tests/Unit/MSFT_xVMProcessor.Tests.ps1 @@ -1,39 +1,37 @@ -$script:DSCModuleName = 'xHyper-V' -$script:DSCResourceName = 'MSFT_xVMProcessor' +$script:dscModuleName = 'xHyper-V' +$script:dscResourceName = 'MSFT_xVMProcessor' -#region HEADER - -# Unit Test Template Version: 1.2.0 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +function Invoke-TestSetup { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import the stub functions. + Import-Module -Name "$PSScriptRoot/Stubs/Hyper-V.stubs.psm1" -Force } -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceName ` - -TestType Unit - -#endregion HEADER - -function Invoke-TestSetup { - +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } -function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment -} +Invoke-TestSetup -# Begin Testing try { - Invoke-TestSetup - - InModuleScope $script:DSCResourceName { + InModuleScope $script:dscResourceName { $testVMName = 'UnitTestVM' $testResourcePoolName = 'Unit Test Resource Pool' @@ -45,67 +43,37 @@ try } # Guard mocks - Mock Assert-Module { } - - function Get-VMProcessor { - [CmdletBinding()] - param - ( - [System.String] - $VMName - ) - } + Mock -CommandName Assert-Module It 'Should return a [System.Collections.Hashtable] object type' { - Mock Get-VMProcessor { return $fakeVMProcessor } + Mock -CommandName Get-VMProcessor { return $fakeVMProcessor } $result = Get-TargetResource -VMName $testVMName - $result -is [System.Collections.Hashtable] | Should Be $true + $result -is [System.Collections.Hashtable] | Should -Be $true } It 'Should assert Hyper-V module is installed' { - Mock Assert-Module { } - Mock Get-VMProcessor { return $fakeVMProcessor } + Mock -CommandName Assert-Module + Mock -CommandName Get-VMProcessor { return $fakeVMProcessor } $null = Get-TargetResource -VMName $testVMName - Assert-MockCalled Assert-Module -ParameterFilter { $Name -eq 'Hyper-V' } -Scope It + Assert-MockCalled -CommandName Assert-Module -ParameterFilter { $ModuleName -eq 'Hyper-V' } -Scope It } It 'Should throw when VM processor is not found' { - Mock Get-Module { return $true } - Mock Get-VMProcessor { Write-Error 'Not Found' } - { $null = Get-TargetResource -VMName $testVMName } | Should Throw 'Not Found' + Mock -CommandName Get-Module { return $true } + Mock -CommandName Get-VMProcessor { Write-Error 'Not Found' } + { $null = Get-TargetResource -VMName $testVMName } | Should -Throw 'Not Found' } } # descrive Get-TargetResource Describe 'MSFT_xVMProcessor\Test-TargetResource' { # Guard mocks - Mock Assert-Module { } - Mock Assert-TargetResourceParameter { } - - function Get-VM { - param ( - [System.String] - $Name - ) - } - - function Get-VMProcessor { - param ( - [System.String] - $VMName - ) - } - - function Set-VMProcessor { - param ( - [System.String] - $VMName - ) - } + Mock -CommandName Assert-Module + Mock -CommandName Assert-TargetResourceParameter $fakeTargetResource = @{ VMName = $testVMName @@ -123,27 +91,27 @@ try } It 'Should return a [System.Boolean] object type' { - Mock Get-TargetResource { return $fakeTargetResource } + Mock -CommandName Get-TargetResource { return $fakeTargetResource } $result = Test-TargetResource -VMName $testVMName - $result -is [System.Boolean] | Should Be $true + $result -is [System.Boolean] | Should -Be $true } It 'Should assert Hyper-V module is installed' { - Mock Get-VMProcessor { return $fakeVMProcessor } + Mock -CommandName Get-VMProcessor { return $fakeVMProcessor } $null = Test-TargetResource -VMName $testVMName - Assert-MockCalled Assert-Module -ParameterFilter { $Name -eq 'Hyper-V' } -Scope It + Assert-MockCalled -CommandName Assert-Module -ParameterFilter { $ModuleName -eq 'Hyper-V' } -Scope It } It 'Should assert parameter values are valid' { - Mock Get-VMProcessor { return $fakeVMProcessor } + Mock -CommandName Get-VMProcessor { return $fakeVMProcessor } $null = Test-TargetResource -VMName $testVMName - Assert-MockCalled Assert-TargetResourceParameter -Scope It + Assert-MockCalled -CommandName Assert-TargetResourceParameter -Scope It } $parameterNames = @( @@ -174,7 +142,7 @@ try $result = Test-TargetResource @testTargetResourceParams - $result | Should Be $true + $result | Should -Be $true } if ($parameterValue -is [System.Boolean]) @@ -196,115 +164,98 @@ try It "Should fail when parameter '$parameterName' is incorrect" { $result = Test-TargetResource @testTargetResourceParams - $result | Should Be $false + $result | Should -Be $false } } } # describe Test-TargetResource Describe 'MSFT_xVMProcessor\Set-TargetResource' { - - function Get-VM { - param - ( - [System.String] - $Name - ) - } - - function Get-VMProcessor { - param - ( - [System.String] - $VMName - ) - } - - function Set-VMProcessor { - param - ( - [System.String] - $VMName - ) - } - # Guard mocks - Mock Assert-Module { } - Mock Assert-TargetResourceParameter { } - Mock Get-VM { } - Mock Set-VMProcessor { } - Mock Set-VMProperty { } + Mock -CommandName Assert-Module + Mock -CommandName Assert-TargetResourceParameter + Mock -CommandName Get-VM + Mock -CommandName Set-VMProcessor + Mock -CommandName Set-VMProperty It 'Should assert Hyper-V module is installed' { $null = Set-TargetResource -VMName $testVMName - Assert-MockCalled Assert-Module -ParameterFilter { $Name -eq 'Hyper-V' } -Scope It + Assert-MockCalled -CommandName Assert-Module -ParameterFilter { $ModuleName -eq 'Hyper-V' } -Scope It } It 'Should assert parameter values are valid' { $null = Set-TargetResource -VMName $testVMName - Assert-MockCalled Assert-TargetResourceParameter -Scope It + Assert-MockCalled -CommandName Assert-TargetResourceParameter -Scope It } $restartRequiredParameters = @{ - 'ExposeVirtualizationExtensions' = $false; - 'CompatibilityForMigrationEnabled' = $true; - 'CompatibilityForOlderOperatingSystemsEnabled' = $true; - 'HwThreadCountPerCore' = 2; + 'ExposeVirtualizationExtensions' = $false + 'CompatibilityForMigrationEnabled' = $true + 'CompatibilityForOlderOperatingSystemsEnabled' = $true + 'HwThreadCountPerCore' = 2 'MaximumCountPerNumaNode' = 2 'MaximumCountPerNumaSocket' = 2 - 'ResourcePoolName' = $testResourcePoolName; + 'ResourcePoolName' = $testResourcePoolName } foreach ($parameter in $restartRequiredParameters.GetEnumerator()) { $setTargetResourceParams = @{ - VMName = $testVMName; - $parameter.Name = $parameter.Value; + VMName = $testVMName + $parameter.Name = $parameter.Value } It "Should not throw when VM is off, '$($parameter.Name)' is specified and 'RestartIfNeeded' is False" { - Mock Get-VM { return @{ State = 'Off' } } + Mock -CommandName Get-VM -MockWith { + return @{ + State = 'Off' + } + } - { Set-TargetResource @setTargetResourceParams } | Should Not Throw + { Set-TargetResource @setTargetResourceParams } | Should -Not -throw } It "Should throw when VM is running, '$($parameter.Name)' is specified and 'RestartIfNeeded' is False" { - Mock Get-VM { return @{ State = 'Running' } } + Mock -CommandName Get-VM { return @{ State = 'Running' } } - { Set-TargetResource @setTargetResourceParams } | Should Throw + { Set-TargetResource @setTargetResourceParams } | Should -Throw } It "Should shutdown VM when running, '$($parameter.Name)' is specified and 'RestartIfNeeded' is True" { - Mock Get-VM { return @{ State = 'Running' } } + Mock -CommandName Get-VM { return @{ State = 'Running' } } Set-TargetResource @setTargetResourceParams -RestartIfNeeded $true - Assert-MockCalled Set-VMProperty -Scope It -Exactly 1 + Assert-MockCalled -CommandName Set-VMProperty -Scope It -Exactly 1 } } $noRestartRequiredParameters = @{ - 'EnableHostResourceProtection' = $true; - 'Maximum' = 50; - 'RelativeWeight' = 50; - 'Reserve' = 50; + 'EnableHostResourceProtection' = $true + 'Maximum' = 50 + 'RelativeWeight' = 50 + 'Reserve' = 50 } foreach ($parameter in $noRestartRequiredParameters.GetEnumerator()) { $setTargetResourceParams = @{ - VMName = $testVMName; - $parameter.Name = $parameter.Value; + VMName = $testVMName + $parameter.Name = $parameter.Value } It "Should not shutdown VM running and '$($parameter.Name) is specified" { - Mock Get-VM { return @{ State = 'Running' } } + Mock -CommandName Get-VM -MockWith { + return @{ + State = 'Running' + } + } Set-TargetResource @setTargetResourceParams - Assert-MockCalled Set-VMProcessor -Scope It -Exactly 1 - Assert-MockCalled Set-VMProperty -Scope It -Exactly 0 + Assert-MockCalled -CommandName Set-VMProcessor -Scope It -Exactly 1 + Assert-MockCalled -CommandName Set-VMProperty -Scope It -Exactly 0 } } } # describe Set-TargetResource @@ -312,26 +263,26 @@ try Describe 'MSFT_xVMProcessor\Assert-TargetResourceParameter' { # Return Windows Server 2012 R2/Windows 8.1 Update 1 - Mock Get-CimInstance { return @{ BuildNumber = '9600' } } + Mock -CommandName Get-CimInstance { return @{ BuildNumber = '9600' } } It "Should not throw when parameter 'ResourcePoolName' is specified on 2012 R2 host" { - { Assert-TargetResourceParameter -ResourcePoolName 'TestPool' } | Should Not Throw + { Assert-TargetResourceParameter -ResourcePoolName 'TestPool' } | Should -Not -throw } $server2016OnlyParameters = @{ - EnableHostResourceProtection = $true; - ExposeVirtualizationExtensions = $true; - HwThreadCountPerCore = 1; + EnableHostResourceProtection = $true + ExposeVirtualizationExtensions = $true + HwThreadCountPerCore = 1 } foreach ($parameter in $server2016OnlyParameters.GetEnumerator()) { $assertTargetResourceParameterParams = @{ - $parameter.Name = $parameter.Value; + $parameter.Name = $parameter.Value } It "Should throw when parameter '$($parameter.Name)' is specified on 2012 R2 host" { - { Assert-TargetResourceParameter @assertTargetResourceParameterParams } | Should Throw '14393' + { Assert-TargetResourceParameter @assertTargetResourceParameterParams } | Should -Throw '14393' } } } # describe Assert-TargetResourceParameter diff --git a/Tests/Unit/MSFT_xVMScsiController.Tests.ps1 b/tests/Unit/MSFT_xVMScsiController.Tests.ps1 similarity index 50% rename from Tests/Unit/MSFT_xVMScsiController.Tests.ps1 rename to tests/Unit/MSFT_xVMScsiController.Tests.ps1 index 64f534d..1b8d1e7 100644 --- a/Tests/Unit/MSFT_xVMScsiController.Tests.ps1 +++ b/tests/Unit/MSFT_xVMScsiController.Tests.ps1 @@ -1,39 +1,37 @@ -$script:DSCModuleName = 'xHyper-V' -$script:DSCResourceName = 'MSFT_xVMScsiController' +$script:dscModuleName = 'xHyper-V' +$script:dscResourceName = 'MSFT_xVMScsiController' -#region HEADER - -# Unit Test Template Version: 1.2.0 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +function Invoke-TestSetup { - & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import the stub functions. + Import-Module -Name "$PSScriptRoot/Stubs/Hyper-V.stubs.psm1" -Force } -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceName ` - -TestType Unit - -#endregion HEADER - -function Invoke-TestSetup { - +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } -function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment -} +Invoke-TestSetup -# Begin Testing try { - Invoke-TestSetup - - InModuleScope $script:DSCResourceName { + InModuleScope $script:dscResourceName { $testVMName = 'UnitTestVM' @@ -45,58 +43,46 @@ try } # Guard mocks - Mock Assert-Module { } - - function Get-VMScsiController { - [CmdletBinding()] - param - ( - [System.String] - $VMName, - - [System.Int32] - $ControllerNumber - ) - } + Mock -CommandName Assert-Module It 'Should return a [System.Collections.Hashtable] object type' { - Mock Get-VMScsiController { return $stubScsiController } + Mock -CommandName Get-VMScsiController { return $stubScsiController } $result = Get-TargetResource -VMName $testVMName -ControllerNumber 0 - $result -is [System.Collections.Hashtable] | Should Be $true + $result -is [System.Collections.Hashtable] | Should -Be $true } It 'Should return "Present" when controller is attached' { - Mock Get-VMScsiController { return $stubScsiController } + Mock -CommandName Get-VMScsiController { return $stubScsiController } $result = Get-TargetResource -VMName $testVMName -ControllerNumber 0 - $result.Ensure | Should Be 'Present' + $result.Ensure | Should -Be 'Present' } It 'Should return "Absent" when controller is not attached' { - Mock Get-VMScsiController { } + Mock -CommandName Get-VMScsiController $result = Get-TargetResource -VMName $testVMName -ControllerNumber 0 - $result.Ensure | Should Be 'Absent' + $result.Ensure | Should -Be 'Absent' } It 'Should assert Hyper-V module is installed' { - Mock Assert-Module { } - Mock Get-VMScsiController { } + Mock -CommandName Assert-Module + Mock -CommandName Get-VMScsiController $null = Get-TargetResource -VMName $testVMName -ControllerNumber 0 - Assert-MockCalled Assert-Module -ParameterFilter { $Name -eq 'Hyper-V' } -Scope It + Assert-MockCalled -CommandName Assert-Module -ParameterFilter { $ModuleName -eq 'Hyper-V' } -Scope It } - } # descrive Get-TargetResource + } # describe Get-TargetResource Describe 'MSFT_xVMScsiController\Test-TargetResource' { # Guard mocks - Mock Assert-Module { } + Mock -CommandName Assert-Module $stubTargetResource = @{ VMName = $testVMName @@ -105,7 +91,7 @@ try } It 'Should return a [System.Boolean] object type' { - Mock Get-TargetResource { return $stubTargetResource } + Mock -CommandName Get-TargetResource { return $stubTargetResource } $testTargetResourceParams = @{ VMName = $testVMName ControllerNumber = 0 @@ -113,11 +99,11 @@ try $result = Test-TargetResource @testTargetResourceParams - $result -is [System.Boolean] | Should Be $true + $result -is [System.Boolean] | Should -Be $true } It "Should pass when parameter 'Ensure' is correct" { - Mock Get-TargetResource { return $stubTargetResource } + Mock -CommandName Get-TargetResource { return $stubTargetResource } $testTargetResourceParams = @{ VMName = $testVMName ControllerNumber = 0 @@ -126,11 +112,11 @@ try $result = Test-TargetResource @testTargetResourceParams - $result | Should Be $true + $result | Should -Be $true } It "Should fail when parameter 'Ensure' is incorrect" { - Mock Get-TargetResource { return $stubTargetResource } + Mock -CommandName Get-TargetResource { return $stubTargetResource } $testTargetResourceParams = @{ VMName = $testVMName ControllerNumber = 0 @@ -139,53 +125,21 @@ try $result = Test-TargetResource @testTargetResourceParams - $result | Should Be $false + $result | Should -Be $false } } # describe Test-TargetResource Describe 'MSFT_xVMScsiController\Set-TargetResource' { - - function Get-VMScsiController { - param - ( - [System.String] - $VMName - ) - } - - function Add-VMScsiController { - param - ( - [System.String] - $VMName - ) - } - - function Remove-VMScsiController { - param - ( - [System.String] - $VMName - ) - } - - function Remove-VMHardDiskDrive { - param ( - [System.Object] - $VMHardDiskDrive - ) - } - # Guard mocks - Mock Assert-Module { } - Mock Get-VMScsiController { } - Mock Add-VMScsiController { } - Mock Remove-VMScsiController { } - Mock Remove-VMHardDiskDrive { } - Mock Set-VMState { } + Mock -CommandName Assert-Module + Mock -CommandName Get-VMScsiController + Mock -CommandName Add-VMScsiController + Mock -CommandName Remove-VMScsiController + Mock -CommandName Remove-VMHardDiskDrive + Mock -CommandName Set-VMState It 'Should assert Hyper-V module is installed' { - Mock Get-VMHyperV { return @{ State = 'Running' } } + Mock -CommandName Get-VMHyperV { return @{ State = 'Running' } } $setTargetResourceParams = @{ VMName = $testVMName ControllerNumber = 0 @@ -194,31 +148,31 @@ try $null = Set-TargetResource @setTargetResourceParams - Assert-MockCalled Assert-Module + Assert-MockCalled -CommandName Assert-Module } It 'Should throw if "RestartIfNeeded" is not specified and VM is "Running"' { - Mock Get-VMHyperV { return @{ State = 'Running' } } + Mock -CommandName Get-VMHyperV { return @{ State = 'Running' } } $setTargetResourceParams = @{ VMName = $testVMName ControllerNumber = 0 } - { Set-TargetResource @setTargetResourceParams } | Should Throw 'RestartIfNeeded' + { Set-TargetResource @setTargetResourceParams } | Should -Throw 'RestartIfNeeded' } It 'Should not throw if "RestartIfNeeded" is not specified and VM is "Off"' { - Mock Get-VMHyperV { return @{ State = 'Off' } } + Mock -CommandName Get-VMHyperV { return @{ State = 'Off' } } $setTargetResourceParams = @{ VMName = $testVMName ControllerNumber = 0 } - { Set-TargetResource @setTargetResourceParams } | Should Not Throw + { Set-TargetResource @setTargetResourceParams } | Should -Not -throw } It 'Should call "Set-VMState" to stop running VM' { - Mock Get-VMHyperV { return @{ State = 'Running' } } + Mock -CommandName Get-VMHyperV { return @{ State = 'Running' } } $setTargetResourceParams = @{ VMName = $testVMName ControllerNumber = 0 @@ -227,12 +181,12 @@ try $null = Set-TargetResource @setTargetResourceParams - Assert-MockCalled Set-VMState -ParameterFilter { $State -eq 'Off' } -Scope It + Assert-MockCalled -CommandName Set-VMState -ParameterFilter { $State -eq 'Off' } -Scope It } It 'Should call "Set-VMState" to restore VM to its previous state' { $testVMState = 'Paused' - Mock Get-VMHyperV { return @{ State = $testVMState } } + Mock -CommandName Get-VMHyperV { return @{ State = $testVMState } } $setTargetResourceParams = @{ VMName = $testVMName ControllerNumber = 0 @@ -241,12 +195,12 @@ try $null = Set-TargetResource @setTargetResourceParams - Assert-MockCalled Set-VMState -ParameterFilter { $State -eq $testVMState } -Scope It + Assert-MockCalled -CommandName Set-VMState -ParameterFilter { $State -eq $testVMState } -Scope It } It 'Should add single controller when it does not exist' { - Mock Get-VMHyperV { return @{ State = 'Running' } } - Mock Get-VMScsiController { } + Mock -CommandName Get-VMHyperV { return @{ State = 'Running' } } + Mock -CommandName Get-VMScsiController $setTargetResourceParams = @{ VMName = $testVMName ControllerNumber = 0 @@ -255,13 +209,13 @@ try $null = Set-TargetResource @setTargetResourceParams - Assert-MockCalled Add-VMScsiController -Scope It -Exactly 1 + Assert-MockCalled -CommandName Add-VMScsiController -Scope It -Exactly 1 } It 'Should add single controller when one already exists' { - Mock Get-VMHyperV { return @{ State = 'Running' } } + Mock -CommandName Get-VMHyperV { return @{ State = 'Running' } } $fakeVMScsiController = [PSCustomObject] @{ ControllerNumber = 0 } - Mock Get-VMScsiController { return $fakeVMScsiController } + Mock -CommandName Get-VMScsiController { return $fakeVMScsiController } $setTargetResourceParams = @{ VMName = $testVMName ControllerNumber = 1 @@ -270,28 +224,55 @@ try $null = Set-TargetResource @setTargetResourceParams - Assert-MockCalled Add-VMScsiController -Scope It -Exactly 1 + Assert-MockCalled -CommandName Add-VMScsiController -Scope It -Exactly 1 } It 'Should throw when adding controller when intermediate controller(s) do not exist' { - Mock Get-VMHyperV { return @{ State = 'Running' } } - Mock Get-VMScsiController { } + Mock -CommandName Get-VMHyperV { return @{ State = 'Running' } } + Mock -CommandName Get-VMScsiController $setTargetResourceParams = @{ VMName = $testVMName ControllerNumber = 1 RestartIfNeeded = $true } - { Set-TargetResource @setTargetResourceParams } | Should Throw 'Cannot add controller' + { Set-TargetResource @setTargetResourceParams } | Should -Throw 'Cannot add controller' } It 'Should remove controller when Ensure = "Absent"' { - Mock Get-VMHyperV { return @{ State = 'Running' } } - $fakeVMScsiControllers = @( - [PSCustomObject] @{ ControllerNumber = 0 } - [PSCustomObject] @{ ControllerNumber = 1 } + Mock -CommandName Get-VMHyperV { + return @{ + State = 'Running' + } + } + + $stubHardDiskDrive = [Microsoft.HyperV.PowerShell.HardDiskDrive]::CreateTypeInstance() + $stubHardDiskDrive.CimSession = New-MockObject -Type CimSession + $stubHardDiskDrive.Path = 'TestDrive:\disk1.vhdx' + $stubHardDiskDrive.ControllerLocation = 0 + $stubHardDiskDrive.ControllerNumber = 0 + $stubHardDiskDrive.ControllerType = 'SCSI' + + $mockVMScsiController = [Microsoft.HyperV.PowerShell.VMScsiController]::CreateTypeInstance() + $mockVMScsiController.Drives = @( + $stubHardDiskDrive ) - Mock Get-VMScsiController { return $fakeVMScsiControllers } + + # Mock getting all the available controllers + Mock -CommandName Get-VMScsiController -MockWith { + return @( + 'mockController1' + 'mockController2' + ) + } + + # Mock getting the specific controller with ControllerNumber -eq 1 + Mock -CommandName Get-VMScsiController -MockWith { + return $mockVMScsiController + } -ParameterFilter { + $ControllerNumber -eq 1 + } + $setTargetResourceParams = @{ VMName = $testVMName ControllerNumber = 1 @@ -301,19 +282,36 @@ try $null = Set-TargetResource @setTargetResourceParams -WarningAction SilentlyContinue - Assert-MockCalled Remove-VMScsiController -Scope It + Assert-MockCalled -CommandName Remove-VMScsiController -Scope It } It 'Should remove all attached disks when Ensure = "Absent"' { - Mock Get-VMHyperV { return @{ State = 'Running' } } - $fakeVMScsiController = [PSCustomObject] @{ - ControllerNumber = 0 - Drives = @( - [PSCustomObject] @{ Name = 'Hard Drive on SCSI controller number 0 at location 0' } - [PSCustomObject] @{ Name = 'Hard Drive on SCSI controller number 0 at location 1' } - ) - } - Mock Get-VMScsiController { return $fakeVMScsiController } + Mock -CommandName Get-VMHyperV { return @{ State = 'Running' } } + + $stubHardDiskDrive1 = [Microsoft.HyperV.PowerShell.HardDiskDrive]::CreateTypeInstance() + $stubHardDiskDrive1.CimSession = New-MockObject -Type CimSession + $stubHardDiskDrive1.Name = 'Hard Drive on SCSI controller number 0 at location 0' + $stubHardDiskDrive1.Path = 'TestDrive:\disk1.vhdx' + $stubHardDiskDrive1.ControllerLocation = 0 + $stubHardDiskDrive1.ControllerNumber = 0 + $stubHardDiskDrive1.ControllerType = 'SCSI' + + $stubHardDiskDrive2 = [Microsoft.HyperV.PowerShell.HardDiskDrive]::CreateTypeInstance() + $stubHardDiskDrive2.CimSession = New-MockObject -Type CimSession + $stubHardDiskDrive2.Name = 'Hard Drive on SCSI controller number 0 at location 1' + $stubHardDiskDrive2.Path = 'TestDrive:\disk2.vhdx' + $stubHardDiskDrive2.ControllerLocation = 0 + $stubHardDiskDrive2.ControllerNumber = 0 + $stubHardDiskDrive2.ControllerType = 'SCSI' + + $mockVMScsiController = [Microsoft.HyperV.PowerShell.VMScsiController]::CreateTypeInstance() + $mockVMScsiController.Drives = @( + $stubHardDiskDrive1 + $stubHardDiskDrive2 + ) + + Mock -CommandName Get-VMScsiController { return $mockVMScsiController } + $setTargetResourceParams = @{ VMName = $testVMName ControllerNumber = 0 @@ -323,16 +321,16 @@ try $null = Set-TargetResource @setTargetResourceParams -WarningAction SilentlyContinue - Assert-MockCalled Remove-VMHardDiskDrive -Scope It -Exactly ($fakeVMScsiController.Drives.Count) + Assert-MockCalled -CommandName Remove-VMHardDiskDrive -Scope It -Exactly ($mockVMScsiController.Drives.Count) } It 'Should throw removing a controller when additional/subsequent controller(s) exist' { - Mock Get-VMHyperV { return @{ State = 'Running' } } + Mock -CommandName Get-VMHyperV { return @{ State = 'Running' } } $fakeVMScsiControllers = @( [PSCustomObject] @{ ControllerNumber = 0 } [PSCustomObject] @{ ControllerNumber = 1 } ) - Mock Get-VMScsiController { return $fakeVMScsiControllers } + Mock -CommandName Get-VMScsiController { return $fakeVMScsiControllers } $setTargetResourceParams = @{ VMName = $testVMName ControllerNumber = 0 @@ -340,7 +338,7 @@ try Ensure = 'Absent' } - { Set-TargetResource @setTargetResourceParams } | Should Throw 'Cannot remove controller' + { Set-TargetResource @setTargetResourceParams } | Should -Throw 'Cannot remove controller' } } # describe Set-TargetResource diff --git a/Tests/Unit/MSFT_xVMSwitch_BandwidthReservationMode.Tests.ps1 b/tests/Unit/MSFT_xVMSwitch_BandwidthReservationMode.Tests.ps1 similarity index 68% rename from Tests/Unit/MSFT_xVMSwitch_BandwidthReservationMode.Tests.ps1 rename to tests/Unit/MSFT_xVMSwitch_BandwidthReservationMode.Tests.ps1 index eb29268..0e2921d 100644 --- a/Tests/Unit/MSFT_xVMSwitch_BandwidthReservationMode.Tests.ps1 +++ b/tests/Unit/MSFT_xVMSwitch_BandwidthReservationMode.Tests.ps1 @@ -1,38 +1,37 @@ -#region HEADER - -# Unit Test Template Version: 1.2.0 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'xHyper-V' ` - -DSCResourceName 'MSFT_xVMSwitch' ` - -TestType Unit - -#endregion HEADER +$script:dscModuleName = 'xHyper-V' +$script:dscResourceName = 'MSFT_xVMSwitch' function Invoke-TestSetup { + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + # Import the stub functions. + Import-Module -Name "$PSScriptRoot/Stubs/Hyper-V.stubs.psm1" -Force } function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } -# Begin Testing +Invoke-TestSetup + try { - Invoke-TestSetup - - InModuleScope 'MSFT_xVMSwitch' { + InModuleScope $script:dscResourceName { <# Defines a variable that contains all the possible Bandwidth Reservation Modes which will be used @@ -40,88 +39,57 @@ try #> New-Variable -Name 'BANDWIDTH_RESERVATION_MODES' -Option 'Constant' -Value @('Default', 'Weight', 'Absolute', 'None') - # Function to create a exception object for testing output exceptions - function Get-InvalidArgumentError + # A helper function to mock a VMSwitch + function New-MockedVMSwitch { - [CmdletBinding()] param ( [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] [System.String] - $ErrorId, - - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $ErrorMessage - ) - - $exception = New-Object -TypeName System.ArgumentException ` - -ArgumentList $ErrorMessage - $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument - $errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord ` - -ArgumentList $exception, $ErrorId, $errorCategory, $null - return $errorRecord - } # end function Get-InvalidArgumentError - - # A helper function to mock a VMSwitch - function New-MockedVMSwitch - { - Param ( - [Parameter(Mandatory = $true)] - [string] $Name, [Parameter(Mandatory = $true)] [ValidateSet('Default', 'Weight', 'Absolute', 'None', 'NA')] - [string] + [System.String] $BandwidthReservationMode, [Parameter()] - [bool] + [System.Boolean] $AllowManagementOS = $false ) - $mockedVMSwitch = @{ - Name = $Name - SwitchType = 'External' - AllowManagementOS = $AllowManagementOS - NetAdapterInterfaceDescription = 'Microsoft Network Adapter Multiplexor Driver' - } + $mockedVMSwitch = [Microsoft.HyperV.PowerShell.VMSwitch]::CreateTypeInstance() + $mockedVMSwitch.Name = $Name + $mockedVMSwitch.SwitchType = 'External' + $mockedVMSwitch.AllowManagementOS = $AllowManagementOS + $mockedVMSwitch.NetAdapterInterfaceDescription = 'Microsoft Network Adapter Multiplexor Driver' if ($BandwidthReservationMode -ne 'NA') { - $mockedVMSwitch['BandwidthReservationMode'] = $BandwidthReservationMode + $mockedVMSwitch.BandwidthReservationMode = $BandwidthReservationMode } - return [PsObject]$mockedVMSwitch + return $mockedVMSwitch } Describe 'Validates Get-TargetResource Function' { - # Create an empty function to be able to mock the missing Hyper-V cmdlet - function Get-VMSwitch - { - - } - <# - Mocks Get-VMSwitch and will return $global:mockedVMSwitch which is + Mocks Get-VMSwitch and will return $script:mockedVMSwitch which is a variable that is created during most It statements to mock a VMSwitch #> Mock -CommandName Get-VMSwitch -MockWith { param ( - [string] + [System.String] $ErrorAction ) - if ($ErrorAction -eq 'Stop' -and $global:mockedVMSwitch -eq $null) + if ($ErrorAction -eq 'Stop' -and $script:mockedVMSwitch -eq $null) { throw [System.Management.Automation.ActionPreferenceStopException]'No switch can be found by given criteria.' } - return $global:mockedVMSwitch + return $script:mockedVMSwitch } # Mocks Get-NetAdapter which returns a simplified network adapter @@ -151,22 +119,22 @@ try param ( [Parameter()] - [string] + [System.String] $CurrentName, [Parameter()] - [string] + [System.String] $CurrentBandwidthReservationMode ) # Set the mocked VMSwitch to be returned from Get-VMSwitch based on the input from $getTestCases - $global:mockedVMSwitch = New-MockedVMSwitch -Name $CurrentName -BandwidthReservationMode $CurrentBandwidthReservationMode + $script:mockedVMSwitch = New-MockedVMSwitch -Name $CurrentName -BandwidthReservationMode $CurrentBandwidthReservationMode $targetResource = Get-TargetResource -Name $CurrentName -Type 'External' - $targetResource -is [System.Collections.Hashtable] | Should Be $true - $targetResource['BandwidthReservationMode'] | Should Be $CurrentBandwidthReservationMode + $targetResource -is [System.Collections.Hashtable] | Should -Be $true + $targetResource['BandwidthReservationMode'] | Should -Be $CurrentBandwidthReservationMode - Remove-Variable -Scope 'Global' -Name 'mockedVMSwitch' -ErrorAction 'SilentlyContinue' + Remove-Variable -Scope 'script' -Name 'mockedVMSwitch' -ErrorAction 'SilentlyContinue' } <# @@ -175,13 +143,13 @@ try #> It 'BandwidthReservationMode is set to null' { # Set the mocked VMSwitch to be returned from Get-VMSwitch - $global:mockedVMSwitch = New-MockedVMSwitch -Name 'NaBRM' -BandwidthReservationMode 'NA' + $script:mockedVMSwitch = New-MockedVMSwitch -Name 'NaBRM' -BandwidthReservationMode 'NA' $targetResource = Get-TargetResource -Name 'NaBRM' -Type 'External' - $targetResource -is [System.Collections.Hashtable] | Should Be $true - $targetResource['BandwidthReservationMode'] | Should Be "NA" + $targetResource -is [System.Collections.Hashtable] | Should -Be $true + $targetResource['BandwidthReservationMode'] | Should -Be "Default" - Remove-Variable -Scope 'Global' -Name 'mockedVMSwitch' -ErrorAction 'SilentlyContinue' + Remove-Variable -Scope 'script' -Name 'mockedVMSwitch' -ErrorAction 'SilentlyContinue' } } @@ -224,28 +192,22 @@ try } Describe 'Validates Test-TargetResource Function' { - # Create an empty function to be able to mock the missing Hyper-V cmdlet - function Get-VMSwitch - { - - } - <# - Mocks Get-VMSwitch and will return $global:mockedVMSwitch which is + Mocks Get-VMSwitch and will return $script:mockedVMSwitch which is a variable that is created during most It statements to mock a VMSwitch #> Mock -CommandName Get-VMSwitch -MockWith { param ( - [string] + [System.String] $ErrorAction ) - if ($ErrorAction -eq 'Stop' -and $global:mockedVMSwitch -eq $null) + if ($ErrorAction -eq 'Stop' -and $script:mockedVMSwitch -eq $null) { throw [System.Management.Automation.ActionPreferenceStopException]'No switch can be found by given criteria.' } - return $global:mockedVMSwitch + return $script:mockedVMSwitch } # Mocks Get-NetAdapter which returns a simplified network adapter @@ -280,40 +242,40 @@ try param ( [Parameter()] - [string] + [System.String] $CurrentName, [Parameter()] - [string] + [System.String] $CurrentBandwidthReservationMode, [Parameter()] - [string] + [System.String] $DesiredName, [Parameter()] - [string] + [System.String] $DesiredBandwidthReservationMode, [Parameter()] - [string] + [System.String] $Ensure, [Parameter()] - [bool] + [System.Boolean] $ExpectedResult ) # Set the mocked VMSwitch to be returned from Get-VMSwitch if the switch exists if ($CurrentName) { - $global:mockedVMSwitch = New-MockedVMSwitch -Name $CurrentName -BandwidthReservationMode $CurrentBandwidthReservationMode -AllowManagementOS $true + $script:mockedVMSwitch = New-MockedVMSwitch -Name $CurrentName -BandwidthReservationMode $CurrentBandwidthReservationMode -AllowManagementOS $true } $targetResource = Test-TargetResource -Name $DesiredName -BandwidthReservationMode $DesiredBandwidthReservationMode -Type 'External' -NetAdapterName 'SomeNIC' -Ensure $Ensure -AllowManagementOS $true - $targetResource | Should Be $ExpectedResult + $targetResource | Should -Be $ExpectedResult - Remove-Variable -Scope 'Global' -Name 'mockedVMSwitch' -ErrorAction 'SilentlyContinue' + Remove-Variable -Scope 'script' -Name 'mockedVMSwitch' -ErrorAction 'SilentlyContinue' } Mock -CommandName Get-OSVersion -MockWith { @@ -322,120 +284,91 @@ try # Test Test-TargetResource when the version of Windows doesn't support BandwidthReservationMode It 'Invalid Operating System Exception' { - $errorRecord = Get-InvalidArgumentError ` - -ErrorId 'BandwidthReservationModeError' ` - -ErrorMessage $LocalizedData.BandwidthReservationModeError - {Test-TargetResource -Name 'WeightBRM' -Type 'External' -NetAdapterName 'SomeNIC' -AllowManagementOS $true -BandwidthReservationMode 'Weight' -Ensure 'Present'} | Should Throw $errorRecord - } + $errorMessage = $script:localizedData.BandwidthReservationModeError - # Test Test-TargetResource when the version of Windows doesn't support BandwidthReservationMode and specifies NA for BandwidthReservationMode - It 'Simulates Windows Server 2008 R2 | Desired BandwidthReservationMode set to "NA" | Ensure Present | Expected Result is True' { - $global:mockedVMSwitch = New-MockedVMSwitch -Name 'SomeSwitch' -BandwidthReservationMode 'NA' -AllowManagementOS $true - $targetResource = Test-TargetResource -Name 'SomeSwitch' -BandwidthReservationMode 'NA' -Type 'External' -NetAdapterName 'SomeNIC' -Ensure 'Present' -AllowManagementOS $true - $targetResource | Should Be $true + {Test-TargetResource -Name 'WeightBRM' -Type 'External' -NetAdapterName 'SomeNIC' -AllowManagementOS $true -BandwidthReservationMode 'Weight' -Ensure 'Present'} | Should -Throw $errorMessage } It 'Passes when "BandwidthReservationMode" does not match but is not specified (#48)' { - $global:mockedVMSwitch = New-MockedVMSwitch -Name 'SomeSwitch' -BandwidthReservationMode 'Absolute' + $script:mockedVMSwitch = New-MockedVMSwitch -Name 'SomeSwitch' -BandwidthReservationMode 'Absolute' $targetResource = Test-TargetResource -Name 'SomeSwitch' -Type 'Internal' -Ensure 'Present' - $targetResource | Should Be $true + $targetResource | Should -Be $true } } Describe 'Validates Set-TargetResource Function' { - # Create empty functions to be able to mock the missing Hyper-V cmdlet - function Get-VMSwitch - { - - } - - function New-VMSwitch - { - - } - - function Remove-VMSwitch - { - - } - - function Set-VMSwitch - { - - } - <# - Mocks Get-VMSwitch and will return $global:mockedVMSwitch which is + Mocks Get-VMSwitch and will return $script:mockedVMSwitch which is a variable that is created during most It statements to mock a VMSwitch #> Mock -CommandName Get-VMSwitch -MockWith { param ( - [string] + [System.String] $Name, - [string] + [System.String] $SwitchType, - [string] + [System.String] $ErrorAction ) - if ($ErrorAction -eq 'Stop' -and $global:mockedVMSwitch -eq $null) + if ($ErrorAction -eq 'Stop' -and $script:mockedVMSwitch -eq $null) { throw [System.Management.Automation.ActionPreferenceStopException]'No switch can be found by given criteria.' } - return $global:mockedVMSwitch + return $script:mockedVMSwitch } <# - Mocks New-VMSwitch and will assign a mocked switch to $global:mockedVMSwitch. This returns $global:mockedVMSwitch + Mocks New-VMSwitch and will assign a mocked switch to $script:mockedVMSwitch. This returns $script:mockedVMSwitch which is a variable that is created during most It statements to mock a VMSwitch #> Mock -CommandName New-VMSwitch -MockWith { param ( - [string] + [System.String] $Name, - [string] + [System.String] $NetAdapterName, - [string] + [System.String] $MinimumBandwidthMode, - [bool] + [System.Boolean] $AllowManagementOS ) - $global:mockedVMSwitch = New-MockedVMSwitch -Name $Name -BandwidthReservationMode $MinimumBandwidthMode -AllowManagementOS $AllowManagementOS - return $global:mockedVMSwitch + $script:mockedVMSwitch = New-MockedVMSwitch -Name $Name -BandwidthReservationMode $MinimumBandwidthMode -AllowManagementOS $AllowManagementOS + return $script:mockedVMSwitch } <# - Mocks Set-VMSwitch and will modify $global:mockedVMSwitch which is + Mocks Set-VMSwitch and will modify $script:mockedVMSwitch which is a variable that is created during most It statements to mock a VMSwitch #> Mock -CommandName Set-VMSwitch -MockWith { param ( - [bool] + [System.Boolean] $AllowManagementOS ) if ($AllowManagementOS) { - $global:mockedVMSwitch['AllowManagementOS'] = $AllowManagementOS + $script:mockedVMSwitch['AllowManagementOS'] = $AllowManagementOS } } <# - Mocks Remove-VMSwitch and will remove the variable $global:mockedVMSwitch which is + Mocks Remove-VMSwitch and will remove the variable $script:mockedVMSwitch which is a variable that is created during most It statements to mock a VMSwitch #> Mock -CommandName Remove-VMSwitch -MockWith { - $global:mockedVMSwitch = $null + $script:mockedVMSwitch = $null } # Mocks Get-NetAdapter which returns a simplified network adapter @@ -455,52 +388,50 @@ try return [Version]::Parse('6.3.9600') } - # Create all the test cases for Get-TargetResource - $getTestCases = @() - foreach ($brmMode in $BANDWIDTH_RESERVATION_MODES) - { - $getTestCases += @{ - CurrentName = $brmMode + 'BRM' - CurrentBandwidthReservationMode = $brmMode - } - } - It 'Current Name "" | Current BandwidthReservationMode set to "" | Desired BandwidthReservationMode set to "" | Ensure ""' -TestCases $testSetTestCases { param ( [Parameter()] - [string] + [System.String] $CurrentName, [Parameter()] - [string] + [System.String] $CurrentBandwidthReservationMode, [Parameter()] - [string] + [System.String] $DesiredName, [Parameter()] - [string] + [System.String] $DesiredBandwidthReservationMode, [Parameter()] - [string] + [System.String] $Ensure, [Parameter()] - [bool] + [System.Boolean] $ExpectedResult ) - # Set the mocked VMSwitch to be returned from Get-VMSwitch if the switch exists if ($CurrentName) { - $global:mockedVMSwitch = New-MockedVMSwitch -Name $CurrentName -BandwidthReservationMode $CurrentBandwidthReservationMode -AllowManagementOS $true + # Set the mocked VMSwitch to be returned from Get-VMSwitch if the switch exists + $script:mockedVMSwitch = New-MockedVMSwitch -Name $CurrentName -BandwidthReservationMode $CurrentBandwidthReservationMode -AllowManagementOS $true + } + else + { + if ($Ensure -eq 'Absent') + { + # This is called when Ensure = 'Absent'. TO make sure there is a VMSwitch to remove. + $script:mockedVMSwitch = New-MockedVMSwitch -Name $DesiredName -BandwidthReservationMode $DesiredBandwidthReservationMode -AllowManagementOS $true + } } $targetResource = Set-TargetResource -Name $DesiredName -BandwidthReservationMode $DesiredBandwidthReservationMode -Type 'External' -NetAdapterName 'SomeNIC' -Ensure $Ensure -AllowManagementOS $true - $targetResource | Should Be $null + $targetResource | Should -Be $null if ($CurrentName -and $Ensure -eq 'Present') { @@ -526,7 +457,7 @@ try Assert-MockCalled -CommandName Get-VMSwitch -Times 1 -Scope 'It' Assert-MockCalled -CommandName Remove-VMSwitch -Times 1 -Scope 'It' } - Remove-Variable -Scope 'Global' -Name 'mockedVMSwitch' -ErrorAction 'SilentlyContinue' + Remove-Variable -Scope 'script' -Name 'mockedVMSwitch' -ErrorAction 'SilentlyContinue' } # Test Set-TargetResource when the version of Windows doesn't support BandwidthReservationMode @@ -535,10 +466,9 @@ try return [Version]::Parse('6.1.7601') } - $errorRecord = Get-InvalidArgumentError ` - -ErrorId 'BandwidthReservationModeError' ` - -ErrorMessage $LocalizedData.BandwidthReservationModeError - {Set-TargetResource -Name 'WeightBRM' -Type 'External' -NetAdapterName 'SomeNIC' -AllowManagementOS $true -BandwidthReservationMode 'Weight' -Ensure 'Present'} | Should Throw $errorRecord + $errorMessage = $script:localizedData.BandwidthReservationModeError + + {Set-TargetResource -Name 'WeightBRM' -Type 'External' -NetAdapterName 'SomeNIC' -AllowManagementOS $true -BandwidthReservationMode 'Weight' -Ensure 'Present'} | Should -Throw $errorMessage } } } diff --git a/Tests/Unit/MSFT_xVMSwitch_EnableEmbeddedTeaming.Tests.ps1 b/tests/Unit/MSFT_xVMSwitch_EnableEmbeddedTeaming.Tests.ps1 similarity index 56% rename from Tests/Unit/MSFT_xVMSwitch_EnableEmbeddedTeaming.Tests.ps1 rename to tests/Unit/MSFT_xVMSwitch_EnableEmbeddedTeaming.Tests.ps1 index 205f8ed..cca3d1d 100644 --- a/Tests/Unit/MSFT_xVMSwitch_EnableEmbeddedTeaming.Tests.ps1 +++ b/tests/Unit/MSFT_xVMSwitch_EnableEmbeddedTeaming.Tests.ps1 @@ -1,197 +1,134 @@ -#region HEADER - -# Unit Test Template Version: 1.2.0 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) -{ - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName 'xHyper-V' ` - -DSCResourceName 'MSFT_xVMSwitch' ` - -TestType Unit - -#endregion HEADER +$script:dscModuleName = 'xHyper-V' +$script:dscResourceName = 'MSFT_xVMSwitch' function Invoke-TestSetup { + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + # Import the stub functions. + Import-Module -Name "$PSScriptRoot/Stubs/Hyper-V.stubs.psm1" -Force } function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } -# Begin Testing +Invoke-TestSetup + try { - Invoke-TestSetup - - InModuleScope 'MSFT_xVMSwitch' { - # Function to create a exception object for testing output exceptions - function Get-InvalidArgumentError + InModuleScope $script:dscResourceName { + # A helper function to mock a VMSwitch + function New-MockedVMSwitch { - [CmdletBinding()] param ( [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $ErrorId, - - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] [System.String] - $ErrorMessage - ) - - $exception = New-Object -TypeName System.ArgumentException ` - -ArgumentList $ErrorMessage - $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument - $errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord ` - -ArgumentList $exception, $ErrorId, $errorCategory, $null - return $errorRecord - } # end function Get-InvalidArgumentError - - # A helper function to mock a VMSwitch - function New-MockedVMSwitch - { - param ( - [Parameter(Mandatory = $true)] - [string] $Name, [Parameter(Mandatory = $true)] [ValidateSet('Default', 'Weight', 'Absolute', 'None', 'NA')] - [string] + [System.String] $BandwidthReservationMode, - [parameter()] + [Parameter()] [ValidateSet('Dynamic','HyperVPort')] - [String] + [System.String] $LoadBalancingAlgorithm, [Parameter()] - [bool] + [System.Boolean] $AllowManagementOS = $false ) - $mockedVMSwitch = @{ - Name = $Name - SwitchType = 'External' - AllowManagementOS = $AllowManagementOS - NetAdapterInterfaceDescription = 'Microsoft Network Adapter Multiplexor Driver' - } + $mockedVMSwitch = [Microsoft.HyperV.PowerShell.VMSwitch]::CreateTypeInstance() + $mockedVMSwitch.Name = $Name + $mockedVMSwitch.SwitchType = 'External' + $mockedVMSwitch.AllowManagementOS = $AllowManagementOS + $mockedVMSwitch.NetAdapterInterfaceDescriptions = 'Microsoft Network Adapter Multiplexor Driver' if ($BandwidthReservationMode -ne 'NA') { - $mockedVMSwitch['BandwidthReservationMode'] = $BandwidthReservationMode + $mockedVMSwitch.BandwidthReservationMode = $BandwidthReservationMode } - if($PSBoundParameters.ContainsKey('LoadBalancingAlgorithm')) + if ($PSBoundParameters.ContainsKey('LoadBalancingAlgorithm')) { - $mockedVMSwitch['LoadBalancingAlgorithm'] = $LoadBalancingAlgorithm + $mockedVMSwitch.LoadBalancingAlgorithm = $LoadBalancingAlgorithm } - return [PsObject]$mockedVMSwitch + return $mockedVMSwitch } Describe "MSFT_xVMSwitch" { - # Create empty functions to be able to mock the missing Hyper-V cmdlet - function Get-VMSwitch - { - - } - - function New-VMSwitch - { - - } - - function Set-VMSwitch - { - - } - - function Remove-VMSwitch - { - - } - - function Get-VMSwitchTeam - { - - } - - function Set-VMSwitchTeam - { - - } - <# - Mocks Get-VMSwitch and will return $global:mockedVMSwitch which is + Mocks Get-VMSwitch and will return $script:mockedVMSwitch which is a variable that is created during most It statements to mock a VMSwitch #> Mock -CommandName Get-VMSwitch -MockWith { - param - ( - [string] - $Name, - - [string] - $SwitchType, - - [string] - $ErrorAction - ) - - if ($ErrorAction -eq 'Stop' -and $global:mockedVMSwitch -eq $null) + if ($ErrorAction -eq 'Stop' -and $script:mockedVMSwitch -eq $null) { throw [System.Management.Automation.ActionPreferenceStopException]'No switch can be found by given criteria.' } - return $global:mockedVMSwitch + return $script:mockedVMSwitch } <# - Mocks New-VMSwitch and will assign a mocked switch to $global:mockedVMSwitch. This returns $global:mockedVMSwitch + Mocks New-VMSwitch and will assign a mocked switch to $script:mockedVMSwitch. This returns $script:mockedVMSwitch which is a variable that is created during most It statements to mock a VMSwitch #> Mock -CommandName New-VMSwitch -MockWith { param ( - [string] + [Parameter()] + [System.String] $Name, - [string[]] + [Parameter()] + [System.String[]] $NetAdapterName, - [string] + [Parameter()] + [System.String] $MinimumBandwidthMode = 'NA', - [bool] + [Parameter()] + [System.Boolean] $EnableEmbeddedTeaming, - [bool] + [Parameter()] + [System.Boolean] $AllowManagementOS ) - $global:mockedVMSwitch = New-MockedVMSwitch -Name $Name -BandwidthReservationMode $MinimumBandwidthMode -AllowManagementOS $AllowManagementOS + $script:mockedVMSwitch = New-MockedVMSwitch -Name $Name -BandwidthReservationMode $MinimumBandwidthMode -AllowManagementOS $AllowManagementOS #is SET is enabled mok a VMSwitchTeam - if($EnableEmbeddedTeaming){ - $global:mockedVMSwitchTeam = [PSCustomObject]@{ + if ($EnableEmbeddedTeaming) + { + $script:mockedVMSwitchTeam = [PSCustomObject]@{ Name = "TestSwitch" Id = [Guid]::NewGuid() TeamingMode = 'SwitchIndependent' LoadBalancingAlgorithm = 'Dynamic' } } - return $global:mockedVMSwitch + return $script:mockedVMSwitch } Mock -CommandName Get-OSVersion -MockWith { @@ -201,54 +138,21 @@ try } <# - Mocks Set-VMSwitch and will modify $global:mockedVMSwitch which is - a variable that is created during most It statements to mock a VMSwitch - #> - Mock -CommandName Set-VMSwitch -MockWith { - param - ( - [bool] - $AllowManagementOS - ) - - if ($AllowManagementOS) - { - $global:mockedVMSwitch['AllowManagementOS'] = $AllowManagementOS - } - } - - <# - Mocks Remove-VMSwitch and will remove the variable $global:mockedVMSwitch which is + Mocks Remove-VMSwitch and will remove the variable $script:mockedVMSwitch which is a variable that is created during most It statements to mock a VMSwitch #> Mock -CommandName Remove-VMSwitch -MockWith { - $global:mockedVMSwitch = $null + $script:mockedVMSwitch = $null } <# Mocks Get-VMSwitchTeam and will return a moked VMSwitchTeam #> Mock -CommandName Get-VMSwitchTeam -MockWith { - return $global:mockedVMSwitchTeam + return $script:mockedVMSwitchTeam } - <# - Mocks Set-VMSwitchTeam and will return a moked VMSwitchTeam - #> - Mock -CommandName Set-VMSwitchTeam -MockWith { - param - ( - [parameter(Mandatory=$true)] - [ValidateSet('Dynamic','HyperVPort')] - [String] - $LoadBalancingAlgorithm, - - [String] - $Name - ) - - $global:mockedVMSwitchTeam.LoadBalancingAlgorithm = $LoadBalancingAlgorithm - } + Mock -CommandName Set-VMSwitchTeam # Mocks Get-NetAdapter which returns a simplified network adapter Mock -CommandName Get-NetAdapter -MockWith { @@ -270,7 +174,7 @@ try } Context "A virtual switch with embedded teaming does not exist but should" { - $global:mockedVMSwitch = $null + $script:mockedVMSwitch = $null $testParams = @{ Name = "TestSwitch" @@ -283,11 +187,11 @@ try } It "Should return absent in the get method" { - (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should Be "Absent" + (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should -Be "Absent" } It "Should return false in the test method" { - Test-TargetResource @testParams | Should Be $false + Test-TargetResource @testParams | Should -Be $false } It "Should run the set method without exceptions" { @@ -297,42 +201,57 @@ try } Context "A virtual switch with embedded teaming exists and should" { - $global:mockedVMSwitch = @{ - Name = "TestSwitch" - SwitchType = "External" - AllowManagementOS = $true - EmbeddedTeamingEnabled = $true - Id = [Guid]::NewGuid() - NetAdapterInterfaceDescriptions = @("Microsoft Network Adapter Multiplexor Driver #1", "Microsoft Network Adapter Multiplexor Driver #2") + $mockVMSwitch = [Microsoft.HyperV.PowerShell.VMSwitch]::CreateTypeInstance() + $mockVMSwitch.Name = 'NewSwitch' + $mockVMSwitch.SwitchType = 'External' + $mockVMSwitch.AllowManagementOS = $true + $mockVMSwitch.EmbeddedTeamingEnabled = $true + $mockVMSwitch.Id = [Guid]::NewGuid() + $mockVMSwitch.NetAdapterInterfaceDescriptions = @( + 'Microsoft Network Adapter Multiplexor Driver #1', + 'Microsoft Network Adapter Multiplexor Driver #2' + ) + + Mock -CommandName Get-VMSwitch -MockWith { + return $mockVMSwitch + } -ParameterFilter { + $Name -eq 'NewSwitch' } $testParams = @{ - Name = "TestSwitch" + Name = "NewSwitch" Type = "External" NetAdapterName = @("NIC1", "NIC2") AllowManagementOS = $true EnableEmbeddedTeaming = $true - BandwidthReservationMode = "NA" Ensure = "Present" } It "Should return present in the get method" { - (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should Be "Present" + (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should -Be "Present" } It "Should return true in the test method" { - Test-TargetResource @testParams | Should Be $true + Test-TargetResource @testParams | Should -Be $true } } Context "A virtual switch with embedded teaming exists but does not refer to the correct adapters" { - $global:mockedVMSwitch = @{ - Name = "TestSwitch" - SwitchType = "External" - AllowManagementOS = $true - EmbeddedTeamingEnabled = $true - Id = [Guid]::NewGuid() - NetAdapterInterfaceDescriptions = @("Wrong adapter", "Microsoft Network Adapter Multiplexor Driver #2") + $mockVMSwitch = [Microsoft.HyperV.PowerShell.VMSwitch]::CreateTypeInstance() + $mockVMSwitch.Name = 'NewSwitch' + $mockVMSwitch.SwitchType = 'External' + $mockVMSwitch.AllowManagementOS = $true + $mockVMSwitch.EmbeddedTeamingEnabled = $true + $mockVMSwitch.Id = [Guid]::NewGuid() + $mockVMSwitch.NetAdapterInterfaceDescriptions = @( + 'Wrong adapter', + 'Microsoft Network Adapter Multiplexor Driver #2' + ) + + Mock -CommandName Get-VMSwitch -MockWith { + return $mockVMSwitch + } -ParameterFilter { + $Name -eq 'NewSwitch' } Mock -CommandName Get-NetAdapter -MockWith { @@ -349,21 +268,20 @@ try } $testParams = @{ - Name = "TestSwitch" + Name = "NewSwitch" Type = "External" NetAdapterName = @("NIC1", "NIC2") AllowManagementOS = $true EnableEmbeddedTeaming = $true - BandwidthReservationMode = "NA" Ensure = "Present" } It "Should return present in the get method" { - (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should Be "Present" + (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should -Be "Present" } It "Should return false in the test method" { - Test-TargetResource @testParams | Should Be $false + Test-TargetResource @testParams | Should -Be $false } It "Should run the set method without exceptions" { @@ -374,14 +292,30 @@ try } Context "A virtual switch with embedded teaming exists but does not use the correct LB algorithm" { - $global:mockedVMSwitch = @{ - Name = "TestSwitch" - SwitchType = "External" - AllowManagementOS = $true - EmbeddedTeamingEnabled = $true - LoadBalancingAlgorithm = 'Dynamic' - Id = [Guid]::NewGuid() - NetAdapterInterfaceDescriptions = @("Microsoft Network Adapter Multiplexor Driver #1", "Microsoft Network Adapter Multiplexor Driver #2") + $mockVMSwitch = [Microsoft.HyperV.PowerShell.VMSwitch]::CreateTypeInstance() + $mockVMSwitch.Name = 'NewSwitch' + $mockVMSwitch.SwitchType = 'External' + $mockVMSwitch.AllowManagementOS = $true + $mockVMSwitch.EmbeddedTeamingEnabled = $true + $mockVMSwitch.Id = [Guid]::NewGuid() + $mockVMSwitch.NetAdapterInterfaceDescriptions = @( + 'Microsoft Network Adapter Multiplexor Driver #1', + 'Microsoft Network Adapter Multiplexor Driver #2' + ) + + Mock -CommandName Get-VMSwitch -MockWith { + return $mockVMSwitch + } -ParameterFilter { + $Name -eq 'NewSwitch' + } + + $mockVMSwitchTeam = [Microsoft.HyperV.PowerShell.VMSwitchTeam]::CreateTypeInstance() + $mockVMSwitchTeam.Name = 'SwitchTeam' + $mockVMSwitchTeam.LoadBalancingAlgorithm = 'Dynamic' + $mockVMSwitchTeam.Id = [Guid]::NewGuid() + + Mock -CommandName Get-VMSwitchTeam -MockWith { + return $mockVMSwitchTeam } Mock -CommandName Get-NetAdapter -MockWith { @@ -398,7 +332,7 @@ try } $testParams = @{ - Name = "TestSwitch" + Name = "NewSwitch" Type = "External" NetAdapterName = @("NIC1", "NIC2") AllowManagementOS = $true @@ -408,11 +342,11 @@ try } It "Should return present in the get method" { - (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should Be "Present" + (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should -Be "Present" } It "Should return false in the test method" { - Test-TargetResource @testParams | Should Be $false + Test-TargetResource @testParams | Should -Be $false } It "Should run the set method without exceptions" { @@ -423,17 +357,22 @@ try } Context "A virtual switch without embedded teaming exists but should use embedded teaming" { - $global:mockedVMSwitch = @{ - Name = "TestSwitch" - SwitchType = "External" - AllowManagementOS = $true - EmbeddedTeamingEnabled = $false - Id = [Guid]::NewGuid() - NetAdapterInterfaceDescription = "Microsoft Network Adapter Multiplexor Driver #1" + $mockVMSwitch = [Microsoft.HyperV.PowerShell.VMSwitch]::CreateTypeInstance() + $mockVMSwitch.Name = 'NewSwitch' + $mockVMSwitch.SwitchType = 'External' + $mockVMSwitch.AllowManagementOS = $true + $mockVMSwitch.EmbeddedTeamingEnabled = $false + $mockVMSwitch.Id = [Guid]::NewGuid() + $mockVMSwitch.NetAdapterInterfaceDescription = 'Microsoft Network Adapter Multiplexor Driver #1' + + Mock -CommandName Get-VMSwitch -MockWith { + return $mockVMSwitch + } -ParameterFilter { + $Name -eq 'NewSwitch' } $testParams = @{ - Name = "TestSwitch" + Name = "NewSwitch" Type = "External" NetAdapterName = @("NIC1", "NIC2") AllowManagementOS = $true @@ -443,11 +382,11 @@ try } It "Should return present in the get method" { - (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should Be "Present" + (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should -Be "Present" } It "Should return false in the test method" { - Test-TargetResource @testParams | Should Be $false + Test-TargetResource @testParams | Should -Be $false } It "Should run the set method without exceptions" { @@ -458,27 +397,35 @@ try } Context "A virtual switch with embedded teaming exists but shouldn't" { - $global:mockedVMSwitch = @{ - Name = "TestSwitch" - SwitchType = "External" - AllowManagementOS = $true - EmbeddedTeamingEnabled = $true - Id = [Guid]::NewGuid() - NetAdapterInterfaceDescriptions = @("Microsoft Network Adapter Multiplexor Driver #1", "Microsoft Network Adapter Multiplexor Driver #2") + $mockVMSwitch = [Microsoft.HyperV.PowerShell.VMSwitch]::CreateTypeInstance() + $mockVMSwitch.Name = 'NewSwitch' + $mockVMSwitch.SwitchType = 'External' + $mockVMSwitch.AllowManagementOS = $true + $mockVMSwitch.EmbeddedTeamingEnabled = $true + $mockVMSwitch.Id = [Guid]::NewGuid() + $mockVMSwitch.NetAdapterInterfaceDescriptions = @( + 'Microsoft Network Adapter Multiplexor Driver #1', + 'Microsoft Network Adapter Multiplexor Driver #2' + ) + + Mock -CommandName Get-VMSwitch -MockWith { + return $mockVMSwitch + } -ParameterFilter { + $Name -eq 'NewSwitch' } $testParams = @{ - Name = "TestSwitch" + Name = "NewSwitch" Type = "Internal" Ensure = "Absent" } It "Should return present in the get method" { - (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should Be "Present" + (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should -Be "Present" } It "Should return false in the test method" { - Test-TargetResource @testParams | Should Be $false + Test-TargetResource @testParams | Should -Be $false } It "Should run the set method without exceptions" { @@ -488,7 +435,7 @@ try } Context "A virtual switch with embedded teaming does not exist and shouldn't" { - $global:mockedVMSwitch = $null + $script:mockedVMSwitch = $null $testParams = @{ Name = "TestSwitch" @@ -497,16 +444,16 @@ try } It "Should return absent in the get method" { - (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should Be "Absent" + (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should -Be "Absent" } It "Should return true in the test method" { - Test-TargetResource @testParams | Should Be $true + Test-TargetResource @testParams | Should -Be $true } } Context "A server is not running Server 2016 and attempts to use embedded teaming" { - $global:mockedVMSwitch = $null + $script:mockedVMSwitch = $null $testParams = @{ Name = "TestSwitch" @@ -523,28 +470,25 @@ try } It "Should return absent in the get method" { - (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should Be "Absent" + (Get-TargetResource -Name $testParams.Name -Type $testParams.Type).Ensure | Should -Be "Absent" } It "Should throw an error in the test method" { - $errorRecord = Get-InvalidArgumentError ` - -ErrorId 'SETServer2016Error' ` - -ErrorMessage $LocalizedData.SETServer2016Error + $errorMessage = $script:localizedData.SETServer2016Error - {Test-TargetResource @testParams} | Should Throw $errorRecord + {Test-TargetResource @testParams} | Should -Throw $errorMessage } It "Should throw an error in the set method" { - $errorRecord = Get-InvalidArgumentError ` - -ErrorId 'SETServer2016Error' ` - -ErrorMessage $LocalizedData.SETServer2016Error + $errorMessage = $script:localizedData.SETServer2016Error - {Set-TargetResource @testParams} | Should Throw $errorRecord + {Set-TargetResource @testParams} | Should -Throw $errorMessage } } } } } -finally { +finally +{ Invoke-TestCleanup } diff --git a/Tests/Unit/MSFT_xVMSwitch_Id.Tests.ps1 b/tests/Unit/MSFT_xVMSwitch_Id.Tests.ps1 similarity index 71% rename from Tests/Unit/MSFT_xVMSwitch_Id.Tests.ps1 rename to tests/Unit/MSFT_xVMSwitch_Id.Tests.ps1 index 32980a4..806d6bd 100644 --- a/Tests/Unit/MSFT_xVMSwitch_Id.Tests.ps1 +++ b/tests/Unit/MSFT_xVMSwitch_Id.Tests.ps1 @@ -1,73 +1,43 @@ +$script:dscModuleName = 'xHyper-V' +$script:dscResourceName = 'MSFT_xVMSwitch' -#region HEADER -$script:DSCModuleName = 'xHyper-V' -$script:DSCResourceName = 'MSFT_xVMSwitch' - -# Unit Test Template Version: 1.2.4 -$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) -if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` - (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +function Invoke-TestSetup { - & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) -} - -Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force - -$TestEnvironment = Initialize-TestEnvironment ` - -DSCModuleName $script:DSCModuleName ` - -DSCResourceName $script:DSCResourceName ` - -ResourceType 'Mof' ` - -TestType Unit + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } -#endregion HEADER + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' -function Invoke-TestSetup -{ + # Import the stub functions. + Import-Module -Name "$PSScriptRoot/Stubs/Hyper-V.stubs.psm1" -Force } function Invoke-TestCleanup { - Restore-TestEnvironment -TestEnvironment $TestEnvironment + Restore-TestEnvironment -TestEnvironment $script:testEnvironment } -# Begin Testing +Invoke-TestSetup + try { - Invoke-TestSetup - - InModuleScope $script:DSCResourceName { - - # A helper function to create a exception object for testing output exceptions - function Get-InvalidArgumentError - { - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $ErrorId, - - [Parameter(Mandatory = $true)] - [ValidateNotNullOrEmpty()] - [System.String] - $ErrorMessage - ) - - $exception = New-Object -TypeName System.ArgumentException ` - -ArgumentList $ErrorMessage - $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument - $errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord ` - -ArgumentList $exception, $ErrorId, $errorCategory, $null - return $errorRecord - } - + InModuleScope $script:dscResourceName { # A helper function to mock a VMSwitch function New-MockedVMSwitch { param ( [Parameter(Mandatory = $true)] - [String] + [System.String] $Name, [Parameter()] @@ -76,25 +46,27 @@ try $Id ) - $mockedVMSwitch = @{ - Name = $Name - SwitchType = 'External' - AllowManagementOS = $true - EmbeddedTeamingEnabled = $true - LoadBalancingAlgorithm = 'HyperVPort' - BandwidthReservationMode = 'Default' - NetAdapterInterfaceDescriptions = @("Microsoft Network Adapter Multiplexor Driver #1", "Microsoft Network Adapter Multiplexor Driver #2") - } + $mockedVMSwitch = [Microsoft.HyperV.PowerShell.VMSwitch]::CreateTypeInstance() + $mockedVMSwitch.Name = $Name + $mockedVMSwitch.SwitchType = 'External' + $mockedVMSwitch.AllowManagementOS = $true + $mockedVMSwitch.EmbeddedTeamingEnabled = $true + $mockedVMSwitch.BandwidthReservationMode = 'Default' + $mockedVMSwitch.NetAdapterInterfaceDescriptions = @( + 'Microsoft Network Adapter Multiplexor Driver #1', + 'Microsoft Network Adapter Multiplexor Driver #2' + ) if ($PSBoundParameters.ContainsKey('Id')) { - $mockedVMSwitch['Id'] = $Id + $mockedVMSwitch.Id = $Id } else { - $mockedVMSwitch['Id'] = New-Guid + $mockedVMSwitch.Id = New-Guid } - return [PsObject]$mockedVMSwitch + + return $mockedVMSwitch } # Mocks "Get-Module -Name Hyper-V" so that the DSC resource thinks the Hyper-V module is on the test system @@ -102,16 +74,10 @@ try return $true } - function Get-VMSwitch - { - } Mock -CommandName Get-VMSwitch -MockWith { - return $Global:MockedVMSwitch + return $script:MockedVMSwitch } - function Get-NetAdapter - { - } Mock -CommandName Get-NetAdapter -MockWith { return @( [PSCustomObject]@{ @@ -125,9 +91,6 @@ try ) } - function Get-VMSwitchTeam - { - } Mock -CommandName Get-VMSwitchTeam -MockWith { return [PSCustomObject]@{ Name = 'TestTeam' @@ -138,36 +101,35 @@ try } } - function Remove-VMSwitch {} Mock -CommandName Remove-VMSwitch -MockWith { - $Global:mockedVMSwitch = $null + $script:mockedVMSwitch = $null } - function New-VMSwitch {} Mock -CommandName New-VMSwitch -MockWith { - Param( + param + ( [Parameter()] - [String] + [System.String] $Name, [Parameter()] - [String[]] + [System.String[]] $NetAdapterName, [Parameter()] - [String] + [System.String] $MinimumBandwidthMode, [Parameter()] - [bool] + [System.Boolean] $AllowManagementOS, [Parameter()] - [String] + [System.String] $SwitchType, [Parameter()] - [bool] + [System.Boolean] $EnableEmbeddedTeaming, [Parameter()] @@ -175,19 +137,16 @@ try $Id ) - if($PSBoundParameters.ContainsKey('Id')) + if ($PSBoundParameters.ContainsKey('Id')) { - $Global:MockedVMSwitch = New-MockedVMSwitch -Name $Name -Id $id + $script:MockedVMSwitch = New-MockedVMSwitch -Name $Name -Id $id } else { - $Global:MockedVMSwitch = New-MockedVMSwitch -Name $Name + $script:MockedVMSwitch = New-MockedVMSwitch -Name $Name } } - function Get-OSVersion - { - } Mock -CommandName Get-OSVersion -MockWith { [PSCustomObject]@{ Major = 10 @@ -202,10 +161,10 @@ try Describe 'MSFT_xVMSwitch\Get-TargetResource' -Tag 'Get' { Context 'When the system is in the desired state (VMSwitch has the desired Id)' { - $Global:MockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' + $script:MockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' It 'Should return "present"' { - (Get-TargetResource -Name 'TestSwitch' -Type 'External').Ensure | Should Be 'Present' + (Get-TargetResource -Name 'TestSwitch' -Type 'External').Ensure | Should -Be 'Present' Assert-MockCalled -CommandName "Get-VMSwitch" -Times 1 Assert-MockCalled -CommandName "Get-VMSwitchTeam" -Times 1 } @@ -213,10 +172,10 @@ try Context 'When the system is not in the desired state (VMSwitch has not the desired Id)' { - $Global:mockedVMSwitch = $null + $script:mockedVMSwitch = $null It 'Should return "absent"' { - (Get-TargetResource -Name 'TestSwitch' -Type 'External').Ensure | Should Be 'Absent' + (Get-TargetResource -Name 'TestSwitch' -Type 'External').Ensure | Should -Be 'Absent' Assert-MockCalled -CommandName "Get-VMSwitch" -Times 1 Assert-MockCalled -CommandName "Get-VMSwitchTeam" -Times 0 } @@ -228,7 +187,7 @@ try Context 'When the system is in the desired state (VMSwitch has the desired Id)' { $desiredVMSwitchID = New-Guid - $Global:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' -Id $desiredVMSwitchID + $script:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' -Id $desiredVMSwitchID $testParams = @{ Name = 'TestSwitch' @@ -241,7 +200,7 @@ try } It 'Should run without without exceptions' { - {Set-TargetResource @testParams} | Should -Not -Throw + {Set-TargetResource @testParams} | Should -Not -throw Assert-MockCalled -CommandName "Get-VMSwitch" -Times 1 Assert-MockCalled -CommandName 'Get-NetAdapter' -Times 1 } @@ -249,7 +208,7 @@ try Context 'When the system is not in the desired state (VMSwitch has not the desired Id)' { - $Global:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' + $script:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' $testParams = @{ Name = 'TestSwitch' @@ -262,7 +221,7 @@ try } It 'Should run without exception while re-creating the VMSwitch' { - {Set-TargetResource @testParams} | Should -Not -Throw + {Set-TargetResource @testParams} | Should -Not -throw Assert-MockCalled -CommandName "Get-VMSwitch" -Times 1 Assert-MockCalled -CommandName 'Get-NetAdapter' -Times 1 Assert-MockCalled -CommandName 'Remove-VMSwitch' -Times 1 @@ -272,7 +231,7 @@ try Context 'When the specified value for Id parameter is not a GUID' { - $Global:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' + $script:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' $testParams = @{ Name = 'TestSwitch' @@ -293,7 +252,7 @@ try $desiredVMSwitchID = New-Guid - $Global:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' -Id $desiredVMSwitchID + $script:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' -Id $desiredVMSwitchID $testParams = @{ Name = 'TestSwitch' @@ -309,12 +268,10 @@ try return [Version]::Parse('6.3.9600') } - $errorRecord = Get-InvalidArgumentError ` - -ErrorId 'VMSwitchIDServer2016Error' ` - -ErrorMessage $LocalizedData.VMSwitchIDServer2016Error + $errorMessage = $script:localizedData.VMSwitchIDServer2016Error It 'Should throw "VMSwitchIDServer2016Error"' { - {Set-TargetResource @testParams} | Should -Throw $errorRecord + {Set-TargetResource @testParams} | Should -Throw $errorMessage } } } @@ -324,7 +281,7 @@ try $desiredVMSwitchID = New-Guid - $Global:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' -Id $desiredVMSwitchID + $script:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' -Id $desiredVMSwitchID $testParams = @{ Name = 'TestSwitch' @@ -337,7 +294,7 @@ try } It 'Should return $true' { - {Test-TargetResource @testParams} | Should -Not -Throw + {Test-TargetResource @testParams} | Should -Not -throw Assert-MockCalled -CommandName "Get-VMSwitch" -Times 1 Assert-MockCalled -CommandName 'Get-NetAdapter' -Times 1 } @@ -345,7 +302,7 @@ try Context 'When the system is not in the desired state (VMSwitch has not the desired Id)' { - $Global:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' + $script:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' $testParams = @{ Name = 'TestSwitch' @@ -358,7 +315,7 @@ try } It 'Should return $false' { - {Test-TargetResource @testParams} | Should -Not -Throw + {Test-TargetResource @testParams} | Should -Not -throw Assert-MockCalled -CommandName "Get-VMSwitch" -Times 1 Assert-MockCalled -CommandName 'Get-NetAdapter' -Times 1 } @@ -366,7 +323,7 @@ try Context 'When the specified value for Id parameter is not a GUID' { - $Global:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' + $script:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' $testParams = @{ Name = 'TestSwitch' @@ -387,7 +344,7 @@ try $desiredVMSwitchID = New-Guid - $Global:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' -Id $desiredVMSwitchID + $script:mockedVMSwitch = New-MockedVMSwitch -Name 'TestSwitch' -Id $desiredVMSwitchID $testParams = @{ Name = 'TestSwitch' @@ -403,12 +360,10 @@ try return [Version]::Parse('6.3.9600') } - $errorRecord = Get-InvalidArgumentError ` - -ErrorId 'VMSwitchIDServer2016Error' ` - -ErrorMessage $LocalizedData.VMSwitchIDServer2016Error + $errorMessage = $script:localizedData.VMSwitchIDServer2016Error It 'Should throw "VMSwitchIDServer2016Error"' { - {Test-TargetResource @testParams} | Should -Throw $errorRecord + {Test-TargetResource @testParams} | Should -Throw $errorMessage } } diff --git a/tests/Unit/MSFT_xVhdFileDirectory.Tests.ps1 b/tests/Unit/MSFT_xVhdFileDirectory.Tests.ps1 new file mode 100644 index 0000000..7b448bb --- /dev/null +++ b/tests/Unit/MSFT_xVhdFileDirectory.Tests.ps1 @@ -0,0 +1,531 @@ +$script:dscModuleName = 'xHyper-V' +$script:dscResourceName = 'MSFT_xVhdFileDirectory' + +function Invoke-TestSetup +{ + try + { + Import-Module -Name DscResource.Test -Force -ErrorAction 'Stop' + } + catch [System.IO.FileNotFoundException] + { + throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -Tasks build" first.' + } + + $script:testEnvironment = Initialize-TestEnvironment ` + -DSCModuleName $script:dscModuleName ` + -DSCResourceName $script:dscResourceName ` + -ResourceType 'Mof' ` + -TestType 'Unit' + + # Import the stub functions. + Import-Module -Name "$PSScriptRoot/Stubs/Hyper-V.stubs.psm1" -Force +} + +function Invoke-TestCleanup +{ + Restore-TestEnvironment -TestEnvironment $script:testEnvironment +} + +Invoke-TestSetup + +try +{ + InModuleScope $script:dscResourceName { + + #region Functions, Variables and Mocks + function Get-FreeDriveLetter + { + [CmdletBinding()] + param() + + $upperCaseChars = 67..90 | ForEach-Object { [char]$_ } + $driveLettersInUse = Get-PsDrive | Where-Object -FilterScript { + $upperCaseChars -contains $_.name + } | Select-Object -ExpandProperty Name + + foreach ($char in $upperCaseChars) + { + if ($driveLettersInUse -notcontains $char) + { + Write-Verbose "Selecting $char to use as VhdDriveLetter" + + return $char + break + } + } +} + +function New-TestDriveLayout +{ + [CmdletBinding(SupportsShouldProcess, ConfirmImpact = "Medium")] + param( + [Parameter()] + [System.String] + $DriveLetter + ) + + # Source file structure + New-item -Path TestDrive:\VhdExists.vhdx + 'TestFile1' | Out-File TestDrive:\FileExists.txt + 'TestFile2' | Out-File TestDrive:\FileExists2.txt + 'TestFile3' | Out-File TestDrive:\FileExists3.txt + New-Item -Path TestDrive:\SourceDirectoryExists -ItemType Directory + New-Item -Path TestDrive:\SourceDirectoryExists2 -ItemType Directory + 'Some Text' | Out-File TestDrive:\SourceDirectoryExists\File1.txt + 'Some More Text' | Out-File TestDrive:\SourceDirectoryExists2\File2.txt + + # VhdRoot structure + New-Item -Path TestDrive:\MockVhdRoot -ItemType Directory + New-Item -Path TestDrive:\MockVhdRoot\DestinationDirectoryExists -ItemType Directory + Copy-Item -Path TestDrive:\FileExists.txt -Destination TestDrive:\MockVhdRoot\DestinationDirectoryExists\FileExists.txt + Copy-Item -Path TestDrive:\FileExists2.txt -Destination TestDrive:\MockVhdRoot\DestinationDirectoryExists\FileExists2.txt + Copy-Item -Path TestDrive:\SourceDirectoryExists TestDrive:\DestinationDirectoryExists\SourceDirectory -Recurse + (Get-Item TestDrive:\MockVhdRoot\DestinationDirectoryExists\FileExists2.txt).Attributes = '' + + # ShouldProcess supported by New-PsDrive + New-PSDrive -PSProvider FileSystem -Name $DriveLetter -Root TestDrive:\MockVhdRoot -scope 1 +} + +$script:vhdDriveLetter = Get-FreeDriveLetter + +# function Mount-Vhd {} +# function Dismount-Vhd {} +# function Get-Disk {} +# function Get-Partition {} +# function Get-Volume {} + +$script:dscFileDirClassName = 'MSFT_FileDirectoryConfiguration' +$script:dscNamespace = 'root/microsoft/windows/desiredstateconfiguration' + +Mock -CommandName Mount-Vhd { [PSCustomObject] @{ Path = 'TestDrive:\VhdExists.vhdx' } } + +Mock -CommandName Dismount-Vhd { } + +Mock -CommandName Get-Disk { + New-CimInstance -ClassName MSFT_Disk -Namespace root/Microsoft/Windows/Storage -ClientOnly +} + +Mock -CommandName Get-Partition { + New-CimInstance -ClassName MSFT_Partitions -Namespace ROOT/Microsoft/Windows/Storage -ClientOnly | + Add-Member -MemberType NoteProperty -Name Type -Value 'Mocked' -Force -PassThru | + Add-Member -MemberType NoteProperty -Name DriveLetter -Value $script:vhdDriveLetter -PassThru +} + +Mock -CommandName Get-Volume { + New-CimInstance -ClassName MSFT_Volumes -Namespace ROOT/Microsoft/Windows/Storage -ClientOnly | + Add-Member -MemberType NoteProperty -Name DriveLetter -Value $script:vhdDriveLetter -PassThru +} + +Mock -CommandName Get-Module { + $true +} -ParameterFilter { $Name -and $Name -eq "Hyper-V" } + +#endregion + +Describe 'MSFT_xVhdFileDirectory\Get-TargetResource' -Tag 'Get' { + + BeforeAll { + New-TestDriveLayout -DriveLetter $script:vhdDriveLetter + } + + AfterAll { + Remove-PSDrive $script:vhdDriveLetter -ErrorAction SilentlyContinue + } + + It 'Should return a [System.Collections.Hashtable] object type' { + $fdProperties = @{ + SourcePath = 'TestDrive:\FileExists.txt' + DestinationPath = '\DestinationDirectoryExists\' + Type = 'File' + Ensure = 'Present' + } + + $fileDirectory = New-CimInstance -Property $fdProperties -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly + $result = Get-TargetResource -VhdPath TestDrive:\VhdExists.vhdx -FileDirectory $fileDirectory + + $result -is [System.Collections.Hashtable] | + Should -Be $true + } + + #region Testcases for Get-TargetResource + $testCases_Get = @( + @{ + TestName = 'VhdFile exists, Source File exists, Destination File exists' + FileDirectoryProperties = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists.txt' + DestinationPath = 'DestinationDirectoryExists\FileExists.txt' + Type = 'File' + Ensure = 'Present' + } + VhdPath = 'TestDrive:\VhdExists.vhdx' + ExpectedResult = @{ + FileDirectory = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + DestinationPath = $script:vhdDriveLetter + ':\DestinationDirectoryExists\FileExists.txt' + Ensure = 'Present' + } + VhdPath = 'TestDrive:\VhdExists.vhdx' + } + } + @{ + TestName = 'VhdFile exists, Source File exists, Destination File does not exist' + FileDirectoryProperties = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists.txt' + DestinationPath = 'DestinationDirectoryExists\DoesNotExist.txt' + Type = 'File' + Ensure = 'Present' + } + VhdPath = 'TestDrive:\VhdExists.vhdx' + ExpectedResult = @{ + FileDirectory = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + DestinationPath = $script:vhdDriveLetter + ':\DestinationDirectoryExists\DoesNotExist.txt' + Ensure = 'Absent' + } + VhdPath = 'TestDrive:\VhdExists.vhdx' + } + } + @{ + TestName = 'VhdFile exists, Source File does not exist, Destination File exists' + FileDirectoryProperties = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\DoesNotExist.txt' + DestinationPath = 'DestinationDirectoryExists\FileExists.txt' + Type = 'File' + Ensure = 'Present' + } + VhdPath = 'TestDrive:\VhdExists.vhdx' + ExpectedResult = @{ + FileDirectory = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + DestinationPath = $script:vhdDriveLetter + ':\DestinationDirectoryExists\FileExists.txt' + Ensure = 'Present' + } + VhdPath = 'TestDrive:\VhdExists.vhdx' + } + } + @{ + TestName = 'VhdFile exists, Source File does not exist, Destination File does not exist' + FileDirectoryProperties = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\DoesNotExist.txt' + DestinationPath = 'DestinationDirectoryExists\DoesNotExist.txt' + Type = 'File' + Ensure = 'Present' + } + VhdPath = 'TestDrive:\VhdExists.vhdx' + ExpectedResult = @{ + FileDirectory = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + DestinationPath = $script:vhdDriveLetter + ':\DestinationDirectoryExists\DoesNotExist.txt' + Ensure = 'Absent' + } + VhdPath = 'TestDrive:\VhdExists.vhdx' + } + } + @{ + TestName = 'Vhd does not exist, Source File exists, Destination Path does not exist' + FileDirectoryProperties = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists.txt' + DestinationPath = 'DoesNotExist\' + Type = 'File' + Ensure = 'Present' + } + VhdPath = 'TestDrive:\VhdDoesNotExist.vhdx' + ExpectedResult = @{ + FileDirectory = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + DestinationPath = 'TestDrive:\VhdDoesNotExist.vhdx' + Ensure = 'Absent' + } + VhdPath = 'TestDrive:\VhdDoesNotExist.vhdx' + } + } + @{ + TestName = 'Vhd does not exist, Source File does not exist, Destination Path does not exist' + FileDirectoryProperties = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\DoesNotExist.txt' + DestinationPath = 'DoesNotExist\' + Type = 'File' + Ensure = 'Present' + } + VhdPath = 'TestDrive:\VhdDoesNotExist.vhdx' + ExpectedResult = @{ + FileDirectory = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + DestinationPath = 'TestDrive:\VhdDoesNotExist.vhdx' + Ensure = 'Absent' + } + VhdPath = 'TestDrive:\VhdDoesNotExist.vhdx' + } + } + ) + #endRegion + + It 'Should correctly return state when: ' -TestCases $testCases_Get { + param( + $FileDirectoryProperties, + $VhdPath, + $ExpectedResult + ) + + $result = Get-TargetResource -VhdPath $VhdPath -FileDirectory $FileDirectoryProperties + + $result['FileDirectory'].CimInstanceProperties.Value | + Should -Be $ExpectedResult['FileDirectory'].CimInstanceProperties.Value + + $result['VhdPath'] | + Should -Be $ExpectedResult['VhdPath'] + } +} + +Describe "MSFT_xVhdFileDirectory\Test-TargetResource" -Tag 'Test' { + + BeforeAll { + New-TestDriveLayout -DriveLetter $script:vhdDriveLetter + } + + AfterAll { + Remove-PSDrive $script:vhdDriveLetter -ErrorAction SilentlyContinue + } + + Context 'When the system is in the desired state' { + + $testCases_Test_InDesiredState = @( + @{ + TestName = 'VhdPath exists, Destination File exists, DestinationPath includes filename' + VhdPath = 'TestDrive:\VhdExists.vhdx' + FileDirectory = ( + New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists.txt' + DestinationPath = '\DestinationDirectoryExists\FileExists.txt' + Ensure = 'Present' + } + ) + } + @{ + TestName = 'VhdPath exists, Destination File exists, "Archive" attribute specified and set on file' + VhdPath = 'TestDrive:\VhdExists.vhdx' + FileDirectory = ( + New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists.txt' + DestinationPath = '\DestinationDirectoryExists\FileExists.txt' + Attributes = 'Archive' + Ensure = 'Present' + } + ) + } + @{ + TestName = 'VhdPath exists, Destination File exists, DestinationPath does not include filename' + VhdPath = 'TestDrive:\VhdExists.vhdx' + FileDirectory = ( + New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists.txt' + DestinationPath = '\DestinationDirectoryExists' + Ensure = 'Present' + } + ) + } + @{ + TestName = 'Source is Directory, exists at destination' + VhdPath = 'TestDrive:\VhdExists.vhdx' + FileDirectory = ( + New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\SourceDirectoryExists' + DestinationPath = '\DestinationDirectoryExists' + Ensure = 'Present' + } + ) + } + ) + + It 'Should return [$true] when ' -TestCases $testCases_Test_InDesiredState { + param ( + $VhdPath, + $FileDirectory + ) + + $result = Test-TargetResource -VhdPath $VhdPath -FileDirectory $FileDirectory + $result | Should -Be $true + } + } + + Context 'When the system is not in the desired state' { + $testCases_Test_NotInDesiredState = @( + @{ + TestName = 'VhdPath exists, Destination File does not exist, DestinationPath includes Filename' + VhdPath = 'TestDrive:\VhdExists.vhdx' + FileDirectory = ( + New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists.txt' + DestinationPath = '\DestinationDirectoryExists\DoesNotExist.txt' + Ensure = 'Present' + } + ) + } + @{ + TestName = 'VhdPath exists, Destination File does not exist, DestinationPath does not include Filename' + VhdPath = 'TestDrive:\VhdExists.vhdx' + FileDirectory = ( + New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists3.txt' + DestinationPath = '\DestinationDirectoryExists' + Ensure = 'Present' + } + ) + } + @{ + TestName = 'Destination File exists, but "Ensure" is set to "Absent"' + VhdPath = 'TestDrive:\VhdExists.vhdx' + FileDirectory = ( + New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists.txt' + DestinationPath = '\DestinationDirectoryExists\FileExists.txt' + Ensure = 'Absent' + } + ) + } + @{ + TestName = 'Destination File exists, "Archive" attribute specified but not set on file' + VhdPath = 'TestDrive:\VhdExists.vhdx' + FileDirectory = ( + New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists2.txt' + DestinationPath = '\DestinationDirectoryExists\FileExists2.txt' + Attributes = 'Archive' + Ensure = 'Present' + } + ) + } + ) + + It 'Should return [$false] when ' -TestCases $testCases_Test_NotInDesiredState { + param ( + $VhdPath, + $FileDirectory + ) + + $result = Test-TargetResource -VhdPath $VhdPath -FileDirectory $FileDirectory + $result | Should -Be $false + } + + It 'Should throw error when VhdPath does not exist' { + $vhdPath = 'TestDrive:\VhdDoesNotExist.vhdx' + $fileDirectory = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists.txt' + DestinationPath = '\DestinationDirectoryExists\DoesNotExist.txt' + Ensure = 'Present' + } + { Test-TargetResource -VhdPath $vhdPath -FileDirectory $fileDirectory } | + Should -Throw "VHD does not exist in the specified path $vhdPath" + } + } +} + +Describe "MSFT_xVhdFileDirectory\Set-TargetResource" -Tag 'Set' { + BeforeAll { + New-TestDriveLayout -DriveLetter $script:vhdDriveLetter + } + + AfterAll { + Remove-PSDrive $script:vhdDriveLetter -ErrorAction SilentlyContinue + } + + Context 'When the system is in the desired state' { + $testCases_Set_InDesiredState = @( + @{ + TestName = 'not throw' + VhdPath = 'TestDrive:\VhdExists.vhdx' + FileDirectory = ( + New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists.txt' + DestinationPath = '\DestinationDirectoryExists\FileExists.txt' + Ensure = 'Present' + } + ) + ExpectedResult = $null + } + ) + + It 'Should ' -TestCases $testCases_Set_InDesiredState { + param ( + $VhdPath, + $FileDirectory, + $ExpectedResult + ) + + { Set-TargetResource -VhdPath $VhdPath -FileDirectory $FileDirectory } | Should -Not -throw + } + } + + Context 'When the system is not in the desired state' { + + It 'Should copy the source file to DestinationPath' { + $vhdPath = 'TestDrive:\VhdExists.vhdx' + $fileDirectory = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists.txt' + DestinationPath = '\DestinationDirectoryExists\FileDoesNotExist.txt' + Ensure = 'Present' + } + + Set-TargetResource -VhdPath $VhdPath -FileDirectory $FileDirectory + + (Get-FileHash TestDrive:\FileExists.txt).Hash | + Should -Be (Get-FileHash TestDrive:\MockVhdRoot\DestinationDirectoryExists\FileDoesNotExist.txt).hash + } + + It 'Should Insert content into file when "Content" is specified' { + $vhdPath = 'TestDrive:\VhdExists.vhdx' + $fileDirectory = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + Content = 'This is some text' + DestinationPath = '\DestinationDirectoryExists\FileDoesNotExist2.txt' + Ensure = 'Present' + } + + Set-TargetResource -VhdPath $vhdPath -FileDirectory $fileDirectory + + Get-Content TestDrive:\MockVhdRoot\DestinationDirectoryExists\FileDoesNotExist2.txt | + Should -Be 'This is some text' + } + + It 'Should set "hidden" attribute when specified for nonexistent file' { + $vhdPath = 'TestDrive:\VhdExists.vhdx' + $fileDirectory = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists.txt' + DestinationPath = '\DestinationDirectoryExists\FileDoesNotExist3.txt' + Ensure = 'Present' + Attributes = 'Hidden' + } + + Set-TargetResource -VhdPath $vhdPath -FileDirectory $fileDirectory + + (Get-Item TestDrive:\MockVhdRoot\DestinationDirectoryExists\FileDoesNotExist3.txt -Force).Attributes | + Should -Be 'Hidden' + } + + It 'Should remove the file when "Ensure" is set to "Absent"' { + $vhdPath = 'TestDrive:\VhdExists.vhdx' + $fileDirectory = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists.txt' + DestinationPath = '\DestinationDirectoryExists\FileExists.txt' + Ensure = 'Absent' + } + + Set-TargetResource -VhdPath $vhdPath -FileDirectory $fileDirectory + + Test-Path TestDrive:\MockVhdRoot\DestinationDirectoryExists\FileExists.txt | + Should -Be $false + } + + It 'Should throw error when VhdPath does not exist' { + $vhdPath = 'TestDrive:\VhdDoesNotExist.vhdx' + $fileDirectory = New-CimInstance -ClassName $script:dscFileDirClassName -Namespace $script:dscNamespace -ClientOnly -Property @{ + SourcePath = 'TestDrive:\FileExists.txt' + DestinationPath = '\DestinationDirectoryDoesNotExist\FileDoesNotExist.txt' + Ensure = 'Present' + } + + { Set-TargetResource -VhdPath $vhdPath -FileDirectory $fileDirectory } | + Should -Throw "Specified destination path $vhdPath does not exist!" + } + } +} +} +} +finally +{ + Invoke-TestCleanup +} diff --git a/tests/Unit/Stubs/Hyper-V.stubs.psm1 b/tests/Unit/Stubs/Hyper-V.stubs.psm1 new file mode 100644 index 0000000..5f070ed --- /dev/null +++ b/tests/Unit/Stubs/Hyper-V.stubs.psm1 @@ -0,0 +1,20501 @@ +# Name: Hyper-V +# Version: 2.0.0.0 +# CreatedOn: 2020-03-08 16:10:56Z +Add-Type -IgnoreWarnings -ReferencedAssemblies 'C:\Program Files (x86)\Reference Assemblies\Microsoft\WMI\v1.0\Microsoft.Management.Infrastructure.dll' -TypeDefinition @' + +namespace Microsoft.HyperV.PowerShell +{ + public enum BootDevice : int + { + Floppy = 0, + CD = 1, + IDE = 2, + LegacyNetworkAdapter = 3, + NetworkAdapter = 4, + VHD = 5, + } + + public enum CacheAttributes : int + { + Default = 0, + WriteCacheEnabled = 1, + WriteCacheAndFUAEnabled = 2, + WriteCacheDisabled = 3, + } + + public enum CaptureLiveState : int + { + CaptureCrashConsistentState = 0, + CaptureSavedState = 1, + CaptureDataConsistentState = 2, + } + + public enum CheckpointType : int + { + Disabled = 2, + Production = 3, + ProductionOnly = 4, + Standard = 5, + } + + public enum ConsoleModeType : int + { + Default = 0, + COM1 = 1, + COM2 = 2, + None = 3, + } + + public enum ControllerType : int + { + IDE = 0, + SCSI = 1, + PMEM = 2, + } + + public enum CopyFileSourceType : int + { + Host = 0, + } + + public enum CriticalErrorAction : int + { + None = 0, + Pause = 1, + } + + public class Drive + { + public bool IsSecondaryStubType = true; + + public Drive() { } + } + + public class DvdDrive + { + // Property + public Microsoft.HyperV.PowerShell.DvdMediaType DvdMediaType { get; set; } + public System.String Path { get; set; } + public System.Int32 ControllerLocation { get; set; } + public System.Int32 ControllerNumber { get; set; } + public Microsoft.HyperV.PowerShell.ControllerType ControllerType { get; set; } + public System.String Name { get; set; } + public System.String PoolName { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private DvdDrive() { } + public static DvdDrive CreateTypeInstance() + { + return new DvdDrive(); + } + } + + public enum DvdMediaType : int + { + None = 0, + ISO = 1, + PassThrough = 2, + } + + public enum EnhancedSessionTransportType : int + { + VMBus = 0, + HvSocket = 1, + } + + public enum GroupType : int + { + VMCollectionType = 0, + ManagementCollectionType = 1, + } + + public class HardDiskDrive : Drive + { + // Property + public System.String Path { get; set; } + public System.Nullable DiskNumber { get; set; } + public System.Nullable MaximumIOPS { get; set; } + public System.Nullable MinimumIOPS { get; set; } + public System.Nullable QoSPolicyID { get; set; } + public System.Nullable SupportPersistentReservations { get; set; } + public System.Nullable WriteHardeningMethod { get; set; } + public System.Int32 ControllerLocation { get; set; } + public System.Int32 ControllerNumber { get; set; } + public Microsoft.HyperV.PowerShell.ControllerType ControllerType { get; set; } + public System.String Name { get; set; } + public System.String PoolName { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private HardDiskDrive() { } + public static HardDiskDrive CreateTypeInstance() + { + return new HardDiskDrive(); + } + } + + public enum IovInterruptModerationValue : int + { + Default = 0, + Adaptive = 1, + Off = 2, + Low = 100, + Medium = 200, + High = 300, + } + + public enum IPProtocolPreference : int + { + IPv4 = 0, + IPv6 = 1, + } + + public class KeyStorageDrive + { + // Property + public System.Int32 ControllerLocation { get; set; } + public System.Int32 ControllerNumber { get; set; } + public Microsoft.HyperV.PowerShell.ControllerType ControllerType { get; set; } + public System.String Name { get; set; } + public System.String Path { get; set; } + public System.String PoolName { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private KeyStorageDrive() { } + public static KeyStorageDrive CreateTypeInstance() + { + return new KeyStorageDrive(); + } + } + + public enum MigrationAuthenticationType : int + { + CredSSP = 0, + Kerberos = 1, + } + + public enum OnOffState : int + { + On = 0, + Off = 1, + } + + public enum OperationType : int + { + MoveVirtualMachine = 0, + ImportVirtualMachine = 1, + MoveVirtualMachineAndStorage = 2, + } + + public enum RecoveryAuthenticationType : int + { + Kerberos = 1, + Certificate = 2, + CertificateAndKerberos = 3, + } + + public enum ReplicationAuthenticationType : int + { + Kerberos = 1, + Certificate = 2, + } + + public enum ResolutionType : int + { + Maximum = 2, + Single = 3, + Default = 4, + } + + public enum SnapshotType : int + { + Standard = 0, + Recovery = 1, + Planned = 2, + Missing = 5, + Replica = 6, + AppConsistentReplica = 7, + SyncedReplica = 8, + } + + public enum StartAction : int + { + Nothing = 2, + StartIfRunning = 3, + Start = 4, + } + + public enum StopAction : int + { + TurnOff = 2, + Save = 3, + ShutDown = 4, + } + + public enum ThreadCount : int + { + Automatic = 0, + Low = 1, + Medium = 2, + High = 3, + } + + public class VHDMetrics + { + public bool IsSecondaryStubType = true; + + public VHDMetrics() { } + } + + public class VirtualMachine + { + // Property + public System.String ConfigurationLocation { get; set; } + public System.Boolean SmartPagingFileInUse { get; set; } + public System.String SmartPagingFilePath { get; set; } + public System.String SnapshotFileLocation { get; set; } + public Microsoft.HyperV.PowerShell.StartAction AutomaticStartAction { get; set; } + public System.Int32 AutomaticStartDelay { get; set; } + public Microsoft.HyperV.PowerShell.StopAction AutomaticStopAction { get; set; } + public Microsoft.HyperV.PowerShell.CriticalErrorAction AutomaticCriticalErrorAction { get; set; } + public System.Int32 AutomaticCriticalErrorActionTimeout { get; set; } + public System.Boolean AutomaticCheckpointsEnabled { get; set; } + public System.Int32 CPUUsage { get; set; } + public System.Int64 MemoryAssigned { get; set; } + public System.Int64 MemoryDemand { get; set; } + public System.String MemoryStatus { get; set; } + public System.Nullable NumaAligned { get; set; } + public System.Int32 NumaNodesCount { get; set; } + public System.Int32 NumaSocketCount { get; set; } + public System.Nullable Heartbeat { get; set; } + public System.String IntegrationServicesState { get; set; } + public System.Version IntegrationServicesVersion { get; set; } + public System.TimeSpan Uptime { get; set; } + public Microsoft.HyperV.PowerShell.VMOperationalStatus[] OperationalStatus { get; set; } + public System.Nullable PrimaryOperationalStatus { get; set; } + public System.Nullable SecondaryOperationalStatus { get; set; } + public System.String[] StatusDescriptions { get; set; } + public System.String PrimaryStatusDescription { get; set; } + public System.String SecondaryStatusDescription { get; set; } + public System.String Status { get; set; } + public Microsoft.HyperV.PowerShell.VMReplicationHealthState ReplicationHealth { get; set; } + public Microsoft.HyperV.PowerShell.VMReplicationMode ReplicationMode { get; set; } + public Microsoft.HyperV.PowerShell.VMReplicationState ReplicationState { get; set; } + public System.Boolean ResourceMeteringEnabled { get; set; } + public Microsoft.HyperV.PowerShell.CheckpointType CheckpointType { get; set; } + public Microsoft.HyperV.PowerShell.EnhancedSessionTransportType EnhancedSessionTransportType { get; set; } + public System.Collections.Generic.IReadOnlyList Groups { get; set; } + public System.String Version { get; set; } + public Microsoft.HyperV.PowerShell.VirtualMachineType VirtualMachineType { get; set; } + public Microsoft.HyperV.PowerShell.VirtualMachineSubType VirtualMachineSubType { get; set; } + public System.String Notes { get; set; } + public Microsoft.HyperV.PowerShell.VMState State { get; set; } + public Microsoft.HyperV.PowerShell.VMComPort ComPort1 { get; set; } + public Microsoft.HyperV.PowerShell.VMComPort ComPort2 { get; set; } + public Microsoft.HyperV.PowerShell.DvdDrive[] DVDDrives { get; set; } + public System.Collections.Generic.List FibreChannelHostBusAdapters { get; set; } + public Microsoft.HyperV.PowerShell.VMFloppyDiskDrive FloppyDrive { get; set; } + public Microsoft.HyperV.PowerShell.HardDiskDrive[] HardDrives { get; set; } + public Microsoft.HyperV.PowerShell.VMRemoteFx3DVideoAdapter RemoteFxAdapter { get; set; } + public System.Collections.Generic.List VMIntegrationService { get; set; } + public System.Boolean DynamicMemoryEnabled { get; set; } + public System.Int64 MemoryMaximum { get; set; } + public System.Int64 MemoryMinimum { get; set; } + public System.Int64 MemoryStartup { get; set; } + public System.Int64 ProcessorCount { get; set; } + public System.Boolean BatteryPassthroughEnabled { get; set; } + public System.Int32 Generation { get; set; } + public System.Boolean IsClustered { get; set; } + public System.Nullable ParentSnapshotId { get; set; } + public System.String ParentSnapshotName { get; set; } + public System.String Path { get; set; } + public System.Int64 SizeOfSystemFiles { get; set; } + public System.Boolean GuestControlledCacheTypes { get; set; } + public System.UInt32 LowMemoryMappedIoSpace { get; set; } + public System.UInt64 HighMemoryMappedIoSpace { get; set; } + public System.Nullable LockOnDisconnect { get; set; } + public System.DateTime CreationTime { get; set; } + public System.Guid Id { get; set; } + public System.String Name { get; set; } + public System.Collections.Generic.List NetworkAdapters { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VirtualMachine() { } + public static VirtualMachine CreateTypeInstance() + { + return new VirtualMachine(); + } + } + + public class VirtualMachineBase + { + // Property + public Microsoft.HyperV.PowerShell.VMComPort ComPort1 { get; set; } + public Microsoft.HyperV.PowerShell.VMComPort ComPort2 { get; set; } + public Microsoft.HyperV.PowerShell.DvdDrive[] DVDDrives { get; set; } + public System.Collections.Generic.List FibreChannelHostBusAdapters { get; set; } + public Microsoft.HyperV.PowerShell.VMFloppyDiskDrive FloppyDrive { get; set; } + public Microsoft.HyperV.PowerShell.HardDiskDrive[] HardDrives { get; set; } + public Microsoft.HyperV.PowerShell.VMRemoteFx3DVideoAdapter RemoteFxAdapter { get; set; } + public System.Collections.Generic.List VMIntegrationService { get; set; } + public System.Boolean DynamicMemoryEnabled { get; set; } + public System.Int64 MemoryMaximum { get; set; } + public System.Int64 MemoryMinimum { get; set; } + public System.Int64 MemoryStartup { get; set; } + public System.Int64 ProcessorCount { get; set; } + public System.Boolean BatteryPassthroughEnabled { get; set; } + public System.Int32 Generation { get; set; } + public System.Boolean IsClustered { get; set; } + public System.String Notes { get; set; } + public System.Nullable ParentSnapshotId { get; set; } + public System.String ParentSnapshotName { get; set; } + public System.String Path { get; set; } + public System.Int64 SizeOfSystemFiles { get; set; } + public Microsoft.HyperV.PowerShell.VMState State { get; set; } + public System.String Version { get; set; } + public System.Boolean GuestControlledCacheTypes { get; set; } + public System.UInt32 LowMemoryMappedIoSpace { get; set; } + public System.UInt64 HighMemoryMappedIoSpace { get; set; } + public System.Nullable LockOnDisconnect { get; set; } + public System.DateTime CreationTime { get; set; } + public System.Guid Id { get; set; } + public System.String Name { get; set; } + public System.Collections.Generic.List NetworkAdapters { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VirtualMachineBase() { } + public static VirtualMachineBase CreateTypeInstance() + { + return new VirtualMachineBase(); + } + } + + public enum VirtualMachineSubType : int + { + Unknown = 0, + Generation1 = 1, + Generation2 = 2, + } + + public enum VirtualMachineType : int + { + RealizedVirtualMachine = 3, + PlannedVirtualMachine = 4, + } + + public class VMAssignedDevice + { + // Property + public System.String InstanceID { get; set; } + public System.String LocationPath { get; set; } + public System.String ResourcePoolName { get; set; } + public System.UInt16 VirtualFunction { get; set; } + public System.String Name { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMAssignedDevice() { } + public static VMAssignedDevice CreateTypeInstance() + { + return new VMAssignedDevice(); + } + } + + public class VMBios + { + // Property + public System.Boolean NumLockEnabled { get; set; } + public Microsoft.HyperV.PowerShell.BootDevice[] StartupOrder { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMBios() { } + public static VMBios CreateTypeInstance() + { + return new VMBios(); + } + } + + public class VMBootSource + { + public bool IsSecondaryStubType = true; + + public VMBootSource() { } + } + + public class VMCompatibilityError + { + public bool IsSecondaryStubType = true; + + public VMCompatibilityError() { } + } + + public class VMCompatibilityReport + { + // Property + public Microsoft.HyperV.PowerShell.VirtualMachine VM { get; set; } + public Microsoft.HyperV.PowerShell.OperationType OperationType { get; set; } + public System.String Destination { get; set; } + public System.String Path { get; set; } + public System.String SnapshotPath { get; set; } + public System.String VhdDestinationPath { get; set; } + public System.String VhdSourcePath { get; set; } + public Microsoft.HyperV.PowerShell.VMCompatibilityError[] Incompatibilities { get; set; } + + // Fabricated constructor + private VMCompatibilityReport() { } + public static VMCompatibilityReport CreateTypeInstance() + { + return new VMCompatibilityReport(); + } + } + + public class VMComponentObject + { + // Property + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMComponentObject() { } + public static VMComponentObject CreateTypeInstance() + { + return new VMComponentObject(); + } + } + + public class VMComPort + { + // Property + public System.String Path { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState DebuggerMode { get; set; } + public System.String Name { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMComPort() { } + public static VMComPort CreateTypeInstance() + { + return new VMComPort(); + } + } + + public class VMConnectAce + { + // Property + public System.String UserName { get; set; } + public System.Security.Principal.SecurityIdentifier UserId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMId { get; set; } + public System.String ComputerName { get; set; } + public Microsoft.HyperV.PowerShell.VMConnectAceAccessType Access { get; set; } + + // Fabricated constructor + private VMConnectAce() { } + public static VMConnectAce CreateTypeInstance() + { + return new VMConnectAce(); + } + } + + public enum VMConnectAceAccessType : int + { + Allowed = 0, + Denied = 1, + } + + public class VMCurrentTask + { + public bool IsSecondaryStubType = true; + + public VMCurrentTask() { } + } + + public class VMDriveController + { + // Property + public System.Int32 ControllerNumber { get; set; } + public Microsoft.HyperV.PowerShell.Drive[] Drives { get; set; } + public System.String Name { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMDriveController() { } + public static VMDriveController CreateTypeInstance() + { + return new VMDriveController(); + } + } + + public class VMExternalNetworkAdapter + { + public bool IsSecondaryStubType = true; + + public VMExternalNetworkAdapter() { } + } + + public class VMFibreChannelHba + { + // Property + public System.String SanName { get; set; } + public System.String WorldWideNodeNameSetA { get; set; } + public System.String WorldWidePortNameSetA { get; set; } + public System.String WorldWideNodeNameSetB { get; set; } + public System.String WorldWidePortNameSetB { get; set; } + public System.Boolean IsTemplate { get; set; } + public System.String Name { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMFibreChannelHba() { } + public static VMFibreChannelHba CreateTypeInstance() + { + return new VMFibreChannelHba(); + } + } + + public class VMFirmware + { + // Property + public Microsoft.HyperV.PowerShell.VMBootSource[] BootOrder { get; set; } + public Microsoft.HyperV.PowerShell.IPProtocolPreference PreferredNetworkBootProtocol { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState SecureBoot { get; set; } + public System.Nullable SecureBootTemplateId { get; set; } + public System.String SecureBootTemplate { get; set; } + public Microsoft.HyperV.PowerShell.ConsoleModeType ConsoleMode { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState PauseAfterBootFailure { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMFirmware() { } + public static VMFirmware CreateTypeInstance() + { + return new VMFirmware(); + } + } + + public class VMFloppyDiskDrive + { + // Property + public System.String Path { get; set; } + public System.String PoolName { get; set; } + public System.String Name { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMFloppyDiskDrive() { } + public static VMFloppyDiskDrive CreateTypeInstance() + { + return new VMFloppyDiskDrive(); + } + } + + public class VMGpuPartitionAdapter + { + // Property + public System.Nullable MinPartitionVRAM { get; set; } + public System.Nullable MaxPartitionVRAM { get; set; } + public System.Nullable OptimalPartitionVRAM { get; set; } + public System.Nullable MinPartitionEncode { get; set; } + public System.Nullable MaxPartitionEncode { get; set; } + public System.Nullable OptimalPartitionEncode { get; set; } + public System.Nullable MinPartitionDecode { get; set; } + public System.Nullable MaxPartitionDecode { get; set; } + public System.Nullable OptimalPartitionDecode { get; set; } + public System.Nullable MinPartitionCompute { get; set; } + public System.Nullable MaxPartitionCompute { get; set; } + public System.Nullable OptimalPartitionCompute { get; set; } + public System.String Name { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMGpuPartitionAdapter() { } + public static VMGpuPartitionAdapter CreateTypeInstance() + { + return new VMGpuPartitionAdapter(); + } + } + + public class VMGroup + { + // Property + public System.String Name { get; set; } + public System.Guid InstanceId { get; set; } + public Microsoft.HyperV.PowerShell.GroupType GroupType { get; set; } + public System.Collections.Generic.IReadOnlyList VMMembers { get; set; } + public System.Collections.Generic.IReadOnlyList VMGroupMembers { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMGroup() { } + public static VMGroup CreateTypeInstance() + { + return new VMGroup(); + } + } + + public enum VMHeartbeatStatus : int + { + Unknown = 0, + Disabled = 1, + NoContact = 2, + Error = 3, + LostCommunication = 4, + OkApplicationsUnknown = 5, + OkApplicationsHealthy = 6, + OkApplicationsCritical = 7, + Paused = 8, + } + + public class VMHost + { + // Property + public System.Int32 LogicalProcessorCount { get; set; } + public System.TimeSpan ResourceMeteringSaveInterval { get; set; } + public Microsoft.HyperV.PowerShell.VMHostNumaNode[] HostNumaStatus { get; set; } + public Microsoft.HyperV.PowerShell.VMNumaNodeStatus[] NumaStatus { get; set; } + public System.Boolean IovSupport { get; set; } + public System.String[] IovSupportReasons { get; set; } + public System.Collections.Generic.List InternalNetworkAdapters { get; set; } + public System.Collections.Generic.List ExternalNetworkAdapters { get; set; } + public System.Collections.Generic.IReadOnlyList SupportedVmVersions { get; set; } + public System.Collections.Generic.IReadOnlyList SecureBootTemplates { get; set; } + public System.Boolean EnableEnhancedSessionMode { get; set; } + public System.String FibreChannelWwnn { get; set; } + public System.String FibreChannelWwpnMaximum { get; set; } + public System.String FibreChannelWwpnMinimum { get; set; } + public System.String MacAddressMaximum { get; set; } + public System.String MacAddressMinimum { get; set; } + public System.Boolean NumaSpanningEnabled { get; set; } + public System.String VirtualHardDiskPath { get; set; } + public System.String VirtualMachinePath { get; set; } + public System.String FullyQualifiedDomainName { get; set; } + public System.Int64 MemoryCapacity { get; set; } + public System.String Name { get; set; } + public System.UInt32 MaximumStorageMigrations { get; set; } + public System.UInt32 MaximumVirtualMachineMigrations { get; set; } + public System.Boolean UseAnyNetworkForMigration { get; set; } + public Microsoft.HyperV.PowerShell.MigrationAuthenticationType VirtualMachineMigrationAuthenticationType { get; set; } + public System.Boolean VirtualMachineMigrationEnabled { get; set; } + public Microsoft.HyperV.PowerShell.VMMigrationPerformance VirtualMachineMigrationPerformanceOption { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMHost() { } + public static VMHost CreateTypeInstance() + { + return new VMHost(); + } + } + + public class VMHostAssignableDevice + { + // Property + public System.String InstanceID { get; set; } + public System.String LocationPath { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMHostAssignableDevice() { } + public static VMHostAssignableDevice CreateTypeInstance() + { + return new VMHostAssignableDevice(); + } + } + + public class VMHostCluster + { + // Property + public System.String ClusterName { get; set; } + public System.String SharedStoragePath { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMHostCluster() { } + public static VMHostCluster CreateTypeInstance() + { + return new VMHostCluster(); + } + } + + public class VMHostNumaNode + { + // Property + public System.Int32 NodeId { get; set; } + public System.Int32[] ProcessorsAvailability { get; set; } + public System.Int32 MemoryAvailable { get; set; } + public System.Int32 MemoryTotal { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMHostNumaNode() { } + public static VMHostNumaNode CreateTypeInstance() + { + return new VMHostNumaNode(); + } + } + + public class VMHostSupportedVersion + { + // Property + public System.String Name { get; set; } + public System.Version Version { get; set; } + public System.Boolean IsDefault { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMHostSupportedVersion() { } + public static VMHostSupportedVersion CreateTypeInstance() + { + return new VMHostSupportedVersion(); + } + } + + public class VMIdeController + { + // Property + public System.Int32 ControllerNumber { get; set; } + public Microsoft.HyperV.PowerShell.Drive[] Drives { get; set; } + public System.String Name { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMIdeController() { } + public static VMIdeController CreateTypeInstance() + { + return new VMIdeController(); + } + } + + public class VMIntegrationComponent + { + // Property + public System.Boolean Enabled { get; set; } + public Microsoft.HyperV.PowerShell.VMIntegrationComponentOperationalStatus[] OperationalStatus { get; set; } + public System.Nullable PrimaryOperationalStatus { get; set; } + public System.String PrimaryStatusDescription { get; set; } + public System.Nullable SecondaryOperationalStatus { get; set; } + public System.String SecondaryStatusDescription { get; set; } + public System.String[] StatusDescription { get; set; } + public System.String Name { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMIntegrationComponent() { } + public static VMIntegrationComponent CreateTypeInstance() + { + return new VMIntegrationComponent(); + } + } + + public enum VMIntegrationComponentOperationalStatus : int + { + Ok = 2, + Degraded = 3, + Error = 6, + NonRecoverableError = 7, + NoContact = 12, + LostCommunication = 13, + ProtocolMismatch = 32775, + ApplicationCritical = 32782, + CommunicationTimedOut = 32783, + CommunicationFailed = 32784, + Disabled = 32896, + } + + public class VMInternalNetworkAdapter + { + // Property + public System.Boolean IsManagementOs { get; set; } + public System.String MacAddress { get; set; } + public System.String DeviceId { get; set; } + public System.String AdapterId { get; set; } + public System.String Name { get; set; } + public System.String SwitchName { get; set; } + public System.String[] StatusDescription { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterOperationalStatus[] Status { get; set; } + public System.Boolean IsExternalAdapter { get; set; } + public System.String Id { get; set; } + public System.Nullable SwitchId { get; set; } + public System.Collections.Generic.List AclList { get; set; } + public System.Collections.Generic.List ExtendedAclList { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterIsolationSetting IsolationSetting { get; set; } + public System.Collections.Generic.List RoutingDomainList { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterVlanSetting VlanSetting { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterBandwidthSetting BandwidthSetting { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterIsolationMode CurrentIsolationMode { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState MacAddressSpoofing { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState DhcpGuard { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState RouterGuard { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterPortMirroringMode PortMirroringMode { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState IeeePriorityTag { get; set; } + public System.UInt32 VirtualSubnetId { get; set; } + public System.UInt32 DynamicIPAddressLimit { get; set; } + public System.UInt32 StormLimit { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState AllowTeaming { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState FixSpeed10G { get; set; } + public System.UInt32 VMQWeight { get; set; } + public System.Int64 IPsecOffloadMaxSA { get; set; } + public System.Boolean VrssEnabled { get; set; } + public System.Boolean VrssEnabledRequested { get; set; } + public System.Boolean VmmqEnabled { get; set; } + public System.Boolean VmmqEnabledRequested { get; set; } + public System.UInt32 VrssMaxQueuePairs { get; set; } + public System.UInt32 VrssMaxQueuePairsRequested { get; set; } + public System.UInt32 VrssMinQueuePairs { get; set; } + public System.UInt32 VrssMinQueuePairsRequested { get; set; } + public Microsoft.HyperV.PowerShell.VrssQueueSchedulingModeType VrssQueueSchedulingMode { get; set; } + public Microsoft.HyperV.PowerShell.VrssQueueSchedulingModeType VrssQueueSchedulingModeRequested { get; set; } + public System.Boolean VrssExcludePrimaryProcessor { get; set; } + public System.Boolean VrssExcludePrimaryProcessorRequested { get; set; } + public System.Boolean VrssIndependentHostSpreading { get; set; } + public System.Boolean VrssIndependentHostSpreadingRequested { get; set; } + public Microsoft.HyperV.PowerShell.VrssVmbusChannelAffinityPolicyType VrssVmbusChannelAffinityPolicy { get; set; } + public Microsoft.HyperV.PowerShell.VrssVmbusChannelAffinityPolicyType VrssVmbusChannelAffinityPolicyRequested { get; set; } + public System.Int32 VmqUsage { get; set; } + public System.UInt32 IPsecOffloadSAUsage { get; set; } + public System.Boolean VFDataPathActive { get; set; } + public Microsoft.Management.Infrastructure.CimInstance VMQueue { get; set; } + public System.UInt32 BandwidthPercentage { get; set; } + public System.Boolean IsTemplate { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMInternalNetworkAdapter() { } + public static VMInternalNetworkAdapter CreateTypeInstance() + { + return new VMInternalNetworkAdapter(); + } + } + + public class VMMemory + { + // Property + public System.String ResourcePoolName { get; set; } + public System.Int32 Buffer { get; set; } + public System.Boolean DynamicMemoryEnabled { get; set; } + public System.Int64 Maximum { get; set; } + public System.Int64 MaximumPerNumaNode { get; set; } + public System.Int64 Minimum { get; set; } + public System.Int32 Priority { get; set; } + public System.Int64 Startup { get; set; } + public System.String Name { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMMemory() { } + public static VMMemory CreateTypeInstance() + { + return new VMMemory(); + } + } + + public class VMMeteringReportForResourcePool + { + // Property + public System.String ResourcePoolName { get; set; } + public Microsoft.HyperV.PowerShell.VMResourcePoolType[] ResourcePoolType { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Nullable MeteringDuration { get; set; } + public System.Nullable AverageProcessorUsage { get; set; } + public System.Nullable AverageMemoryUsage { get; set; } + public System.Nullable MaximumMemoryUsage { get; set; } + public System.Nullable MinimumMemoryUsage { get; set; } + public System.Nullable TotalDiskAllocation { get; set; } + public System.Nullable AggregatedAverageNormalizedIOPS { get; set; } + public System.Nullable AggregatedAverageLatency { get; set; } + public System.Nullable AggregatedDiskDataRead { get; set; } + public System.Nullable AggregatedDiskDataWritten { get; set; } + public System.Nullable AggregatedNormalizedIOCount { get; set; } + public Microsoft.HyperV.PowerShell.VMPortAclMeteringReport[] NetworkMeteredTrafficReport { get; set; } + public Microsoft.HyperV.PowerShell.VHDMetrics[] HardDiskMetrics { get; set; } + + // Fabricated constructor + private VMMeteringReportForResourcePool() { } + public static VMMeteringReportForResourcePool CreateTypeInstance() + { + return new VMMeteringReportForResourcePool(); + } + } + + public class VMMeteringReportForVirtualMachine + { + // Property + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Nullable MeteringDuration { get; set; } + public System.Nullable AverageProcessorUsage { get; set; } + public System.Nullable AverageMemoryUsage { get; set; } + public System.Nullable MaximumMemoryUsage { get; set; } + public System.Nullable MinimumMemoryUsage { get; set; } + public System.Nullable TotalDiskAllocation { get; set; } + public System.Nullable AggregatedAverageNormalizedIOPS { get; set; } + public System.Nullable AggregatedAverageLatency { get; set; } + public System.Nullable AggregatedDiskDataRead { get; set; } + public System.Nullable AggregatedDiskDataWritten { get; set; } + public System.Nullable AggregatedNormalizedIOCount { get; set; } + public Microsoft.HyperV.PowerShell.VMPortAclMeteringReport[] NetworkMeteredTrafficReport { get; set; } + public Microsoft.HyperV.PowerShell.VHDMetrics[] HardDiskMetrics { get; set; } + + // Fabricated constructor + private VMMeteringReportForVirtualMachine() { } + public static VMMeteringReportForVirtualMachine CreateTypeInstance() + { + return new VMMeteringReportForVirtualMachine(); + } + } + + public class VMMigrationNetwork + { + // Property + public System.String Subnet { get; set; } + public System.Nullable Priority { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMMigrationNetwork() { } + public static VMMigrationNetwork CreateTypeInstance() + { + return new VMMigrationNetwork(); + } + } + + public enum VMMigrationPerformance : int + { + TCPIP = 0, + Compression = 1, + SMB = 2, + } + + public class VMNetworkAdapter + { + // Property + public System.Boolean ClusterMonitored { get; set; } + public System.String MacAddress { get; set; } + public System.UInt32 MediaType { get; set; } + public System.Boolean DynamicMacAddressEnabled { get; set; } + public System.Boolean InterruptModeration { get; set; } + public System.Boolean AllowPacketDirect { get; set; } + public System.Boolean NumaAwarePlacement { get; set; } + public System.Boolean IsLegacy { get; set; } + public System.Boolean IsSynthetic { get; set; } + public System.String[] IPAddresses { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState DeviceNaming { get; set; } + public System.UInt32 IovWeight { get; set; } + public System.UInt32 IovQueuePairsRequested { get; set; } + public Microsoft.HyperV.PowerShell.IovInterruptModerationValue IovInterruptModeration { get; set; } + public System.UInt32 PacketDirectNumProcs { get; set; } + public System.UInt32 PacketDirectModerationCount { get; set; } + public System.UInt32 PacketDirectModerationInterval { get; set; } + public System.UInt32 IovQueuePairsAssigned { get; set; } + public System.Int32 IovUsage { get; set; } + public Microsoft.Management.Infrastructure.CimInstance VirtualFunction { get; set; } + public System.String[] MandatoryFeatureId { get; set; } + public System.String[] MandatoryFeatureName { get; set; } + public System.String PoolName { get; set; } + public System.Boolean Connected { get; set; } + public System.String SwitchName { get; set; } + public System.String AdapterId { get; set; } + public System.String TestReplicaPoolName { get; set; } + public System.String TestReplicaSwitchName { get; set; } + public System.String[] StatusDescription { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterOperationalStatus[] Status { get; set; } + public System.Boolean IsManagementOs { get; set; } + public System.Boolean IsExternalAdapter { get; set; } + public System.String Id { get; set; } + public System.Nullable SwitchId { get; set; } + public System.Collections.Generic.List AclList { get; set; } + public System.Collections.Generic.List ExtendedAclList { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterIsolationSetting IsolationSetting { get; set; } + public System.Collections.Generic.List RoutingDomainList { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterVlanSetting VlanSetting { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterBandwidthSetting BandwidthSetting { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterIsolationMode CurrentIsolationMode { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState MacAddressSpoofing { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState DhcpGuard { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState RouterGuard { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterPortMirroringMode PortMirroringMode { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState IeeePriorityTag { get; set; } + public System.UInt32 VirtualSubnetId { get; set; } + public System.UInt32 DynamicIPAddressLimit { get; set; } + public System.UInt32 StormLimit { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState AllowTeaming { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState FixSpeed10G { get; set; } + public System.UInt32 VMQWeight { get; set; } + public System.Int64 IPsecOffloadMaxSA { get; set; } + public System.Boolean VrssEnabled { get; set; } + public System.Boolean VrssEnabledRequested { get; set; } + public System.Boolean VmmqEnabled { get; set; } + public System.Boolean VmmqEnabledRequested { get; set; } + public System.UInt32 VrssMaxQueuePairs { get; set; } + public System.UInt32 VrssMaxQueuePairsRequested { get; set; } + public System.UInt32 VrssMinQueuePairs { get; set; } + public System.UInt32 VrssMinQueuePairsRequested { get; set; } + public Microsoft.HyperV.PowerShell.VrssQueueSchedulingModeType VrssQueueSchedulingMode { get; set; } + public Microsoft.HyperV.PowerShell.VrssQueueSchedulingModeType VrssQueueSchedulingModeRequested { get; set; } + public System.Boolean VrssExcludePrimaryProcessor { get; set; } + public System.Boolean VrssExcludePrimaryProcessorRequested { get; set; } + public System.Boolean VrssIndependentHostSpreading { get; set; } + public System.Boolean VrssIndependentHostSpreadingRequested { get; set; } + public Microsoft.HyperV.PowerShell.VrssVmbusChannelAffinityPolicyType VrssVmbusChannelAffinityPolicy { get; set; } + public Microsoft.HyperV.PowerShell.VrssVmbusChannelAffinityPolicyType VrssVmbusChannelAffinityPolicyRequested { get; set; } + public System.Int32 VmqUsage { get; set; } + public System.UInt32 IPsecOffloadSAUsage { get; set; } + public System.Boolean VFDataPathActive { get; set; } + public Microsoft.Management.Infrastructure.CimInstance VMQueue { get; set; } + public System.UInt32 BandwidthPercentage { get; set; } + public System.Boolean IsTemplate { get; set; } + public System.String Name { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMNetworkAdapter() { } + public static VMNetworkAdapter CreateTypeInstance() + { + return new VMNetworkAdapter(); + } + } + + public enum VMNetworkAdapterAclAction : byte + { + Allow = 1, + Deny = 2, + Meter = 3, + } + + public enum VMNetworkAdapterAclDirection : byte + { + Inbound = 1, + Outbound = 2, + Both = 3, + } + + public class VMNetworkAdapterAclSetting + { + // Property + public Microsoft.HyperV.PowerShell.VMNetworkAdapterAclAction Action { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterAclDirection Direction { get; set; } + public System.String LocalAddress { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterAclType LocalAddressType { get; set; } + public System.String MeteredMegabytes { get; set; } + public System.String RemoteAddress { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterAclType RemoteAddressType { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterBase ParentAdapter { get; set; } + public System.Boolean IsTemplate { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMNetworkAdapterAclSetting() { } + public static VMNetworkAdapterAclSetting CreateTypeInstance() + { + return new VMNetworkAdapterAclSetting(); + } + } + + public enum VMNetworkAdapterAclType : byte + { + Mac = 1, + IPv4 = 2, + IPv6 = 3, + WildcardIPv4 = 4, + WildcardIPv6 = 5, + WildcardBoth = 6, + WildcardMac = 7, + } + + public class VMNetworkAdapterBandwidthSetting + { + public bool IsSecondaryStubType = true; + + public VMNetworkAdapterBandwidthSetting() { } + } + + public class VMNetworkAdapterBase + { + // Manually added properties + public System.String MacAddress { get; set; } + + // Property + public System.String SwitchName { get; set; } + public System.String AdapterId { get; set; } + public System.String[] StatusDescription { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterOperationalStatus[] Status { get; set; } + public System.Boolean IsManagementOs { get; set; } + public System.Boolean IsExternalAdapter { get; set; } + public System.String Id { get; set; } + public System.Nullable SwitchId { get; set; } + public System.Collections.Generic.List AclList { get; set; } + public System.Collections.Generic.List ExtendedAclList { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterIsolationSetting IsolationSetting { get; set; } + public System.Collections.Generic.List RoutingDomainList { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterVlanSetting VlanSetting { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterBandwidthSetting BandwidthSetting { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterIsolationMode CurrentIsolationMode { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState MacAddressSpoofing { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState DhcpGuard { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState RouterGuard { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterPortMirroringMode PortMirroringMode { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState IeeePriorityTag { get; set; } + public System.UInt32 VirtualSubnetId { get; set; } + public System.UInt32 DynamicIPAddressLimit { get; set; } + public System.UInt32 StormLimit { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState AllowTeaming { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState FixSpeed10G { get; set; } + public System.UInt32 VMQWeight { get; set; } + public System.Int64 IPsecOffloadMaxSA { get; set; } + public System.Boolean VrssEnabled { get; set; } + public System.Boolean VrssEnabledRequested { get; set; } + public System.Boolean VmmqEnabled { get; set; } + public System.Boolean VmmqEnabledRequested { get; set; } + public System.UInt32 VrssMaxQueuePairs { get; set; } + public System.UInt32 VrssMaxQueuePairsRequested { get; set; } + public System.UInt32 VrssMinQueuePairs { get; set; } + public System.UInt32 VrssMinQueuePairsRequested { get; set; } + public Microsoft.HyperV.PowerShell.VrssQueueSchedulingModeType VrssQueueSchedulingMode { get; set; } + public Microsoft.HyperV.PowerShell.VrssQueueSchedulingModeType VrssQueueSchedulingModeRequested { get; set; } + public System.Boolean VrssExcludePrimaryProcessor { get; set; } + public System.Boolean VrssExcludePrimaryProcessorRequested { get; set; } + public System.Boolean VrssIndependentHostSpreading { get; set; } + public System.Boolean VrssIndependentHostSpreadingRequested { get; set; } + public Microsoft.HyperV.PowerShell.VrssVmbusChannelAffinityPolicyType VrssVmbusChannelAffinityPolicy { get; set; } + public Microsoft.HyperV.PowerShell.VrssVmbusChannelAffinityPolicyType VrssVmbusChannelAffinityPolicyRequested { get; set; } + public System.Int32 VmqUsage { get; set; } + public System.UInt32 IPsecOffloadSAUsage { get; set; } + public System.Boolean VFDataPathActive { get; set; } + public Microsoft.Management.Infrastructure.CimInstance VMQueue { get; set; } + public System.UInt32 BandwidthPercentage { get; set; } + public System.Boolean IsTemplate { get; set; } + public System.String Name { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMNetworkAdapterBase() { } + public static VMNetworkAdapterBase CreateTypeInstance() + { + return new VMNetworkAdapterBase(); + } + } + + public class VMNetworkAdapterConnectionTestResult + { + // Property + public System.Int32 RoundTripTime { get; set; } + + // Fabricated constructor + private VMNetworkAdapterConnectionTestResult() { } + public static VMNetworkAdapterConnectionTestResult CreateTypeInstance() + { + return new VMNetworkAdapterConnectionTestResult(); + } + } + + public enum VMNetworkAdapterExtendedAclAction : byte + { + Allow = 1, + Deny = 2, + } + + public enum VMNetworkAdapterExtendedAclDirection : byte + { + Inbound = 1, + Outbound = 2, + } + + public class VMNetworkAdapterExtendedAclSetting + { + // Property + public Microsoft.HyperV.PowerShell.VMNetworkAdapterExtendedAclDirection Direction { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterExtendedAclAction Action { get; set; } + public System.String LocalIPAddress { get; set; } + public System.String RemoteIPAddress { get; set; } + public System.String LocalPort { get; set; } + public System.String RemotePort { get; set; } + public System.String Protocol { get; set; } + public System.Int32 Weight { get; set; } + public System.Boolean Stateful { get; set; } + public System.Int32 IdleSessionTimeout { get; set; } + public System.Int32 IsolationID { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterBase ParentAdapter { get; set; } + public System.Boolean IsTemplate { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMNetworkAdapterExtendedAclSetting() { } + public static VMNetworkAdapterExtendedAclSetting CreateTypeInstance() + { + return new VMNetworkAdapterExtendedAclSetting(); + } + } + + public class VMNetworkAdapterFailoverSetting + { + // Property + public System.String IPv4Address { get; set; } + public System.String IPv4SubnetMask { get; set; } + public System.String IPv4DefaultGateway { get; set; } + public System.String IPv4PreferredDNSServer { get; set; } + public System.String IPv4AlternateDNSServer { get; set; } + public System.String IPv6Address { get; set; } + public System.String IPv6SubnetPrefixLength { get; set; } + public System.String IPv6DefaultGateway { get; set; } + public System.String IPv6PreferredDNSServer { get; set; } + public System.String IPv6AlternateDNSServer { get; set; } + public Microsoft.HyperV.PowerShell.WmiProtocolIFType ProtocolIFType { get; set; } + + // Fabricated constructor + private VMNetworkAdapterFailoverSetting() { } + public static VMNetworkAdapterFailoverSetting CreateTypeInstance() + { + return new VMNetworkAdapterFailoverSetting(); + } + } + + public enum VMNetworkAdapterIsolationMode : byte + { + None = 0, + NativeVirtualSubnet = 1, + ExternalVirtualSubnet = 2, + Vlan = 3, + } + + public class VMNetworkAdapterIsolationSetting + { + // Property + public Microsoft.HyperV.PowerShell.VMNetworkAdapterIsolationMode IsolationMode { get; set; } + public System.Boolean AllowUntaggedTraffic { get; set; } + public System.Int32 DefaultIsolationID { get; set; } + public Microsoft.HyperV.PowerShell.OnOffState MultiTenantStack { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterBase ParentAdapter { get; set; } + public System.Boolean IsTemplate { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMNetworkAdapterIsolationSetting() { } + public static VMNetworkAdapterIsolationSetting CreateTypeInstance() + { + return new VMNetworkAdapterIsolationSetting(); + } + } + + public enum VMNetworkAdapterOperationalStatus : int + { + Unknown = 0, + Other = 1, + Ok = 2, + Degraded = 3, + Stressed = 4, + PredictiveFailure = 5, + Error = 6, + NonRecoverableError = 7, + Starting = 8, + Stopping = 9, + Stopped = 10, + InService = 11, + NoContact = 12, + LostCommunication = 13, + Aborted = 14, + Dormant = 15, + SupportingEntity = 16, + Completed = 17, + PowerMode = 18, + ProtocolVersion = 32775, + } + + public enum VMNetworkAdapterPortMirroringMode : int + { + None = 0, + Destination = 1, + Source = 2, + } + + public enum VMNetworkAdapterPrivateVlanMode : int + { + Isolated = 1, + Community = 2, + Promiscuous = 3, + } + + public class VMNetworkAdapterRdmaSetting + { + // Property + public System.UInt32 RdmaWeight { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterBase ParentAdapter { get; set; } + public System.Boolean IsTemplate { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMNetworkAdapterRdmaSetting() { } + public static VMNetworkAdapterRdmaSetting CreateTypeInstance() + { + return new VMNetworkAdapterRdmaSetting(); + } + } + + public class VMNetworkAdapterRoutingDomainSetting + { + // Property + public System.Guid RoutingDomainID { get; set; } + public System.String RoutingDomainName { get; set; } + public System.Int32[] IsolationID { get; set; } + public System.String[] IsolationName { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterBase ParentAdapter { get; set; } + public System.Boolean IsTemplate { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMNetworkAdapterRoutingDomainSetting() { } + public static VMNetworkAdapterRoutingDomainSetting CreateTypeInstance() + { + return new VMNetworkAdapterRoutingDomainSetting(); + } + } + + public class VMNetworkAdapterTeamMappingSetting + { + // Property + public System.String NetAdapterName { get; set; } + public System.String NetAdapterDeviceId { get; set; } + public Microsoft.Virtualization.Client.Management.DisableOnFailoverFeature DisableOnFailover { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterBase ParentAdapter { get; set; } + public System.Boolean IsTemplate { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMNetworkAdapterTeamMappingSetting() { } + public static VMNetworkAdapterTeamMappingSetting CreateTypeInstance() + { + return new VMNetworkAdapterTeamMappingSetting(); + } + } + + public enum VMNetworkAdapterVlanMode : int + { + Untagged = 0, + Access = 1, + Trunk = 2, + Private = 3, + } + + public class VMNetworkAdapterVlanSetting + { + // Property + public Microsoft.HyperV.PowerShell.VMNetworkAdapterVlanMode OperationMode { get; set; } + public System.Int32 AccessVlanId { get; set; } + public System.Int32 NativeVlanId { get; set; } + public System.Collections.Generic.List AllowedVlanIdList { get; set; } + public System.String AllowedVlanIdListString { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterPrivateVlanMode PrivateVlanMode { get; set; } + public System.Int32 PrimaryVlanId { get; set; } + public System.Int32 SecondaryVlanId { get; set; } + public System.Collections.Generic.List SecondaryVlanIdList { get; set; } + public System.String SecondaryVlanIdListString { get; set; } + public Microsoft.HyperV.PowerShell.VMNetworkAdapterBase ParentAdapter { get; set; } + public System.Boolean IsTemplate { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMNetworkAdapterVlanSetting() { } + public static VMNetworkAdapterVlanSetting CreateTypeInstance() + { + return new VMNetworkAdapterVlanSetting(); + } + } + + public class VMNumaNodeStatus + { + public bool IsSecondaryStubType = true; + + public VMNumaNodeStatus() { } + } + + public enum VMOperationalStatus : int + { + Ok = 2, + Degraded = 3, + PredictiveFailure = 5, + InService = 11, + Dormant = 15, + SupportingEntityInError = 16, + ApplyingSnapshot = 23769, + CreatingSnapshot = 32768, + DeletingSnapshot = 32770, + WaitingToStart = 32771, + MergingDisks = 32772, + ExportingVirtualMachine = 32773, + MigratingVirtualMachine = 32774, + BackingUpVirtualMachine = 32776, + ModifyingUpVirtualMachine = 32777, + StorageMigrationPhaseOne = 32778, + StorageMigrationPhaseTwo = 32779, + MigratingPlannedVm = 32780, + CheckingCompatibility = 32781, + ApplicationCriticalState = 32782, + CommunicationTimedOut = 32783, + CommunicationFailed = 32784, + NoIommu = 32785, + NoIovSupportInNic = 32786, + SwitchNotInIovMode = 32787, + IovBlockedByPolicy = 32788, + IovNoAvailResources = 32789, + IovGuestDriversNeeded = 32790, + CriticalIoError = 32795, + } + + public class VMPartitionableGpu + { + // Property + public System.String Name { get; set; } + public System.Collections.Generic.IList ValidPartitionCounts { get; set; } + public System.UInt16 PartitionCount { get; set; } + public System.UInt64 TotalVRAM { get; set; } + public System.UInt64 AvailableVRAM { get; set; } + public System.UInt64 MinPartitionVRAM { get; set; } + public System.UInt64 MaxPartitionVRAM { get; set; } + public System.UInt64 OptimalPartitionVRAM { get; set; } + public System.UInt64 TotalEncode { get; set; } + public System.UInt64 AvailableEncode { get; set; } + public System.UInt64 MinPartitionEncode { get; set; } + public System.UInt64 MaxPartitionEncode { get; set; } + public System.UInt64 OptimalPartitionEncode { get; set; } + public System.UInt64 TotalDecode { get; set; } + public System.UInt64 AvailableDecode { get; set; } + public System.UInt64 MinPartitionDecode { get; set; } + public System.UInt64 MaxPartitionDecode { get; set; } + public System.UInt64 OptimalPartitionDecode { get; set; } + public System.UInt64 TotalCompute { get; set; } + public System.UInt64 AvailableCompute { get; set; } + public System.UInt64 MinPartitionCompute { get; set; } + public System.UInt64 MaxPartitionCompute { get; set; } + public System.UInt64 OptimalPartitionCompute { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMPartitionableGpu() { } + public static VMPartitionableGpu CreateTypeInstance() + { + return new VMPartitionableGpu(); + } + } + + public class VMPmemController + { + // Property + public System.Int32 ControllerNumber { get; set; } + public System.Boolean IsTemplate { get; set; } + public System.String DescriptionForAdd { get; set; } + public Microsoft.HyperV.PowerShell.Drive[] Drives { get; set; } + public System.String Name { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMPmemController() { } + public static VMPmemController CreateTypeInstance() + { + return new VMPmemController(); + } + } + + public class VMPortAclMeteringReport + { + public bool IsSecondaryStubType = true; + + public VMPortAclMeteringReport() { } + } + + public class VMProcessor + { + // Property + public System.String ResourcePoolName { get; set; } + public System.Int64 Count { get; set; } + public System.Boolean CompatibilityForMigrationEnabled { get; set; } + public System.Boolean CompatibilityForOlderOperatingSystemsEnabled { get; set; } + public System.Int64 HwThreadCountPerCore { get; set; } + public System.Boolean ExposeVirtualizationExtensions { get; set; } + public System.Boolean EnablePerfmonPmu { get; set; } + public System.Boolean EnablePerfmonLbr { get; set; } + public System.Boolean EnablePerfmonPebs { get; set; } + public System.Boolean EnablePerfmonIpt { get; set; } + public System.Boolean EnableLegacyApicMode { get; set; } + public System.Boolean AllowACountMCount { get; set; } + public System.Int64 Maximum { get; set; } + public System.Int64 Reserve { get; set; } + public System.Int32 RelativeWeight { get; set; } + public System.Int64 MaximumCountPerNumaNode { get; set; } + public System.Int64 MaximumCountPerNumaSocket { get; set; } + public System.Boolean EnableHostResourceProtection { get; set; } + public System.Collections.Generic.IReadOnlyList OperationalStatus { get; set; } + public System.Collections.Generic.IReadOnlyList StatusDescription { get; set; } + public System.String Name { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMProcessor() { } + public static VMProcessor CreateTypeInstance() + { + return new VMProcessor(); + } + } + + public enum VMProcessorOperationalStatus : int + { + Ok = 2, + HostResourceProtectionFirst = 40000, + HostResourceProtectionUnknown = 40000, + HostResourceProtectionEnabled = 40001, + HostResourceProtectionDisabled = 40002, + HostResourceProtectionDegradedSuspended = 40003, + HostResourceProtectionLast = 40004, + HostResourceProtectionDegradedFirst = 40020, + HostResourceProtectionDegradedSerialPipe = 40020, + HostResourceProtectionDegradedSynthDebug = 40021, + HostResourceProtectionDegradedLegacyNic = 40022, + HostResourceProtectionDegradedDvdMedia = 40023, + HostResourceProtectionDegradedFloppyMedia = 40024, + HostResourceProtectionDegradedLast = 40025, + } + + public class VMRemoteFx3DVideoAdapter + { + // Property + public System.String MaximumScreenResolution { get; set; } + public System.Byte MaximumMonitors { get; set; } + public System.UInt64 VRAMSizeBytes { get; set; } + public System.String Name { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMRemoteFx3DVideoAdapter() { } + public static VMRemoteFx3DVideoAdapter CreateTypeInstance() + { + return new VMRemoteFx3DVideoAdapter(); + } + } + + public class VMRemoteFXPhysicalVideoAdapter + { + // Property + public System.String Id { get; set; } + public System.String Name { get; set; } + public System.String GPUID { get; set; } + public System.Int64 TotalVideoMemory { get; set; } + public System.Int64 AvailableVideoMemory { get; set; } + public System.Int64 DedicatedSystemMemory { get; set; } + public System.Int64 DedicatedVideoMemory { get; set; } + public System.Int64 SharedSystemMemory { get; set; } + public System.Boolean Enabled { get; set; } + public System.Boolean CompatibleForVirtualization { get; set; } + public System.String DirectXVersion { get; set; } + public System.String PixelShaderVersion { get; set; } + public System.String DriverProvider { get; set; } + public System.String DriverDate { get; set; } + public System.String DriverInstalledDate { get; set; } + public System.String DriverVersion { get; set; } + public System.String DriverModelVersion { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMRemoteFXPhysicalVideoAdapter() { } + public static VMRemoteFXPhysicalVideoAdapter CreateTypeInstance() + { + return new VMRemoteFXPhysicalVideoAdapter(); + } + } + + public class VMReplication + { + // Property + public Microsoft.HyperV.PowerShell.ReplicationAuthenticationType AuthenticationType { get; set; } + public System.Boolean AutoResynchronizeEnabled { get; set; } + public System.TimeSpan AutoResynchronizeIntervalEnd { get; set; } + public System.TimeSpan AutoResynchronizeIntervalStart { get; set; } + public System.Boolean BypassProxyServer { get; set; } + public System.String CertificateThumbprint { get; set; } + public System.Boolean CompressionEnabled { get; set; } + public System.Boolean EnableWriteOrderPreservationAcrossDisks { get; set; } + public System.Collections.Generic.IList ExcludedDisks { get; set; } + public System.Nullable InitialReplicationStartTime { get; set; } + public System.Int32 RecoveryHistory { get; set; } + public System.Int32 ReplicaServerPort { get; set; } + public System.Boolean ReplicateHostKvpItems { get; set; } + public System.Int32 ReplicationFrequencySec { get; set; } + public System.Nullable ResynchronizeStartTime { get; set; } + public System.Int32 VSSSnapshotFrequencyHour { get; set; } + public System.Boolean VSSSnapshotReplicationEnabled { get; set; } + public System.String AllowedPrimaryServer { get; set; } + public System.String CurrentReplicaServerName { get; set; } + public System.Nullable LastAppliedLogTime { get; set; } + public System.Nullable LastReplicationTime { get; set; } + public System.String PrimaryServerName { get; set; } + public System.String ReplicaServerName { get; set; } + public System.Collections.Generic.IList ReplicatedDisks { get; set; } + public Microsoft.HyperV.PowerShell.VMReplicationHealthState ReplicationHealth { get; set; } + public Microsoft.HyperV.PowerShell.VMReplicationMode ReplicationMode { get; set; } + public Microsoft.HyperV.PowerShell.VMReplicationRelationshipType ReplicationRelationshipType { get; set; } + public Microsoft.HyperV.PowerShell.VMReplicationState ReplicationState { get; set; } + public Microsoft.HyperV.PowerShell.VirtualMachine TestVirtualMachine { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMReplication() { } + public static VMReplication CreateTypeInstance() + { + return new VMReplication(); + } + } + + public class VMReplicationAuthorizationEntry + { + // Property + public System.String AllowedPrimaryServer { get; set; } + public System.String ReplicaStorageLocation { get; set; } + public System.String TrustGroup { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMReplicationAuthorizationEntry() { } + public static VMReplicationAuthorizationEntry CreateTypeInstance() + { + return new VMReplicationAuthorizationEntry(); + } + } + + public class VMReplicationHealth + { + // Property + public System.Collections.Generic.IList CurrentTask { get; set; } + public System.Nullable MonitoringStartTime { get; set; } + public System.Nullable MonitoringEndTime { get; set; } + public Microsoft.HyperV.PowerShell.VMReplicationType LastReplicationType { get; set; } + public Microsoft.HyperV.PowerShell.VMReplicationType FailedOverReplicationType { get; set; } + public System.Nullable LastTestFailoverInitiatedTime { get; set; } + public System.Nullable LastVSSSnapshotTime { get; set; } + public System.UInt64 InitialReplicationSize { get; set; } + public System.UInt64 PendingReplicationSize { get; set; } + public System.UInt64 AverageReplicationSize { get; set; } + public System.UInt64 MaximumReplicationSize { get; set; } + public System.Nullable AverageReplicationLatency { get; set; } + public System.Nullable MaximumReplicationLatency { get; set; } + public System.UInt32 ReplicationErrors { get; set; } + public System.UInt32 SuccessfulReplicationCount { get; set; } + public System.UInt32 MissedReplicationCount { get; set; } + public System.String[] ReplicationHealthDetails { get; set; } + public System.String AllowedPrimaryServer { get; set; } + public System.String CurrentReplicaServerName { get; set; } + public System.Nullable LastAppliedLogTime { get; set; } + public System.Nullable LastReplicationTime { get; set; } + public System.String PrimaryServerName { get; set; } + public System.String ReplicaServerName { get; set; } + public System.Collections.Generic.IList ReplicatedDisks { get; set; } + public Microsoft.HyperV.PowerShell.VMReplicationHealthState ReplicationHealth { get; set; } + public Microsoft.HyperV.PowerShell.VMReplicationMode ReplicationMode { get; set; } + public Microsoft.HyperV.PowerShell.VMReplicationRelationshipType ReplicationRelationshipType { get; set; } + public Microsoft.HyperV.PowerShell.VMReplicationState ReplicationState { get; set; } + public Microsoft.HyperV.PowerShell.VirtualMachine TestVirtualMachine { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMReplicationHealth() { } + public static VMReplicationHealth CreateTypeInstance() + { + return new VMReplicationHealth(); + } + } + + public enum VMReplicationHealthState : int + { + NotApplicable = 0, + Normal = 1, + Warning = 2, + Critical = 3, + } + + public enum VMReplicationMode : int + { + None = 0, + Primary = 1, + Replica = 2, + TestReplica = 3, + ExtendedReplica = 4, + } + + public enum VMReplicationRelationshipType : int + { + Simple = 0, + Extended = 1, + } + + public class VMReplicationServer + { + // Property + public Microsoft.HyperV.PowerShell.RecoveryAuthenticationType AllowedAuthenticationType { get; set; } + public Microsoft.HyperV.PowerShell.VMReplicationAuthorizationEntry[] AuthorizationEntries { get; set; } + public System.Int32 CertificateAuthenticationPort { get; set; } + public System.Collections.Hashtable CertificateAuthenticationPortMapping { get; set; } + public System.String CertificateThumbprint { get; set; } + public System.String DefaultStorageLocation { get; set; } + public System.Int32 KerberosAuthenticationPort { get; set; } + public System.Collections.Hashtable KerberosAuthenticationPortMapping { get; set; } + public System.TimeSpan MonitoringInterval { get; set; } + public System.TimeSpan MonitoringStartTime { get; set; } + public Microsoft.HyperV.PowerShell.VMReplicationServerOperationalStatus[] OperationalStatus { get; set; } + public System.Boolean ReplicationAllowedFromAnyServer { get; set; } + public System.Boolean ReplicationEnabled { get; set; } + public System.String[] StatusDescriptions { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMReplicationServer() { } + public static VMReplicationServer CreateTypeInstance() + { + return new VMReplicationServer(); + } + } + + public enum VMReplicationServerOperationalStatus : int + { + Unknown = 0, + Other = 1, + Ok = 2, + Degraded = 3, + Stressed = 4, + PredictiveFailure = 5, + Error = 6, + NonRecoverableError = 7, + Starting = 8, + Stopping = 9, + Stopped = 10, + InService = 11, + NoContact = 12, + LostCommunication = 13, + Aborted = 14, + Dormant = 15, + SupportingEntityInError = 16, + Completed = 17, + PowerMode = 18, + } + + public enum VMReplicationState : int + { + Disabled = 0, + ReadyForInitialReplication = 1, + InitialReplicationInProgress = 2, + WaitingForInitialReplication = 3, + Replicating = 4, + PreparedForFailover = 5, + FailedOverWaitingCompletion = 6, + FailedOver = 7, + Suspended = 8, + Error = 9, + WaitingForStartResynchronize = 10, + Resynchronizing = 11, + ResynchronizeSuspended = 12, + RecoveryInProgress = 13, + FailbackInProgress = 14, + FailbackComplete = 15, + WaitingForUpdateCompletion = 16, + UpdateError = 17, + WaitingForRepurposeCompletion = 18, + PreparedForSyncReplication = 19, + PreparedForGroupReverseReplication = 20, + FiredrillInProgress = 21, + } + + public enum VMReplicationType : int + { + None = 0, + Regular = 1, + ApplicationConsistent = 2, + Planned = 3, + } + + public class VMResourcePool + { + // Property + public System.String Name { get; set; } + public System.String[] ParentName { get; set; } + public System.Boolean ResourceMeteringEnabled { get; set; } + public Microsoft.HyperV.PowerShell.VMResourcePoolType ResourcePoolType { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMResourcePool() { } + public static VMResourcePool CreateTypeInstance() + { + return new VMResourcePool(); + } + } + + public enum VMResourcePoolType : int + { + Memory = 0, + Processor = 1, + Ethernet = 2, + VHD = 3, + ISO = 4, + VFD = 5, + FibreChannelPort = 6, + FibreChannelConnection = 7, + PciExpress = 8, + } + + public class VMSan + { + // Property + public Microsoft.Management.Infrastructure.CimInstance[] HBAs { get; set; } + public System.String Note { get; set; } + public System.String Name { get; set; } + public System.String[] ParentName { get; set; } + public System.Boolean ResourceMeteringEnabled { get; set; } + public Microsoft.HyperV.PowerShell.VMResourcePoolType ResourcePoolType { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMSan() { } + public static VMSan CreateTypeInstance() + { + return new VMSan(); + } + } + + public class VMScsiController + { + // Property + public System.Int32 ControllerNumber { get; set; } + public System.Boolean IsTemplate { get; set; } + public Microsoft.HyperV.PowerShell.Drive[] Drives { get; set; } + public System.String Name { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMScsiController() { } + public static VMScsiController CreateTypeInstance() + { + return new VMScsiController(); + } + } + + public class VMSecurity + { + // Property + public System.Boolean TpmEnabled { get; set; } + public System.Boolean KsdEnabled { get; set; } + public System.Boolean Shielded { get; set; } + public System.Boolean EncryptStateAndVmMigrationTraffic { get; set; } + public System.Boolean VirtualizationBasedSecurityOptOut { get; set; } + public System.Boolean BindToHostTpm { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMSecurity() { } + public static VMSecurity CreateTypeInstance() + { + return new VMSecurity(); + } + } + + public class VMSnapshot + { + // Property + public Microsoft.HyperV.PowerShell.SnapshotType SnapshotType { get; set; } + public System.Boolean IsAutomaticCheckpoint { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public Microsoft.HyperV.PowerShell.VMState State { get; set; } + public Microsoft.HyperV.PowerShell.VMComPort ComPort1 { get; set; } + public Microsoft.HyperV.PowerShell.VMComPort ComPort2 { get; set; } + public Microsoft.HyperV.PowerShell.DvdDrive[] DVDDrives { get; set; } + public System.Collections.Generic.List FibreChannelHostBusAdapters { get; set; } + public Microsoft.HyperV.PowerShell.VMFloppyDiskDrive FloppyDrive { get; set; } + public Microsoft.HyperV.PowerShell.HardDiskDrive[] HardDrives { get; set; } + public Microsoft.HyperV.PowerShell.VMRemoteFx3DVideoAdapter RemoteFxAdapter { get; set; } + public System.Collections.Generic.List VMIntegrationService { get; set; } + public System.Boolean DynamicMemoryEnabled { get; set; } + public System.Int64 MemoryMaximum { get; set; } + public System.Int64 MemoryMinimum { get; set; } + public System.Int64 MemoryStartup { get; set; } + public System.Int64 ProcessorCount { get; set; } + public System.Boolean BatteryPassthroughEnabled { get; set; } + public System.Int32 Generation { get; set; } + public System.Boolean IsClustered { get; set; } + public System.String Notes { get; set; } + public System.Nullable ParentSnapshotId { get; set; } + public System.String ParentSnapshotName { get; set; } + public System.String Path { get; set; } + public System.Int64 SizeOfSystemFiles { get; set; } + public System.String Version { get; set; } + public System.Boolean GuestControlledCacheTypes { get; set; } + public System.UInt32 LowMemoryMappedIoSpace { get; set; } + public System.UInt64 HighMemoryMappedIoSpace { get; set; } + public System.Nullable LockOnDisconnect { get; set; } + public System.DateTime CreationTime { get; set; } + public System.Guid Id { get; set; } + public System.String Name { get; set; } + public System.Collections.Generic.List NetworkAdapters { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMSnapshot() { } + public static VMSnapshot CreateTypeInstance() + { + return new VMSnapshot(); + } + } + + public enum VMState : int + { + Other = 1, + Running = 2, + Off = 3, + Stopping = 4, + Saved = 6, + Paused = 9, + Starting = 10, + Reset = 11, + Saving = 32773, + Pausing = 32776, + Resuming = 32777, + FastSaved = 32779, + FastSaving = 32780, + ForceShutdown = 32781, + ForceReboot = 32782, + Hibernated = 32783, + ComponentServicing = 32784, + RunningCritical = 32785, + OffCritical = 32786, + StoppingCritical = 32787, + SavedCritical = 32788, + PausedCritical = 32789, + StartingCritical = 32790, + ResetCritical = 32791, + SavingCritical = 32792, + PausingCritical = 32793, + ResumingCritical = 32794, + FastSavedCritical = 32795, + FastSavingCritical = 32796, + } + + public class VMStorageResourcePool + { + // Property + public System.String[] Paths { get; set; } + public System.String Name { get; set; } + public System.String[] ParentName { get; set; } + public System.Boolean ResourceMeteringEnabled { get; set; } + public Microsoft.HyperV.PowerShell.VMResourcePoolType ResourcePoolType { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMStorageResourcePool() { } + public static VMStorageResourcePool CreateTypeInstance() + { + return new VMStorageResourcePool(); + } + } + + public class VMStorageSetting + { + // Property + public Microsoft.HyperV.PowerShell.ThreadCount ThreadCountPerChannel { get; set; } + public System.UInt16 VirtualProcessorsPerChannel { get; set; } + public System.Boolean DisableInterruptBatching { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMStorageSetting() { } + public static VMStorageSetting CreateTypeInstance() + { + return new VMStorageSetting(); + } + } + + public class VMSwitch + { + // Property + public System.String Name { get; set; } + public System.Guid Id { get; set; } + public System.String Notes { get; set; } + public Microsoft.HyperV.PowerShell.VMSwitchExtension[] Extensions { get; set; } + public Microsoft.HyperV.PowerShell.VMSwitchBandwidthMode BandwidthReservationMode { get; set; } + public System.Boolean PacketDirectEnabled { get; set; } + public System.Boolean EmbeddedTeamingEnabled { get; set; } + public System.Boolean IovEnabled { get; set; } + public Microsoft.HyperV.PowerShell.VMSwitchType SwitchType { get; set; } + public System.Boolean AllowManagementOS { get; set; } + public System.String NetAdapterInterfaceDescription { get; set; } + public System.String[] NetAdapterInterfaceDescriptions { get; set; } + public System.Guid[] NetAdapterInterfaceGuid { get; set; } + public System.Boolean IovSupport { get; set; } + public System.String[] IovSupportReasons { get; set; } + public System.UInt32 AvailableIPSecSA { get; set; } + public System.UInt32 NumberIPSecSAAllocated { get; set; } + public System.UInt32 AvailableVMQueues { get; set; } + public System.UInt32 NumberVmqAllocated { get; set; } + public System.UInt32 IovQueuePairCount { get; set; } + public System.UInt32 IovQueuePairsInUse { get; set; } + public System.UInt32 IovVirtualFunctionCount { get; set; } + public System.UInt32 IovVirtualFunctionsInUse { get; set; } + public System.Boolean PacketDirectInUse { get; set; } + public System.Boolean DefaultQueueVrssEnabledRequested { get; set; } + public System.Boolean DefaultQueueVrssEnabled { get; set; } + public System.Boolean DefaultQueueVmmqEnabledRequested { get; set; } + public System.Boolean DefaultQueueVmmqEnabled { get; set; } + public System.UInt32 DefaultQueueVrssMaxQueuePairsRequested { get; set; } + public System.UInt32 DefaultQueueVrssMaxQueuePairs { get; set; } + public System.UInt32 DefaultQueueVrssMinQueuePairsRequested { get; set; } + public System.UInt32 DefaultQueueVrssMinQueuePairs { get; set; } + public Microsoft.HyperV.PowerShell.VrssQueueSchedulingModeType DefaultQueueVrssQueueSchedulingModeRequested { get; set; } + public Microsoft.HyperV.PowerShell.VrssQueueSchedulingModeType DefaultQueueVrssQueueSchedulingMode { get; set; } + public System.Boolean DefaultQueueVrssExcludePrimaryProcessorRequested { get; set; } + public System.Boolean DefaultQueueVrssExcludePrimaryProcessor { get; set; } + public System.Boolean SoftwareRscEnabled { get; set; } + public System.UInt32 BandwidthPercentage { get; set; } + public System.UInt64 DefaultFlowMinimumBandwidthAbsolute { get; set; } + public System.UInt64 DefaultFlowMinimumBandwidthWeight { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMSwitch() { } + public static VMSwitch CreateTypeInstance() + { + return new VMSwitch(); + } + } + + public enum VMSwitchBandwidthMode : int + { + Default = 0, + Weight = 1, + Absolute = 2, + None = 3, + } + + public class VMSwitchExtension + { + // Property + public System.String Id { get; set; } + public System.String Name { get; set; } + public System.String Vendor { get; set; } + public System.String Version { get; set; } + public Microsoft.HyperV.PowerShell.VMSwitchExtensionType ExtensionType { get; set; } + public System.String ParentExtensionId { get; set; } + public System.String ParentExtensionName { get; set; } + public System.String SwitchId { get; set; } + public System.String SwitchName { get; set; } + public System.Boolean Enabled { get; set; } + public System.Boolean Running { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMSwitchExtension() { } + public static VMSwitchExtension CreateTypeInstance() + { + return new VMSwitchExtension(); + } + } + + public class VMSwitchExtensionPortData + { + // Property + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.String VMNetworkAdapterName { get; set; } + public System.String Name { get; set; } + public System.Nullable Id { get; set; } + public System.String ExtensionId { get; set; } + public System.String ExtensionName { get; set; } + public System.Management.Automation.PSObject Data { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMSwitchExtensionPortData() { } + public static VMSwitchExtensionPortData CreateTypeInstance() + { + return new VMSwitchExtensionPortData(); + } + } + + public class VMSwitchExtensionPortFeature + { + // Property + public System.Nullable Id { get; set; } + public System.String ExtensionId { get; set; } + public System.String ExtensionName { get; set; } + public System.String Name { get; set; } + public Microsoft.Management.Infrastructure.CimInstance SettingData { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMSwitchExtensionPortFeature() { } + public static VMSwitchExtensionPortFeature CreateTypeInstance() + { + return new VMSwitchExtensionPortFeature(); + } + } + + public class VMSwitchExtensionSwitchData + { + // Property + public System.String SwitchName { get; set; } + public System.String Name { get; set; } + public System.Nullable Id { get; set; } + public System.String ExtensionId { get; set; } + public System.String ExtensionName { get; set; } + public System.Management.Automation.PSObject Data { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMSwitchExtensionSwitchData() { } + public static VMSwitchExtensionSwitchData CreateTypeInstance() + { + return new VMSwitchExtensionSwitchData(); + } + } + + public class VMSwitchExtensionSwitchFeature + { + // Property + public System.Nullable Id { get; set; } + public System.String ExtensionId { get; set; } + public System.String ExtensionName { get; set; } + public System.String Name { get; set; } + public Microsoft.Management.Infrastructure.CimInstance SettingData { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMSwitchExtensionSwitchFeature() { } + public static VMSwitchExtensionSwitchFeature CreateTypeInstance() + { + return new VMSwitchExtensionSwitchFeature(); + } + } + + public enum VMSwitchExtensionType : int + { + Unknown = 0, + Capture = 1, + Filter = 2, + Forwarding = 3, + Monitoring = 4, + Native = 5, + } + + public enum VMSwitchLoadBalancingAlgorithm : int + { + HyperVPort = 4, + Dynamic = 5, + } + + public class VMSwitchTeam + { + // Property + public System.String Name { get; set; } + public System.Guid Id { get; set; } + public System.String[] NetAdapterInterfaceDescription { get; set; } + public System.Guid[] NetAdapterInterfaceGuid { get; set; } + public System.Nullable TeamingMode { get; set; } + public System.Nullable LoadBalancingAlgorithm { get; set; } + + // Fabricated constructor + private VMSwitchTeam() { } + public static VMSwitchTeam CreateTypeInstance() + { + return new VMSwitchTeam(); + } + } + + public enum VMSwitchTeamingMode : int + { + SwitchIndependent = 1, + } + + public enum VMSwitchType : int + { + Private = 0, + Internal = 1, + External = 2, + } + + public class VMSystemSwitchExtension + { + // Property + public System.String Id { get; set; } + public System.String Name { get; set; } + public System.String Vendor { get; set; } + public System.String Version { get; set; } + public Microsoft.HyperV.PowerShell.VMSwitchExtensionType ExtensionType { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMSystemSwitchExtension() { } + public static VMSystemSwitchExtension CreateTypeInstance() + { + return new VMSystemSwitchExtension(); + } + } + + public class VMVideo + { + // Property + public Microsoft.HyperV.PowerShell.ResolutionType ResolutionType { get; set; } + public System.Int32 HorizontalResolution { get; set; } + public System.Int32 VerticalResolution { get; set; } + public System.String Name { get; set; } + public System.String Id { get; set; } + public System.Guid VMId { get; set; } + public System.String VMName { get; set; } + public System.Guid VMSnapshotId { get; set; } + public System.String VMSnapshotName { get; set; } + public Microsoft.Management.Infrastructure.CimSession CimSession { get; set; } + public System.String ComputerName { get; set; } + public System.Boolean IsDeleted { get; set; } + + // Fabricated constructor + private VMVideo() { } + public static VMVideo CreateTypeInstance() + { + return new VMVideo(); + } + } + + public enum VrssQueueSchedulingModeType : int + { + Dynamic = 0, + StaticVmq = 1, + StaticVrss = 2, + } + + public enum VrssVmbusChannelAffinityPolicyType : int + { + None = 1, + Weak = 2, + Strong = 3, + Strict = 4, + } + + public enum WaitVMTypes : int + { + Heartbeat = 0, + IPAddress = 1, + Reboot = 2, + MemoryOperations = 3, + } + + public enum WmiProtocolIFType : int + { + None = 0, + Other = 1, + IPv4 = 4096, + IPv6 = 4097, + IPv4v6 = 4098, + } + +} + +namespace Microsoft.HyperV.PowerShell.Commands +{ + public class GetVMHostNumaNodeStatus + { + // Constructor + public GetVMHostNumaNodeStatus() { } + + // Property + public Microsoft.Management.Infrastructure.CimSession[] CimSession { get; set; } + public System.String[] ComputerName { get; set; } + public System.Management.Automation.PSCredential[] Credential { get; set; } + public System.Nullable Id { get; set; } + public Microsoft.HyperV.PowerShell.Commands.VirtualMachineParameterType VirtualMachineParameterType { get; set; } + public System.String ParameterSetName { get; set; } + public System.Management.Automation.InvocationInfo MyInvocation { get; set; } + public System.Management.Automation.PagingParameters PagingParameters { get; set; } + public System.Management.Automation.CommandInvocationIntrinsics InvokeCommand { get; set; } + public System.Management.Automation.Host.PSHost Host { get; set; } + public System.Management.Automation.SessionState SessionState { get; set; } + public System.Management.Automation.PSEventManager Events { get; set; } + public System.Management.Automation.JobRepository JobRepository { get; set; } + public System.Management.Automation.JobManager JobManager { get; set; } + public System.Management.Automation.ProviderIntrinsics InvokeProvider { get; set; } + public System.Boolean Stopping { get; set; } + public System.Management.Automation.ICommandRuntime CommandRuntime { get; set; } + public System.Management.Automation.PSTransactionContext CurrentPSTransaction { get; set; } + public System.Management.Automation.CommandOrigin CommandOrigin { get; set; } + + } + + public class RestartVM + { + // Constructor + public RestartVM() { } + + // Property + public Microsoft.Management.Infrastructure.CimSession[] CimSession { get; set; } + public System.String[] ComputerName { get; set; } + public System.Management.Automation.PSCredential[] Credential { get; set; } + public Microsoft.HyperV.PowerShell.VirtualMachine[] VM { get; set; } + public System.String[] Name { get; set; } + public System.Management.Automation.SwitchParameter Force { get; set; } + public System.Management.Automation.SwitchParameter AsJob { get; set; } + public System.Management.Automation.SwitchParameter Passthru { get; set; } + public System.Management.Automation.SwitchParameter Wait { get; set; } + public Microsoft.HyperV.PowerShell.Commands.RestartVM.WaitVMTypes For { get; set; } + public System.UInt16 Delay { get; set; } + public System.Nullable Timeout { get; set; } + public Microsoft.HyperV.PowerShell.Commands.RestartVM.RestartType Type { get; set; } + public Microsoft.HyperV.PowerShell.Commands.VirtualMachineParameterType VirtualMachineParameterType { get; set; } + public System.String ParameterSetName { get; set; } + public System.Management.Automation.InvocationInfo MyInvocation { get; set; } + public System.Management.Automation.PagingParameters PagingParameters { get; set; } + public System.Management.Automation.CommandInvocationIntrinsics InvokeCommand { get; set; } + public System.Management.Automation.Host.PSHost Host { get; set; } + public System.Management.Automation.SessionState SessionState { get; set; } + public System.Management.Automation.PSEventManager Events { get; set; } + public System.Management.Automation.JobRepository JobRepository { get; set; } + public System.Management.Automation.JobManager JobManager { get; set; } + public System.Management.Automation.ProviderIntrinsics InvokeProvider { get; set; } + public System.Boolean Stopping { get; set; } + public System.Management.Automation.ICommandRuntime CommandRuntime { get; set; } + public System.Management.Automation.PSTransactionContext CurrentPSTransaction { get; set; } + public System.Management.Automation.CommandOrigin CommandOrigin { get; set; } + + public enum WaitVMTypes : int + { + Heartbeat = 0, + IPAddress = 1, + } + + public enum RestartType : int + { + Reset = 0, + Reboot = 1, + } + } + + public enum VirtualMachineParameterType : int + { + None = 0, + VMObject = 1, + SingularVMObject = 2, + Name = 3, + SingularName = 4, + VMName = 5, + SingularVMName = 6, + VMId = 7, + } +} + +namespace Microsoft.Vhd.PowerShell +{ + public enum VhdCompactMode : int + { + Full = 0, + Quick = 1, + Retrim = 2, + Pretrimmed = 3, + Prezeroed = 4, + } + + public enum VhdFormat : int + { + Unknown = 0, + VHD = 2, + VHDX = 3, + VHDSet = 4, + } + + public class VHDSetInfo + { + // Property + public System.String ComputerName { get; set; } + public System.String Path { get; set; } + public System.Collections.Generic.IReadOnlyCollection SnapshotIdList { get; set; } + public System.Collections.Generic.IReadOnlyCollection AllPaths { get; set; } + + // Fabricated constructor + private VHDSetInfo() { } + public static VHDSetInfo CreateTypeInstance() + { + return new VHDSetInfo(); + } + } + + public class VHDSnapshotInfo + { + // Property + public System.String ComputerName { get; set; } + public System.String FilePath { get; set; } + public System.Guid SnapshotId { get; set; } + public System.String SnapshotPath { get; set; } + public System.DateTime CreationTime { get; set; } + public System.String ResilientChangeTrackingId { get; set; } + public System.Collections.Generic.IReadOnlyCollection ParentPathsList { get; set; } + + // Fabricated constructor + private VHDSnapshotInfo() { } + public static VHDSnapshotInfo CreateTypeInstance() + { + return new VHDSnapshotInfo(); + } + } + + public enum VhdType : int + { + Unknown = 0, + Fixed = 2, + Dynamic = 3, + Differencing = 4, + } + + public class VirtualHardDisk + { + // Property + public System.String ComputerName { get; set; } + public System.String Path { get; set; } + public Microsoft.Vhd.PowerShell.VhdFormat VhdFormat { get; set; } + public Microsoft.Vhd.PowerShell.VhdType VhdType { get; set; } + public System.UInt64 FileSize { get; set; } + public System.UInt64 Size { get; set; } + public System.Nullable MinimumSize { get; set; } + public System.UInt32 LogicalSectorSize { get; set; } + public System.UInt32 PhysicalSectorSize { get; set; } + public System.UInt32 BlockSize { get; set; } + public System.String ParentPath { get; set; } + public System.String DiskIdentifier { get; set; } + public System.Nullable FragmentationPercentage { get; set; } + public System.UInt32 Alignment { get; set; } + public System.Boolean Attached { get; set; } + public System.Nullable DiskNumber { get; set; } + public System.Boolean IsPMEMCompatible { get; set; } + public Microsoft.Virtualization.Client.Management.VirtualHardDiskPmemAddressAbstractionType AddressAbstractionType { get; set; } + + // Fabricated constructor + private VirtualHardDisk() { } + public static VirtualHardDisk CreateTypeInstance() + { + return new VirtualHardDisk(); + } + } + +} + +namespace Microsoft.Virtualization.Client.Management +{ + [System.Flags] + public enum DisableOnFailoverFeature : int + { + None = 0, + RDMA = 1, + } + + public class SecureBootTemplate + { + public bool IsSecondaryStubType = true; + + public SecureBootTemplate() { } + } + + public enum VirtualHardDiskPmemAddressAbstractionType : int + { + None = 0, + BTT = 1, + Unknown = 65535, + } + +} + +'@ + +function Add-VMAssignableDevice { + <# + .SYNOPSIS + Add-VMAssignableDevice [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [-InstancePath ] [-LocationPath ] [-VirtualFunction ] [-ResourcePoolName ] [-Passthru] [-WhatIf] [-Confirm] [] + +Add-VMAssignableDevice [-VM] [-InstancePath ] [-LocationPath ] [-VirtualFunction ] [-ResourcePoolName ] [-Passthru] [-WhatIf] [-Confirm] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMAssignedDevice])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [ValidateNotNullOrEmpty()] + [string] + ${InstancePath}, + + [ValidateNotNullOrEmpty()] + [string] + ${LocationPath}, + + [System.Nullable[uint16]] + ${VirtualFunction}, + + [ValidateNotNull()] + [string] + ${ResourcePoolName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMDvdDrive { + <# + .SYNOPSIS + Adds a DVD drive to a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-v hosts on which the DVD drive is to be added. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine to which the DVD drive is to be added. + .PARAMETER VM + Specifies the virtual machine to which the DVD drive is to be added. + .PARAMETER VMDriveController + Specifies the drive controller 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. If not specified, the first IDE controller on which the specified ControllerLocation is available is used. + .PARAMETER ControllerLocation + Specifies the number of the location on the controller at which the DVD drive is to be added. If not specified, the number of the first available location on the controller is used. + .PARAMETER Path + Specifies the full path to the virtual hard disk file or physical hard disk volume for the added DVD drive. + .PARAMETER ResourcePoolName + Specifies the friendly name of the ISO resource pool to which this DVD drive is to be associated. + .PARAMETER AllowUnverifiedPaths + Specifies that no error is to be thrown if the specified path is not verified as accessible by the cluster. This parameter is applicable to clustered virtual machines. + .PARAMETER Passthru + Passes the added Microsoft.HyperV.PowerShell.DvdDrive through to the pipeline. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.DvdDrive])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMDriveController', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMDriveController[]] + ${VMDriveController}, + + [Parameter(ParameterSetName='VMObject', Position=2)] + [Parameter(ParameterSetName='VMName', Position=2)] + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerNumber}, + + [Parameter(Position=3)] + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerLocation}, + + [Parameter(Position=4)] + [string] + ${Path}, + + [ValidateNotNull()] + [string] + ${ResourcePoolName}, + + [switch] + ${AllowUnverifiedPaths}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMFibreChannelHba { + <# + .SYNOPSIS + Adds a virtual Fibre Channel host bus adapter to a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a virtual Fibre Channel host bus adapter is to be added. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine to which the virtual Fibre Channel host bus adapter is to be added. + .PARAMETER VMName + Specifies the name of the virtual machine to which the virtual Fibre Channel host bus adapter is to be added. + .PARAMETER SanName + Specifies the virtual storage area network (SAN) name to associate with this virtual Fibre Channel host bus adapter. Use the Get-VMSan cmdlet to get a list of all virtual SANs on the host. + .PARAMETER GenerateWwn + Specifies that the world wide names for the Fibre Channel host bus adapter are to be generated automatically. When specified, the WorldWideNodeNameSetA , WorldWideNodeNameSetB , WorldWidePortNameSetA , and WorldWidePortNameSetB parameters cannot be used. + .PARAMETER WorldWideNodeNameSetA + Specifies the world wide node name of address A associated with the Fibre Channel host bus adapter to be added. + .PARAMETER WorldWidePortNameSetA + Specifies the world wide port name of address A associated with the Fibre Channel host bus adapter to be added. + .PARAMETER WorldWideNodeNameSetB + Specifies the world wide node name of address B associated with the Fibre Channel host bus adapter to be added. + .PARAMETER WorldWidePortNameSetB + Specifies the world wide port name of address B associated with the Fibre Channel host bus adapter to be added. + .PARAMETER Passthru + Specifies that an object representing the virtual machine to which the virtual Fibre Channel host bus adapter being added is to be passed through to the pipeline. + #> + + [CmdletBinding(DefaultParameterSetName='VMName and GenerateWwn', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMFibreChannelHba])] + param ( + [Parameter(ParameterSetName='VMName and GenerateWwn')] + [Parameter(ParameterSetName='VMName and manual WWN')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName and manual WWN')] + [Parameter(ParameterSetName='VMName and GenerateWwn')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName and manual WWN')] + [Parameter(ParameterSetName='VMName and GenerateWwn')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VM object and GenerateWwn', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VM Object and manual WWN', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName and GenerateWwn', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMName and manual WWN', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${SanName}, + + [Parameter(ParameterSetName='VMName and GenerateWwn')] + [Parameter(ParameterSetName='VM object and GenerateWwn')] + [switch] + ${GenerateWwn}, + + [Parameter(ParameterSetName='VMName and manual WWN', Mandatory=$true)] + [Parameter(ParameterSetName='VM Object and manual WWN', Mandatory=$true)] + [Alias('Wwnn1')] + [ValidateNotNullOrEmpty()] + [string] + ${WorldWideNodeNameSetA}, + + [Parameter(ParameterSetName='VMName and manual WWN', Mandatory=$true)] + [Parameter(ParameterSetName='VM Object and manual WWN', Mandatory=$true)] + [Alias('Wwpn1')] + [ValidateNotNullOrEmpty()] + [string] + ${WorldWidePortNameSetA}, + + [Parameter(ParameterSetName='VMName and manual WWN', Mandatory=$true)] + [Parameter(ParameterSetName='VM Object and manual WWN', Mandatory=$true)] + [Alias('Wwnn2')] + [ValidateNotNullOrEmpty()] + [string] + ${WorldWideNodeNameSetB}, + + [Parameter(ParameterSetName='VMName and manual WWN', Mandatory=$true)] + [Parameter(ParameterSetName='VM Object and manual WWN', Mandatory=$true)] + [Alias('Wwpn2')] + [ValidateNotNullOrEmpty()] + [string] + ${WorldWidePortNameSetB}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMGpuPartitionAdapter { + <# + .SYNOPSIS + Add-VMGpuPartitionAdapter [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [-Passthru] [-MinPartitionVRAM ] [-MaxPartitionVRAM ] [-OptimalPartitionVRAM ] [-MinPartitionEncode ] [-MaxPartitionEncode ] [-OptimalPartitionEncode ] [-MinPartitionDecode ] [-MaxPartitionDecode ] [-OptimalPartitionDecode ] [-MinPartitionCompute ] [-MaxPartitionCompute ] [-OptimalPartitionCompute ] [-WhatIf] [-Confirm] [] + +Add-VMGpuPartitionAdapter [-VM] [-Passthru] [-MinPartitionVRAM ] [-MaxPartitionVRAM ] [-OptimalPartitionVRAM ] [-MinPartitionEncode ] [-MaxPartitionEncode ] [-OptimalPartitionEncode ] [-MinPartitionDecode ] [-MaxPartitionDecode ] [-OptimalPartitionDecode ] [-MinPartitionCompute ] [-MaxPartitionCompute ] [-OptimalPartitionCompute ] [-WhatIf] [-Confirm] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMGpuPartitionAdapter])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${Passthru}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MinPartitionVRAM}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MaxPartitionVRAM}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${OptimalPartitionVRAM}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MinPartitionEncode}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MaxPartitionEncode}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${OptimalPartitionEncode}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MinPartitionDecode}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MaxPartitionDecode}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${OptimalPartitionDecode}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MinPartitionCompute}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MaxPartitionCompute}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${OptimalPartitionCompute} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMGroupMember { + <# + .SYNOPSIS + Adds group members to a virtual machine group. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies on or more Hyper-V hosts where this cmdlet adds a group member. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the name of the virtual machine group to which this cmdlet adds virtual machines or groups of virtual machines. + .PARAMETER Id + Specifies the unique ID of the virtual machine group to which this cmdlet adds virtual machines or groups of virtual machines. + .PARAMETER VMGroup + Specifies the virtual machine group to which this cmdlet adds virtual machines or groups of virtual machines. To obtain a VMGroup object, use the Get-VMGroup cmdlet. + .PARAMETER VM + Specifies an array of virtual machines that this cmdlet adds to a virtual machine group. To obtain a VirtualMachine object, use the Get-VM cmdlet. + .PARAMETER VMGroupMember + Specifies an array of virtual machine groups that this cmdlet adds to a virtual machine group. + .PARAMETER Passthru + Indicates that this cmdlet returns the Microsoft.HyperV.PowerShell.VMGroup object that it configures. + #> + + [CmdletBinding(DefaultParameterSetName='VM Using Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMGroup])] + param ( + [Parameter(ParameterSetName='VMGroup Using ID')] + [Parameter(ParameterSetName='VM Using Name')] + [Parameter(ParameterSetName='VMGroup Using Name')] + [Parameter(ParameterSetName='VM Using ID')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VM Using Name')] + [Parameter(ParameterSetName='VMGroup Using Name')] + [Parameter(ParameterSetName='VM Using ID')] + [Parameter(ParameterSetName='VMGroup Using ID')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VM Using ID')] + [Parameter(ParameterSetName='VM Using Name')] + [Parameter(ParameterSetName='VMGroup Using Name')] + [Parameter(ParameterSetName='VMGroup Using ID')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMGroup Using Name', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='VM Using Name', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='VMGroup Using ID', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='VM Using ID', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [guid] + ${Id}, + + [Parameter(ParameterSetName='VMGroup Using InputObject', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='VM Using InputObject', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMGroup] + ${VMGroup}, + + [Parameter(ParameterSetName='VM Using InputObject', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VM Using Name', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VM Using ID', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMGroup Using ID', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VMGroup Using Name', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VMGroup Using InputObject', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMGroup[]] + ${VMGroupMember}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMHardDiskDrive { + <# + .SYNOPSIS + Adds a hard disk drive to a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine to which the hard disk drive is to be added. + .PARAMETER VM + Specifies the virtual machine to which the hard disk drive is to be added. + .PARAMETER VMDriveController + Specifies the controller to which the hard disk drive is to be added. + .PARAMETER ControllerType + Specifies the type of the controller to which the hard disk drive is to be added. If not specified, IDE is attempted first. If the IDE controller port at the specified number and location is already connected to a drive, then it will try to create one on the SCSI controller specified by ControllerNumber . Allowed values are IDE and SCSI . + .PARAMETER ControllerNumber + Specifies the number of the controller to which the hard disk drive is to be added. If not specified, this parameter assumes the value of the first available controller at the location specified in the ControllerLocation parameter. + .PARAMETER ControllerLocation + Specifies the number of the location on the controller at which the hard disk drive is to be added. If not specified, the first available location in the controller specified with the ControllerNumber parameter is used. + .PARAMETER Path + Specifies the full path of the hard disk drive file to be added. + .PARAMETER DiskNumber + Specifies the disk number of the offline physical hard drive to be connected as a passthrough disk. + .PARAMETER ResourcePoolName + Specifies the friendly name of the ISO resource pool to which this virtual hard disk is to be associated. + .PARAMETER SupportPersistentReservations + Indicates that the hard disk supports SCSI persistent reservation semantics. Specify this parameter when the hard disk is a shared disk that is used by multiple virtual machines. + .PARAMETER AllowUnverifiedPaths + Specifies that no error is to be thrown if the specified path is not verified as accessible by the cluster. This parameter is applicable to clustered virtual machines. + .PARAMETER MaximumIOPS + Specifies the maximum normalized I/O operations per second (IOPS) for the hard disk. Hyper-V calculates normalized IOPS as the total size of I/O per second divided by 8 KB. + .PARAMETER MinimumIOPS + Specifies the minimum normalized I/O operations per second (IOPS) for the hard disk. Hyper-V calculates normalized IOPS as the total size of I/O per second divided by 8 KB. + .PARAMETER QoSPolicyID + Specifies the unique ID for a storage QoS policy that this cmdlet associates with the hard disk drive. + .PARAMETER QoSPolicy + Specifies the name of the storage Quality of Service (QoS) policy that this cmdlet associates with the hard disk drive. + .PARAMETER Passthru + Passes the added Microsoft.HyperV.PowerShell.HardDiskDrive object through to the pipeline. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.HardDiskDrive])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Alias('PSComputerName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMDriveController', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMDriveController] + ${VMDriveController}, + + [Parameter(ParameterSetName='VMName', Position=1)] + [Parameter(ParameterSetName='VMObject', Position=1)] + [System.Nullable[Microsoft.HyperV.PowerShell.ControllerType]] + ${ControllerType}, + + [Parameter(ParameterSetName='VMObject', Position=2)] + [Parameter(ParameterSetName='VMName', Position=2)] + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerNumber}, + + [Parameter(Position=3)] + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerLocation}, + + [Parameter(Position=4)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(ValueFromPipelineByPropertyName=$true)] + [Alias('Number')] + [uint32] + ${DiskNumber}, + + [ValidateNotNull()] + [string] + ${ResourcePoolName}, + + [Alias('ShareVirtualDisk')] + [switch] + ${SupportPersistentReservations}, + + [switch] + ${AllowUnverifiedPaths}, + + [System.Nullable[uint64]] + ${MaximumIOPS}, + + [System.Nullable[uint64]] + ${MinimumIOPS}, + + [string] + ${QoSPolicyID}, + + [ciminstance] + ${QoSPolicy}, + + [switch] + ${Passthru}, + + [System.Nullable[Microsoft.HyperV.PowerShell.CacheAttributes]] + ${OverrideCacheAttributes} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMHostAssignableDevice { + <# + .SYNOPSIS + Add-VMHostAssignableDevice -ResourcePoolName [-CimSession ] [-ComputerName ] [-Credential ] [-Force] [-InstancePath ] [-LocationPath ] [] + +Add-VMHostAssignableDevice [-VMHostAssignableDevice] -ResourcePoolName [-Force] [] + #> + + [CmdletBinding(DefaultParameterSetName='Path')] + param ( + [Parameter(ParameterSetName='Path')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Path')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Path')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [switch] + ${Force}, + + [Parameter(ParameterSetName='Path')] + [ValidateNotNullOrEmpty()] + [string] + ${InstancePath}, + + [Parameter(ParameterSetName='Path')] + [ValidateNotNullOrEmpty()] + [string] + ${LocationPath}, + + [Parameter(ParameterSetName='Object', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMHostAssignableDevice[]] + ${VMHostAssignableDevice}, + + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ResourcePoolName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMKeyStorageDrive { + <# + .SYNOPSIS + Add-VMKeyStorageDrive [-VMName] [[-ControllerNumber] ] [[-ControllerLocation] ] [-CimSession ] [-ComputerName ] [-Credential ] [-ResourcePoolName ] [-Passthru] [-WhatIf] [-Confirm] [] + +Add-VMKeyStorageDrive [-VM] [[-ControllerNumber] ] [[-ControllerLocation] ] [-ResourcePoolName ] [-Passthru] [-WhatIf] [-Confirm] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.KeyStorageDrive])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Alias('PSComputerName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMObject', Position=2)] + [Parameter(ParameterSetName='VMName', Position=2)] + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerNumber}, + + [Parameter(Position=3)] + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerLocation}, + + [ValidateNotNull()] + [string] + ${ResourcePoolName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMMigrationNetwork { + <# + .SYNOPSIS + Adds a network for virtual machine migration on one or more virtual machine hosts. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Subnet + Specifies a string representing an IPv4 or IPv6 subnet mask which identifies the network to be added for virtual machine migration. + .PARAMETER Priority + Specifies the priority of the network to be added for virtual machine migration. Multiple networks can have the same priority. + .PARAMETER Passthru + Specifies that an Microsoft.HyperV.PowerShell.MigrationNetwork object is to be passed through to the pipeline representing the network added for virtual machine migration. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the network is to be added for virtual machine migration. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMMigrationNetwork])] + param ( + [Parameter(ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Subnet}, + + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [uint32] + ${Priority}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMNetworkAdapter { + <# + .SYNOPSIS + Adds a virtual network adapter to a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual network adapter is to be added. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine on which the network adapter is to be added. + .PARAMETER ManagementOS + Specifies the management operating system. + .PARAMETER SwitchName + Specifies the name of the virtual switch to connect to the new network adapter. If the switch name is not unique, then the operation fails. + .PARAMETER IsLegacy + Specifies whether the virtual network adapter is the legacy type. + .PARAMETER Name + Specifies a name for the new virtual network adapter. The default value is "Network Adapter." + .PARAMETER DynamicMacAddress + Assigns a dynamically generated MAC address to the new virtual network adapter. + .PARAMETER StaticMacAddress + Assigns a specific MAC address to the new virtual network adapter. + .PARAMETER Passthru + Specifies that an object is to be passed through to be pipeline representing the network adapter to be added. If you specify -ManagementOS , the object passed is a Microsoft.HyperV.PowerShell.VMInternalNetworkAdapter ; otherwise the object passed is a Microsoft.HyperV.PowerShell.VMNetworkAdapter . + .PARAMETER ResourcePoolName + Specifies the friendly name of a resource pool. + .PARAMETER VM + Specifies the virtual machine on which the network adapter is to be added. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapter])] + [OutputType([Microsoft.HyperV.PowerShell.VMInternalNetworkAdapter])] + param ( + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='ManagementOS')] + [switch] + ${ManagementOS}, + + [ValidateNotNullOrEmpty()] + [string] + ${SwitchName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [bool] + ${IsLegacy}, + + [Alias('VMNetworkAdapterName')] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [switch] + ${DynamicMacAddress}, + + [ValidateNotNull()] + [bool] + ${NumaAwarePlacement}, + + [ValidateNotNullOrEmpty()] + [string] + ${StaticMacAddress}, + + [switch] + ${Passthru}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [ValidateNotNull()] + [string] + ${ResourcePoolName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Microsoft.HyperV.PowerShell.OnOffState] + ${DeviceNaming} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMNetworkAdapterAcl { + <# + .SYNOPSIS + Creates an ACL to apply to the traffic through a virtual machine network adapter. + .PARAMETER Action + Specifies the action for the ACL. Allowed values are Allow , Deny , and Meter . A metering ACL must be IP-based, i.e. either -RemoteIPAddress or -LocalIPAddress must be specified. + .PARAMETER Direction + Specifies the direction of the network traffic to which the ACL is to apply. Allowed values are Inbound , Outbound , or Both . . If Both is specified, the new ACL entry is added to both the inbound direction and the outbound direction. In the output of Get-VMNetworkAdapterAcl, the ACL entry appears in both the inbound ACL list and the outbound ACL list. + .PARAMETER LocalIPAddress + Specifies the local IP address to which the ACL is to apply. For an inbound packet, this is the destination IP address in the packet header; for an outbound packet, this is the source IP address in the packet header. It can be either IPv4 or IPv6 address. It can be either a host address or a subnet address, e.g. 1.2.3.4, 2001::2008, 192.168.1.0/24, or f001:f002:f003:f004::1/64. The IP address can also be a wildcard, 0.0.0.0/0 for all IPv4 addresses, ::/0 for all IPv6 addresses, or ANY for all IPv4 and IPv6 addresses. + .PARAMETER LocalMacAddress + Specifies the local MAC address to which the ACL is to apply. For an inbound packet, this is the destination MAC address in the packet header; for an outbound packet, this is the source MAC address in the packet header. It can be a host MAC address, e.g. 00-ab-00-11-22-33, or a wildcard, ANY, for all MAC addresses. + .PARAMETER RemoteIPAddress + Specifies the remote IP address to which this ACL is to apply. For an inbound packet, this is the source IP address in the packet header; for an outbound packet, this is the destination IP address in the packet header. It can be either IPv4 or IPv6 address. It can be either a host address or a subnet address, e.g. 1.2.3.4, 2001::2008, 192.168.1.0/24, or f001:f002:f003:f004::1/64.the IP address can also be a wildcard, 0.0.0.0/0 for all IPv4 addresses, ::/0 for all IPv6 addresses, or ANY for all IPv4 and IPv6 addresses. + .PARAMETER RemoteMacAddress + Specifies the remote MAC address to which this ACL is to apply. For an inbound packet, this is the source MAC address in the packet header; for an outbound packet, this is the destination MAC address in the packet header. It can be a host MAC address, e.g. 00-ab-00-11-22-33, or a wildcard, ANY, for all MAC addresses. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the ACL to be added. + .PARAMETER VMNetworkAdapter + Specifies the virtual machine network adapter to which the ACL is to apply. + .PARAMETER ManagementOS + Specifies that the ACL is to be applied in the management (i.e. the parent, or host) operating system. + .PARAMETER VMNetworkAdapterName + Specifies the name of the virtual machine network adapter to which the ACL is to apply. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the ACL is to be created. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine on which the ACL is to apply. + .PARAMETER VM + Specifies the virtual machine on which the ACL is to apply. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterAclSetting])] + param ( + [Parameter(Mandatory=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterAclAction] + ${Action}, + + [Parameter(Mandatory=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterAclDirection] + ${Direction}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${LocalIPAddress}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${LocalMacAddress}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${RemoteIPAddress}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${RemoteMacAddress}, + + [switch] + ${Passthru}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMNetworkAdapterExtendedAcl { + <# + .SYNOPSIS + Creates an extended ACL for a virtual network adapter. + .PARAMETER Action + Specifies the action for the ACL. The acceptable values for this parameter are: + + - Allow + + - Deny + .PARAMETER Direction + Specifies the direction of network traffic, from the perspective of the virtual machine, to which the ACL applies. The cmdlet adds an ACL that has the value that you specify. The acceptable values for this parameter are: + + - Inbound + + - Outbound + + If you run the Get-VMNetworkAdapterExtendedAcl cmdlet, the entry that you create appears in both the inbound ACL and the outbound ACL. + + .PARAMETER LocalIPAddress + Specifies the local IP address for the ACL. For an inbound packet, the local address is the destination IP address. For an outbound packet, the local address is the source IP address. You can specify a host address or a subnet address, or specify a wildcard, such as 0.0.0.0/0 for all IPv4 addresses, ::/0 for all IPv6 addresses, or ANY for all IPv4 and IPv6 addresses. + .PARAMETER RemoteIPAddress + Specifies the local IP address for the ACL. For an inbound packet, the remote address is the source IP address. For an outbound packet, the remote address is the destination IP address. You can specify a host address or a subnet address, or specify a wildcard, such as 0.0.0.0/0 for all IPv4 addresses, ::/0 for all IPv6 addresses, or ANY for all IPv4 and IPv6 addresses. + .PARAMETER LocalPort + Specifies the local port for the ACL. For an inbound TCP or UDP packet, the local port is the destination port. For an outbound packet, the local port is the source port. + .PARAMETER RemotePort + Specifies the remote port for the ACL. For an inbound TCP or UDP packet, the remote port is the source port. For an outbound packet, the remote port is the destination port. + .PARAMETER Protocol + Specifies the protocol that the ACL applies to. The acceptable values for this parameter are: + + - TCP + + - UDP + + - ICMP + + - an integer IP protocol ID + .PARAMETER Weight + Specifies the weight of an ACL entry. Larger weight values apply first, and once an ACL entry applies to a packet, other entries are no longer relevant for that packet. + .PARAMETER Stateful + Indicates whether the ACL applies to packets in both directions of the same session. If you specify a value of $True, the ACL applies to a return packet even though that packet has the opposite direction with respect to the ACL. + .PARAMETER IdleSessionTimeout + Specifies a time-out period, in seconds, for idle sessions. + .PARAMETER IsolationID + Specifies an ID of a virtual subnet. The cmdlet adds an ACL that applies to traffic on the isolated network that you specify. The subnet uses virtual local area network (VLAN) or Hyper-V Network Virtualization. For more information about isolation IDs, see the Set-VmNetworkAdapterIsolation cmdlet. + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + .PARAMETER VMNetworkAdapter + Specifies an array VM network adapters as VMNetworkAdapterBase objects. The cmdlet adds an ACL to the adapters that you specify. To obtain a network adapter, use the Get-VMNetworkAdapter cmdlet. + .PARAMETER ManagementOS + Indicates that the cmdlet operates on the parent or host operating system. If you specify this parameter, this cmdlet creates an ACL that applies to the parent or host operating system. + .PARAMETER VMNetworkAdapterName + Specifies the name of a virtual network adapter. The cmdlet adds an ACL to the adapter that you specify. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies an array of Hyper-V hosts. The cmdlet adds the ACL to the network adapters on the Hyper-V hosts that you specify. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies an array of names of virtual machines. The cmdlet adds an ACL for the virtual machines that you specify. + .PARAMETER VM + Specifies an array of virtual machine objects. The cmdlet adds an ACL for the virtual machines that you specify. To obtain a virtual machine object, use the Get-VM cmdlet. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterExtendedAclSetting])] + param ( + [Parameter(Mandatory=$true, Position=1)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterExtendedAclAction] + ${Action}, + + [Parameter(Mandatory=$true, Position=2)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterExtendedAclDirection] + ${Direction}, + + [Parameter(Position=3)] + [ValidateNotNullOrEmpty()] + [string] + ${LocalIPAddress}, + + [Parameter(Position=4)] + [ValidateNotNullOrEmpty()] + [string] + ${RemoteIPAddress}, + + [Parameter(Position=5)] + [ValidateNotNullOrEmpty()] + [string] + ${LocalPort}, + + [Parameter(Position=6)] + [ValidateNotNullOrEmpty()] + [string] + ${RemotePort}, + + [Parameter(Position=7)] + [ValidateNotNull()] + [string] + ${Protocol}, + + [Parameter(Mandatory=$true, Position=8)] + [ValidateNotNull()] + [System.Nullable[int]] + ${Weight}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${Stateful}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${IdleSessionTimeout}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${IsolationID}, + + [switch] + ${Passthru}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMNetworkAdapterRoutingDomainMapping { + <# + .SYNOPSIS + Adds a routing domain and virtual subnets to a virtual network adapter. + .PARAMETER RoutingDomainID + Specifies the ID of a routing domain. The ID of a routing domain is a system-assigned GUID. The cmdlet adds the routing domain that you specify to the virtual network adapter. + .PARAMETER RoutingDomainName + Specifies the name of a routing domain. The cmdlet adds the routing domain that you specify to the virtual network adapter. + .PARAMETER IsolationID + Specifies an array of IDs of virtual subnets. The cmdlet adds the virtual subnets that you specify to the virtual network adapter. You can isolate a virtual machine adapter by using virtual local area network (VLAN), Hyper-V Network Virtualization, or a third party virtualization solution. For more information about isolation IDs, see the Set-VmNetworkAdapterIsolation cmdlet. + .PARAMETER IsolationName + Specifies an array of names of virtual subnets. The cmdlet adds the virtual subnets that you specify to the virtual network adapter. The subnet uses VLAN or Hyper-V Network Virtualization. + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + .PARAMETER VMNetworkAdapter + Specifies an array of virtual network adapter as VMNetworkAdapterBase objects. The cmdlet adds the routing domain on the adapters that you specify. To obtain a network adapter, use the Get-VMNetworkAdapter cmdlet. + .PARAMETER ManagementOS + Indicates that the cmdlet operates on the parent or host operating system. + .PARAMETER VMNetworkAdapterName + Specifies the name of a virtual network adapter. The cmdlet adds the routing domain on adapter that you specify. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies an array of Hyper-V hosts. The cmdlet adds the routing domain and virtual subnet to a virtual network adapter on the Hyper-V hosts that you specify. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies an array of friendly names of virtual machines. The cmdlet adds the routing domain to the network interfaces that belong to the virtual machines that you specify. + .PARAMETER VM + Specifies an array of virtual machine objects. The cmdlet adds the routing domain to the network interfaces that belong to the virtual machines that you specify. To obtain a virtual machine object, use the Get-VM cmdlet. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterRoutingDomainSetting])] + param ( + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [guid] + ${RoutingDomainID}, + + [Parameter(Mandatory=$true, Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${RoutingDomainName}, + + [Parameter(Mandatory=$true, Position=3)] + [ValidateNotNullOrEmpty()] + [int[]] + ${IsolationID}, + + [Parameter(Position=4)] + [string[]] + ${IsolationName}, + + [switch] + ${Passthru}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMPmemController { + <# + .SYNOPSIS + Add-VMPmemController [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [-Passthru] [-WhatIf] [-Confirm] [] + +Add-VMPmemController [-VM] [-Passthru] [-WhatIf] [-Confirm] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMPmemController])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMRemoteFx3dVideoAdapter { + <# + .SYNOPSIS + Adds a RemoteFX video adapter in a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the RemoteFX video adapter is to be added. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine on which the RemoteFX video adapter is to be added. + .PARAMETER VMName + Specifies the name of virtual machine on which the RemoteFX video adapter is to be added. + .PARAMETER Passthru + Specifies that a VMRemoteFxVideoAdapter object is to be passed through to the pipeline representing the RemoteFX video adapter to be added. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMRemoteFx3DVideoAdapter])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMScsiController { + <# + .SYNOPSIS + Adds a SCSI controller in a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a SCSI controller is to be added. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine in which the SCSI controller is to be added. + .PARAMETER VMName + Specifies the name of the virtual machine in which the SCSI controller is to be added. + .PARAMETER Passthru + Specifies that a VMScsiController object is to be passed through to the pipeline representing the SCSI controller to be added. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMScsiController])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMStoragePath { + <# + .SYNOPSIS + Adds a path to a storage resource pool. + .PARAMETER Path + Specifies the path to be added to the storage resource pool. + .PARAMETER ResourcePoolName + Specifies the name of the resource pool to which the path is to be added. + .PARAMETER ResourcePoolType + Specifies the type of the resource pool for which storage paths are to be added. Allowed values are VFD , VHD , and ISO . + .PARAMETER Passthru + Indicates that this cmdlet returns a String . + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the path to the storage resource pool is to be added. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMStorageResourcePool])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ResourcePoolName}, + + [Parameter(Mandatory=$true, Position=2)] + [ValidateSet('VHD','ISO','VFD')] + [Microsoft.HyperV.PowerShell.VMResourcePoolType] + ${ResourcePoolType}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMSwitch { + <# + .SYNOPSIS + Adds a virtual switch to an Ethernet resource pool. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies an array of Hyper-V hosts. The cmdlet adds the virtual switch on the Hyper-V hosts that you specify. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the name of the virtual switch to be added. + .PARAMETER VMSwitch + Specifies the virtual switch to be added to the Ethernet resource pool. + .PARAMETER ResourcePoolName + Specifies the name of the resource pool to which the virtual switch is to be added. + #> + + [CmdletBinding(DefaultParameterSetName='NetworkByName')] + param ( + [Parameter(ParameterSetName='NetworkByName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='NetworkByName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='NetworkByName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='NetworkByName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('SwitchName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='NetworkByObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMSwitch[]] + ${VMSwitch}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ResourcePoolName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMSwitchExtensionPortFeature { + <# + .SYNOPSIS + Adds a feature to a virtual network adapter. + .PARAMETER VMName + Specifies the name of the virtual machine in which the feature is to be added. + .PARAMETER VMNetworkAdapter + Specifies the virtual machine network adapter for which the feature is to be added. + .PARAMETER ManagementOS + Specifies that the feature is to be added in the management (i.e. the parent, or host) operating system. + .PARAMETER ExternalPort + Specifies the virtual switch port connected to the external network adapter. + .PARAMETER SwitchName + Specifies the name of the virtual switch. + .PARAMETER VMNetworkAdapterName + Specifies the name of the virtual machine network adapter for which the feature is to be added. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a feature is to be added to a virtual network adapter. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine in which the feature is to be added. + .PARAMETER VMSwitchExtensionFeature + Specifies the feature to be added to the virtual switch. You can get such a feature object from Get-VMSystemSwitchExtensionPortFeature to add a new configuration to a virtual network adapter, or from the Get-VMSwitchExtensionPortFeature cmdlet to update an existing configuration. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the feature to be added. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchExtensionPortFeature])] + param ( + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='ExternalPort', Mandatory=$true)] + [switch] + ${ExternalPort}, + + [Parameter(ParameterSetName='ExternalPort')] + [string] + ${SwitchName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='ExternalPort')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='ExternalPort')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='ExternalPort')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitchExtensionPortFeature[]] + ${VMSwitchExtensionFeature}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMSwitchExtensionSwitchFeature { + <# + .SYNOPSIS + Adds a feature to a virtual switch. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a feature is to be added to a virtual switch. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMSwitchExtensionFeature + Specifies the feature to be added to the virtual switch. + .PARAMETER SwitchName + Specifies the name of the virtual switch to which the feature is to be added. + .PARAMETER VMSwitch + Specifies the virtual switch to which the feature is to be added. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the feature to be added. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchExtensionSwitchFeature])] + param ( + [Parameter(ParameterSetName='SwitchName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='SwitchName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='SwitchName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitchExtensionSwitchFeature[]] + ${VMSwitchExtensionFeature}, + + [Parameter(ParameterSetName='SwitchName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${SwitchName}, + + [Parameter(ParameterSetName='SwitchObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMSwitch[]] + ${VMSwitch}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Add-VMSwitchTeamMember { + <# + .SYNOPSIS + Adds members to a virtual switch team. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that runs this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER VMSwitch + Specifies an array of virtual switches that this cmdlet configures. To obtain a VMSwitch object, use the Get-VMSwitch cmdlet. + .PARAMETER VMSwitchName + Specifies an array of names of virtual switches that this cmdlet configures. + .PARAMETER NetAdapterName + Specifies an array of names of virtual network adapters that this cmdlet adds to the switch team. + .PARAMETER NetAdapterInterfaceDescription + Specifies an array of interface descriptions of the virtual network adapters that this cmdlet adds to the switch team. + .PARAMETER Passthru + Indicates that this cmdlet returns the Microsoft.HyperV.PowerShell.VMSwitch object that it modifies. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='SwitchName_NetAdapterName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitch])] + param ( + [Parameter(ParameterSetName='SwitchName_NetAdapterInterfaceDescription', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='SwitchName_NetAdapterName', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='SwitchObject_NetAdapterInterfaceDescription', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='SwitchObject_NetAdapterName', ValueFromPipelineByPropertyName=$true)] + [Alias('PSComputerName')] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='SwitchObject_NetAdapterName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='SwitchObject_NetAdapterInterfaceDescription', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitch[]] + ${VMSwitch}, + + [Parameter(ParameterSetName='SwitchName_NetAdapterInterfaceDescription', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='SwitchName_NetAdapterName', Mandatory=$true, Position=0)] + [Alias('SwitchName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMSwitchName}, + + [Parameter(ParameterSetName='SwitchObject_NetAdapterName')] + [Parameter(ParameterSetName='SwitchName_NetAdapterName')] + [Alias('InterfaceAlias')] + [ValidateNotNullOrEmpty()] + [string[]] + ${NetAdapterName}, + + [Parameter(ParameterSetName='SwitchName_NetAdapterInterfaceDescription')] + [Parameter(ParameterSetName='SwitchObject_NetAdapterInterfaceDescription')] + [ValidateNotNullOrEmpty()] + [string[]] + ${NetAdapterInterfaceDescription}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Checkpoint-VM { + <# + .SYNOPSIS + Creates a checkpoint of a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more virtual machine hosts on which the virtual machine checkpoint is to be created. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine of which a checkpoint is to be taken. + .PARAMETER Name + Specifies the name of the virtual machine of which a checkpoint is to be taken. + .PARAMETER SnapshotName + Specifies the name of the checkpoint to be taken. If not provided, a combination of the virtual machine's name and a current timestamp is used. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual machine of which a checkpoint is to be taken. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSnapshot])] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(Position=1)] + [Alias('CheckpointName')] + [ValidateNotNullOrEmpty()] + [string] + ${SnapshotName}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Compare-VM { + <# + .SYNOPSIS + Compares a virtual machine and a virtual machine host for compatibility, returning a compatibility report. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-v hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VirtualMachinePath + Specifies the path where the resulting virtual machine configuration files are to be stored. + .PARAMETER SnapshotFilePath + Specifies the path for any snapshot files associated with the virtual machine. + .PARAMETER SmartPagingFilePath + Specifies the new path to use for a smart paging file, if one is needed. + .PARAMETER CompatibilityReport + Specifies a compatibility report which resolves any incompatibilities between the virtual machine and the virtual machine host. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Name + Specifies the name of the virtual machine to be compared. + .PARAMETER VM + Specifies a virtual machine. + .PARAMETER DestinationCimSession + Specifies the CIMSession on the Hyper-V host to which this cmdlet compares the virtual machine for compatibility. + .PARAMETER DestinationHost + Specifies the Hyper-V host to which the virtual machine is to be compared for compatibility. + .PARAMETER DestinationCredential + Specifies a user account that has permission to perform this action. The default is the current user. + .PARAMETER IncludeStorage + Specifies that the compatibility comparison should include both the virtual machine and its storage. + .PARAMETER DestinationStoragePath + Specifies a destination storage path to which all virtual machine storage is to be moved. + .PARAMETER Vhds + Specifies an array of hash tables that specifies a location for each individual virtual hard disk that needs to be compared. Each hash table has two entries. The first entry specifies the current location of the virtual hard disk to move, and has a key of SourceFilePath . The second entry specifies the new location for the virtual hard disk, and has a key of DestinationFilePath . The virtual hard disk names must be identical in both entries. + .PARAMETER ResourcePoolName + Specifies the friendly name of the resource pool. + .PARAMETER RetainVhdCopiesOnSource + Indicates that this cmdlet retains parent virtual hard disks on the source computer. + .PARAMETER Path + Specifies the path to the configuration file of the virtual machine to be compared. + .PARAMETER VhdDestinationPath + Specifies the folder to which the virtual machine's VHD is to be copied. + .PARAMETER Register + Specifies that the comparison should be made for an in-place import operation. + .PARAMETER Copy + Specifies that the comparison should be made for a copy import operation. + .PARAMETER VhdSourcePath + Specifies the folder from which the virtual machine's VHD files are to be copied. + .PARAMETER GenerateNewId + Specifies that the virtual machine should be copied and given a new unique identifier. + #> + + [CmdletBinding(DefaultParameterSetName='NameSingleDestination', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMCompatibilityReport])] + param ( + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession')] + [Parameter(ParameterSetName='NameSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='Register')] + [Parameter(ParameterSetName='Copy')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Copy')] + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='Register')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='Register')] + [Parameter(ParameterSetName='Copy')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Copy')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession', Mandatory=$true)] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession', Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${VirtualMachinePath}, + + [Parameter(ParameterSetName='VMMultipleDestinations')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession')] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession')] + [Parameter(ParameterSetName='Copy')] + [Alias('CheckpointFileLocation','SnapshotFileLocation')] + [ValidateNotNullOrEmpty()] + [string] + ${SnapshotFilePath}, + + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession')] + [Parameter(ParameterSetName='Copy')] + [ValidateNotNullOrEmpty()] + [string] + ${SmartPagingFilePath}, + + [Parameter(ParameterSetName='CompatibilityReport', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMCompatibilityReport] + ${CompatibilityReport}, + + [switch] + ${AsJob}, + + [Parameter(ParameterSetName='NameMultipleDestinations', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='NameSingleDestination', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='NameSingleDestinationAndCimSession', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='VMSingleDestination', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMSingleDestinationAndCimSession', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMMultipleDestinations', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine] + ${VM}, + + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='NameSingleDestinationAndCimSession', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VMSingleDestinationAndCimSession', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [CimSession] + ${DestinationCimSession}, + + [Parameter(ParameterSetName='NameSingleDestination', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='NameMultipleDestinations', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VMSingleDestination', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VMMultipleDestinations', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${DestinationHost}, + + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='VMSingleDestination')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${DestinationCredential}, + + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='VMSingleDestination')] + [Parameter(ParameterSetName='VMSingleDestinationAndCimSession')] + [switch] + ${IncludeStorage}, + + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='VMSingleDestination')] + [Parameter(ParameterSetName='VMSingleDestinationAndCimSession')] + [ValidateNotNullOrEmpty()] + [string] + ${DestinationStoragePath}, + + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [ValidateNotNullOrEmpty()] + [hashtable[]] + ${Vhds}, + + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession')] + [Parameter(ParameterSetName='VMSingleDestination')] + [Parameter(ParameterSetName='VMSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession')] + [ValidateNotNullOrEmpty()] + [string] + ${ResourcePoolName}, + + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession')] + [Parameter(ParameterSetName='VMSingleDestination')] + [Parameter(ParameterSetName='VMSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession')] + [switch] + ${RetainVhdCopiesOnSource}, + + [Parameter(ParameterSetName='Register', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='Copy', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(ParameterSetName='Copy', Position=1)] + [string] + ${VhdDestinationPath}, + + [Parameter(ParameterSetName='Register')] + [switch] + ${Register}, + + [Parameter(ParameterSetName='Copy', Mandatory=$true)] + [switch] + ${Copy}, + + [Parameter(ParameterSetName='Copy')] + [string] + ${VhdSourcePath}, + + [Parameter(ParameterSetName='Copy')] + [switch] + ${GenerateNewId} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Complete-VMFailover { + <# + .SYNOPSIS + Completes a virtual machine's failover process on the Replica server. Removes all recovery points on a failed over virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the failover process is to be completed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine whose failover process is to be completed. + .PARAMETER VM + Specifies the virtual machine whose failover process is to be completed. + .PARAMETER Passthru + Indicates that this cmdlet returns the Microsoft.HyperV.PowerShell.VirtualMachine on which it operates. By default, this cmdlet does not return a value. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='High')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Connect-VMNetworkAdapter { + <# + .SYNOPSIS + Connects a virtual network adapter to a virtual switch. + .PARAMETER VMNetworkAdapter + Specifies the virtual network adapter to be connected. + .PARAMETER Name + Specifies the name of the virtual network adapter to be connected. + .PARAMETER SwitchName + Specifies the name of the virtual switch to which the virtual network adapter is to be connected. + .PARAMETER VMSwitch + Specifies the virtual switch to which the virtual network adapter is to be connected. + .PARAMETER UseAutomaticConnection + Specifies that the network adapter is to be connected to any virtual switch in the resource pool, rather than to a specific virtual switch. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.VMNetworkAdapter object is to be passed through to the pipeline representing the virtual network adapter to be connected. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more virtual machine hosts on which the virtual network adapter is to be connected. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine in which the network adapter is to be connected. + #> + + [CmdletBinding(DefaultParameterSetName='Name_SwitchName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapter])] + param ( + [Parameter(ParameterSetName='Object_SwitchName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='Object_SwitchObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='Object_UseAutomaticConnection', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMNetworkAdapter[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='Name_SwitchObject', Position=1)] + [Parameter(ParameterSetName='Name_SwitchName', Position=1)] + [Parameter(ParameterSetName='Name_UseAutomaticConnection', Position=1)] + [Alias('VMNetworkAdapterName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='Object_SwitchName', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='Name_SwitchName', Mandatory=$true, Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${SwitchName}, + + [Parameter(ParameterSetName='Name_SwitchObject', Mandatory=$true, Position=2, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='Object_SwitchObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMSwitch] + ${VMSwitch}, + + [Parameter(ParameterSetName='Object_UseAutomaticConnection', Mandatory=$true)] + [Parameter(ParameterSetName='Name_UseAutomaticConnection', Mandatory=$true)] + [switch] + ${UseAutomaticConnection}, + + [switch] + ${Passthru}, + + [Parameter(ParameterSetName='Name_SwitchName')] + [Parameter(ParameterSetName='Name_UseAutomaticConnection')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name_SwitchName')] + [Parameter(ParameterSetName='Name_UseAutomaticConnection')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name_UseAutomaticConnection')] + [Parameter(ParameterSetName='Name_SwitchName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Name_SwitchObject', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='Name_SwitchName', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='Name_UseAutomaticConnection', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Connect-VMSan { + <# + .SYNOPSIS + Associates a host bus adapter with a virtual storage area network (SAN). + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts where the host bus adapter is to be associated with the virtual storage area network (SAN). NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the name of the virtual storage area network (SAN) with which the host bus adapter is to be associated. + .PARAMETER HostBusAdapter + Specifies the host bus adapter to be associated with the virtual storage area network (SAN). + .PARAMETER WorldWideNodeName + Specifies the world wide node name of the host bus adapter to be associated with the virtual storage area network (SAN). + .PARAMETER WorldWidePortName + The port world wide name of the host bus adapter to be associated with the virtual storage area network (SAN). + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.Powershell.VMSan object is to be passed through to the pipeline representing the virtual storage area network (SAN) to be associated with the host bus adapter. + #> + + [CmdletBinding(DefaultParameterSetName='StringWwn', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSan])] + param ( + [Parameter(ParameterSetName='StringWwn', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='StringWwn', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='StringWwn', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [Alias('SanName')] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='HbaObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [ciminstance[]] + ${HostBusAdapter}, + + [Parameter(ParameterSetName='StringWwn', Mandatory=$true)] + [Alias('Wwnn','NodeName','Wwnns','NodeNames','WorldWideNodeNames','NodeAddress')] + [ValidateNotNullOrEmpty()] + [string[]] + ${WorldWideNodeName}, + + [Parameter(ParameterSetName='StringWwn', Mandatory=$true)] + [Alias('Wwpn','PortName','Wwpns','PortNames','WorldWidePortNames','PortAddress')] + [ValidateNotNullOrEmpty()] + [string[]] + ${WorldWidePortName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Convert-VHD { + <# + .SYNOPSIS + Converts the format, version type, and block size of a virtual hard disk file. + .PARAMETER Path + Specifies the path to the virtual hard disk file to be converted. If a file name or relative path is specified, the path of the converted hard disk path is calculated relative to the current working directory + .PARAMETER DestinationPath + Specifies the path to the converted virtual hard disk file. + .PARAMETER VHDType + Specifies the type of the converted virtual hard disk. Allowed values are Fixed , Dynamic , and Differencing . The default is determined by the type of source virtual hard disk. + .PARAMETER ParentPath + Specifies the parent path for the destination-differencing virtual hard disk file. + .PARAMETER BlockSizeBytes + Specifies the block size, in bytes, of the virtual hard disk after conversion. + .PARAMETER DeleteSource + Specifies that the source virtual hard disk is to be deleted after the conversion. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the converted virtual hard disk. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual hard disk is to be converted. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.Vhd.PowerShell.VirtualHardDisk])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('FullName')] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${DestinationPath}, + + [ValidateNotNullOrEmpty()] + [Microsoft.Vhd.PowerShell.VhdType] + ${VHDType}, + + [ValidateNotNullOrEmpty()] + [string] + ${ParentPath}, + + [ValidateNotNullOrEmpty()] + [uint32] + ${BlockSizeBytes}, + + [switch] + ${DeleteSource}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru}, + + [Microsoft.Virtualization.Client.Management.VirtualHardDiskPmemAddressAbstractionType] + ${AddressAbstractionType}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Copy-VMFile { + <# + .SYNOPSIS + Copies a file to a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies an array of Hyper-V hosts. The cmdlet copies the file to the hosts you specify. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies an array of virtual machine objects by name. The cmdlet copies files to the virtual machines you specify. + .PARAMETER VM + Specifies an array of virtual machine objects. The cmdlet copies files to the virtual machines you specify. To obtain a virtual machine object, use the Get-VM cmdlet. + .PARAMETER SourcePath + Specifies a path. The cmdlet copies the file from the source path. + .PARAMETER DestinationPath + Specifies a path. The cmdlet copies the file to the destination path. + .PARAMETER FileSource + Specifies the type of a file source. + .PARAMETER CreateFullPath + Indicates that when the cmdlet copies a file, it creates folders if the folder does not already exist. + .PARAMETER Force + Forces the command to run without asking for user confirmation. + .PARAMETER AsJob + Runs the cmdlet as a background job. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${SourcePath}, + + [Parameter(Mandatory=$true, Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${DestinationPath}, + + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.CopyFileSourceType] + ${FileSource}, + + [switch] + ${CreateFullPath}, + + [switch] + ${Force}, + + [switch] + ${AsJob} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Debug-VM { + <# + .SYNOPSIS + Debugs a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies an array of Hyper-V hosts. The cmdlet debugs the virtual machines on the hosts you specify. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies an array of virtual machine objects that are to be debugged. To obtain virtual machine objects, use the Get-VM cmdlet. + .PARAMETER Name + Specifies an array of names of virtual machines to be debugged. + .PARAMETER Force + Forces the command to run without asking for user confirmation. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + .PARAMETER InjectNonMaskableInterrupt + Indicates that the cmdlet sends a nonmaskable interrupt (NMI) to the virtual machine. An interrupt handler must process a nonmaskable interrupt. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [switch] + ${Force}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru}, + + [switch] + ${InjectNonMaskableInterrupt} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Disable-VMConsoleSupport { + <# + .SYNOPSIS + Disables keyboard, video, and mouse for a generation 2 virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies an array of virtual machines on which this cmdlet disables support for keyboard, video, and mouse. To obtain a VirtualMachine object, use the Get-VM cmdlet. + .PARAMETER VMName + Specifies an array of names of virtual machines on which this cmdlet disables support for keyboard, video, and mouse. + .PARAMETER Passthru + Indicates that this cmdlet returns the Microsoft.HyperV.VirtualMachine object that it modifies. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Disable-VMEventing { + <# + .SYNOPSIS + Disables virtual machine eventing. + .PARAMETER Force + Specifies that the confirmation prompt is to be suppressed. (This is useful in scripting the cmdlet.) + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which virtual machine eventing is to be disabled. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + param ( + [switch] + ${Force}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Disable-VMIntegrationService { + <# + .SYNOPSIS + Disables an integration service on a virtual machine. + .PARAMETER VMIntegrationService + Specifies the integration service to be disabled. + .PARAMETER Name + Specifies the name of the integration service to be disabled. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the integration service on a virtual machine is to be disabled. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine on which the integration service is to be disabled. + .PARAMETER VMName + Specifies the name of the virtual machine on which the integration service is to be disabled. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.IntegrationService object is to be passed through to the pipeline representing the integration service to be disabled. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMIntegrationComponent])] + param ( + [Parameter(ParameterSetName='VMIntegrationService', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMIntegrationComponent[]] + ${VMIntegrationService}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Disable-VMMigration { + <# + .SYNOPSIS + Disables migration on one or more virtual machine hosts. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Passthru + Indicates that this cmdlet returns a Microsoft.HyperV.PowerShell.Host object. By default, this cmdlet does not return a value. + #> + + [CmdletBinding(DefaultParameterSetName='ComputerName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMHost])] + param ( + [Parameter(ParameterSetName='CimSession', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ComputerName', Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ComputerName', Position=1)] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Disable-VMRemoteFXPhysicalVideoAdapter { + <# + .SYNOPSIS + Disables one or more RemoteFX physical video adapters from use with RemoteFX-enabled virtual machines. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the RemoteFX physical video adapters are to be disabled. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER GPU + Specifies one or more RemoteFX physical video adapters to disable. + .PARAMETER Name + Specifies an array of names of adapters. The cmdlet disables the RemoteFX physical video adapters that you specify. + .PARAMETER Passthru + Specifies that Microsoft.HyperV.PowerShell.VMRemoteFXPhysicalVideoAdapter objects are to be passed to the pipeline representing the RemoteFX physical video adapters to be disabled. + #> + + [CmdletBinding(DefaultParameterSetName='GPUByName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMRemoteFXPhysicalVideoAdapter])] + param ( + [Parameter(ParameterSetName='GPUByName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='GPUByName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='GPUByName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='GPUByObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMRemoteFXPhysicalVideoAdapter[]] + ${GPU}, + + [Parameter(ParameterSetName='GPUByName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Disable-VMResourceMetering { + <# + .SYNOPSIS + Disables collection of resource utilization data for a virtual machine or resource pool. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which resource utilization data collection is to be disabled. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine on which resource utilization data collection is to be disabled. + .PARAMETER VMName + Specifies the friendly name of the virtual machine on which resource utilization data collection is to be disabled. + .PARAMETER ResourcePoolName + Specifies the friendly name of the resource pool on which resource utilization data collection is to be disabled. + .PARAMETER ResourcePoolType + Specifies the resource type of the resource pool on which resource utilization data collection is to be disabled. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + param ( + [Parameter(ParameterSetName='ResourcePool', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='VMName', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ResourcePool')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ResourcePool')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='ResourcePool', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('Name')] + [ValidateNotNullOrEmpty()] + [string] + ${ResourcePoolName}, + + [Parameter(ParameterSetName='ResourcePool', Position=1, ValueFromPipelineByPropertyName=$true)] + [ValidateSet('Ethernet','Memory','Processor','VHD')] + [Microsoft.HyperV.PowerShell.VMResourcePoolType] + ${ResourcePoolType} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Disable-VMSwitchExtension { + <# + .SYNOPSIS + Disables one or more extensions on one or more virtual switches. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the extension is to be disabled. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the name of the extension to be disabled. + .PARAMETER VMSwitchExtension + Specifies the extension to be disabled. + .PARAMETER VMSwitchName + Specifies the name of the switch on which the extension is to be disabled. + .PARAMETER VMSwitch + Specifies the virtual switch on which the extension is to be disabled. + #> + + [CmdletBinding(DefaultParameterSetName='ExtensionName')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchExtension])] + param ( + [Parameter(ParameterSetName='ExtensionNameSwitchName', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='ExtensionName', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ExtensionName')] + [Parameter(ParameterSetName='ExtensionNameSwitchName')] + [Alias('PSComputerName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ExtensionName')] + [Parameter(ParameterSetName='ExtensionNameSwitchName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='ExtensionName', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='ExtensionNameSwitchName', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='ExtensionNameSwitchObject', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='ExtensionObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitchExtension[]] + ${VMSwitchExtension}, + + [Parameter(ParameterSetName='ExtensionNameSwitchName', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMSwitchName}, + + [Parameter(ParameterSetName='ExtensionNameSwitchObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitch[]] + ${VMSwitch} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Disable-VMTPM { + <# + .SYNOPSIS + Disables TPM functionality on a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts to run the cmdlet. NetBIOS names, IP addresses, and fully-qualified domain names are allowable. The default is the local computer. Use "localhost" or a dot (".") to specify the local computer explicitly. + .PARAMETER Credential + Specifies a user account that has permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine for which you want to disable TPM. + .PARAMETER VMName + Specifies the name of the virtual machine for which you want to disable TPM. + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Disconnect-VMNetworkAdapter { + <# + .SYNOPSIS + Disconnects a virtual network adapter from a virtual switch or Ethernet resource pool. + .PARAMETER VMNetworkAdapter + Specifies the virtual network adapter to be disconnected. + .PARAMETER VMName + Specifies the name of the virtual machine in which the virtual network adapter is to be disconnected. + .PARAMETER Name + Specifies the name of the virtual network adapter to be disconnected. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a virtual network adapter is to be disconnected. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.VMNetworkAdapter object is to be passed through to the pipeline representing the virtual network adapter to be disconnected. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapter])] + param ( + [Parameter(ParameterSetName='Obj', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapter[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='Name', Position=1)] + [Alias('VMNetworkAdapterName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Disconnect-VMSan { + <# + .SYNOPSIS + Removes a host bus adapter from a virtual storage area network (SAN). + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a host bus adapter is to be removed from a virtual storage area network (SAN). NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the name of the virtual storage area network (SAN) from which the host bus adapter is to be removed. + .PARAMETER HostBusAdapter + Specifies the host bus adapter to be removed from the virtual storage area network (SAN). + .PARAMETER WorldWideNodeName + The world wide node name of the host bus adapter to be removed from the virtual storage area network (SAN). + .PARAMETER WorldWidePortName + The world wide port name of the host bus adapter to be removed from the virtual storage area network (SAN). + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual storage area network (SAN) from which the host bus adapter is to be removed. + #> + + [CmdletBinding(DefaultParameterSetName='StringWwn', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSan])] + param ( + [Parameter(ParameterSetName='StringWwn', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='StringWwn')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='StringWwn')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [Alias('SanName')] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='HbaObject', Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [ciminstance[]] + ${HostBusAdapter}, + + [Parameter(ParameterSetName='StringWwn', Mandatory=$true)] + [Alias('Wwnn','NodeName','Wwnns','NodeNames','WorldWideNodeNames','NodeAddress')] + [ValidateNotNullOrEmpty()] + [string[]] + ${WorldWideNodeName}, + + [Parameter(ParameterSetName='StringWwn', Mandatory=$true)] + [Alias('Wwpn','PortName','Wwpns','PortNames','WorldWidePortNames','PortAddress')] + [ValidateNotNullOrEmpty()] + [string[]] + ${WorldWidePortName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Dismount-VHD { + <# + .SYNOPSIS + Dismounts a virtual hard disk. + .PARAMETER DiskNumber + Specifies the disk number of the virtual hard disk to be dismounted. + .PARAMETER Path + Specifies one or more virtual hard disk files for which the corresponding virtual hard disks are to be dismounted. + .PARAMETER SnapshotId + Specifies the unique ID of a VHD set snapshot. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual hard disk to be dismounted. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a virtual hard disk is to be dismounted. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='Path', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.Vhd.PowerShell.VirtualHardDisk])] + param ( + [Parameter(ParameterSetName='Disk', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [Alias('Number')] + [ValidateNotNullOrEmpty()] + [uint32] + ${DiskNumber}, + + [Parameter(ParameterSetName='Path', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('FullName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='Path', ValueFromPipelineByPropertyName=$true)] + [System.Nullable[guid]] + ${SnapshotId}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Dismount-VMHostAssignableDevice { + <# + .SYNOPSIS + Dismount-VMHostAssignableDevice [[-InstancePath] ] [[-LocationPath] ] [-Force] [-Passthru] [-WhatIf] [-Confirm] [] + #> + + [CmdletBinding(DefaultParameterSetName='ComputerName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMHostAssignableDevice])] + param ( + [Parameter(Position=2)] + [string] + ${InstancePath}, + + [Parameter(Position=3)] + [string] + ${LocationPath}, + + [Parameter(Position=4)] + [switch] + ${Force}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Enable-VMConsoleSupport { + <# + .SYNOPSIS + Enables keyboard, video, and mouse for virtual machines. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies an array of virtual machines on which this cmdlet enables support for keyboard, video, and mouse. To obtain a VirtualMachine object, use the Get-VM cmdlet. + .PARAMETER VMName + Specifies an array of names of virtual machines on which this cmdlet enables support keyboard, video, and mouse. + .PARAMETER Passthru + Indicates that this cmdlet returns the Microsoft.HyperV.VirtualMachine object that it modifies. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='VMName')] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Enable-VMEventing { + <# + .SYNOPSIS + Enables virtual machine eventing. + .PARAMETER Force + Specifies that the confirmation prompt is to be suppressed. (This is useful in scripting the cmdlet.) + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which virtual machine eventing is to be enabled. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + param ( + [switch] + ${Force}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Enable-VMIntegrationService { + <# + .SYNOPSIS + Enables an integration service on a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which an integration service is to be enabled. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMIntegrationService + Specifies the integration service to be enabled. + .PARAMETER Name + Specifies the name of the integration service to be enabled. + .PARAMETER VM + Specifies the virtual machine on which the integration service is to be enabled. + .PARAMETER VMName + Specifies the name of the virtual machine on which the integration service is to be enabled. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.IntegrationService object is to be passed through to the pipeline representing the integration service to be enabled. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMIntegrationComponent])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMIntegrationService', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMIntegrationComponent[]] + ${VMIntegrationService}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Enable-VMMigration { + <# + .SYNOPSIS + Enables migration on one or more virtual machine hosts. + .PARAMETER Passthru + Indicates that this cmdlet returns a Microsoft.HyperV.PowerShell.Host object. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='ComputerName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMHost])] + param ( + [switch] + ${Passthru}, + + [Parameter(ParameterSetName='CimSession', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ComputerName', Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ComputerName', Position=1)] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Enable-VMRemoteFXPhysicalVideoAdapter { + <# + .SYNOPSIS + Enables one or more RemoteFX physical video adapters for use with RemoteFX-enabled virtual machines. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the RemoteFX physical video adapters are to be enabled. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER GPU + Specifies the RemoteFX physical video adapters to be enabled. + .PARAMETER Name + Specifies an array of names of adapters. The cmdlet enables the RemoteFX physical video adapters that you specify. + .PARAMETER Passthru + Specifies that one or more Microsoft.HyperV.PowerShell.VMRemoteFXPhysicalVideoAdapter objects are to be passed through to the pipeline representing the RemoteFX physical video adapters to be enabled. + #> + + [CmdletBinding(DefaultParameterSetName='GPUByName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMRemoteFXPhysicalVideoAdapter])] + param ( + [Parameter(ParameterSetName='GPUByName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='GPUByName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='GPUByName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='GPUByObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMRemoteFXPhysicalVideoAdapter[]] + ${GPU}, + + [Parameter(ParameterSetName='GPUByName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Enable-VMReplication { + <# + .SYNOPSIS + Enables replication of a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that have the virtual machines for which you want to enable replication. NetBIOS names, IP addresses, and fully qualified domain names (FQDN) are allowed. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine you want to configure for replication. + .PARAMETER VM + Specifies the virtual machine you want to configure for replication. + .PARAMETER ReplicaServerName + Specifies the name of the Replica server to which this virtual machine will be replicated. + .PARAMETER ReplicaServerPort + Specifies the port on the Replica server to use for replication traffic. Make sure you specify a port that is configured on the Replica server to support the same authentication type you specify using the AuthenticationType parameter in this cmdlet. Run the Get-VMReplicationServer cmdlet on the Replica server to check the configuration of the port, or contact the administrator of the specified Replica server. + .PARAMETER AuthenticationType + Specifies the authentication type to use for virtual machine replication, either Kerberos or Certificate. The specified Replica server must support the chosen authentication type. Run the Get-VMReplicationServer cmdlet to verify the authentication configured for the specified Replica server, or contact the administrator of the specified Replica server. + .PARAMETER CertificateThumbprint + Specifies the certificate to use for mutual authentication of the replication data. This parameter is required only when "Certificate" is specified as the type of authentication. Specify the thumbprint of a valid computer certificate from the Personal store. + + The certificate must have all of the following properties to be valid: - It must not be expired. + + - It must include both client and server authentication extensions for extended key usage (EKU), and an associated private key. + + - It must terminate at a valid root certificate. + + The requirement for the subject common name (CN) differs depending on whether the virtual machine belongs to a cluster. For virtual machines that do not belong to a cluster, the subject common name (CN) must be equal to, or subject alternative name (DNS Name) should contain, the FQDN of the host. For virtual machines that belong to a cluster, the subject common name (CN) must be equal to, or subject alternative name (DNS Name) must contain, the and fully qualified domain name (FQDN) of the Hyper-V Replica Broker. + + To display a list of certificates in the computer's My store and the thumbprint of each certificate, type the following: + + `PS C:\> cd cert:\LocalMachine\My` + + `PS C:\> dir | format-list` + For more information about certificate stores, see http://technet.microsoft.com//library/cc757138.aspx (http://technet.microsoft.com//library/cc757138.aspx). + + .PARAMETER CompressionEnabled + Specifies whether to compress replication data for this virtual machine when it is sent over the network. + .PARAMETER ReplicateHostKvpItems + Specifies whether to replicate host-only key value pairs (KVP) for this virtual machine. + .PARAMETER BypassProxyServer + Specifies whether to bypass a proxy server while replicating data to the Replica server. + .PARAMETER EnableWriteOrderPreservationAcrossDisks + Determines whether all virtual hard disks selected for replication are replicated to the same point in time. This is useful if the virtual machine runs an application that saves data across virtual hard disks (for example, one virtual hard disk dedicated for application data, and another virtual hard disk dedicated for application log files). + .PARAMETER VSSSnapshotFrequencyHour + Specifies the frequency, in hours, at which Volume Shadow Copy Service (VSS) performs a snapshot backup of the virtual machines. Specify this parameter only if application-consistent replication is enabled for the virtual machines and the value you set for the RecoveryHistory parameter is not zero. The cmdlet sets a value of zero for this parameter if application-consistent replication is disabled. Do not specify this parameter if you are extending replication from the Replica virtual machine. + .PARAMETER RecoveryHistory + Specifies whether to store additional recovery points on the replica virtual machine. Storing more than the most recent recovery point of the primary virtual machine allows you to recover to an earlier point in time. However, storing additional recovery points requires more storage and processing resources. You can configure as many as 24 recovery points to be stored. + .PARAMETER ReplicationFrequencySec + Specifies the frequency, in seconds, at which Hyper-V replicates changes to the Replica server. + .PARAMETER ExcludedVhd + Specifies one or more virtual hard disks to exclude from replication (for example, a virtual hard disk dedicated for the paging file). Be careful not to exclude virtual hard disks that are critical to the virtual machine's ability to start up, such as the virtual hard disk that stores the guest operating system. Excluding a critical disk could prevent the replica virtual machine from starting up properly. + .PARAMETER ExcludedVhdPath + Specifies the fully qualified path names to the virtual hard disks to exclude from replication. + .PARAMETER AutoResynchronizeEnabled + Enables replicating virtual machines that require resynchronization to be resynchronized automatically. (For example, a virtual machine requires resynchronization if the primary server shuts down abruptly). Resynchronization requires significant storage and processing resources. We recommended scheduling resynchronization during off-peak hours to reduce the impact to the host and other virtual machines running on the host. Use the AutoResynchronizeIntervalStart and AutoResynchronizeIntervalEnd parameters to specify an off-peak time to start the automatic resynchronization. + .PARAMETER AutoResynchronizeIntervalStart + Specifies the start of the time period in which you want resynchronization to start automatically. + .PARAMETER AutoResynchronizeIntervalEnd + Specifies the end of the time period in which you want resynchronization to start automatically. + .PARAMETER AsReplica + Specifies that the virtual machine is a replica virtual machine, enabling it to be used as the source for the initial replication of the primary virtual machine. + .PARAMETER AllowedPrimaryServer + When you use the AsReplica parameter to specify a virtual machine as a replica virtual machine, this parameter determines which primary servers can send replication to the replica virtual machine. Replication is accepted only from the server specified in the chosen authentication entry, or any other authentication entry that has the same trust group. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplication])] + param ( + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMName_AsReplica')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMName_AsReplica')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMName_AsReplica')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMName_AsReplica', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMObject_AsReplica', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=1)] + [Alias('ReplicaServer')] + [ValidateNotNullOrEmpty()] + [string] + ${ReplicaServerName}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=2)] + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=2)] + [Alias('ReplicaPort')] + [ValidateRange(1, 65535)] + [int] + ${ReplicaServerPort}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=3)] + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=3)] + [Alias('AuthType')] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.ReplicationAuthenticationType] + ${AuthenticationType}, + + [Parameter(ParameterSetName='VMName', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='VMObject', ValueFromPipelineByPropertyName=$true)] + [Alias('Thumbprint','Cert')] + [ValidateNotNullOrEmpty()] + [string] + ${CertificateThumbprint}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [ValidateNotNull()] + [System.Nullable[bool]] + ${CompressionEnabled}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [ValidateNotNull()] + [System.Nullable[bool]] + ${ReplicateHostKvpItems}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [ValidateNotNull()] + [System.Nullable[bool]] + ${BypassProxyServer}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [ValidateNotNull()] + [System.Nullable[bool]] + ${EnableWriteOrderPreservationAcrossDisks}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Alias('VSSFreq')] + [ValidateRange(1, 12)] + [ValidateNotNull()] + [System.Nullable[int]] + ${VSSSnapshotFrequencyHour}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Alias('RecHist')] + [ValidateRange(0, 24)] + [System.Nullable[int]] + ${RecoveryHistory}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Alias('RepFreq')] + [ValidateRange(30, 900)] + [System.Nullable[int]] + ${ReplicationFrequencySec}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.HardDiskDrive[]] + ${ExcludedVhd}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ExcludedVhdPath}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Alias('AutoResync')] + [ValidateNotNull()] + [System.Nullable[bool]] + ${AutoResynchronizeEnabled}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Alias('AutoResyncStart')] + [ValidateNotNull()] + [System.Nullable[timespan]] + ${AutoResynchronizeIntervalStart}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Alias('AutoResyncEnd')] + [ValidateNotNull()] + [System.Nullable[timespan]] + ${AutoResynchronizeIntervalEnd}, + + [Parameter(ParameterSetName='VMObject_AsReplica')] + [Parameter(ParameterSetName='VMName_AsReplica')] + [switch] + ${AsReplica}, + + [Parameter(ParameterSetName='VMName_AsReplica', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='VMObject_AsReplica', ValueFromPipelineByPropertyName=$true)] + [Alias('AllowedPS')] + [ValidateNotNullOrEmpty()] + [string] + ${AllowedPrimaryServer}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Enable-VMResourceMetering { + <# + .SYNOPSIS + Collects resource utilization data for a virtual machine or resource pool. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies the virtual machine host or hosts on which resource utilization data collection is to be enabled. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine for which you want to collect resource utilization data. + .PARAMETER VMName + Specifies the friendly name of the virtual machine for which you want to collect resource utilization data. + .PARAMETER ResourcePoolName + Specifies the friendly name of the resource pool for which you want to collect resource utilization data. + .PARAMETER ResourcePoolType + Specifies the resource type of the resource pool for which you want to collect resource utilization data. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + param ( + [Parameter(ParameterSetName='ResourcePool', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='VMName', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ResourcePool')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ResourcePool')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='ResourcePool', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('Name')] + [ValidateNotNullOrEmpty()] + [string] + ${ResourcePoolName}, + + [Parameter(ParameterSetName='ResourcePool', Position=1, ValueFromPipelineByPropertyName=$true)] + [ValidateSet('Ethernet','Memory','Processor','VHD')] + [Microsoft.HyperV.PowerShell.VMResourcePoolType] + ${ResourcePoolType} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Enable-VMSwitchExtension { + <# + .SYNOPSIS + Enables one or more extensions on one or more switches. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which an extension is to be enabled. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the name of the network extension to be enabled. + .PARAMETER VMSwitchExtension + Specifies the extension to be enabled. + .PARAMETER VMSwitchName + Specifies the name of the switch on which the extension is to be enabled. + .PARAMETER VMSwitch + Specifies the virtual switch on which the extension is to be enabled. + #> + + [CmdletBinding(DefaultParameterSetName='ExtensionName')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchExtension])] + param ( + [Parameter(ParameterSetName='ExtensionNameSwitchName', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='ExtensionName', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ExtensionName')] + [Parameter(ParameterSetName='ExtensionNameSwitchName')] + [Alias('PSComputerName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ExtensionName')] + [Parameter(ParameterSetName='ExtensionNameSwitchName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='ExtensionName', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='ExtensionNameSwitchName', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='ExtensionNameSwitchObject', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='ExtensionObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitchExtension[]] + ${VMSwitchExtension}, + + [Parameter(ParameterSetName='ExtensionNameSwitchName', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMSwitchName}, + + [Parameter(ParameterSetName='ExtensionNameSwitchObject', Mandatory=$true, Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitch[]] + ${VMSwitch} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Enable-VMTPM { + <# + .SYNOPSIS + Enables TPM functionality on a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession or Get-CimSession cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts to run the cmdlet. NetBIOS names, IP addresses, and fully-qualified domain names are allowable. The default is the local computer. Use "localhost" or a dot (".") to specify the local computer explicitly. + .PARAMETER Credential + Specifies a user account that has permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine for which to enable TPM. + .PARAMETER VMName + Specifies the name of the virtual machine for which to enable TPM. + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='VMName')] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Export-VM { + <# + .SYNOPSIS + Exports a virtual machine to disk. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual machine is to be exported. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine to be exported. + .PARAMETER Name + Specifies the name of the virtual machine to be exported. + .PARAMETER Path + Specifies the path to the folder into which the virtual machine is to be exported. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.VirtualMachine object is to be passed through to the pipeline representing the virtual machine to be exported. + .PARAMETER CaptureLiveState + Specifies how Hyper-V captures the running virtual machine memory state. The acceptable values for this parameter are: + + - CaptureSavedState. Include memory state. - CaptureDataConsistentState. Use Production Checkpoint technology. - CaptureCrashConsistentState. Do nothing to handle virtual machine state. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(Mandatory=$true, Position=1)] + [string] + ${Path}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.CaptureLiveState]] + ${CaptureLiveState} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Export-VMSnapshot { + <# + .SYNOPSIS + Exports a virtual machine checkpoint to disk. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual machine checkpoint is to be exported. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine of which the checkpoint is to be exported. + .PARAMETER VMSnapshot + Specifies the checkpoint to be exported. + .PARAMETER Name + Specifies the name of the checkpoint to be exported. + .PARAMETER Path + Specifies the path to the folder into which the checkpoint is to be exported. + .PARAMETER VMName + Specifies the name of the virtual machine of which the checkpoint is to be exported. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that a VMSnapshot object is to be passed through to the pipeline representing the checkpoint to be exported. + #> + + [CmdletBinding(DefaultParameterSetName='SnapshotName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSnapshot])] + param ( + [Parameter(ParameterSetName='SnapshotName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='SnapshotName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='SnapshotName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='SnapshotObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot[]] + ${VMSnapshot}, + + [Parameter(ParameterSetName='SnapshotName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMObject', Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(ParameterSetName='SnapshotName', Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VHD { + <# + .SYNOPSIS + Gets the virtual hard disk object associated with a virtual hard disk. + .PARAMETER DiskNumber + Specifies the disk number associated with the virtual hard disk to be retrieved. + .PARAMETER Path + Specifies the path to the virtual hard disk file of the virtual hard disk to be retrieved. If a filename or relative path is specified, the path is calculated relative to the current working directory. + .PARAMETER VMId + Specifies the virtual machine identifier of the virtual machine whose virtual hard disks are to be retrieved. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a virtual hard disk is to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='Path')] + [OutputType([Microsoft.Vhd.PowerShell.VirtualHardDisk])] + param ( + [Parameter(ParameterSetName='Disk', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [Alias('Number')] + [ValidateNotNullOrEmpty()] + [uint32] + ${DiskNumber}, + + [Parameter(ParameterSetName='Path', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('FullName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='VMId', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('Id')] + [ValidateNotNullOrEmpty()] + [guid[]] + ${VMId}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VHDSet { + <# + .SYNOPSIS + Gets information about a VHD set. + .PARAMETER Path + Specifies an array of paths of VHD set files that this cmdlet gets. If you specify a file name or a relative path, the cmdlet determines the full path relative to the current working folder. + .PARAMETER GetAllPaths + Indicates that this cmdlet gets the paths of all files on which this VHD set file depends. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding()] + [OutputType([Microsoft.Vhd.PowerShell.VHDSetInfo])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('FullName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [switch] + ${GetAllPaths}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VHDSnapshot { + <# + .SYNOPSIS + Gets information about a checkpoint in a VHD set. + .PARAMETER Path + Specifies an array of paths of VHD set files from which this cmdlet gets checkpoints. If you specify a file name or relative path, the cmdlet determines the full path relative to the current working folder. + .PARAMETER GetParentPaths + Gets the paths of all files on which this VHD checkpoint depends. + .PARAMETER SnapshotId + Specifies an array of unique IDs of VHD checkpoints that this cmdlet gets from a VHD set file. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this command. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding()] + [OutputType([Microsoft.Vhd.PowerShell.VHDSnapshotInfo])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('FullName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [switch] + ${GetParentPaths}, + + [guid[]] + ${SnapshotId}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VM { + <# + .SYNOPSIS + Gets the virtual machines from one or more Hyper-V hosts. + .PARAMETER Name + Specifies the name of the virtual machine to be retrieved. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which virtual machines are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Id + Specifies the identifier of the virtual machine to be retrieved. + .PARAMETER ClusterObject + Specifies the cluster resource or cluster group of the virtual machine to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='Name')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='Name', Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='Id')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='Id')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='Id')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Id', Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNull()] + [System.Nullable[guid]] + ${Id}, + + [Parameter(ParameterSetName='ClusterObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [PSTypeName('Microsoft.FailoverClusters.PowerShell.ClusterObject')] + [psobject] + ${ClusterObject} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMAssignableDevice { + <# + .SYNOPSIS + Get-VMAssignableDevice [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [] + +Get-VMAssignableDevice [-VM] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMAssignedDevice])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMBios { + <# + .SYNOPSIS + Gets the BIOS of a virtual machine or snapshot. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the BIOS of a virtual machine or snapshot is to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine whose BIOS is to be retrieved. + .PARAMETER VMSnapshot + Specifies the virtual machine snapshot whose BIOS is to be retrieved. + .PARAMETER VMName + Specifies the name of the virtual machine whose BIOS is to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMBios])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMComPort { + <# + .SYNOPSIS + Gets the COM ports of a virtual machine or snapshot. + .PARAMETER VM + Specifies the virtual machine whose COM ports are to be retrieved. + .PARAMETER VMName + Specifies the name of the virtual machine whose COM ports are to be retrieved. + .PARAMETER VMSnapshot + Specifies the snapshot whose COM ports are to be retrieved. + .PARAMETER Number + Specifies the Id (1 or 2) of the COM ports to be retrieved. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the COM ports of a virtual machine or snapshot are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMComPort])] + param ( + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(Position=1)] + [ValidateRange(1, 2)] + [int] + ${Number}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMConnectAccess { + <# + .SYNOPSIS + Gets entries showing users and the virtual machines to which they can connect on one or more Hyper-V hosts. + .PARAMETER VMId + Specifies the unique identifier of a virtual machine for which connect access entries are being sought. + .PARAMETER VMName + Specifies the name of the virtual machine for which connect access entries are being sought. + .PARAMETER UserName + Specifies the user or users for whom connect access entries are being sought. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMConnectAce])] + param ( + [Parameter(ParameterSetName='VMId', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [guid[]] + ${VMId}, + + [Parameter(ParameterSetName='VMName', Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ValueFromPipelineByPropertyName=$true)] + [Alias('UserId','Sid')] + [ValidateNotNullOrEmpty()] + [string[]] + ${UserName}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMDvdDrive { + <# + .SYNOPSIS + Gets the DVD drives attached to a virtual machine or snapshot. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which the DVD drives are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine from which the DVD drives are to be retrieved. + .PARAMETER VM + Specifies the virtual machine from which the DVD drives are to be retrieved. + .PARAMETER ControllerLocation + Specifies the number of the location on the controller from which the DVD drives are to be retrieved. + .PARAMETER ControllerNumber + Specifies the number of the controller from which the DVD drives are to be retrieved. + .PARAMETER VMDriveController + Specifies the controller from which the DVD drives are to be retrieved. + .PARAMETER VMSnapshot + Specifies the virtual machine snapshot from which the DVD drives are to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.DvdDrive])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerLocation}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMSnapshot')] + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerNumber}, + + [Parameter(ParameterSetName='VMDriveController', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMDriveController[]] + ${VMDriveController}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMFibreChannelHba { + <# + .SYNOPSIS + Gets the Fibre Channel host bus adapters associated with one or more virtual machines. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the Fibre Channel host bus adapters are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies a virtual machine or machines for which the Fibre Channel host bus adapters are to be retrieved. + .PARAMETER VMName + Specifies the friendly name or names of the virtual machines for which the Fibre Channel host bus adapters are to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMFibreChannelHba])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMFirmware { + <# + .SYNOPSIS + Gets the firmware configuration of a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies an array of Hyper-V hosts. The cmdlet gets the virtual machine firmware from the hosts you specify. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies an array of virtual machine objects. The cmdlet gets the firmware configuration for the virtual machines you specify. To obtain a virtual machine object, use the Get-VM cmdlet. + .PARAMETER VMSnapshot + Specifies the virtual machine snapshot to be used with the VM when retrieving the firmware configuration. + .PARAMETER VMName + Specifies an array of names of virtual machines. The cmdlet gets the firmware configuration for the virtual machines you specify. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMFirmware])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMFloppyDiskDrive { + <# + .SYNOPSIS + Gets the floppy disk drives of a virtual machine or snapshot. + .PARAMETER VMSnapshot + Specifies the snapshot whose floppy disk drives are to be retrieved. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which floppy disk drives are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine whose floppy disk drives are to be retrieved. + .PARAMETER VMName + Specifies the name of the virtual machine whose floppy disk drives are to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMFloppyDiskDrive])] + param ( + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMGpuPartitionAdapter { + <# + .SYNOPSIS + Get-VMGpuPartitionAdapter [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [-AdapterId ] [] + +Get-VMGpuPartitionAdapter [-VMSnapshot] [] + +Get-VMGpuPartitionAdapter [-VM] [-AdapterId ] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMGpuPartitionAdapter])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [ValidateNotNullOrEmpty()] + [string] + ${AdapterId} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMGroup { + <# + .SYNOPSIS + Gets virtual machine groups. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies an array of names of virtual machine groups that this cmdlet gets. + .PARAMETER Id + Specifies the unique ID of the virtual machine group that this cmdlet gets. + #> + + [CmdletBinding(DefaultParameterSetName='Name')] + [OutputType([Microsoft.HyperV.PowerShell.VMGroup])] + param ( + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='Id')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='Id')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='Id')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Name', Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='Id', Position=0)] + [ValidateNotNullOrEmpty()] + [guid] + ${Id} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMHardDiskDrive { + <# + .SYNOPSIS + Gets the virtual hard disk drives attached to one or more virtual machines. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which the virtual hard disk drives are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine from which the virtual hard disks drives are to be retrieved. + .PARAMETER VM + Specifies the virtual machine from which the virtual hard disk drives are to be retrieved. + .PARAMETER VMSnapshot + Specifies the snapshot from which the virtual hard disk drives are to be retrieved. + .PARAMETER ControllerLocation + Specifies the number of the location on the controller at which the virtual hard disk drives are to be retrieved. If not specified, the number of the first available location on the controller is used. + .PARAMETER VMDriveController + Specifies the drive controller from which the virtual hard disk drives are to be retreived. + .PARAMETER ControllerNumber + Specifies the number of the controller at which the virtual hard disk drives are to be retrieved. If not specified, the first controller on which the specified ControllerLocation is available is used. + .PARAMETER ControllerType + Specifies the type of the controller from which the virtual hard disk drives are to be retrieved. Allowed values are Floppy , IDE , and SCSI . + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.HardDiskDrive])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerLocation}, + + [Parameter(ParameterSetName='VMDriveController', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMDriveController[]] + ${VMDriveController}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMSnapshot')] + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerNumber}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMSnapshot')] + [System.Nullable[Microsoft.HyperV.PowerShell.ControllerType]] + ${ControllerType} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMHost { + <# + .SYNOPSIS + Gets a Hyper-V host. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='ComputerName')] + [OutputType([Microsoft.HyperV.PowerShell.VMHost])] + param ( + [Parameter(ParameterSetName='CimSession', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ComputerName', Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ComputerName', Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMHostAssignableDevice { + <# + .SYNOPSIS + Get-VMHostAssignableDevice [-CimSession ] [-ComputerName ] [-Credential ] [] + #> + + [CmdletBinding()] + [OutputType([Microsoft.HyperV.PowerShell.VMHostAssignableDevice])] + param ( + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMHostCluster { + <# + .SYNOPSIS + Gets virtual machine host clusters. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ClusterName + Specifies an array of names of the virtual machine host clusters that this cmdlet gets. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='ClusterName')] + [OutputType([Microsoft.HyperV.PowerShell.VMHostCluster])] + param ( + [Parameter(ParameterSetName='CimSession', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ClusterName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ClusterName}, + + [Parameter(ParameterSetName='ClusterName', Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMHostNumaNode { + <# + .SYNOPSIS + Gets the NUMA topology of a virtual machine host. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Id + Identifies a NUMA node for which a VMHostNumaNode is to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='ComputerName')] + [OutputType([Microsoft.HyperV.PowerShell.VMHostNumaNode])] + param ( + [Parameter(ParameterSetName='CimSession', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ComputerName', Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ComputerName', Position=1)] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${Id} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMHostNumaNodeStatus { + <# + .SYNOPSIS + Gets the status of the virtual machines on the non-uniform memory access (NUMA) nodes of a virtual machine host or hosts. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Id + Identifies a NUMA node for which virtual machine status is to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='ComputerName')] + [OutputType([Microsoft.HyperV.PowerShell.Commands.GetVMHostNumaNodeStatus])] + param ( + [Parameter(ParameterSetName='CimSession', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ComputerName', Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ComputerName', Position=1)] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${Id} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMHostSupportedVersion { + <# + .SYNOPSIS + Returns a list of virtual machine configuration versions that are supported on a host. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts to run the cmdlet. NetBIOS names, IP addresses, and fully-qualified domain names are allowable. The default is the local computer. Use "localhost" or a dot (".") to specify the local computer explicitly. + .PARAMETER Credential + Specifies a user account that has permission to perform this action. The default is the current user. + .PARAMETER Default + Specifies that the cmdlet is to return the default virtual machine configuration version for this host. + #> + + [CmdletBinding(DefaultParameterSetName='ComputerName')] + [OutputType([Microsoft.HyperV.PowerShell.VMHostSupportedVersion])] + param ( + [Parameter(ParameterSetName='CimSession', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ComputerName', Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ComputerName', Position=1)] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [switch] + ${Default} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMIdeController { + <# + .SYNOPSIS + Gets the IDE controllers of a virtual machine or snapshot. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the IDE controllers of a virtual machine or snapshot are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine whose IDE controllers are to be retrieved. + .PARAMETER VMSnapshot + Specifies the snapshot whose IDE controllers are to be retrieved. + .PARAMETER VMName + Specifies the name of the virtual machine whose IDE controllers are to be retrieved. + .PARAMETER ControllerNumber + Specifies the number of the IDE controller to be retrieved. Allowed values are 0 and 1. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMIdeController])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(Position=1)] + [ValidateNotNull()] + [ValidateRange(0, 1)] + [System.Nullable[int]] + ${ControllerNumber} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMIntegrationService { + <# + .SYNOPSIS + Gets the integration services of a virtual machine or snapshot. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the integration services are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine from which the integration services are to be retrieved. + .PARAMETER VMSnapshot + Specifies the snapshot from which the integration services are to be retrieved. + .PARAMETER VMName + Specifies the name of the virtual machine from which the integration services are to be retrieved. + .PARAMETER Name + Specifies the name of the integration service to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMIntegrationComponent])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMKeyProtector { + <# + .SYNOPSIS + Retrieves a key protector for a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts to run the cmdlet. NetBIOS names, IP addresses, and fully-qualified domain names are allowable. The default is the local computer. Use "localhost" or a dot (".") to specify the local computer explicitly. + .PARAMETER Credential + Specifies a user account that has permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine for which the cmdlet gets a key protector. + .PARAMETER VMName + Specifies the name of the virtual machine for which the cmdlet gets a key protector. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='VMName')] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMKeyStorageDrive { + <# + .SYNOPSIS + Get-VMKeyStorageDrive [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [-ControllerLocation ] [-ControllerNumber ] [] + +Get-VMKeyStorageDrive [-VM] [-ControllerLocation ] [-ControllerNumber ] [] + +Get-VMKeyStorageDrive [-VMDriveController] [-ControllerLocation ] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.KeyStorageDrive])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerLocation}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerNumber}, + + [Parameter(ParameterSetName='VMDriveController', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMDriveController[]] + ${VMDriveController} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMMemory { + <# + .SYNOPSIS + Gets the memory of a virtual machine or snapshot. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the memory of a virtual machine or snapshot is to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine whose memory is to be retrieved. + .PARAMETER VMSnapshot + Specifies the snapshot whose memory is to be retrieved. + .PARAMETER VMName + Specifies the name of the virtual machine whose memory is to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMMemory])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMMigrationNetwork { + <# + .SYNOPSIS + Gets the networks added for migration to one or more virtual machine hosts. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the networks added for migration are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Subnet + Specifies a string representing an IPv4 or IPv6 subnet mask which identifies the networks to be retrieved. + .PARAMETER Priority + Specifies the priority of the networks to be retrieved. + #> + + [CmdletBinding()] + [OutputType([Microsoft.HyperV.PowerShell.VMMigrationNetwork])] + param ( + [Parameter(ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Subnet}, + + [ValidateNotNullOrEmpty()] + [uint32[]] + ${Priority} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMNetworkAdapter { + <# + .SYNOPSIS + Gets the virtual network adapters of a virtual machine, snapshot, management operating system, or of a virtual machine and management operating system. + .PARAMETER IsLegacy + Specify as $TRUE to retrieve only legacy network adapters, or as $FALSE to retrieve only Hyper-V-specific network adapters. If not specified, virtual network adapters of both types are retrieved. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on the virtual network adapters are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine whose virtual network adapters are to be retrieved. . The asterisk, "*", is the wildcard. If it is specified the cmdlet returns virtual network adapters from every virtual machine in the system. + .PARAMETER VMName + Specifies the name of the virtual machine whose network adapters are to be retrieved. + .PARAMETER Name + Specifies the name of the network adapter to be retrieved. + .PARAMETER All + Specifies all virtual network adapters in the system, regardless of whether the virtual network adapter is in the management operating system or in a virtual machine. + .PARAMETER ManagementOS + Specifies the management operating system, i.e. the virtual machine host operating system. + .PARAMETER VMSnapshot + Specifies the snapshot whose network adapters are to be retrieved. + .PARAMETER SwitchName + Specifies the name of the virtual switch whose network adapters are to be retrieved. (This parameter is available only for virtual network adapters in the management operating system.) + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterBase])] + param ( + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [bool] + ${IsLegacy}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='All')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='All')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='All')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(Position=1)] + [Alias('VMNetworkAdapterName')] + [string] + ${Name}, + + [Parameter(ParameterSetName='All', Mandatory=$true)] + [switch] + ${All}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string] + ${SwitchName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMNetworkAdapterAcl { + <# + .SYNOPSIS + Gets the ACLs configured for a virtual machine network adapter. + .PARAMETER VMSnapshot + Specifies the snapshot in which the ACLs configured for a virtual machine network adapter are to be retrieved. + .PARAMETER VMName + Specifies the name of the virtual machine in which the ACLs configured for a virtual machine network adapter are to be retrieved. + .PARAMETER VMNetworkAdapter + Specifies the virtual network adapter for which the configured ACLs are to be retrieved. + .PARAMETER ManagementOS + Specifies that the ACLs are to be configured in the management (i.e. the parent, or host) operating system. + .PARAMETER VMNetworkAdapterName + Specifies the virtual network adapter name for which the configured ACLs are to be retrieved. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the ACLs configured for a virtual machine network adapter are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine in which the ACLs configured for a virtual machine network adapter are to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterAclSetting])] + param ( + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName', Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMNetworkAdapterExtendedAcl { + <# + .SYNOPSIS + Gets extended ACLs configured for a virtual network adapter. + .PARAMETER VMSnapshot + Specifies a snapshot as a VMSnapshot object. The cmdlet gets ACLs for network adapters that belong to the snapshot that you specify. To obtain a snapshot, use the Get-VMSnapshot cmdlet. + .PARAMETER VMName + Specifies an array of names of VMs. The cmdlet gets ACLs associated with network adapters that belong to the VMs that you specify. + .PARAMETER VMNetworkAdapter + Specifies an array of virtual network adapter objects. The cmdlet gets ACLs associated with the adapters that you specify. To obtain a network adapter, use the Get-VMNetworkAdapter cmdlet. + .PARAMETER ManagementOS + Indicates that the cmdlet operates on the parent or host operating system. If you specify this parameter, this cmdlet gets ACLs associated with network adapters in the parent or host operating system. + .PARAMETER VMNetworkAdapterName + Specifies the name of a virtual network adapter. The cmdlet gets extended ACLs associated with the adapter that you specify. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies an array of Hyper-V hosts. The cmdlet gets the ACLs associated with the virtual network adapters on the Hyper-V hosts that you specify. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies an array of virtual machines as VirtualMachine objects. The cmdlet gets ACLs for network adapters that belong to the virtual machines that you specify. To obtain a virtual machine object, use the Get-VM cmdlet. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterExtendedAclSetting])] + param ( + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName', Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMNetworkAdapterFailoverConfiguration { + <# + .SYNOPSIS + Gets the IP address of a virtual network adapter configured to be used when a virtual machine fails over. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the IP address configuration of a virtual network adapter is to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine for which you want to get the IP address configuration of a virtual network adapter. + .PARAMETER VM + Specifies the virtual machine for which you want to get the IP address configuration of a virtual network adapter. + .PARAMETER VMNetworkAdapter + Specifies the virtual network adapter whose IP address configuration you want to get. + .PARAMETER VMNetworkAdapterName + Specifies the name of the virtual network adapter whose IP address configuration you want to get. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterFailoverSetting])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMNetworkAdapter[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [string] + ${VMNetworkAdapterName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMNetworkAdapterIsolation { + <# + .SYNOPSIS + Gets isolation settings for a virtual network adapter. + .PARAMETER VMSnapshot + Specifies a snapshot as a VMSnapshot object. The cmdlet gets isolation settings for network adapters that belong to the snapshot that you specify. To obtain a snapshot, use the Get-VMSnapshot cmdlet. + .PARAMETER VMName + Specifies an array of names of virtual machines. The cmdlet gets isolation settings for adapters that belong to the virtual machines that you specify. + .PARAMETER VMNetworkAdapter + Specifies an array virtual machine network adapters as VMNetworkAdapterBase objects. The cmdlet gets isolation settings for the adapters that you specify. To obtain a network adapter, use the Get-VMNetworkAdapter cmdlet. + .PARAMETER ManagementOS + Indicates that the cmdlet operates on the parent or host operating system. If you specify this parameter, this cmdlet gets isolation settings for the parent or host operating system. + .PARAMETER VMNetworkAdapterName + Specifies the name of a virtual network adapter. The cmdlet gets isolation settings for the adapters that you specify. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies an array of Hyper-V hosts. The cmdlet gets isolation settings for virtual machines hosted by the computers that you specify. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies an array of virtual machines. The cmdlet gets isolation settings for adapters that belong to the virtual machines that you specify. To obtain a virtual machine object, use the Get-VM cmdlet. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterIsolationSetting])] + param ( + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName', Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMNetworkAdapterRdma { + <# + .SYNOPSIS + Get-VMNetworkAdapterRdma [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [-Name ] [-Passthru] [] + +Get-VMNetworkAdapterRdma -ManagementOS [-CimSession ] [-ComputerName ] [-Credential ] [-Name ] [-SwitchName ] [-Passthru] [] + +Get-VMNetworkAdapterRdma [-VMNetworkAdapter] [-Passthru] [] + +Get-VMNetworkAdapterRdma [-VM] [-Name ] [-Passthru] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterRdmaSetting])] + param ( + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine] + ${VM}, + + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Alias('VMNetworkAdapterName')] + [string] + ${Name}, + + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string] + ${SwitchName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMNetworkAdapterRoutingDomainMapping { + <# + .SYNOPSIS + Gets members of a routing domain. + .PARAMETER RoutingDomainID + Specifies the ID of a routing domain. The ID of a routing domain is a system-assigned GUID. The cmdlet gets the members of the routing domain that you specify. + .PARAMETER RoutingDomainName + Specifies the name of a routing domain. The cmdlet gets the members of the routing domain that you specify. + .PARAMETER VMSnapshot + Specifies a snapshot as a VMSnapshot object. The cmdlet gets the members of the routing domain for network adapters that belong to the snapshot that you specify. To obtain a snapshot object, use the Get-VMSnapshot cmdlet. + .PARAMETER VMName + Specifies an array of friendly names of virtual machines. The cmdlet gets the members of the routing domain from the network interfaces that belong to the virtual machines that you specify. + .PARAMETER VMNetworkAdapter + Specifies an array of virtual network adapters as a VMNetworkAdapterBase object. The cmdlet gets the members of the routing domain on the adapters that you specify. To obtain a network adapter, use the Get-VMNetworkAdapter cmdlet. + .PARAMETER ManagementOS + Indicates that the cmdlet operates on the parent partition or host operating system. + .PARAMETER VMNetworkAdapterName + Specifies the name of a virtual network adapter. The cmdlet gets the members of the routing domain on the adapter that you specify. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies an array of Hyper-V hosts. The cmdlet gets the members of a routing domain on the Hyper-V hosts that you specify. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies an array of virtual machine objects. The cmdlet gets the members of the routing domain from the network interfaces that belong to the virtual machines that you specify. To obtain a virtual machine object, use the Get-VM cmdlet. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterRoutingDomainSetting])] + param ( + [guid] + ${RoutingDomainID}, + + [string] + ${RoutingDomainName}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName', Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMNetworkAdapterTeamMapping { + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterTeamMappingSetting])] + param ( + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine] + ${VM}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [Alias('VMNetworkAdapterName')] + [string] + ${Name}, + + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string] + ${SwitchName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMNetworkAdapterVlan { + <# + .SYNOPSIS + Gets the virtual LAN settings configured on a virtual network adapter. + .PARAMETER VMSnapshot + Specifies the snapshot in which the virtual LAN settings are to be retrieved. + .PARAMETER VMName + Specifies the name of the virtual machine in which the virtual LAN settings configured on a virtual network adapter are to be retrieved. + + Friendly name of the virtual machine + .PARAMETER VMNetworkAdapter + Specifies the virtual network adapter for which the virtual LAN settings are to be retrieved. + .PARAMETER ManagementOS + Specifies that the virtual LAN settings are to be retrieved from the management (i.e. parent, or host) operating system. + .PARAMETER VMNetworkAdapterName + Specifies the name of the virtual network adapter for which the virtual LAN settings are to be retrieved. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual LAN settings configured on a virtual network adapter are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine in which the virtual LAN settings configured on a virtual network adapter are to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterVlanSetting])] + param ( + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName', Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMPartitionableGpu { + <# + .SYNOPSIS + Get-VMPartitionableGpu [[-ComputerName] ] [[-Credential] ] [-Name ] [] + +Get-VMPartitionableGpu [-CimSession] [-Name ] [] + #> + + [CmdletBinding(DefaultParameterSetName='ComputerName')] + [OutputType([Microsoft.HyperV.PowerShell.VMPartitionableGpu])] + param ( + [Parameter(ParameterSetName='CimSession', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ComputerName', Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ComputerName', Position=1)] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [ValidateNotNullOrEmpty()] + [string] + ${Name} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMPmemController { + <# + .SYNOPSIS + Get-VMPmemController [-VMName] [[-ControllerNumber] ] [-CimSession ] [-ComputerName ] [-Credential ] [] + +Get-VMPmemController [-VMSnapshot] [[-ControllerNumber] ] [] + +Get-VMPmemController [-VM] [[-ControllerNumber] ] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMPmemController])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(Position=1)] + [ValidateNotNull()] + [ValidateRange(0, 0)] + [System.Nullable[int]] + ${ControllerNumber}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMProcessor { + <# + .SYNOPSIS + Gets the processor of a virtual machine or snapshot. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the processor of a virtual machine or snapshot is to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMSnapshot + Specifies the snapshot whose processor is to be retrieved. + .PARAMETER VMName + Specifies the name of the virtual machine whose processor is to be retrieved. + .PARAMETER VM + Specifies the virtual machine whose processor is to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMProcessor])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMRemoteFx3dVideoAdapter { + <# + .SYNOPSIS + Gets the RemoteFX video adapter of a virtual machine or snapshot. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the RemoteFX video adapter is to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine whose RemoteFX video adapter is to be retrieved. + .PARAMETER VM + Specifies the virtual machine whose RemoteFX video adapter is to be retrieved. + .PARAMETER VMSnapshot + Specifies the snapshot whose RemoteFX video adapter is to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMRemoteFx3DVideoAdapter])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMRemoteFXPhysicalVideoAdapter { + <# + .SYNOPSIS + Gets the RemoteFX physical graphics adapters on one or more Hyper-V hosts. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the names of one or more RemoteFX physical graphics adapters to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='ComputerName')] + [OutputType([Microsoft.HyperV.PowerShell.VMRemoteFXPhysicalVideoAdapter])] + param ( + [Parameter(ParameterSetName='CimSession', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ComputerName', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ComputerName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMReplication { + <# + .SYNOPSIS + Gets the replication settings for a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which virtual machine replication settings are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine whose replication settings are to be retrieved. + .PARAMETER VM + Specifies the virtual machine whose replication settings are to be retrieved. + .PARAMETER ReplicaServerName + Specifies the replica server name of the virtual machines whose replication settings are to be retrieved. + .PARAMETER PrimaryServerName + Specifies the primary server of the virtual machines whose replication settings are to be retrieved. + .PARAMETER ReplicationState + Gets replication settings for virtual machines with the specified replication state. Valid values are: + + - Error + + - FailOverWaitingCompletion + + - FailedOver + + - NotApplicable + + - ReadyForInitialReplication + + - Replicating + + - Resynchronizing + + - ResynchronizeSuspended + + - Suspended + + - SyncedReplicationComplete + + - WaitingForInitialReplication + + - WaitingForStartResynchronize + .PARAMETER ReplicationHealth + Gets replication settings for virtual machines with the specified replication health state. Valid values are Normal, Warning, and Critical. + .PARAMETER ReplicationMode + Gets the replication settings for virtual machines with the specified replication mode. Valid values are None, Primary, Replica, and TestReplica. + .PARAMETER ReplicationRelationshipType + Specifies the replication relationship type of the virtual machine. Specify whether the replication relationship is a simple primary to replica or is an extended replication chain. The cmdlet gets the replication settings for the virtual machines that have the replication type that you specify. + .PARAMETER TrustGroup + Specifies the trust group of the virtual machines whose replication settings you want to retrieve. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplication])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Position=0, ValueFromPipeline=$true)] + [Alias('Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName')] + [Alias('ReplicaServer')] + [ValidateNotNullOrEmpty()] + [string] + ${ReplicaServerName}, + + [Parameter(ParameterSetName='VMName')] + [Alias('PrimaryServer')] + [ValidateNotNullOrEmpty()] + [string] + ${PrimaryServerName}, + + [Parameter(ParameterSetName='VMName')] + [Alias('State')] + [ValidateNotNullOrEmpty()] + [System.Nullable[Microsoft.HyperV.PowerShell.VMReplicationState]] + ${ReplicationState}, + + [Parameter(ParameterSetName='VMName')] + [Alias('Health')] + [ValidateNotNullOrEmpty()] + [System.Nullable[Microsoft.HyperV.PowerShell.VMReplicationHealthState]] + ${ReplicationHealth}, + + [Parameter(ParameterSetName='VMName')] + [Alias('Mode')] + [ValidateNotNullOrEmpty()] + [System.Nullable[Microsoft.HyperV.PowerShell.VMReplicationMode]] + ${ReplicationMode}, + + [Alias('Relationship')] + [System.Nullable[Microsoft.HyperV.PowerShell.VMReplicationRelationshipType]] + ${ReplicationRelationshipType}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string] + ${TrustGroup} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMReplicationAuthorizationEntry { + <# + .SYNOPSIS + Gets the authorization entries of a Replica server. + .PARAMETER AllowedPrimaryServer + Specifies the allowed primary server for which replication authorization entries are to be retrieved. + .PARAMETER ReplicaStorageLocation + Specifies the location where virtual hard disk files are stored when an authorized primary server sends replication data to the specified Replica server. + .PARAMETER TrustGroup + Gets the replication authorization entries that have the specified value for TrustGroup. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which replication authorization entries are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding()] + [OutputType([Microsoft.HyperV.PowerShell.VMReplicationAuthorizationEntry])] + param ( + [Parameter(Position=0, ValueFromPipeline=$true)] + [Alias('AllowedPS')] + [ValidateNotNullOrEmpty()] + [string] + ${AllowedPrimaryServer}, + + [Alias('StorageLoc')] + [ValidateNotNullOrEmpty()] + [string] + ${ReplicaStorageLocation}, + + [ValidateNotNullOrEmpty()] + [string] + ${TrustGroup}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMReplicationServer { + <# + .SYNOPSIS + Gets the replication and authentication settings of a Replica server. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-v hosts which run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='ComputerName')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplicationServer])] + param ( + [Parameter(ParameterSetName='CimSession', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ComputerName', Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ComputerName', Position=1)] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMResourcePool { + <# + .SYNOPSIS + Gets the resource pools on one or more virtual machine hosts. + .PARAMETER Name + Specifies the name of the resource pool or pools to be retrieved. Wildcards are allowed. + .PARAMETER ResourcePoolType + Specifies the type of the resource pool or pools to be retrieved. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the resource pools are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding()] + [OutputType([Microsoft.HyperV.PowerShell.VMResourcePool])] + param ( + [Parameter(Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMResourcePoolType[]] + ${ResourcePoolType}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMSan { + <# + .SYNOPSIS + Gets the available virtual machine storage area networks on a Hyper-V host or hosts. + .PARAMETER Name + Specifies the friendly name of a virtual storage area network (SAN) to be retrieved. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which the available virtual machine storage area networks (SANs) are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding()] + [OutputType([Microsoft.HyperV.PowerShell.VMSan])] + param ( + [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] + [Alias('SanName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMScsiController { + <# + .SYNOPSIS + Gets the SCSI controllers of a virtual machine or snapshot. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the SCSI controllers are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMSnapshot + Specifies the snapshot whose SCSI controllers are to be retrieved. + .PARAMETER VMName + Specifies the name of the virtual machine whose SCSI controllers are to be retrieved. + .PARAMETER ControllerNumber + Specifies the number of the SCSI controller to be retrieved. + .PARAMETER VM + Specifies the virtual machine whose SCSI controllers are to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMScsiController])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(Position=1)] + [ValidateNotNull()] + [ValidateRange(0, 63)] + [System.Nullable[int]] + ${ControllerNumber}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMSecurity { + <# + .SYNOPSIS + Gets security information about a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts to run the cmdlet. NetBIOS names, IP addresses, and fully-qualified domain names are allowable. The default is the local computer. Use "localhost" or a dot (".") to specify the local computer explicitly. + .PARAMETER Credential + Specifies a user account that has permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of one or more virtual machines for which this cmdlet gets security settings. + .PARAMETER VM + Specifies one or more virtual machines for which this cmdlet gets security settings. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMSecurity])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMSnapshot { + <# + .SYNOPSIS + Gets the checkpoints associated with a virtual machine or checkpoint. + .PARAMETER VMName + Specifies the name of the virtual machine whose checkpoints are to be retrieved. + .PARAMETER VM + Specifies the virtual machine whose checkpoints are to be retrieved. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which checkpoints are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Id + Specifies the unique identifier of the virtual machine whose checkpoints are to be retrieved. + .PARAMETER Name + Specifies the name of the checkpoint to be retrieved. + .PARAMETER ChildOf + Specifies the checkpoint whose child checkpoints are to be retrieved. This retrieves immediate children only. + .PARAMETER ParentOf + Specifies the checkpoint whose immediate parent checkpoint is to be retrieved. + .PARAMETER SnapshotType + Specifies the type of the checkpoints to be retrieved. Allowed values are Standard , Recovery , Planned , Missing , Replica , AppConsistentReplica , and SyncedReplica . + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMSnapshot])] + param ( + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='Id')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='Id')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='Id')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Id', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNull()] + [System.Nullable[guid]] + ${Id}, + + [Parameter(ParameterSetName='VMName', Position=1)] + [Parameter(ParameterSetName='Parent', Position=0)] + [Parameter(ParameterSetName='Child', Position=0)] + [Parameter(ParameterSetName='VMObject', Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='Child', Mandatory=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${ChildOf}, + + [Parameter(ParameterSetName='Parent', Mandatory=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VirtualMachineBase] + ${ParentOf}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='Parent')] + [Parameter(ParameterSetName='Child')] + [Parameter(ParameterSetName='VMName')] + [Alias('VMRecoveryCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.SnapshotType] + ${SnapshotType} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMStoragePath { + <# + .SYNOPSIS + Gets the storage paths in a storage resource pool. + .PARAMETER Path + Specifies the path for which matching storage paths are to be retrieved. + .PARAMETER ResourcePoolName + Specifies the name of the resource pool for which storage paths are to be retrieved. + .PARAMETER ResourcePoolType + Specifies the type of the resource pool for which storage paths are to be retrieved. Valid values are: + + - Memory + + - Processor + + - Ethernet + + - VHD + + - ISO + + - VFD + + - FibreChannelPort + + - FibreChannelConnection + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which storage paths are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding()] + [OutputType([Microsoft.HyperV.PowerShell.VMStorageResourcePool])] + param ( + [Parameter(Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ResourcePoolName}, + + [Parameter(Mandatory=$true, Position=2)] + [Microsoft.HyperV.PowerShell.VMResourcePoolType] + ${ResourcePoolType}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMStorageSettings { + <# + .SYNOPSIS + Get-VMStorageSettings [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [] + +Get-VMStorageSettings [-VM] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMStorageSetting])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMSwitch { + <# + .SYNOPSIS + Gets virtual switches from one or more virtual Hyper-V hosts. + .PARAMETER Id + Specifies the unique identifier of the virtual switch to be retrieved. + .PARAMETER Name + Specifies the name of the virtual switch to be retrieved. + .PARAMETER ResourcePoolName + Specifies the resource pool from which the virtual switches are to be retrieved. + .PARAMETER SwitchType + Specifies the type of the virtual switches to be retrieved. Allowed values are External , Internal , and Private . + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which virtual switches are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='Name')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitch])] + param ( + [Parameter(ParameterSetName='Id', Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('SwitchId')] + [ValidateNotNull()] + [guid[]] + ${Id}, + + [Parameter(ParameterSetName='Name', Position=0)] + [Alias('SwitchName')] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ResourcePoolName}, + + [Microsoft.HyperV.PowerShell.VMSwitchType[]] + ${SwitchType}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMSwitchExtension { + <# + .SYNOPSIS + Gets the extensions on one or more virtual switches. + .PARAMETER VMSwitchName + Specifies the name of the virtual switch from which the extensions are to be retrieved. + .PARAMETER VMSwitch + Specifies the virtual switch from which the extensions are to be retrieved. + .PARAMETER Name + Specifies the name of the extension to be retrieved. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the extensions are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='SwitchName')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchExtension])] + param ( + [Parameter(ParameterSetName='SwitchName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMSwitchName}, + + [Parameter(ParameterSetName='SwitchObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitch[]] + ${VMSwitch}, + + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='SwitchName', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='SwitchName')] + [Alias('PSComputerName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='SwitchName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMSwitchExtensionPortData { + <# + .SYNOPSIS + Retrieves the status of a virtual switch extension feature applied to a virtual network adapter. + .PARAMETER VMName + Specifies the name of the virtual machine. + .PARAMETER VMNetworkAdapter + Specifies the virtual machine network adapter. + .PARAMETER ManagementOS + Specifies that the status is to be retrieved from the management (i.e. parent, or host) operating system. + .PARAMETER ExternalPort + Specifies the virtual switch port connected to the external network adapter. + .PARAMETER SwitchName + Specifies the name of the virtual switch. + .PARAMETER VMNetworkAdapterName + Specifies the name of the virtual machine network adapter. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the status of a virtual switch extension applied to a virtual network adapter is to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies an array of virtual machine objects. The cmdlet gets the status of the virtual switch extension for the virtual machines that you specify. To obtain a virtual machine object, use the Get-VM cmdlet. + .PARAMETER FeatureName + Specifies the name of the feature supported by the virtual switch extension. + .PARAMETER FeatureId + Specifies the unique identifier of the feature supported by the virtual switch extension. + .PARAMETER Extension + Specifies the virtual switch extension for which status is to be retrieved. + .PARAMETER ExtensionName + Specifies the name of the virtual switch extension for which status is to be retrieved. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchExtensionPortData])] + param ( + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='ExternalPort', Mandatory=$true)] + [switch] + ${ExternalPort}, + + [Parameter(ParameterSetName='ExternalPort')] + [string] + ${SwitchName}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='ExternalPort')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ExternalPort')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='ExternalPort')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${FeatureName}, + + [ValidateNotNullOrEmpty()] + [guid[]] + ${FeatureId}, + + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitchExtension[]] + ${Extension}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ExtensionName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMSwitchExtensionPortFeature { + <# + .SYNOPSIS + Gets the features configured on a virtual network adapter. + .PARAMETER VMName + Specifies the name of the virtual machine on which the features configured on a virtual switch are to be retrieved. + .PARAMETER VMNetworkAdapter + Specifies the network adapter. + .PARAMETER ManagementOS + Specifies that the features are to be retrieved from the management (i.e. parent, or host) operating system. + .PARAMETER ExternalPort + Specifies the virtual switch port connected to the external network adapter. + .PARAMETER SwitchName + Specifies the name of the virtual switch. + .PARAMETER VMNetworkAdapterName + Specifies the name of the network adapter. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more virtual machine hosts on which the features configured on a virtual network adapter are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine on which the features configured on a virtual switch are to be retrieved. + .PARAMETER FeatureName + Specifies the name of the feature supported by the virtual switch extension. + .PARAMETER FeatureId + Specifies the unique identifier of the feature supported by the virtual switch extension. + .PARAMETER Extension + Specifies the virtual switch extension. + .PARAMETER ExtensionName + Specifies the name of the virtual switch extension. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchExtensionPortFeature])] + param ( + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='ExternalPort', Mandatory=$true)] + [switch] + ${ExternalPort}, + + [Parameter(ParameterSetName='ExternalPort')] + [string] + ${SwitchName}, + + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='ExternalPort')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='ExternalPort')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='ExternalPort')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${FeatureName}, + + [ValidateNotNullOrEmpty()] + [guid[]] + ${FeatureId}, + + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitchExtension[]] + ${Extension}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ExtensionName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMSwitchExtensionSwitchData { + <# + .SYNOPSIS + Gets the status of a virtual switch extension feature applied on a virtual switch. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the status of a virtual switch extension is to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER SwitchName + Specifies the name of the virtual switch. + .PARAMETER VMSwitch + Specifies the virtual switch. + .PARAMETER FeatureName + Specifies the name of a feature supported by the virtual switch extension. + .PARAMETER FeatureId + Specifies the unique identifier of a feature supported by the virtual switch extension. + .PARAMETER Extension + Specifies the virtual switch extension for which status is to be retrieved. + .PARAMETER ExtensionName + Specifies the name of the virtual switch extension for which status is to be retrieved. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchExtensionSwitchData])] + param ( + [Parameter(ParameterSetName='SwitchName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='SwitchName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='SwitchName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='SwitchName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${SwitchName}, + + [Parameter(ParameterSetName='SwitchObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMSwitch[]] + ${VMSwitch}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${FeatureName}, + + [ValidateNotNullOrEmpty()] + [guid[]] + ${FeatureId}, + + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitchExtension[]] + ${Extension}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ExtensionName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMSwitchExtensionSwitchFeature { + <# + .SYNOPSIS + Gets the features configured on a virtual switch. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the features configured on a virtual switch are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER SwitchName + Specifies the name of the virtual switch. + .PARAMETER VMSwitch + Specifies the virtual switch. + .PARAMETER FeatureName + Specifies the name of the feature. + .PARAMETER FeatureId + Specifies the unique identifier of the feature. + .PARAMETER Extension + Specifies the virtual switch extension. + .PARAMETER ExtensionName + Specifies the name of the virtual switch extension. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchExtensionSwitchFeature])] + param ( + [Parameter(ParameterSetName='SwitchName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='SwitchName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='SwitchName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='SwitchName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${SwitchName}, + + [Parameter(ParameterSetName='SwitchObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMSwitch[]] + ${VMSwitch}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${FeatureName}, + + [ValidateNotNullOrEmpty()] + [guid[]] + ${FeatureId}, + + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitchExtension[]] + ${Extension}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ExtensionName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMSwitchTeam { + <# + .SYNOPSIS + Gets virtual switch teams from Hyper-V hosts. + .PARAMETER Name + Specifies the name of the virtual switch team that this cmdlet gets. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='Name')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchTeam])] + param ( + [Parameter(ParameterSetName='Name', Position=0)] + [Alias('SwitchName')] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='SwitchObject', Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitch[]] + ${VMSwitch}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMSystemSwitchExtension { + <# + .SYNOPSIS + Gets the switch extensions installed on a virtual machine host. + .PARAMETER Name + Specifies the name of the switch extension to be retrieved. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which the switch extensions are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding()] + [OutputType([Microsoft.HyperV.PowerShell.VMSystemSwitchExtension])] + param ( + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMSystemSwitchExtensionPortFeature { + <# + .SYNOPSIS + Gets the port-level features supported by virtual switch extensions on one or more Hyper-V hosts. + .PARAMETER FeatureName + Specifies the name of the feature to be retrieved. + .PARAMETER FeatureId + Specifies the unique identifier of the feature to be retrieved. + .PARAMETER ExtensionName + Specifies one or more extension names for which the features are to be retrieved. + .PARAMETER SystemSwitchExtension + Specifies one or more system extensions for which the features are to be retrieved. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which the available port-level features are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding()] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchExtensionPortFeature])] + param ( + [string[]] + ${FeatureName}, + + [guid[]] + ${FeatureId}, + + [string[]] + ${ExtensionName}, + + [Microsoft.HyperV.PowerShell.VMSystemSwitchExtension[]] + ${SystemSwitchExtension}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMSystemSwitchExtensionSwitchFeature { + <# + .SYNOPSIS + Gets the switch-level features on one or more Hyper-V hosts. + .PARAMETER FeatureName + Specifies the name of the switch-level features to be retrieved. + .PARAMETER FeatureId + Specifies the unique identifier of the features are to be retrieved. + .PARAMETER ExtensionName + Specifies the name of the extension from which the switch-level features are to be retrieved. + .PARAMETER SystemSwitchExtension + Specifies the extension from which the switch-level features are to be retrieved. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which the switch-level features in an extension are to be retrieved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding()] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchExtensionSwitchFeature])] + param ( + [string[]] + ${FeatureName}, + + [guid[]] + ${FeatureId}, + + [string[]] + ${ExtensionName}, + + [Microsoft.HyperV.PowerShell.VMSystemSwitchExtension[]] + ${SystemSwitchExtension}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Get-VMVideo { + <# + .SYNOPSIS + Gets video settings for virtual machines. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMSnapshot + Specifies virtual machine checkpoint for which this cmdlet gets video settings. To obtain a VMSnapshot object, use the Get-VMSnapshot cmdlet. + + Checkpoint replaces the previous term, snapshot. + .PARAMETER VMName + Specifies an array of names of virtual machines for which this cmdlet gets video settings. + .PARAMETER VM + Specifies an array of virtual machines for which this cmdlet gets video settings. To obtain a VirtualMachine object, use the Get-VM cmdlet. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMVideo])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Grant-VMConnectAccess { + <# + .SYNOPSIS + Grants a user or users access to connect to a virtual machine or machines. + .PARAMETER VMId + Specifies the unique identifier of a virtual machine to which connect access is to be granted. + .PARAMETER VMName + Specifies the name of a virtual machine to which connect access is to be granted. + .PARAMETER UserName + Specifies a user or users to whom access to connect to a virtual machine or machines is to be granted. + .PARAMETER Passthru + Indicates that this cmdlet returns a Microsoft.HyperV.PowerShell.VMConnectAce object. By default, this cmdlet does not return any output. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-v hosts which run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMConnectAce])] + param ( + [Parameter(ParameterSetName='VMId', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [guid[]] + ${VMId}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(Mandatory=$true, Position=1, ValueFromPipelineByPropertyName=$true)] + [Alias('UserId','Sid')] + [ValidateNotNullOrEmpty()] + [string[]] + ${UserName}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Import-VM { + <# + .SYNOPSIS + Imports a virtual machine from a file. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which the virtual machine is to be imported. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER CompatibilityReport + Specifies a compatibility report which resolves any incompatibilities between the virtual machine and the Hyper-V host. + .PARAMETER Path + Specifies the path to the exported virtual machine to be imported. + .PARAMETER VhdDestinationPath + Specifies the folder to which the virtual machine's VHD files are to be copied. + .PARAMETER Register + Specifies that the imported virtual machine is to be registered in-place, as opposed to copying its files to the server's default locations. Choose this option if the virtual machines files are already in the location from which they are to run. + .PARAMETER Copy + Specifies that the imported virtual machine's files should be copied to the server's default locations, as opposed to registering the virtual machine in-place. + .PARAMETER VirtualMachinePath + Specifies the path where the virtual machine configuration files are to be stored. + .PARAMETER SnapshotFilePath + Specifies the path for any snapshot files associated with the virtual machine. + .PARAMETER SmartPagingFilePath + Specifies the new path to use for a smart paging file, if one is needed. + .PARAMETER VhdSourcePath + Specifies the folder from which the virtual machine's VHD files are to be copied. + .PARAMETER GenerateNewId + Specifies that the imported virtual machine should be copied and given a new unique identifier. (By default, Import-VM gives the new virtual machine the same unique identifier as the imported virtual machine.) + .PARAMETER AsJob + Runs the cmdlet as a background job. + #> + + [CmdletBinding(DefaultParameterSetName='Register', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='Register')] + [Parameter(ParameterSetName='Copy')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Register')] + [Parameter(ParameterSetName='Copy')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Register')] + [Parameter(ParameterSetName='Copy')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='CompatibilityReport', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMCompatibilityReport] + ${CompatibilityReport}, + + [Parameter(ParameterSetName='Register', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='Copy', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(ParameterSetName='Copy', Position=1)] + [string] + ${VhdDestinationPath}, + + [Parameter(ParameterSetName='Register')] + [switch] + ${Register}, + + [Parameter(ParameterSetName='Copy', Mandatory=$true)] + [switch] + ${Copy}, + + [Parameter(ParameterSetName='Copy')] + [string] + ${VirtualMachinePath}, + + [Parameter(ParameterSetName='Copy')] + [Alias('CheckpointFileLocation','SnapshotFileLocation')] + [string] + ${SnapshotFilePath}, + + [Parameter(ParameterSetName='Copy')] + [string] + ${SmartPagingFilePath}, + + [Parameter(ParameterSetName='Copy')] + [string] + ${VhdSourcePath}, + + [Parameter(ParameterSetName='Copy')] + [switch] + ${GenerateNewId}, + + [switch] + ${AsJob} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Import-VMInitialReplication { + <# + .SYNOPSIS + Imports initial replication files for a Replica virtual machine to complete the initial replication when using external media as the source. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which initial replication files are to be imported. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine for which the initial replication files are to be imported. + .PARAMETER VM + Specifies the virtual machine for which the initial replication files are to be imported. + .PARAMETER VMReplication + Specifies the virtual machine replication object for which initial replication files are to be imported. + .PARAMETER Path + Specifies the path of the initial replication files to import. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Indicates that this cmdlet returns a Microsoft.HyperV.PowerShell.VirtualMachine object. By default, this cmdlet does not generate any output. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplication])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMReplication', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMReplication[]] + ${VMReplication}, + + [Parameter(Mandatory=$true, Position=1)] + [Alias('IRLoc')] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Measure-VM { + <# + .SYNOPSIS + Reports resource utilization data for one or more virtual machines. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more virtual machine hosts for which resource utilization is to be reported. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the friendly name of the virtual machine whose resource utilization data will be reported. + .PARAMETER VM + Specifies the virtual machine whose resource utilization will be reported. + #> + + [CmdletBinding(DefaultParameterSetName='Name')] + [OutputType([Microsoft.HyperV.PowerShell.VMMeteringReportForVirtualMachine])] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Measure-VMReplication { + <# + .SYNOPSIS + Gets replication statistics and information associated with a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which to get replication statistics. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine for which you want to get virtual machine replication statistics. + .PARAMETER VM + Specifies the virtual machine for which you want to get replication statistics. + .PARAMETER ReplicaServerName + Specifies the name of a Replica server of the virtual machines whose replication statistics you want to get. + .PARAMETER PrimaryServerName + Specifies the name of a primary server. Replication statistics are retrieved for all virtual machines from the specified primary server. + .PARAMETER ReplicationState + Specifies the replication state of the virtual machines for which you want to get replication statistics. Valid values are: + + - Error + + - FailOverWaitingCompletion + + - FailedOver + + - NotApplicable + + - ReadyForInitialReplication + + - Replicating + + - Resynchronizing + + - ResynchronizeSuspended + + - Suspended + + - SyncedReplicationComplete + + - WaitingForInitialReplication + + - WaitingForStartResynchronize + .PARAMETER ReplicationHealth + Specifies the replication health of the virtual machines whose replication statistics you want to get. Valid values are "Critical", "Warning", "Normal", and "NotApplicable". + .PARAMETER ReplicationMode + Specifies the replication mode of the virtual machines whose replication statistics you want to get. Valid values are "None", "Primary", "Replica" and "TestReplica". + .PARAMETER ReplicationRelationshipType + Specifies the replication relationship type of the virtual machine. Specify whether the replication relationship is a simple primary to replica or is an extended replication chain. The cmdlet gets replication statistics and information associated with the virtual machines that have the replication type that you specify. + .PARAMETER TrustGroup + Specifies a trust group associated with the virtual machines whose replication statistics you want to get. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplicationHealth])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Position=0, ValueFromPipeline=$true)] + [Alias('Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName')] + [Alias('ReplicaServer')] + [ValidateNotNullOrEmpty()] + [string] + ${ReplicaServerName}, + + [Parameter(ParameterSetName='VMName')] + [Alias('PrimaryServer')] + [ValidateNotNullOrEmpty()] + [string] + ${PrimaryServerName}, + + [Parameter(ParameterSetName='VMName')] + [Alias('State')] + [ValidateNotNullOrEmpty()] + [System.Nullable[Microsoft.HyperV.PowerShell.VMReplicationState]] + ${ReplicationState}, + + [Parameter(ParameterSetName='VMName')] + [Alias('Health')] + [ValidateNotNullOrEmpty()] + [System.Nullable[Microsoft.HyperV.PowerShell.VMReplicationHealthState]] + ${ReplicationHealth}, + + [Parameter(ParameterSetName='VMName')] + [Alias('Mode')] + [ValidateNotNullOrEmpty()] + [System.Nullable[Microsoft.HyperV.PowerShell.VMReplicationMode]] + ${ReplicationMode}, + + [Alias('Relationship')] + [System.Nullable[Microsoft.HyperV.PowerShell.VMReplicationRelationshipType]] + ${ReplicationRelationshipType}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string] + ${TrustGroup} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Measure-VMResourcePool { + <# + .SYNOPSIS + Reports resource utilization data for one or more resource pools. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more virtual machine hosts for which resource utilization is to be reported. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the friendly name of the resource pool for which resource utilization is to be reported. + .PARAMETER ResourcePoolType + Specifies the resource type of the virtual machine resource pool for which resource utilization is to be reported. Valid values are: + + - Ethernet + + - Memory + + - Processor + + - VHD + #> + + [CmdletBinding()] + [OutputType([Microsoft.HyperV.PowerShell.VMMeteringReportForResourcePool])] + param ( + [Parameter(ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(Position=1, ValueFromPipelineByPropertyName=$true)] + [ValidateSet('Ethernet','Memory','Processor','VHD')] + [Microsoft.HyperV.PowerShell.VMResourcePoolType[]] + ${ResourcePoolType} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Merge-VHD { + <# + .SYNOPSIS + Merges virtual hard disks. + .PARAMETER Path + Specifies the path to the child in the virtual hard disk chain that is the source for the merge command. If a filename or relative path is specified, the virtual hard disk path will be calculated relative to the current working directory. + .PARAMETER DestinationPath + Specifies the path to the child in the virtual hard disk chain that is the destination for the merge command. + .PARAMETER Force + Runs the cmdlet without prompting for confirmation. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the merged virtual hard disk. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which virtual hard disks are to be merged. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.Vhd.PowerShell.VirtualHardDisk])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('FullName')] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${DestinationPath}, + + [switch] + ${Force}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Mount-VHD { + <# + .SYNOPSIS + Mounts one or more virtual hard disks. + .PARAMETER Path + Specifies the path to the virtual hard disk file for the virtual hard disk to be mounted. If a filename or relative path is specified, the virtual hard disk path is calculated relative to the current working directory. + .PARAMETER NoDriveLetter + Specifies that the virtual hard disk is to be mounted without assigning drive letters to the volumes contained within the virtual hard disk. + .PARAMETER ReadOnly + Specifies that the virtual hard disk is to be mounted in read-only mode. + .PARAMETER SnapshotId + Specifies the unique ID of a VHD set. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual hard disk to be mounted. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a virtual hard disk is to be mounted. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.Vhd.PowerShell.VirtualHardDisk])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('FullName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [switch] + ${NoDriveLetter}, + + [switch] + ${ReadOnly}, + + [Parameter(ValueFromPipelineByPropertyName=$true)] + [System.Nullable[guid]] + ${SnapshotId}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Mount-VMHostAssignableDevice { + <# + .SYNOPSIS + Mount-VMHostAssignableDevice [[-HostAssignableDevice] ] [[-InstancePath] ] [[-LocationPath] ] [-Passthru] [-WhatIf] [-Confirm] [] + #> + + [CmdletBinding(DefaultParameterSetName='ComputerName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMHostAssignableDevice])] + param ( + [Parameter(Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMHostAssignableDevice[]] + ${HostAssignableDevice}, + + [Parameter(Position=2)] + [string] + ${InstancePath}, + + [Parameter(Position=3)] + [string] + ${LocationPath}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Move-VM { + <# + .SYNOPSIS + Moves a virtual machine to a new Hyper-V host. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER CompatibilityReport + Specifies a compatibility report which includes any adjustments required for the move. + .PARAMETER Name + Specifies the friendly name of the virtual machine to be moved. + .PARAMETER VM + Specifies the virtual machine to be moved. + .PARAMETER DestinationCimSession + Specifies the CIMSession on the Hyper-V host to which the virtual machine is to be moved. + .PARAMETER DestinationHost + Specifies the Hyper-V host to which the virtual machine is to be moved. + .PARAMETER DestinationCredential + Specifies a user account that has permission to perform this action. The default is the current user. + .PARAMETER IncludeStorage + Specifies that both the virtual machine and its storage are to be moved. + .PARAMETER DestinationStoragePath + Specifies a destination storage path to which all virtual machine storage is to be moved. + .PARAMETER VirtualMachinePath + Specifies the path where the virtual machine configuration files are to be stored. + .PARAMETER SnapshotFilePath + Specifies the path for any snapshot files associated with the virtual machine. + .PARAMETER SmartPagingFilePath + Specifies the new path to use for a smart paging file, if one is needed. + .PARAMETER Vhds + Specifies an array of hashtables that contain locations for each individual virtual hard disk to be moved. Each hashtable should have two entries. The first entry specifies the current location of the virtual hard disk to move, and has a key of SourceFilePath . The second entry specifies the new location for the virtual hard disk, and has a key of DestinationFilePath . The virtual hard disk name must be identical in both entries. + .PARAMETER ResourcePoolName + Specifies the name of the processor resource pool to be used. + .PARAMETER RetainVhdCopiesOnSource + Indicates that this cmdlet retains parent virtual hard disks on the source computer. + .PARAMETER RemoveSourceUnmanagedVhds + Indicates that Hyper-V deletes the parent virtual hard disk on the source after this cmdlet moves a differencing virtual hard disk, when the migration is finished. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that an object is to be passed through to be pipeline representing the moved virtual machine. + #> + + [CmdletBinding(DefaultParameterSetName='NameSingleDestination', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='NameSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='NameSingleDestination')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='CompatibilityReport', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMCompatibilityReport] + ${CompatibilityReport}, + + [Parameter(ParameterSetName='NameSingleDestination', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='NameSingleDestinationAndCimSession', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='NameMultipleDestinations', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='VMSingleDestination', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMSingleDestinationAndCimSession', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMMultipleDestinations', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine] + ${VM}, + + [Parameter(ParameterSetName='NameSingleDestinationAndCimSession', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VMSingleDestinationAndCimSession', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [CimSession] + ${DestinationCimSession}, + + [Parameter(ParameterSetName='NameSingleDestination', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='NameMultipleDestinations', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VMSingleDestination', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VMMultipleDestinations', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${DestinationHost}, + + [Parameter(ParameterSetName='VMSingleDestination')] + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${DestinationCredential}, + + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='VMSingleDestination')] + [Parameter(ParameterSetName='VMSingleDestinationAndCimSession')] + [switch] + ${IncludeStorage}, + + [Parameter(ParameterSetName='VMSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='VMSingleDestination')] + [ValidateNotNullOrEmpty()] + [string] + ${DestinationStoragePath}, + + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession', Mandatory=$true)] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession', Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${VirtualMachinePath}, + + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession')] + [Alias('CheckpointFileLocation','SnapshotFileLocation')] + [ValidateNotNullOrEmpty()] + [string] + ${SnapshotFilePath}, + + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession')] + [ValidateNotNullOrEmpty()] + [string] + ${SmartPagingFilePath}, + + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession')] + [ValidateNotNullOrEmpty()] + [hashtable[]] + ${Vhds}, + + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession')] + [Parameter(ParameterSetName='VMSingleDestination')] + [Parameter(ParameterSetName='VMSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession')] + [ValidateNotNullOrEmpty()] + [string] + ${ResourcePoolName}, + + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession')] + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='VMSingleDestination')] + [Parameter(ParameterSetName='VMSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession')] + [switch] + ${RetainVhdCopiesOnSource}, + + [Parameter(ParameterSetName='NameSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='NameMultipleDestinationsAndCimSession')] + [Parameter(ParameterSetName='VMSingleDestination')] + [Parameter(ParameterSetName='VMSingleDestinationAndCimSession')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinationsAndCimSession')] + [switch] + ${RemoveSourceUnmanagedVhds}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Move-VMStorage { + <# + .SYNOPSIS + Moves the storage of a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more virtual machine hosts on which the virtual machine storage is to be moved. NetBIOS names, IP addresses, and fully-qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies a name. + .PARAMETER VM + Specifies the virtual machine whose storage is to be moved. + .PARAMETER DestinationStoragePath + Specifies a destination storage path to which all virtual machine storage is to be moved. + .PARAMETER VirtualMachinePath + Specifies the path to the virtual machine configuration file and associated memory files. + .PARAMETER SnapshotFilePath + Specifies the new path for any snapshot files associated with the virtual machine. + .PARAMETER SmartPagingFilePath + Specifies the new path to use for a smart paging file, if one is needed. + .PARAMETER Vhds + Specifies an array of hashtables that contain locations for each individual virtual hard disk to be moved. Each hashtable should have two entries. The first entry specifies the current location of the virtual hard disk to move, and has a key of SourceFilePath. The second entry specifies the new location for the virtual hard disk, and has a key of DestinationFilePath. The virtual hard disk name must be identical in both entries. + .PARAMETER ResourcePoolName + Specifies the name of the storage resource pool to use after the move operation is complete. + .PARAMETER RetainVhdCopiesOnSource + Specify $true to keep any parent virtual hard disks on the source computer. If not specified, all virtual hard disks will be removed from the source computer once the virtual machine is successfully moved. + .PARAMETER RemoveSourceUnmanagedVhds + Indicates that Hyper-V deletes the parent virtual hard disk on the source after this cmdlet moves a differencing virtual hard disk, when the migration is finished. + .PARAMETER AllowUnverifiedPaths + Allows the move operation to be attempted even if the paths specified for the destination computer cannot be verified prior to attempting the move operation. + .PARAMETER AsJob + Runs the cmdlet as a background job. + #> + + [CmdletBinding(DefaultParameterSetName='NameSingleDestination', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + param ( + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='NameSingleDestination')] + [Parameter(ParameterSetName='NameMultipleDestinations')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='NameSingleDestination', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='NameMultipleDestinations', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='VMSingleDestination', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMMultipleDestinations', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine] + ${VM}, + + [Parameter(ParameterSetName='VMSingleDestination', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='NameSingleDestination', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${DestinationStoragePath}, + + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [ValidateNotNullOrEmpty()] + [string] + ${VirtualMachinePath}, + + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [Alias('CheckpointFileLocation','SnapshotFileLocation')] + [ValidateNotNullOrEmpty()] + [string] + ${SnapshotFilePath}, + + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [ValidateNotNullOrEmpty()] + [string] + ${SmartPagingFilePath}, + + [Parameter(ParameterSetName='NameMultipleDestinations')] + [Parameter(ParameterSetName='VMMultipleDestinations')] + [ValidateNotNullOrEmpty()] + [hashtable[]] + ${Vhds}, + + [ValidateNotNullOrEmpty()] + [string] + ${ResourcePoolName}, + + [switch] + ${RetainVhdCopiesOnSource}, + + [switch] + ${RemoveSourceUnmanagedVhds}, + + [switch] + ${AllowUnverifiedPaths}, + + [switch] + ${AsJob} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function New-VFD { + <# + .SYNOPSIS + Creates a virtual floppy disk. + .PARAMETER Path + Specifies the path to the new virtual floppy disk files to be created. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more virtual machine hosts on which the virtual floppy disk is to be created. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([System.IO.FileInfo])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function New-VHD { + <# + .SYNOPSIS + Creates one or more new virtual hard disks. + .PARAMETER Path + Path to the new virtual hard disk file(s) that is being created as a result of a command. If a filename or relative path is specified, the new virtual hard disk path is calculated relative to the current working directory. + .PARAMETER ParentPath + Specifies the path to the parent of the differencing disk to be created (this parameter may be specified only for the creation of a differencing disk). + .PARAMETER SizeBytes + The maximum size, in bytes, of the virtual hard disk to be created. + .PARAMETER SourceDisk + Specifies the physical disk to be used as the source for the virtual hard disk to be created. + .PARAMETER Dynamic + Specifies that a dynamic virtual hard disk is to be created. + .PARAMETER Fixed + Specifies that a fixed virtual hard disk is to be created. + .PARAMETER Differencing + Specifies that a differencing virtual hard disk is to be created. + .PARAMETER BlockSizeBytes + Specifies the block size, in bytes, of the virtual hard disk to be created. + .PARAMETER LogicalSectorSizeBytes + Specifies the logical sector size, in bytes, of the virtual hard disk to be created. Valid values are 512 and 4096. + .PARAMETER PhysicalSectorSizeBytes + Specifies the physical sector size, in bytes. Valid values are 512 and 4096. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual hard disk file(s) are to be created. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='DynamicWithoutSource', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.Vhd.PowerShell.VirtualHardDisk])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='Differencing', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${ParentPath}, + + [Parameter(ParameterSetName='FixedWithoutSource', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='DynamicWithoutSource', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='Differencing', Position=2)] + [ValidateNotNullOrEmpty()] + [uint64] + ${SizeBytes}, + + [Parameter(ParameterSetName='FixedWithSource', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='DynamicWithSource', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('Number')] + [ValidateNotNullOrEmpty()] + [uint32] + ${SourceDisk}, + + [Parameter(ParameterSetName='DynamicWithSource', Mandatory=$true)] + [Parameter(ParameterSetName='DynamicWithoutSource')] + [switch] + ${Dynamic}, + + [Parameter(ParameterSetName='FixedWithSource', Mandatory=$true)] + [Parameter(ParameterSetName='FixedWithoutSource', Mandatory=$true)] + [switch] + ${Fixed}, + + [Parameter(ParameterSetName='Differencing')] + [switch] + ${Differencing}, + + [ValidateNotNullOrEmpty()] + [uint32] + ${BlockSizeBytes}, + + [Parameter(ParameterSetName='FixedWithoutSource')] + [Parameter(ParameterSetName='DynamicWithoutSource')] + [ValidateSet('512','4096')] + [ValidateNotNullOrEmpty()] + [uint32] + ${LogicalSectorSizeBytes}, + + [Parameter(ParameterSetName='Differencing')] + [Parameter(ParameterSetName='FixedWithoutSource')] + [Parameter(ParameterSetName='DynamicWithoutSource')] + [ValidateSet('512','4096')] + [ValidateNotNullOrEmpty()] + [uint32] + ${PhysicalSectorSizeBytes}, + + [Parameter(ParameterSetName='FixedWithoutSource')] + [ValidateSet('None','BTT')] + [Microsoft.Virtualization.Client.Management.VirtualHardDiskPmemAddressAbstractionType] + ${AddressAbstractionType}, + + [Parameter(ParameterSetName='FixedWithoutSource')] + [ValidateSet('0','1GB','1073741824')] + [uint64] + ${DataAlignmentBytes}, + + [switch] + ${AsJob}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function New-VM { + <# + .SYNOPSIS + Creates a new virtual machine. + .PARAMETER Name + Specifies the name of the new virtual machine. The default name is New virtual machine. + .PARAMETER MemoryStartupBytes + Specifies the amount of memory, in bytes, to assign to the virtual machine. The default value is 512 MB. + .PARAMETER BootDevice + Specifies the device to use as the boot device for the new virtual machine. Allowed values are CD , Floppy , LegacyNetworkAdapter , IDE , NetworkAdapter, and VHD. + + When LegacyNetworkAdapter is specified, this configures the new virtual machine with a network adapter that can be used to perform a PXE boot and install an operating system from a network installation server. + + Note: Generation 2 virtual machines do not support Floppy, LegacyNetworkAdapter or IDE. Using these values with a Generation 2 virtual machine will cause an error. + + VHD and NetworkAdapter are new to Generation 2 virtual machines. If you specify them on a Generation 1 virtual machine, then they are interpreted to be IDE and LegacyNetworkAdapter, respectively. + .PARAMETER NoVHD + Creates a virtual machine without attaching any virtual hard disks. + .PARAMETER SwitchName + Specifies the friendly name of the virtual switch if you want to connect the new virtual machine to an existing virtual switch to provide connectivity to a network. Hyper-V automatically creates a virtual machine with one virtual network adapter, but connecting it to a virtual switch is optional. + .PARAMETER NewVHDPath + Creates a new virtual hard disk with the specified path and connects it to the new virtual machine. Absolute paths are allowed. If only a file name is specified, the virtual hard disk is created in the default path configured for the host. + .PARAMETER NewVHDSizeBytes + Specifies the size of the dynamic virtual hard disk that is created and attached to the new virtual machine. + .PARAMETER VHDPath + Specifies the path to a virtual hard disk file. + .PARAMETER Path + Specifies the directory to store the files for the new virtual machine. + .PARAMETER Generation + Specifies the generation, as an integer, for the virtual machine. The values that are valid in this version of Windows are 1 and 2. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual machine is to be created. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='No VHD', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(Position=1)] + [ValidateNotNull()] + [System.Nullable[long]] + ${MemoryStartupBytes}, + + [ValidateNotNullOrEmpty()] + [System.Nullable[Microsoft.HyperV.PowerShell.BootDevice]] + ${BootDevice}, + + [Parameter(ParameterSetName='No VHD')] + [switch] + ${NoVHD}, + + [ValidateNotNullOrEmpty()] + [string] + ${SwitchName}, + + [Parameter(ParameterSetName='New VHD', Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${NewVHDPath}, + + [Parameter(ParameterSetName='New VHD', Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [uint64] + ${NewVHDSizeBytes}, + + [Parameter(ParameterSetName='Existing VHD', Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${VHDPath}, + + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [ValidateNotNull()] + [version] + ${Version}, + + [switch] + ${Prerelease}, + + [switch] + ${Experimental}, + + [Parameter(Position=2)] + [ValidateSet('1','2')] + [ValidateNotNullOrEmpty()] + [System.Nullable[int16]] + ${Generation}, + + [switch] + ${Force}, + + [switch] + ${AsJob}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function New-VMGroup { + <# + .SYNOPSIS + Creates a virtual machine group. + .PARAMETER Name + Specifies the name for the group that this cmdlet creates. + .PARAMETER GroupType + Specifies the type of group that this cmdlet creates. The acceptable values for this parameter are: ManagementCollectionType and VMCollectionType. + .PARAMETER Id + Specifies the unique ID of the group that this cmdlet creates. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding()] + [OutputType([Microsoft.HyperV.PowerShell.VMGroup])] + param ( + [Parameter(Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.GroupType] + ${GroupType}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [guid] + ${Id}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function New-VMReplicationAuthorizationEntry { + <# + .SYNOPSIS + Creates a new authorization entry that allows one or more primary servers to replicate data to a specified Replica server. + .PARAMETER AllowedPrimaryServer + Specifies the server that is allowed to send replication data to the Replica server. Only fully-qualified domain names and fully qualified international domain names are supported. You can use a wildcard (for example, " ") in the first octect to specify a fully qualified domain name, such as .contoso.com. + .PARAMETER ReplicaStorageLocation + Specifies the location to store the Replica virtual hard disk files sent from the allowed server when a new Replica virtual machine is created. + .PARAMETER TrustGroup + Identifies a group of primary servers within which a given primary virtual machine can move so replications of the primary virtual machine are accepted by the Replica server only from primary servers that belong to the trust group. You can use any string to create a new trust group. Ensure all primary servers within a specific trust group use the same string as the value you specify for this parameter. + + Use of a trust group can help you keep virtual machines isolated by maintaining control over which primary servers are trusted to provide replication, while also allowing the virtual machines to move from one primary server to another (such as through live migration or failover from a cluster node). + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the authorization entry is to be created. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplicationAuthorizationEntry])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('AllowedPS')] + [ValidateNotNullOrEmpty()] + [string] + ${AllowedPrimaryServer}, + + [Parameter(Mandatory=$true, Position=1)] + [Alias('StorageLoc')] + [ValidateNotNullOrEmpty()] + [string] + ${ReplicaStorageLocation}, + + [Parameter(Mandatory=$true, Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${TrustGroup}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function New-VMResourcePool { + <# + .SYNOPSIS + Creates a resource pool. + .PARAMETER Name + Specifies the name of the resource pool + .PARAMETER ResourcePoolType + Specifies the resource type of the resource pool. + .PARAMETER ParentName + Specifies the name of the parent resource pool for the new resource pool. + .PARAMETER Paths + Specifies an array of paths to be associated with a new storage resource pool. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the resource pool is to be created. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMResourcePool])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMResourcePoolType[]] + ${ResourcePoolType}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ParentName}, + + [Parameter(Position=3)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Paths}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function New-VMSan { + <# + .SYNOPSIS + Creates a new virtual storage area network (SAN) on a Hyper-V host. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies the friendly name of a Hyper-V host on which the new virtual storage area network (SAN) is to be created. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the friendly name of the virtual storage area network (SAN) to be created. + .PARAMETER Note + Specifies a note to be associated with the virtual storage area network (SAN) to be created. + .PARAMETER HostBusAdapter + Specifies the host bus adapter (HBA) to be associated with the virtual storage area network (SAN) to be created. This can be retrieved by running the Get-InitiatorPort cmdlet. + .PARAMETER WorldWideNodeName + Specifies the world wide node name (WWNN) of the host bus adapters to be associated with the virtual storage area network (SAN) to be created. + .PARAMETER WorldWidePortName + Specifies the world wide port name (WWPN) of the host bus adapters to be associated with the virtual storage area network (SAN) to be created. + #> + + [CmdletBinding(DefaultParameterSetName='HbaObject', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSan])] + param ( + [ValidateNotNullOrEmpty()] + [CimSession] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential] + [System.Management.Automation.CredentialAttribute()] + ${Credential}, + + [Parameter(Mandatory=$true, Position=0)] + [Alias('SanName')] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [ValidateNotNull()] + [string] + ${Note}, + + [Parameter(ParameterSetName='HbaObject')] + [ValidateNotNullOrEmpty()] + [ciminstance[]] + ${HostBusAdapter}, + + [Parameter(ParameterSetName='StringWwn', Mandatory=$true)] + [Alias('Wwnn','NodeName','Wwnns','NodeNames','WorldWideNodeNames','NodeAddress')] + [ValidateNotNullOrEmpty()] + [string[]] + ${WorldWideNodeName}, + + [Parameter(ParameterSetName='StringWwn', Mandatory=$true)] + [Alias('Wwpn','PortName','Wwpns','PortNames','WorldWidePortNames','PortAddress')] + [ValidateNotNullOrEmpty()] + [string[]] + ${WorldWidePortName} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function New-VMSwitch { + <# + .SYNOPSIS + Creates a new virtual switch on one or more virtual machine hosts. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual switch is to be created. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the name of the switch to be created. + .PARAMETER SwitchType + Specifies the type of the switch to be created. Allowed values are Internal and Private . To create an External virtual switch, specify either the NetAdapterInterfaceDescription or the NetAdapterName parameter, which implicitly set the type of the virtual switch to External. + .PARAMETER AllowManagementOS + Specifies whether the parent partition (i.e. the management operating system) is to have access to the physical NIC bound to the virtual switch to be created. + .PARAMETER NetAdapterName + Specifies the name of the network adapter to be bound to the switch to be created. You can use the Get-NetAdapter cmdlet to get the interface description of a network adapter. + .PARAMETER NetAdapterInterfaceDescription + Specifies the interface description of the network adapter to be bound to the switch to be created. You can use the Get-NetAdapter cmdlet to get the interface description of a network adapter. + .PARAMETER Notes + Specifies a note to be associated with the switch to be created. + .PARAMETER MinimumBandwidthMode + Specifies how minimum bandwidth is to be configured on the virtual switch. Allowed values are Absolute , Default , None , or Weight . If Absolute is specified, minimum bandwidth is bits per second. If Weight is specified, minimum bandwidth is a value ranging from 1 to 100. If None is specified, minimum bandwidth is disabled on the switch - that is, users cannot configure it on any network adapter connected to the switch. If Default is specified, the system will set the mode to Weight , if the switch is not IOV-enabled, or None if the switch is IOV-enabled. + .PARAMETER EnableIov + Specifies that IO virtualization is to be enabled on the virtual switch to be created. + .PARAMETER EnablePacketDirect + Specifies whether this cmdlet enables the packet direct path through the virtual switch. The default value is $False. + .PARAMETER EnableEmbeddedTeaming + Specifies whether this cmdlet enables teaming for the virtual switch. + #> + + [CmdletBinding(DefaultParameterSetName='NetAdapterName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitch])] + param ( + [Parameter(ParameterSetName='NetAdapterName', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='NetAdapterInterfaceDescription', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='SwitchType', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='SwitchType', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='NetAdapterInterfaceDescription', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='NetAdapterName', ValueFromPipelineByPropertyName=$true)] + [Alias('PSComputerName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='NetAdapterInterfaceDescription', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='NetAdapterName', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='SwitchType', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(Mandatory=$true, Position=0)] + [Alias('SwitchName')] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Alias('SwitchId')] + [ValidateNotNullOrEmpty()] + [string] + ${Id}, + + [Parameter(ParameterSetName='SwitchType', Mandatory=$true)] + [ValidateSet('Internal','Private')] + [Microsoft.HyperV.PowerShell.VMSwitchType] + ${SwitchType}, + + [Parameter(ParameterSetName='NetAdapterInterfaceDescription')] + [Parameter(ParameterSetName='NetAdapterName')] + [bool] + ${AllowManagementOS}, + + [Parameter(ParameterSetName='NetAdapterName', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('InterfaceAlias')] + [ValidateNotNullOrEmpty()] + [string[]] + ${NetAdapterName}, + + [Parameter(ParameterSetName='NetAdapterInterfaceDescription', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('InterfaceDescription')] + [ValidateNotNullOrEmpty()] + [string[]] + ${NetAdapterInterfaceDescription}, + + [ValidateNotNull()] + [string] + ${Notes}, + + [Microsoft.HyperV.PowerShell.VMSwitchBandwidthMode] + ${MinimumBandwidthMode}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${EnableIov}, + + [System.Nullable[bool]] + ${EnablePacketDirect}, + + [System.Nullable[bool]] + ${EnableEmbeddedTeaming} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Optimize-VHD { + <# + .SYNOPSIS + Optimizes the allocation of space used by virtual hard disk files, except for fixed virtual hard disks. + .PARAMETER Path + Specifies one or more paths to the dynamic or differencing virtual hard disk files to be optimized. + .PARAMETER Mode + Specifies the mode in which the virtual hard disk is to be optimized. For a VHD disk, the default mode is Full . For a VHDX disk, the default mode is Quick . Valid modes are as follows: + + -- Full scans for zero blocks and reclaims unused blocks. (Allowable only if the virtual hard disk is mounted read-only.) -- Pretrimmed performs as Quick mode, but does not require the virtual hard disk to be mounted read-only. The detection of unused space is less effective than Quick mode (in which the virtual hard disk had been mounted read-only) because the scan cannot query information about free space in the NTFS file system within the virtual hard disk. Useful when the VHDX-format file has been used by operating system instances that are at least Windows 8 or Windows Server 2012, or when this cmdlet has already been run on a .vhdx file in Retrim mode. -- Prezeroed performs as Quick mode, but does not require the virtual hard disk to be mounted read-only. The unused space detection will be less effective than if the virtual hard disk had been mounted read-only as the scan will be unable to query information about free space in the NTFS file system within the virtual hard disk. Useful if a tool was run previously to zero all the free space on the virtual disk as this mode of compaction can then reclaim that space for subsequent block allocations. This form of compaction can also be useful in handling virtual hard disk containing file systems other than NTFS. -- Quick reclaims unused blocks, but does not scan for zero blocks. (Allowable only if the virtual hard disk is mounted read-only.) -- Retrim sends down retrims without scanning for zero blocks or reclaiming unused blocks. (Allowable only if the virtual hard disk is mounted read-only.) + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual hard disk to be optimized. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a virtual machine is to be optimized. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.Vhd.PowerShell.VirtualHardDisk])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('FullName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [ValidateNotNullOrEmpty()] + [Microsoft.Vhd.PowerShell.VhdCompactMode] + ${Mode}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Optimize-VHDSet { + <# + .SYNOPSIS + Optimizes VHD set files. + .PARAMETER Path + Specifies an array of paths of VHD sets that this cmdlet optimizes. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Indicates that this cmdlet returns the Microsoft.HyperV.PowerShell.VirtualHardDisk object that it optimizes. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.Vhd.PowerShell.VirtualHardDisk])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('FullName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VHDSnapshot { + <# + .SYNOPSIS + Removes a checkpoint from a VHD set file. + .PARAMETER Path + Specifies an array of paths of VHD set files. This cmdlet removes a checkpoint from the files that this parameter specifies. If you specify a file name or relative path, the cmdlet determines the full path relative to the current working folder. + .PARAMETER PersistReferencePoint + Indicates that this cmdlet persists an RCT-only reference point after it deletes the checkpoint. + .PARAMETER SnapshotId + Specifies an array of unique IDs of VHD checkpoint that this cmdlet removes from the VHD set file. + .PARAMETER VHDSnapshot + Specifies an array of VHD checkpoints that this cmdlet removes from a VHD set file. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='Path', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + param ( + [Parameter(ParameterSetName='Path', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('FullName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [switch] + ${PersistReferencePoint}, + + [Parameter(ParameterSetName='Path', Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [guid[]] + ${SnapshotId}, + + [Parameter(ParameterSetName='VHDSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.Vhd.PowerShell.VHDSnapshotInfo[]] + ${VHDSnapshot}, + + [switch] + ${AsJob}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VM { + <# + .SYNOPSIS + Deletes a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which the virtual machine is to be deleted. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the name of the virtual machine to be deleted. + .PARAMETER VM + Specifies the virtual machine to be deleted. + .PARAMETER Force + Specifies that confirmation prompts are to be suppressed during deletion of the virtual machine. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual machine to be deleted. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [switch] + ${Force}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMAssignableDevice { + <# + .SYNOPSIS + Remove-VMAssignableDevice [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [-InstancePath ] [-LocationPath ] [-Passthru] [-WhatIf] [-Confirm] [] + +Remove-VMAssignableDevice [-VMAssignableDevice] [-Passthru] [-WhatIf] [-Confirm] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMAssignedDevice])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Object', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMAssignedDevice[]] + ${VMAssignableDevice}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string] + ${InstancePath}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string] + ${LocationPath}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMDvdDrive { + <# + .SYNOPSIS + Deletes a DVD drive from a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which the DVD drive is to be deleted. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine from which the DVD drive is to be deleted. + .PARAMETER VMDvdDrive + Specifies the DVD drive to be deleted. + .PARAMETER ControllerNumber + Specifies the number of the controller from which the DVD drive is to be deleted. If not specified, the first IDE controller on which the specified ControllerLocation is available is used. + .PARAMETER ControllerLocation + Specifies the number of the location on the controller at which the DVD drive is to be deleted. If not specified, the number of the first available location on the controller is used. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the DVD drive to be deleted. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.DvdDrive])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='VMDvdDrive', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.DvdDrive[]] + ${VMDvdDrive}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ControllerNumber}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=2)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ControllerLocation}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMFibreChannelHba { + <# + .SYNOPSIS + Removes a Fibre Channel host bus adapter from a virtual machine. + .PARAMETER VMName + Specifies the virtual machine from which the Fibre Channel host bus adapters are to be removed. + .PARAMETER VMFibreChannelHba + Specifies one or more Fibre Channel host bus adapters to be removed from a virtual machine. + .PARAMETER WorldWideNodeNameSetA + Specifies the World Wide Node name of address set A associated with the Fibre Channel host bus adapter to be removed. + .PARAMETER WorldWidePortNameSetA + Specifies the World Wide Port name of address set A associated with the Fibre Channel host bus adapter to be removed. + .PARAMETER WorldWideNodeNameSetB + Specifies the World Wide Node name of address set B associated with the Fibre Channel host bus adapter to be removed. + .PARAMETER WorldWidePortNameSetB + Specifies the World Wide Port name of address set B associated with the Fibre Channel host bus adapter to be removed. + .PARAMETER Passthru + Specifies that an object is to be passed through to be pipeline representing the removed Fibre Channel host bus adapter. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the Fibre Channel host bus adapter is to be removed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='VMFibreChannelHba', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMFibreChannelHba])] + param ( + [Parameter(ParameterSetName='VMName and WWN', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='VMFibreChannelHba', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMFibreChannelHba[]] + ${VMFibreChannelHba}, + + [Parameter(ParameterSetName='VMName and WWN', Mandatory=$true, Position=1)] + [Alias('Wwnn1')] + [ValidateNotNullOrEmpty()] + [string] + ${WorldWideNodeNameSetA}, + + [Parameter(ParameterSetName='VMName and WWN', Mandatory=$true, Position=2)] + [Alias('Wwpn1')] + [ValidateNotNullOrEmpty()] + [string] + ${WorldWidePortNameSetA}, + + [Parameter(ParameterSetName='VMName and WWN', Mandatory=$true, Position=3)] + [Alias('Wwnn2')] + [ValidateNotNullOrEmpty()] + [string] + ${WorldWideNodeNameSetB}, + + [Parameter(ParameterSetName='VMName and WWN', Mandatory=$true, Position=4)] + [Alias('Wwpn2')] + [ValidateNotNullOrEmpty()] + [string] + ${WorldWidePortNameSetB}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMGpuPartitionAdapter { + <# + .SYNOPSIS + Remove-VMGpuPartitionAdapter [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [-Passthru] [-AdapterId ] [-WhatIf] [-Confirm] [] + +Remove-VMGpuPartitionAdapter [-VM] [-Passthru] [-AdapterId ] [-WhatIf] [-Confirm] [] + +Remove-VMGpuPartitionAdapter [-VMGpuPartitionAdapter] [-Passthru] [-WhatIf] [-Confirm] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMGpuPartitionAdapter])] + param ( + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='Object', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMGpuPartitionAdapter[]] + ${VMGpuPartitionAdapter}, + + [switch] + ${Passthru}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [ValidateNotNullOrEmpty()] + [string] + ${AdapterId} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMGroup { + <# + .SYNOPSIS + Removes a virtual machine group. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the name of an empty virtual machine group that this cmdlet removes. + .PARAMETER Id + Specifies the unique ID of an empty virtual machine group that this cmldet removes. + .PARAMETER VMGroup + Specifies an empty virtual machine group that this cmdlet removes. To obtain a VMGroup object, use the Get-VMGroup cmdlet. + .PARAMETER Force + Forces the command to run without asking for user confirmation. + #> + + [CmdletBinding(DefaultParameterSetName='Name')] + param ( + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='Id')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='Id')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='Id')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='Id', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [guid] + ${Id}, + + [Parameter(ParameterSetName='InputObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMGroup] + ${VMGroup}, + + [switch] + ${Force} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMGroupMember { + <# + .SYNOPSIS + Removes members from a virtual machine group. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the name of the virtual machine group from which this cmdlet removes virtual machines or groups of virtual machines. + .PARAMETER Id + Specifies the unique ID of the virtual machine group from which this cmdlet removes virtual machines or groups of virtual machines. + .PARAMETER VMGroup + Specifies the virtual machine group from which this cmdlet removes virtual machines or groups of virtual machines. To obtain a VMGroup object, use the Get-VMGroup cmdlet. + .PARAMETER VM + Specifies an array of virtual machines that this cmdlet removes from a virtual machine group. To obtain a VirtualMachine object, use the Get-VM cmdlet. + .PARAMETER VMGroupMember + Specifies an array of groups of virtual machines that this cmdlet removes from a virtual machine group. + .PARAMETER Passthru + Indicates that this cmdlet returns the Microsoft.HyperV.PowerShell.VMGroup object that it configures. + #> + + [CmdletBinding(DefaultParameterSetName='VM Using Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMGroup])] + param ( + [Parameter(ParameterSetName='VMGroup Using ID')] + [Parameter(ParameterSetName='VM Using Name')] + [Parameter(ParameterSetName='VMGroup Using Name')] + [Parameter(ParameterSetName='VM Using ID')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VM Using Name')] + [Parameter(ParameterSetName='VMGroup Using Name')] + [Parameter(ParameterSetName='VM Using ID')] + [Parameter(ParameterSetName='VMGroup Using ID')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VM Using Name')] + [Parameter(ParameterSetName='VMGroup Using Name')] + [Parameter(ParameterSetName='VM Using ID')] + [Parameter(ParameterSetName='VMGroup Using ID')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMGroup Using Name', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='VM Using Name', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='VM Using ID', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='VMGroup Using ID', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [guid] + ${Id}, + + [Parameter(ParameterSetName='VM Using InputObject', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='VMGroup Using InputObject', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMGroup] + ${VMGroup}, + + [Parameter(ParameterSetName='VM Using InputObject', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VM Using Name', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VM Using ID', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMGroup Using Name', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VMGroup Using ID', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VMGroup Using InputObject', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMGroup[]] + ${VMGroupMember}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMHardDiskDrive { + <# + .SYNOPSIS + Deletes a hard disk drive from a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which the virtual hard disk drive is to be deleted. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine from which the virtual hard disk is to be deleted. + .PARAMETER VMHardDiskDrive + Specifies the virtual hard disk drive to be deleted. + .PARAMETER ControllerType + Specifies the type of the controller where the virtual hard disk is to be deleted. Allowed values are IDE and SCSI . + .PARAMETER ControllerNumber + Specifies the number of the controller from which the virtual hard disk drive is to be deleted. If not specified, the first controller on which the specified ControllerLocation is available is used. + .PARAMETER ControllerLocation + Specifies the number of the location on the controller at which the virtual hard disk drive is to be deleted. If not specified, the number of the first available location on the controller is used. + .PARAMETER Passthru + Specifies that an object is to be passed through to be pipeline representing the virtual hard disk drive to be deleted. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.HardDiskDrive])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='VMHardDiskDrive', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.HardDiskDrive[]] + ${VMHardDiskDrive}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [System.Nullable[Microsoft.HyperV.PowerShell.ControllerType]] + ${ControllerType}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=2)] + [ValidateNotNullOrEmpty()] + [System.Nullable[int]] + ${ControllerNumber}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=3)] + [System.Nullable[int]] + ${ControllerLocation}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMHostAssignableDevice { + <# + .SYNOPSIS + Remove-VMHostAssignableDevice -ResourcePoolName [-CimSession ] [-ComputerName ] [-Credential ] [-InstancePath ] [-LocationPath ] [-Force] [-WhatIf] [-Confirm] [] + +Remove-VMHostAssignableDevice [-VMHostAssignableDevice] -ResourcePoolName [-Force] [-WhatIf] [-Confirm] [] + #> + + [CmdletBinding(DefaultParameterSetName='Path', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + param ( + [Parameter(ParameterSetName='Path')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Path')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Path')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Path')] + [ValidateNotNullOrEmpty()] + [string] + ${InstancePath}, + + [Parameter(ParameterSetName='Path')] + [ValidateNotNullOrEmpty()] + [string] + ${LocationPath}, + + [Parameter(ParameterSetName='Object', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMHostAssignableDevice[]] + ${VMHostAssignableDevice}, + + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ResourcePoolName}, + + [switch] + ${Force} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMKeyStorageDrive { + <# + .SYNOPSIS + Remove-VMKeyStorageDrive [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [-Passthru] [-WhatIf] [-Confirm] [] + +Remove-VMKeyStorageDrive [-VMKeyStorageDrive] [-Passthru] [-WhatIf] [-Confirm] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.KeyStorageDrive])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='VMKeyStorageDrive', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.KeyStorageDrive[]] + ${VMKeyStorageDrive}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMMigrationNetwork { + <# + .SYNOPSIS + Removes a network from use with migration. + .PARAMETER Subnet + Specifies a string representing an IPv4 or IPv6 subnet mask which identifies the network to be removed from use with migration. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the network is to be removed from use with migration. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.MigrationNetwork object is to be passed through to the pipeline representing the network removed from use with migration. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMMigrationNetwork])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Subnet}, + + [Parameter(ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMNetworkAdapter { + <# + .SYNOPSIS + Removes one or more virtual network adapters from a virtual machine. + .PARAMETER VMNetworkAdapter + Specifies the virtual machine network adapter to be removed. + .PARAMETER ManagementOS + Specifies the management operating system of the virtual network adapter to be removed. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual network adapter is to be removed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine that has the virtual network adapter you want to remove. + .PARAMETER VM + Specifies the virtual machine that has the virtual network adapter you want to remove. + .PARAMETER Name + Specifies the name of the virtual network adapter to be removed. + .PARAMETER SwitchName + Specifies the name of the virtual switch connected to the virtual network adapter to be removed. + .PARAMETER Passthru + Specifies that an object to be passed through to the pipeline representing the virtual machine network adapter to be removed. This is a Microsoft.HyperV.PowerShell.VMInternalNetworkAdapter object, if -ManagementOS is specified; otherwise it is a Microsoft.HyperV.PowerShell.VMNetworkAdapter object. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterBase])] + param ( + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Alias('VMNetworkAdapterName')] + [string] + ${Name}, + + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string] + ${SwitchName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMNetworkAdapterAcl { + <# + .SYNOPSIS + Removes an ACL applied to the traffic through a virtual network adapter. + .PARAMETER VMNetworkAdapter + Specifies the virtual machine network adapter from which ACL is to be removed. + .PARAMETER ManagementOS + Specifies that the ACL is to be removed from the management (e.g. the parent, or host) operating system. + .PARAMETER VMNetworkAdapterName + Specifies the name of the virtual machine network adapter from which the ACL is to be removed. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the ACL applied to a virtual machine network adapter is to be removed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine from which the ACL is to be removed. + .PARAMETER VM + Specifies the virtual machine from which the ACL is to be removed. + .PARAMETER InputObject + Specifies the ACL to be removed. + .PARAMETER Action + Specifies the action of the ACL to be removed. Allowed values are Allow , Deny , and Meter . + .PARAMETER Direction + The direction of the network traffic (from the perspective of the virtual machine) to which the ACL applies. Allowed values are Inbound , Outbound , or Both . + .PARAMETER LocalIPAddress + Specifies the local IP address. It can be either IPv4 or IPv6 address. It can be either a host address or a subnet address, e.g. 1.2.3.4, 2001::2008, 192.168.1.0/24, or f001:f002:f003:f004::1/64.the IP address can also be a wildcard, 0.0.0.0/0 for all IPv4 addresses, ::/0 for all IPv6 addresses, or ANY for all IPv4 and IPv6 addresses. + .PARAMETER LocalMacAddress + Specifies the local MAC address (e.g. 00-ab-00-11-22-33). Use the wildcard ANY to specify all MAC addresses. + .PARAMETER RemoteIPAddress + Specifies the remote IP address. . It can be either IPv4 or IPv6 address. It can be either a host address or a subnet address, e.g. 1.2.3.4, 2001::2008, 192.168.1.0/24, or f001:f002:f003:f004::1/64. the IP address can also be a wildcard, 0.0.0.0/0 for all IPv4 addresses, ::/0 for all IPv6 addresses, or ANY for all IPv4 and IPv6 addresses. + .PARAMETER RemoteMacAddress + Specifies the remote MAC address. . It can be a host MAC address, e.g. 00-ab-00-11-22-33, or a wildcard, ANY, for all MAC addresses. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.VMNetworkAdapterAclSetting object is to be passed through to the pipeline representing the ACL to be removed. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterAclSetting])] + param ( + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='InputObjectParameter', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterAclSetting[]] + ${InputObject}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true)] + [Parameter(ParameterSetName='VMName', Mandatory=$true)] + [Parameter(ParameterSetName='VMObject', Mandatory=$true)] + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterAclAction] + ${Action}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [Parameter(ParameterSetName='VMName', Mandatory=$true)] + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true)] + [Parameter(ParameterSetName='VMObject', Mandatory=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterAclDirection] + ${Direction}, + + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ResourceObject')] + [ValidateNotNullOrEmpty()] + [string[]] + ${LocalIPAddress}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ResourceObject')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${LocalMacAddress}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='ResourceObject')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${RemoteIPAddress}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ResourceObject')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${RemoteMacAddress}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMNetworkAdapterExtendedAcl { + <# + .SYNOPSIS + Removes an extended ACL for a virtual network adapter. + .PARAMETER VMNetworkAdapter + Specifies an array virtual machine network adapters as VMNetworkAdapterBase objects. The cmdlet removes an ACL for the network adapters that you specify. To obtain a network adapter, use the Get-VMNetworkAdapter cmdlet. + .PARAMETER ManagementOS + Indicates that the cmdlet operates on the parent or host operating system. If you specify this parameter, this cmdlet removes an ACL that applies in the parent or host operating system. + .PARAMETER VMNetworkAdapterName + Specifies the name of a virtual network adapter. The cmdlet removes an ACL for the network adapter that you specify. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies an array of Hyper-V hosts. The cmdlet removes an ACL associated with a virtual network adapter on the Hyper-V hosts that you specify. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies an array of names of virtual machines. The cmdlet removes an ACL for network adapters that belong to the virtual machines that you specify. + .PARAMETER VM + Specifies an array of virtual machines as VirutalMachine objects. The cmdlet removes an ACL for network adapters that belong to the virtual machines that you specify. To obtain a virtual machine object, use the Get-VM cmdlet. + .PARAMETER InputObject + Specifies the input to this cmdlet. You can use this parameter, or you can pipe the input to this cmdlet. + .PARAMETER Weight + Specifies the weight of an ACL entry. Because weight is unique for each entry, if you specify a value for this parameter, the cmdlet removes a specific extended ACL entry. + .PARAMETER Direction + Specifies the direction of network traffic, from the perspective of the virtual machine, to which the ACL applies. The cmdlet removes an ACL that has the value that you specify. The acceptable values for this parameter are: + + -- Inbound + + -- Outbound + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterExtendedAclSetting])] + param ( + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='InputObjectParameter', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterExtendedAclSetting[]] + ${InputObject}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [Parameter(ParameterSetName='VMName', Mandatory=$true)] + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true)] + [Parameter(ParameterSetName='VMObject', Mandatory=$true)] + [int] + ${Weight}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true)] + [Parameter(ParameterSetName='VMName', Mandatory=$true)] + [Parameter(ParameterSetName='VMObject', Mandatory=$true)] + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterExtendedAclDirection] + ${Direction}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMNetworkAdapterRoutingDomainMapping { + <# + .SYNOPSIS + Removes a routing domain from a virtual network adapter. + .PARAMETER VMNetworkAdapter + Specifies an array of virtual machine network adapters as VMNetworkAdapterBase objects. The cmdlet removes the virtual subnet for the adapters that you specify. To obtain a network adapter, use the Get-VMNetworkAdapter cmdlet. + .PARAMETER ManagementOS + Indicates that the cmdlet removes the virtual subnet on the parent partition or host operating system. + .PARAMETER VMNetworkAdapterName + Specifies the name of a virtual network adapter. The cmdlet removes the virtual subnet for the adapter that you specify. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies an array of Hyper-V hosts. The cmdlet removes the virtual subnets from the Hyper-V hosts that you specify. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies an array of names of virtual machines. The cmdlet removes the virtual subnet from the virtual machines that you specify. + .PARAMETER VM + Specifies an array of virtual machines. The cmdlet removes the virtual subnet from the virtual machines that you specify. To obtain a virtual machine object, use the Get-VM cmdlet. + .PARAMETER InputObject + Specifies the input to this cmdlet. You can use this parameter, or you can pipe the input to this cmdlet. + .PARAMETER RoutingDomainID + Specifies the ID of a routing domain. The ID of a routing domain is a system-assigned GUID. The cmdlet removes the virtual subnet from the routing domain that you specify. + .PARAMETER RoutingDomainName + Specifies the name of a routing domain. The cmdlet removes the virtual subnet from the routing domain that you specify. + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterRoutingDomainSetting])] + param ( + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='InputObjectParameter', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterRoutingDomainSetting[]] + ${InputObject}, + + [Parameter(ParameterSetName='ResourceObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='ManagementOS')] + [guid] + ${RoutingDomainID}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ResourceObject')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${RoutingDomainName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMNetworkAdapterTeamMapping { + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterTeamMappingSetting])] + param ( + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine] + ${VM}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [Alias('VMNetworkAdapterName')] + [string] + ${Name}, + + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string] + ${SwitchName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMPmemController { + <# + .SYNOPSIS + Remove-VMPmemController [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [-Passthru] [-WhatIf] [-Confirm] [] + +Remove-VMPmemController [-VMPmemController] [-Passthru] [-WhatIf] [-Confirm] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMPmemController])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Object', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMPmemController[]] + ${VMPmemController}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMRemoteFx3dVideoAdapter { + <# + .SYNOPSIS + Removes a RemoteFX 3D video adapter from a virtual machine. + .PARAMETER VM + Specifies the virtual machine from which the RemoteFX 3D video adapter to be removed. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a RemoteFX 3D video adapter is to be removed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine from which the RemoteFX 3D video adapter is to be removed. + .PARAMETER VMRemoteFx3dVideoAdapter + Specifies the RemoteFX 3D video adapater to be removed. + .PARAMETER Passthru + Specifies that a VMRemoteFxVideoAdapter object is to be to be passed through to the pipeline representing the RemoteFX 3D video adapter to be removed. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMRemoteFx3DVideoAdapter])] + param ( + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='RemoteFXAdapter', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMRemoteFx3DVideoAdapter[]] + ${VMRemoteFx3dVideoAdapter}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMReplication { + <# + .SYNOPSIS + Removes the replication relationship of a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the replication relationship of a virtual machine is to be removed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine for which the replication relationship is to be removed. + .PARAMETER VM + Specifies the virtual machine for which the replication relationship is to be removed. + .PARAMETER VMReplication + Specifies a virtual machine replication object associated with the virtual machine whose replication relationship is to be removed. + .PARAMETER ReplicationRelationshipType + Specifies the replication relationship type of the virtual machine. Specify whether the replication relationship is a simple primary to replica or is an extended replication chain. The cmdlet removes the replication relationship of the virtual machines that have the replication type that you specify. + .PARAMETER Passthru + Specifies that a VMReplication object is to be passed through to the pipeline representing the virtual machine for which the replication relationship will be removed. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplication])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMReplication', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMReplication[]] + ${VMReplication}, + + [Parameter(ParameterSetName='VMName')] + [Alias('Relationship')] + [System.Nullable[Microsoft.HyperV.PowerShell.VMReplicationRelationshipType]] + ${ReplicationRelationshipType}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMReplicationAuthorizationEntry { + <# + .SYNOPSIS + Removes an authorization entry from a Replica server. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the authorization entry is to be removed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER AllowedPrimaryServer + Specifies the allowed primary server for which the authorization entry is to be removed. + .PARAMETER VMReplicationAuthorizationEntry + Specifies the authorization entry to be removed. + .PARAMETER TrustGroup + Specifies the trust group for which the authorization entries are to be removed. + .PARAMETER Passthru + Specifies that a VMReplicationAuthorizationEntry object is to be passed through to the pipeline representing the authorization entry to be removed. + #> + + [CmdletBinding(DefaultParameterSetName='PrimaryServerName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplicationAuthorizationEntry])] + param ( + [Parameter(ParameterSetName='PrimaryServerName')] + [Parameter(ParameterSetName='TrustGroup')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='PrimaryServerName')] + [Parameter(ParameterSetName='TrustGroup')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='PrimaryServerName')] + [Parameter(ParameterSetName='TrustGroup')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='PrimaryServerName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('AllowedPS')] + [ValidateNotNullOrEmpty()] + [string] + ${AllowedPrimaryServer}, + + [Parameter(ParameterSetName='Object', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMRepAuthEntry')] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMReplicationAuthorizationEntry[]] + ${VMReplicationAuthorizationEntry}, + + [Parameter(ParameterSetName='TrustGroup', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${TrustGroup}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMResourcePool { + <# + .SYNOPSIS + Deletes a resource pool from one or more virtual machine hosts. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the name of the resource pool. + .PARAMETER ResourcePoolType + Specifies the type of the resource pool to be deleted. + .PARAMETER Passthru + Specifies that a VMResourcePool object is to be passed through to the pipeline representing the removed resource pool. + #> + + [CmdletBinding(DefaultParameterSetName='ComputerName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMResourcePool])] + param ( + [Parameter(ParameterSetName='CimSession', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ComputerName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ComputerName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(Mandatory=$true, Position=1, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMResourcePoolType[]] + ${ResourcePoolType}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMSan { + <# + .SYNOPSIS + Removes a virtual storage area network (SAN) from a Hyper-V host. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Name + Specifies the name of the virtual storage area network (SAN) to be removed from the Hyper-V host. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the removed virtual machine storage area network. + .PARAMETER ComputerName + Specifies a Hyper-V host from which the virtual storage area network (SAN) is to be removed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSan])] + param ( + [Parameter(ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [Alias('SanName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMSavedState { + <# + .SYNOPSIS + Deletes the saved state of a saved virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual machine saved state is to be deleted. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine whose saved state is to be deleted. + .PARAMETER VMName + Specifies the name of the virtual machine whose saved state is to be deleted. + .PARAMETER VMSnapshot + Specifies the snapshot whose saved state is to be deleted. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMScsiController { + <# + .SYNOPSIS + Removes a SCSI controller from a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts from which the SCSI controller is to be removed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMScsiController + Specifies the SCSI controller to be removed. + .PARAMETER VMName + Specifies an array of names of virtual machines. The cmdlet removes an SCSI controller from the virtual machines that you specify. + .PARAMETER ControllerNumber + Specifies the number of the controller. The cmdlet removes the SCSI controller that you specify. + .PARAMETER Passthru + Specifies that a VMScsiController object is to be passed through to the pipeline representing the SCSI controller to be removed. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMScsiController])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Object', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMScsiController[]] + ${VMScsiController}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=1)] + [int] + ${ControllerNumber}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMSnapshot { + <# + .SYNOPSIS + Deletes a virtual machine checkpoint. + .PARAMETER VM + Specifies the virtual machine of which the checkpoint is to be deleted. + .PARAMETER VMName + Specifies the name of the virtual machine of which the checkpoint is to be deleted. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which this cmdlet deletes a checkpoint. NetBIOS names, IP addresses, and fully-qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMSnapshot + Specifies the checkpoint to be deleted. + .PARAMETER Name + Specifies the name of the checkpoint to be deleted. + .PARAMETER IncludeAllChildSnapshots + Specifies that the checkpoint's children are to be deleted along with the checkpoint. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Indicates that this cmdlet returns a Microsoft.HyperV.PowerShell.VirtualMachine object that represents the checkpoint that it deletes. + #> + + [CmdletBinding(DefaultParameterSetName='SnapshotName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSnapshot])] + param ( + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='SnapshotName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='SnapshotName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='SnapshotName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='SnapshotName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='SnapshotObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSnapshot[]] + ${VMSnapshot}, + + [Parameter(ParameterSetName='SnapshotName', Position=1, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMObject', Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Alias('IncludeAllChildCheckpoints')] + [switch] + ${IncludeAllChildSnapshots}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMStoragePath { + <# + .SYNOPSIS + Removes a path from a storage resource pool. + .PARAMETER Path + Specifies the path to be removed from the storage resource pool. + .PARAMETER ResourcePoolName + Specifies the name of the resource pool from which the path is to be removed. + .PARAMETER ResourcePoolType + Specifies the type of the resource pool from which the path is to be removed. Allowed values are VFD , ISO , and VHD . + .PARAMETER Passthru + Specifies that a System.String is to be passed through to the pipeline representing the path to be removed from the resource pool. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a path is to be removed from a resource pool. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding()] + [OutputType([Microsoft.HyperV.PowerShell.VMStorageResourcePool])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ResourcePoolName}, + + [Parameter(Mandatory=$true, Position=2)] + [ValidateSet('VHD','ISO','VFD')] + [Microsoft.HyperV.PowerShell.VMResourcePoolType] + ${ResourcePoolType}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMSwitch { + <# + .SYNOPSIS + Deletes a virtual switch. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual switch is to be deleted. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the name of the virtual switch to be deleted. + .PARAMETER VMSwitch + Specifies the virtual switch to be deleted. + .PARAMETER ResourcePoolName + Specifies the name of the resource pool from which the switch is to be deleted. + .PARAMETER Force + Forces the command to run without asking for user confirmation. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('SwitchName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='SwitchObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMSwitch[]] + ${VMSwitch}, + + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ResourcePoolName}, + + [switch] + ${Force} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMSwitchExtensionPortFeature { + <# + .SYNOPSIS + Removes a feature from a virtual network adapter. + .PARAMETER VMSwitchExtensionFeature + Specifies the feature to be removed. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.VMSwitchExtensionPortFeature is to be passed through to the pipeline representing the feature to be removed. + .PARAMETER VMName + Specifies the name of the virtual machine from which the feature is to be removed. + .PARAMETER VMNetworkAdapter + Specifies the virtual machine network adapter from which the feature is to be removed. + .PARAMETER ManagementOS + Specifies that the feature is to be removed from the management (e.g. the parent, or host) operating system. + .PARAMETER ExternalPort + Specifies the external port on the virtual switch that binds to a physical network adapter. + .PARAMETER SwitchName + Specifies the name of the virtual switch from which the feature is to be removed. + .PARAMETER VMNetworkAdapterName + Specifies the name of the virtual network adapter from which the feature is to be removed. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER VM + Specifies the virtual machine from which the feature is to be removed. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchExtensionPortFeature])] + param ( + [Parameter(Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitchExtensionPortFeature[]] + ${VMSwitchExtensionFeature}, + + [switch] + ${Passthru}, + + [string[]] + ${VMName}, + + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [switch] + ${ManagementOS}, + + [switch] + ${ExternalPort}, + + [string] + ${SwitchName}, + + [string] + ${VMNetworkAdapterName}, + + [string[]] + ${ComputerName}, + + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMSwitchExtensionSwitchFeature { + <# + .SYNOPSIS + Removes a feature from a virtual switch. + .PARAMETER VMSwitchExtensionFeature + Specifies the feature to be removed. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.VMSwitchExtensionSwitchFeature is to be passed through to the pipeline representing the feature to be removed. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER SwitchName + Specifies the name of the virtual switch from which the feature is to be removed. + .PARAMETER VMSwitch + Specifies the virtual switch from which the feature is to be removed. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchExtensionSwitchFeature])] + param ( + [Parameter(Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitchExtensionSwitchFeature[]] + ${VMSwitchExtensionFeature}, + + [switch] + ${Passthru}, + + [string[]] + ${ComputerName}, + + [string[]] + ${SwitchName}, + + [Microsoft.HyperV.PowerShell.VMSwitch[]] + ${VMSwitch}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Remove-VMSwitchTeamMember { + <# + .SYNOPSIS + Removes a member from a virtual machine switch team. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER VMSwitch + Specifies an array of virtual switches from which this cmdlet removes network adapters. To obtain a VMSwitch object, use the Get-VMSwitch cmdlet. + .PARAMETER VMSwitchName + Specifies an array of names of virtual switches from which this cmdlet removes network adapters. + .PARAMETER NetAdapterName + Specifies an array of names of virtual network adapters that this cmdlet removes from a switch team. + .PARAMETER NetAdapterInterfaceDescription + Specifies an array of interface descriptions of virtual network adapters that this cmdlet removes from a switch team. + .PARAMETER Passthru + Indicates that this cmdlet returns the Microsoft.HyperV.PowerShell.VMSwitch object that it modifies. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='SwitchName_NetAdapterName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitch])] + param ( + [Parameter(ParameterSetName='SwitchObject_NetAdapterInterfaceDescription', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='SwitchName_NetAdapterInterfaceDescription', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='SwitchName_NetAdapterName', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='SwitchObject_NetAdapterName', ValueFromPipelineByPropertyName=$true)] + [Alias('PSComputerName')] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='SwitchObject_NetAdapterName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='SwitchObject_NetAdapterInterfaceDescription', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitch[]] + ${VMSwitch}, + + [Parameter(ParameterSetName='SwitchName_NetAdapterInterfaceDescription', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='SwitchName_NetAdapterName', Mandatory=$true, Position=0)] + [Alias('SwitchName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMSwitchName}, + + [Parameter(ParameterSetName='SwitchName_NetAdapterName')] + [Parameter(ParameterSetName='SwitchObject_NetAdapterName')] + [Alias('InterfaceAlias')] + [ValidateNotNullOrEmpty()] + [string[]] + ${NetAdapterName}, + + [Parameter(ParameterSetName='SwitchName_NetAdapterInterfaceDescription')] + [Parameter(ParameterSetName='SwitchObject_NetAdapterInterfaceDescription')] + [ValidateNotNullOrEmpty()] + [string[]] + ${NetAdapterInterfaceDescription}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Rename-VM { + <# + .SYNOPSIS + Renames a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which this cmdlet operates. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine to be renamed. + .PARAMETER Name + Specifies the name of the virtual machine to be renamed. + .PARAMETER NewName + Specifies the name to which the virtual machine is to be renamed. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual machine to be renamed. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${NewName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Rename-VMGroup { + <# + .SYNOPSIS + Renames virtual machine groups. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies an array of names of virtual machine groups that this cmdlet renames. + .PARAMETER Id + Specifies the unique ID of the virtual machine group that this cmdlet renames. + .PARAMETER VMGroup + Specifies an array of virtual machine groups that this cmdlet renames. To obtain a VMGroup object, use the Get-VMGroup cmdlet. + .PARAMETER NewName + Specifies the new name for the virtual machine group. + .PARAMETER Passthru + Indicates that this cmdlet returns the Microsoft.HyperV.PowerShell.VMGroup object that it renames. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMGroup])] + param ( + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='Id')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='Id')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='Id')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='Id', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [guid] + ${Id}, + + [Parameter(ParameterSetName='InputObject', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMGroup[]] + ${VMGroup}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='Id', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='InputObject', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${NewName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Rename-VMNetworkAdapter { + <# + .SYNOPSIS + Renames a virtual network adapter on a virtual machine or on the management operating system. + .PARAMETER VMNetworkAdapter + Specifies the virtual network adapter to be renamed. + .PARAMETER ManagementOS + Specifies that you want to rename a virtual network adapter that belongs to the management operating system. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual network adapter is to be renamed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine that has the virtual network adapter you want to rename. + .PARAMETER VMName + Specifies the name of the virtual machine that has the virtual network adapter you want to rename. + .PARAMETER Name + Specifies the existing name of the virtual network adapter. + .PARAMETER NewName + Specifies the new name for the virtual network adapter. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual network adapter to be renamed. This is a Microsoft.HyperV.PowerShell.VMInternalNetworkAdapter object, if ManagementOS is specified; otherwise it is a Microsoft.HyperV.PowerShell.VMNetworkAdapter object. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterBase])] + param ( + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMName', Position=1)] + [Parameter(ParameterSetName='VMObject', Position=1)] + [Parameter(ParameterSetName='ManagementOS', Position=1)] + [Alias('VMNetworkAdapterName')] + [string] + ${Name}, + + [Parameter(Mandatory=$true, Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${NewName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Rename-VMResourcePool { + <# + .SYNOPSIS + Renames a resource pool on one or more Hyper-V hosts. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Name + Specifies the friendly name of the resource pool to be renamed. + .PARAMETER ResourcePoolType + Specifies the type of the resource pool to be renamed. + .PARAMETER NewName + Specifies the name to which the specified resource pool is to be renamed. + .PARAMETER Passthru + Specifies that a VMResourcePool object is to be passed through to the pipeline representing the resource pool to be renamed. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the resource pool is to be renamed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMResourcePool])] + param ( + [Parameter(ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(Mandatory=$true, Position=1, ValueFromPipelineByPropertyName=$true)] + [Microsoft.HyperV.PowerShell.VMResourcePoolType] + ${ResourcePoolType}, + + [Parameter(Mandatory=$true, Position=2)] + [string] + ${NewName}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Rename-VMSan { + <# + .SYNOPSIS + Renames a virtual storage area network (SAN). + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Name + Specifies the current name of the virtual storage area network (SAN) to be renamed. + .PARAMETER NewName + Specifies the new name of the virtual storage area network (SAN) to be renamed. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the renamed virtual storage area network (SAN). + .PARAMETER ComputerName + Specifies the name of the Hyper-V host on which the virtual storage area network (SAN) is to be renamed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSan])] + param ( + [Parameter(ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [Alias('SanName')] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${NewName}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Rename-VMSnapshot { + <# + .SYNOPSIS + Renames a virtual machine checkpoint. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual machine checkpoint is to be renamed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMSnapshot + Specifies the virtual machine checkpoint to be renamed. + .PARAMETER VM + Specifies the virtual machine of which the checkpoint is to be renamed. + .PARAMETER Name + Specifies the name of the virtual machine checkpoint to be renamed. + .PARAMETER VMName + Specifies the name of the virtual machine of which the checkpoint is to be renamed. + .PARAMETER NewName + Specifies the name to which the virtual machine checkpoint is to be renamed. + .PARAMETER Passthru + Specifies that a VMSnapshot object is to be passed through to the pipeline representing the virtual machine checkpoint to be renamed. + #> + + [CmdletBinding(DefaultParameterSetName='SnapshotName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSnapshot])] + param ( + [Parameter(ParameterSetName='SnapshotName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='SnapshotName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='SnapshotName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='SnapshotObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VM', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VirtualMachine] + ${VM}, + + [Parameter(ParameterSetName='SnapshotName', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='VM', Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='SnapshotName', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(Mandatory=$true, Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${NewName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Rename-VMSwitch { + <# + .SYNOPSIS + Renames a virtual switch. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual switch is to be renamed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMSwitch + Specifies the virtual switch to be renamed. + .PARAMETER Name + Specifies the name of the virtual switch to be renamed. + .PARAMETER NewName + Specifies the name to which the virtual switch is to be renamed. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.EthernetSwitch object is to be passed through to the pipeline representing the virtual switch to be renamed. + #> + + [CmdletBinding(DefaultParameterSetName='SwitchName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitch])] + param ( + [Parameter(ParameterSetName='SwitchName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='SwitchName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='SwitchName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='SwitchObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitch] + ${VMSwitch}, + + [Parameter(ParameterSetName='SwitchName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('SwitchName')] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(Mandatory=$true, Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${NewName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Repair-VM { + <# + .SYNOPSIS + Repairs one or more virtual machines. + .PARAMETER CompatibilityReport + Specifies a compatibility report which includes adjustments to be made during repair. + .PARAMETER SnapshotFilePath + Specifies the path to be search for virtual machine snapshots. + .PARAMETER Path + Specifies the path of the virtual machine to be repaired. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the newly modified compatibility report. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMCompatibilityReport])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMCompatibilityReport] + ${CompatibilityReport}, + + [Alias('CheckpointFileLocation','SnapshotFileLocation')] + [string] + ${SnapshotFilePath}, + + [string] + ${Path}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Reset-VMReplicationStatistics { + <# + .SYNOPSIS + Resets the replication statistics of a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the replication statistics of a virtual machine are to be reset. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine whose replication statistics are to be reset. + .PARAMETER VM + Specifies the virtual machine whose replication statistics are to be reset. + .PARAMETER VMReplication + Specifies the virtual machine replication whose replication statistics are to be reset. + .PARAMETER ReplicationRelationshipType + Specifies the replication relationship type of the virtual machine. Specify whether the replication relationship is a simple primary to replica or is an extended replication chain. The cmdlet resets the replication statistics for the virtual machines that have the replication type that you specify. + .PARAMETER Passthru + Specifies that a VMReplication object is to be passed through to the pipeline representing the replication whose statistics are to be reset. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplication])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMReplication', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMReplication[]] + ${VMReplication}, + + [Parameter(ParameterSetName='VMName')] + [Alias('Relationship')] + [System.Nullable[Microsoft.HyperV.PowerShell.VMReplicationRelationshipType]] + ${ReplicationRelationshipType}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Reset-VMResourceMetering { + <# + .SYNOPSIS + Resets the resource utilization data collected by Hyper-V resource metering. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more virtual machine hosts for which resource utilization data is to be reset. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine for which resource utilization data is to be reset. + .PARAMETER VMName + Specifies the friendly name of the virtual machine for which resource utilization data is to be reset. + .PARAMETER ResourcePoolName + Specifies the friendly name of the virtual machine resource pool for which resource utilization data is to be reset. + .PARAMETER ResourcePoolType + Specifies the resource type of the virtual machine resource pool for which resource utilization data is to be reset. + #> + + [CmdletBinding(DefaultParameterSetName='VMName')] + param ( + [Parameter(ParameterSetName='VMName', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='ResourcePool', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ResourcePool')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ResourcePool')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='ResourcePool', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('Name')] + [ValidateNotNullOrEmpty()] + [string] + ${ResourcePoolName}, + + [Parameter(ParameterSetName='ResourcePool', Position=1, ValueFromPipelineByPropertyName=$true)] + [ValidateSet('Ethernet','Memory','Processor','VHD')] + [Microsoft.HyperV.PowerShell.VMResourcePoolType] + ${ResourcePoolType} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Resize-VHD { + <# + .SYNOPSIS + Resizes a virtual hard disk. + .PARAMETER Path + Specifies the path to the virtual hard disk that is to be resized. + .PARAMETER SizeBytes + Specifies the size to which the virtual hard disk is to be resized. + .PARAMETER ToMinimumSize + Specifies that the virtual hard disk is to be resized to its minimum possible size. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual hard disk to be resized. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a virtual hard disk is to be resized. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='Size', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.Vhd.PowerShell.VirtualHardDisk])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('FullName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='Size', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [uint64] + ${SizeBytes}, + + [Parameter(ParameterSetName='MinimumSize', Mandatory=$true)] + [switch] + ${ToMinimumSize}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Restart-VM { + <# + .SYNOPSIS + Restarts a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual machine is to be restarted. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine to be restarted. + .PARAMETER Name + Specifies the name of the virtual machine to be restarted. + .PARAMETER Force + Specifies that no prompt for confirmation is to appear before the virtual machine is restarted. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual machine to be restarted. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='NameWait')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='NameWait')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='NameWait')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMObjectWait', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='NameWait', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [switch] + ${Force}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru}, + + [Parameter(ParameterSetName='VMObjectWait', Mandatory=$true)] + [Parameter(ParameterSetName='NameWait', Mandatory=$true)] + [switch] + ${Wait}, + + [Parameter(ParameterSetName='NameWait')] + [Parameter(ParameterSetName='VMObjectWait')] + [Microsoft.HyperV.PowerShell.Commands.RestartVM+WaitVMTypes] + ${For}, + + [Parameter(ParameterSetName='NameWait')] + [Parameter(ParameterSetName='VMObjectWait')] + [ValidateRange(1, 65535)] + [uint16] + ${Delay}, + + [Parameter(ParameterSetName='NameWait')] + [Parameter(ParameterSetName='VMObjectWait')] + [Alias('TimeoutSec')] + [ValidateRange(-1, 2147483647)] + [System.Nullable[int]] + ${Timeout}, + + [Parameter(ParameterSetName='Name')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='NameWait')] + [Parameter(ParameterSetName='VMObjectWait')] + [Microsoft.HyperV.PowerShell.Commands.RestartVM+RestartType] + ${Type} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Restore-VMSnapshot { + <# + .SYNOPSIS + Restores a virtual machine checkpoint. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual machine checkpoint is to be restored. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMSnapshot + Specifies an array of VMSnapshot objects. To obtain a VMSnapshot object, use the Get-VMSnapshot cmdlet. The cmdlet restores the virtual machine checkpoints that you specify. + .PARAMETER VM + Specifies the virtual machine to be restored. + .PARAMETER Name + Specifies the name of the checkpoint to be restored. + .PARAMETER VMName + Specifies the name of the virtual machine to be restored. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that a VMSnapshot is to be passed through to the pipeline representing the checkpoint to be restored. + #> + + [CmdletBinding(DefaultParameterSetName='SnapshotName', SupportsShouldProcess=$true, ConfirmImpact='High')] + [OutputType([Microsoft.HyperV.PowerShell.VMSnapshot])] + param ( + [Parameter(ParameterSetName='SnapshotName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='SnapshotName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='SnapshotName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='SnapshotObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMCheckpoint')] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMSnapshot}, + + [Parameter(ParameterSetName='VM', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VirtualMachine] + ${VM}, + + [Parameter(ParameterSetName='VM', Mandatory=$true)] + [Parameter(ParameterSetName='SnapshotName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='SnapshotName', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Resume-VM { + <# + .SYNOPSIS + Resumes a suspended (paused) virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual machine is to be resumed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies an array of virtual machine objects. The cmdlet resumes the virtual machines that you specify. To obtain a virtual machine object, use the Get-VM cmdlet. + .PARAMETER Name + Specifies the name of the virtual machine to be resumed. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual machine to be resumed. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Resume-VMReplication { + <# + .SYNOPSIS + Resumes a virtual machine replication that is in a state of Paused, Error, Resynchronization Required, or Suspended. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual machine replication is to be resumed. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER VMName + Specifies the name of the virtual machine whose replication is to be resumed. + .PARAMETER VM + Specifies the virtual machine whose replication is to be resumed. + .PARAMETER VMReplication + Specifies a virtual machine replication object representing the virtual machine replication to be resumed. + .PARAMETER ReplicationRelationshipType + Specifies the replication relationship type of the virtual machine. Specify whether the replication relationship is a simple primary to replica or is an extended replication chain. The cmdlet resumes the replication of the virtual machines that have the replication type that you specify. + .PARAMETER ResynchronizeStartTime + Specifies when resynchronization should start. If not specified, resynchronization starts immediately. You can schedule the resynchronization to start up to 7 days later. + .PARAMETER Resynchronize + Specifies that resynchronization is to be started for the virtual machine. Resynchronization requires significant storage, processor, and network resources. We recommend running this process during off-peak hours. Use the Set-VMReplication cmdlet to specify whether to automatically resynchronize the virtual machine in the future. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Continue + Indicates that Hyper-V Replica continues the resynchronization comparisons from where it left off when you resume the virtual machine replication. + .PARAMETER Passthru + Indicates that this cmdlet returns a VMReplication object. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplication])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMReplication', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMReplication[]] + ${VMReplication}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Alias('Relationship')] + [System.Nullable[Microsoft.HyperV.PowerShell.VMReplicationRelationshipType]] + ${ReplicationRelationshipType}, + + [Alias('ResyncStart')] + [ValidateNotNull()] + [System.Nullable[datetime]] + ${ResynchronizeStartTime}, + + [Alias('Resync')] + [switch] + ${Resynchronize}, + + [switch] + ${AsJob}, + + [switch] + ${Continue}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Revoke-VMConnectAccess { + <# + .SYNOPSIS + Revokes access for one or more users to connect to a one or more virtual machines. + .PARAMETER UserName + Specifies the user or users to whom access to connect to a virtual machine or machines is to be revoked. + .PARAMETER Passthru + Specifies that a VMConnectAce is to be passed through to the pipeline for each revocation of access. + .PARAMETER VMId + Specifies the unique identifier of a virtual machine or machines to which connect access is to be revoked. + .PARAMETER VMName + Specifies the name or names of the virtual machine or machines to which access is being revoked. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which this cmdlet operates. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMConnectAce])] + param ( + [Parameter(Mandatory=$true, Position=1, ValueFromPipelineByPropertyName=$true)] + [Alias('UserId','Sid')] + [ValidateNotNullOrEmpty()] + [string[]] + ${UserName}, + + [switch] + ${Passthru}, + + [Parameter(ParameterSetName='VMId', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [guid[]] + ${VMId}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Save-VM { + <# + .SYNOPSIS + Saves a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual machine is to be saved. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine to be saved. + .PARAMETER Name + Specifies the name of the virtual machine to be saved. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VHD { + <# + .SYNOPSIS + Sets properties associated with a virtual hard disk. + .PARAMETER Path + Specifies the path to the virtual hard disk file of the virtual hard disk drive whose parent in the virtual hard disk chain is to be set. + .PARAMETER ParentPath + Specifies the path to the parent disk of a differencing virtual hard disk. Can be performed regardless of whether the disk is online or offline. + .PARAMETER LeafPath + Specifies the path to the virtual hard disk file of the virtual hard disk representing the leaf node of the virtual hard disk chain. Required when performing the operation in online mode. + .PARAMETER PhysicalSectorSizeBytes + Specifies the physical sector size, in bytes. Valid values are 512 and 4096. This parameter is supported only on a VHDX-format disk that is not attached when the operation is initiated. + .PARAMETER ResetDiskIdentifier + Indicates that the cmdlet modifies the disk identifier of the virtual disk associated with the virtual hard disk file. The disk identifier is the SCSI Vital Product Data (VPD) Page 0x83h identifier associated with a disk. Use this parameter only for a VHDX-format disk. + .PARAMETER Force + Forces the command to run without asking for user confirmation. + .PARAMETER IgnoreIdMismatch + Specifies that the check for identifier mismatch between the parent and child virtual hard disk is to be skipped. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual hard disk whose parent is to be set. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the parent of a virtual hard disk in a differencing hard disk chain is to be set. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='Parent', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.Vhd.PowerShell.VirtualHardDisk])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('FullName')] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [Parameter(ParameterSetName='Parent', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${ParentPath}, + + [Parameter(ParameterSetName='Parent')] + [ValidateNotNullOrEmpty()] + [string] + ${LeafPath}, + + [Parameter(ParameterSetName='PhysicalSectorSize', Mandatory=$true)] + [ValidateSet('512','4096')] + [ValidateNotNullOrEmpty()] + [uint32] + ${PhysicalSectorSizeBytes}, + + [Parameter(ParameterSetName='DiskIdentifier', Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [switch] + ${ResetDiskIdentifier}, + + [Parameter(ParameterSetName='DiskIdentifier')] + [switch] + ${Force}, + + [Parameter(ParameterSetName='Parent')] + [switch] + ${IgnoreIdMismatch}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VM { + <# + .SYNOPSIS + Configures a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual machine is to be configured. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine to be configured. + .PARAMETER Name + Specifies the name of the virtual machine to be configured. + .PARAMETER GuestControlledCacheTypes + Specifies whether this virtual machine uses guest controlled cache types. + .PARAMETER ProcessorCount + Specifies the number of virtual processors for the virtual machine. + .PARAMETER DynamicMemory + Specifies that the virtual machine is to be configured to use dynamic memory. + .PARAMETER StaticMemory + This cmdlet configures the virtual machine to use static memory. Specify the amount of static memory to allocate by using the MemoryStartupBytes parameter. + .PARAMETER MemoryMinimumBytes + Specifies the minimum amount of memory that the virtual machine is to be allocated. (Applies only to virtual machines using dynamic memory.) + .PARAMETER MemoryMaximumBytes + Specifies the maximum amount of memory that the virtual machine is to be allocated. (Applies only to virtual machines using dynamic memory.) + .PARAMETER MemoryStartupBytes + Specifies the amount of memory that the virtual machine is to be allocated upon startup. (If the virtual machine does not use dynamic memory, then this is the static amount of memory to be allocated.) + .PARAMETER AutomaticStartAction + Specifies the action the virtual machine is to take upon start. Allowed values are Nothing , StartIfRunning , and Start . + .PARAMETER AutomaticStopAction + Specifies the action the virtual machine is to take when the virtual machine host shuts down. Allowed values are TurnOff , Save , and ShutDown . + .PARAMETER AutomaticStartDelay + Specifies the number of seconds by which the virtual machine's start should be delayed. + .PARAMETER AutomaticCriticalErrorAction + Specifies the action to take when the VM encounters a critical error, and exceeds the timeout duration specified by the AutomaticCriticalErrorActionTimeout cmdlet. The acceptable values for this parameter are: Pause and None. + .PARAMETER AutomaticCriticalErrorActionTimeout + Specifies the amount of time, in minutes, to wait in critical pause before powering off the virtual machine. + .PARAMETER LockOnDisconnect + Specifies whether virtual machine connection in basic mode locks the console after a user disconnects. + .PARAMETER Notes + Specifies notes to be associated with the virtual machine. + .PARAMETER NewVMName + Specifies the name to which the virtual machine is to be renamed. + .PARAMETER SnapshotFileLocation + Specifies the folder in which the virtual machine is to store its snapshot files. + .PARAMETER SmartPagingFilePath + Specifies the folder in which the Smart Paging file is to be stored. + .PARAMETER CheckpointType + Allows you to configure the type of checkpoints created by Hyper-V. The acceptable values for this parameter are: + + - Disabled. Block creation of checkpoints. - Standard. Create standard checkpoints. - Production. Create production checkpoints if supported by guest operating system. Otherwise, create standard checkpoints. - ProductionOnly. Create production checkpoints if supported by guest operating system. Otherwise, the operation fails. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual machine to be configured. + .PARAMETER AllowUnverifiedPaths + Specifies that no error is to be thrown if the specified path is not verified as accessible by the cluster. This parameter is applicable to clustered virtual machines. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [bool] + ${GuestControlledCacheTypes}, + + [uint32] + ${LowMemoryMappedIoSpace}, + + [uint64] + ${HighMemoryMappedIoSpace}, + + [bool] + ${BatteryPassthroughEnabled}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${ProcessorCount}, + + [switch] + ${DynamicMemory}, + + [switch] + ${StaticMemory}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${MemoryMinimumBytes}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${MemoryMaximumBytes}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${MemoryStartupBytes}, + + [ValidateNotNullOrEmpty()] + [System.Nullable[Microsoft.HyperV.PowerShell.StartAction]] + ${AutomaticStartAction}, + + [ValidateNotNullOrEmpty()] + [System.Nullable[Microsoft.HyperV.PowerShell.StopAction]] + ${AutomaticStopAction}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${AutomaticStartDelay}, + + [ValidateNotNullOrEmpty()] + [System.Nullable[Microsoft.HyperV.PowerShell.CriticalErrorAction]] + ${AutomaticCriticalErrorAction}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${AutomaticCriticalErrorActionTimeout}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${AutomaticCheckpointsEnabled}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.OnOffState]] + ${LockOnDisconnect}, + + [ValidateNotNull()] + [string] + ${Notes}, + + [ValidateNotNullOrEmpty()] + [string] + ${NewVMName}, + + [ValidateNotNullOrEmpty()] + [string] + ${SnapshotFileLocation}, + + [ValidateNotNullOrEmpty()] + [string] + ${SmartPagingFilePath}, + + [System.Nullable[Microsoft.HyperV.PowerShell.CheckpointType]] + ${CheckpointType}, + + [System.Nullable[Microsoft.HyperV.PowerShell.EnhancedSessionTransportType]] + ${EnhancedSessionTransportType}, + + [switch] + ${Passthru}, + + [switch] + ${AllowUnverifiedPaths} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMBios { + <# + .SYNOPSIS + Configures the BIOS of a Generation 1 virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts for which the BIOS is to be configured. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine for which the BIOS is to be configured. + .PARAMETER VM + Specifies the virtual machine for which the BIOS is to be configured. + .PARAMETER VMBios + Specifies an array of BIOS objects. The cmdlet configures the BIOS that you specify for the virtual machines. To obtain a BIOS object, use the Get-VMBios cmdlet. + .PARAMETER DisableNumLock + Specifies that NumLock is to be disabled in the BIOS of the virtual machine to be configured. + .PARAMETER EnableNumLock + Specifies that NumLock is to be enabled in the BIOS of the virtual machine to be configured. + .PARAMETER StartupOrder + Specifies an array of boot devices representing the boot order in the BIOS of the virtual machine. The boot devices are specified as members of the BootDevices enumeration ( CD , IDE , LegacyNetworkAdapter , Floppy ). + + Note: The other BootDevices enumeration values of VHD and NetworkAdapter are for Generation 2 VMs only, and are not valid with this cmdlet. + .PARAMETER Passthru + Specifies that an Microsoft.HyperV.PowerShell.Bios object is to be passed through to the pipeline representing the BIOS to be configured. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMBios])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMBios', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMBios[]] + ${VMBios}, + + [switch] + ${DisableNumLock}, + + [switch] + ${EnableNumLock}, + + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.BootDevice[]] + ${StartupOrder}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMComPort { + <# + .SYNOPSIS + Configures the COM port of a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the COM port of a virtual machine is to be configured. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine for which the COM port is to be configured. + .PARAMETER VM + Specifies the virtual machine for which the COM port is to be configured. + .PARAMETER VMComPort + Specifies the COM port to be configured. + .PARAMETER Number + Specifies the Id (1 or 2) of the COM port to be configured. + .PARAMETER Path + Specifies a named pipe path for the COM port to be configured. Specify local pipes as "\\.\pipe\PipeName" and remote pipes as "\\RemoteServer\pipe\PipeName". + .PARAMETER DebuggerMode + Specifies the state of the COM port for use by debuggers. The acceptable values for this parameter are: On and Off. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.ComPort object is to be passed through to the pipeline representing the COM port to be configured. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMComPort])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMComPort', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMComPort[]] + ${VMComPort}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true)] + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=1)] + [ValidateRange(1, 2)] + [int] + ${Number}, + + [Parameter(Position=2)] + [AllowEmptyString()] + [AllowNull()] + [string] + ${Path}, + + [Microsoft.HyperV.PowerShell.OnOffState] + ${DebuggerMode}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMDvdDrive { + <# + .SYNOPSIS + Configures a virtual DVD drive. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the DVD drive is to be configured. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMDvdDrive + Specifies the virtual DVD drive to be configured. + .PARAMETER VMName + Specifies the name of the virtual machine on which the DVD drive is to be configured. + .PARAMETER ControllerNumber + Specifies the IDE controller of the DVD drives to be configured. If not specified, DVD drives attached to all controllers are configured. + .PARAMETER ControllerLocation + Specifies the IDE controller location of the DVD drives to be configured. If not specified, DVD drives in all controller locations are configured. + .PARAMETER ToControllerNumber + Specifies the controller number to which this VMDvdDrive should be moved. + .PARAMETER ToControllerLocation + Specifies the controller location to which this virtual DVD drive should be moved. + .PARAMETER Path + Specifies the path to the ISO file or physical DVD drive that will serve as media for the virtual DVD drive. + .PARAMETER ResourcePoolName + Specifies the friendly name of the ISO resource pool to which this DVD drive is to be associated. + .PARAMETER AllowUnverifiedPaths + Specifies that no error is to be thrown if the specified path is not verified as accessible by the cluster. This parameter is applicable to clustered virtual machines. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.DvdDrive object is to be passed through to the pipeline representing the virtual DVD drive to be configured. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.DvdDrive])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Object', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.DvdDrive[]] + ${VMDvdDrive}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='VMName', Position=1)] + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerNumber}, + + [Parameter(ParameterSetName='VMName', Position=2)] + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerLocation}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${ToControllerNumber}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${ToControllerLocation}, + + [Parameter(Position=3)] + [string] + ${Path}, + + [ValidateNotNullOrEmpty()] + [string] + ${ResourcePoolName}, + + [switch] + ${AllowUnverifiedPaths}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMFibreChannelHba { + <# + .SYNOPSIS + Configures a Fibre Channel host bus adapter on a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a Fibre Channel host bus adapter is to be configured. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMFibreChannelHba + Specifies the Fibre Channel host bus adapter to be configured. + .PARAMETER VMName + Specifies the name of the virtual machine to which the virtual Fibre Channel host bus adapter parameters are to be set. + .PARAMETER WorldWideNodeNameSetA + Specifies the World Wide Node name of address set A that is associated with the Fibre Channel host bus adapter. + .PARAMETER WorldWidePortNameSetA + Specifies the World Wide Port name of address set A that is associated with the Fibre Channel host bus adapter. + .PARAMETER WorldWideNodeNameSetB + Specifies the World Wide Node name of address set B that is associated with the Fibre Channel host bus adapter. + .PARAMETER WorldWidePortNameSetB + Specifies the World Wide Port name of address set B that is associated with the Fibre Channel host bus adapter. + .PARAMETER GenerateWwn + Specifies that the World Wide Names for sets A and B are to be generated automatically. When this parameter is specified, parameters WorldWideNodeNameSetA , WorldWideNodeNameSetB , WorldWidePortNameSetA , and WorldWidePortNameSetB cannot be used. + .PARAMETER SanName + Specifies the name of the virtual storage area network (SAN) to be associated with the Fibre Channel host bus adapter. + .PARAMETER NewWorldWideNodeNameSetA + Specifies the World Wide Node name of address set A to be associated with the Fibre Channel host bus adapter. + .PARAMETER NewWorldWidePortNameSetA + Specifies the World Wide Port name of address set A to be associated with the Fibre Channel host bus adapter. + .PARAMETER NewWorldWideNodeNameSetB + Specifies the World Wide Node name of address set B to be associated with the Fibre Channel host bus adapter. + .PARAMETER NewWorldWidePortNameSetB + Specifies the World Wide Port name of address set B to be associated with the Fibre Channel host bus adapter. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the configured Fibre Channel host bus adapter. + #> + + [CmdletBinding(DefaultParameterSetName='VMName And Only SAN', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMFibreChannelHba])] + param ( + [Parameter(ParameterSetName='VMName And Generate WWN')] + [Parameter(ParameterSetName='VMName And Manual WWN')] + [Parameter(ParameterSetName='VMName And Only SAN')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName And Generate WWN')] + [Parameter(ParameterSetName='VMName And Manual WWN')] + [Parameter(ParameterSetName='VMName And Only SAN')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName And Generate WWN')] + [Parameter(ParameterSetName='VMName And Manual WWN')] + [Parameter(ParameterSetName='VMName And Only SAN')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Object And Generate WWN', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='Object And Manual WWN', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='Object And Only SAN', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMFibreChannelHba] + ${VMFibreChannelHba}, + + [Parameter(ParameterSetName='VMName And Only SAN', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='VMName And Manual WWN', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='VMName And Generate WWN', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='VMName And Generate WWN', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VMName And Manual WWN', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='VMName And Only SAN', Mandatory=$true, Position=1)] + [Alias('Wwnn1')] + [ValidateNotNullOrEmpty()] + [string] + ${WorldWideNodeNameSetA}, + + [Parameter(ParameterSetName='VMName And Generate WWN', Mandatory=$true, Position=2)] + [Parameter(ParameterSetName='VMName And Manual WWN', Mandatory=$true, Position=2)] + [Parameter(ParameterSetName='VMName And Only SAN', Mandatory=$true, Position=2)] + [Alias('Wwpn1')] + [ValidateNotNullOrEmpty()] + [string] + ${WorldWidePortNameSetA}, + + [Parameter(ParameterSetName='VMName And Only SAN', Mandatory=$true, Position=3)] + [Parameter(ParameterSetName='VMName And Generate WWN', Mandatory=$true, Position=3)] + [Parameter(ParameterSetName='VMName And Manual WWN', Mandatory=$true, Position=3)] + [Alias('Wwnn2')] + [ValidateNotNullOrEmpty()] + [string] + ${WorldWideNodeNameSetB}, + + [Parameter(ParameterSetName='VMName And Generate WWN', Mandatory=$true, Position=4)] + [Parameter(ParameterSetName='VMName And Manual WWN', Mandatory=$true, Position=4)] + [Parameter(ParameterSetName='VMName And Only SAN', Mandatory=$true, Position=4)] + [Alias('Wwpn2')] + [ValidateNotNullOrEmpty()] + [string] + ${WorldWidePortNameSetB}, + + [Parameter(ParameterSetName='VMName And Generate WWN', Mandatory=$true)] + [Parameter(ParameterSetName='Object And Generate WWN', Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [switch] + ${GenerateWwn}, + + [Parameter(ParameterSetName='Object And Only SAN', Mandatory=$true)] + [Parameter(ParameterSetName='VMName And Only SAN', Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${SanName}, + + [Parameter(ParameterSetName='Object And Manual WWN')] + [Parameter(ParameterSetName='VMName And Manual WWN')] + [ValidateNotNullOrEmpty()] + [string] + ${NewWorldWideNodeNameSetA}, + + [Parameter(ParameterSetName='Object And Manual WWN')] + [Parameter(ParameterSetName='VMName And Manual WWN')] + [ValidateNotNullOrEmpty()] + [string] + ${NewWorldWidePortNameSetA}, + + [Parameter(ParameterSetName='Object And Manual WWN')] + [Parameter(ParameterSetName='VMName And Manual WWN')] + [ValidateNotNullOrEmpty()] + [string] + ${NewWorldWideNodeNameSetB}, + + [Parameter(ParameterSetName='Object And Manual WWN')] + [Parameter(ParameterSetName='VMName And Manual WWN')] + [ValidateNotNullOrEmpty()] + [string] + ${NewWorldWidePortNameSetB}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMFirmware { + <# + .SYNOPSIS + Sets the firmware configuration of a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies the names of the Hyper-V hosts whose firmware configuration you want to modify. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies an array of names of virtual machines for which you want to modify the firmware configuration. + .PARAMETER VM + Specifies the virtual machine objects for which want to modify the firmware configuration. To obtain a virtual machine object, use the Get-VM cmdlet. + .PARAMETER VMFirmware + Specifies an array of virtual machine firmware configurations. The cmdlet sets the firmware configurations you specify. + .PARAMETER BootOrder + Specifies an array of devices. The boot order determines the order of the devices from which to boot. The acceptable values for this parameter are: + + -- VMBootSource + + -- VMNetworkAdapter + + -- HardDiskDrive + + -- DVDDrive + The VMBootSource value describes a boot entry in firmware nonvolatile Random Access Memory (NVRAM). + + .PARAMETER FirstBootDevice + Specifies the device from which to attempt to boot from first. The acceptable values for this parameter are: + + -- VMBootSource + + -- VMNetworkAdapter + + -- HardDiskDrive + + -- DVDDrive + The VMBootSource value describes a boot entry in firmware NVRAM. + + .PARAMETER EnableSecureBoot + Specifies whether to enable secure boot. The acceptable values for this parameter are: + + -- On + + -- Off + Secure boot uses a public key infrastructure that protects the integrity of the operating system. + + .PARAMETER SecureBootTemplate + Specifies the name of the secure boot template. If secure boot is enabled, you must have a valid secure boot template for the guest operating system to start. + .PARAMETER SecureBootTemplateId + Specifies the ID of the secure boot template. + .PARAMETER PreferredNetworkBootProtocol + Specifies the IP protocol version to use during a network boot. + .PARAMETER ConsoleMode + Specifies the console mode type for the virtual machine. This parameter allows a virtual machine to run without graphical user interface. + .PARAMETER PauseAfterBootFailure + Specifies the behavior of the virtual machine after a start failure. For a value of On, if the virtual machine fails to start correctly from a device, the virtual machine is paused. + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMFirmware])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMFirmware', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMFirmware[]] + ${VMFirmware}, + + [Microsoft.HyperV.PowerShell.VMComponentObject[]] + ${BootOrder}, + + [Microsoft.HyperV.PowerShell.VMComponentObject] + ${FirstBootDevice}, + + [System.Nullable[Microsoft.HyperV.PowerShell.OnOffState]] + ${EnableSecureBoot}, + + [string] + ${SecureBootTemplate}, + + [System.Nullable[guid]] + ${SecureBootTemplateId}, + + [System.Nullable[Microsoft.HyperV.PowerShell.IPProtocolPreference]] + ${PreferredNetworkBootProtocol}, + + [System.Nullable[Microsoft.HyperV.PowerShell.ConsoleModeType]] + ${ConsoleMode}, + + [System.Nullable[Microsoft.HyperV.PowerShell.OnOffState]] + ${PauseAfterBootFailure}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMFloppyDiskDrive { + <# + .SYNOPSIS + Configures a virtual floppy disk drive. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual floppy disk drive is to be configured. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine on which the virtual floppy disk drive is to be configured. + .PARAMETER VM + Specifies the virtual machine in which the virtual floppy disk drive is to be configured. + .PARAMETER VMFloppyDiskDrive + Specifies the virtual floppy disk drive to be configured. + .PARAMETER Path + Specifies the path to the virtual floppy drive file. If specified as $null , the drive is set to contain no media. + .PARAMETER ResourcePoolName + Specifies the name of the virtual floppy disk resource pool to use for this virtual floppy disk. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.FloppyDiskDrive object is to be passed through to the pipeline representing the virtual floppy disk drive to be configured. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMFloppyDiskDrive])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMFloppyDiskDrive', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMFloppyDiskDrive[]] + ${VMFloppyDiskDrive}, + + [Parameter(Position=1, ValueFromPipelineByPropertyName=$true)] + [Alias('FullName')] + [string] + ${Path}, + + [ValidateNotNullOrEmpty()] + [string] + ${ResourcePoolName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMGpuPartitionAdapter { + <# + .SYNOPSIS + Set-VMGpuPartitionAdapter [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [-Passthru] [-AdapterId ] [-MinPartitionVRAM ] [-MaxPartitionVRAM ] [-OptimalPartitionVRAM ] [-MinPartitionEncode ] [-MaxPartitionEncode ] [-OptimalPartitionEncode ] [-MinPartitionDecode ] [-MaxPartitionDecode ] [-OptimalPartitionDecode ] [-MinPartitionCompute ] [-MaxPartitionCompute ] [-OptimalPartitionCompute ] [-WhatIf] [-Confirm] [] + +Set-VMGpuPartitionAdapter [-VM] [-Passthru] [-AdapterId ] [-MinPartitionVRAM ] [-MaxPartitionVRAM ] [-OptimalPartitionVRAM ] [-MinPartitionEncode ] [-MaxPartitionEncode ] [-OptimalPartitionEncode ] [-MinPartitionDecode ] [-MaxPartitionDecode ] [-OptimalPartitionDecode ] [-MinPartitionCompute ] [-MaxPartitionCompute ] [-OptimalPartitionCompute ] [-WhatIf] [-Confirm] [] + +Set-VMGpuPartitionAdapter [-VMGpuPartitionAdapter] [-Passthru] [-MinPartitionVRAM ] [-MaxPartitionVRAM ] [-OptimalPartitionVRAM ] [-MinPartitionEncode ] [-MaxPartitionEncode ] [-OptimalPartitionEncode ] [-MinPartitionDecode ] [-MaxPartitionDecode ] [-OptimalPartitionDecode ] [-MinPartitionCompute ] [-MaxPartitionCompute ] [-OptimalPartitionCompute ] [-WhatIf] [-Confirm] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMGpuPartitionAdapter])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='Object', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMGpuPartitionAdapter[]] + ${VMGpuPartitionAdapter}, + + [switch] + ${Passthru}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [ValidateNotNullOrEmpty()] + [string] + ${AdapterId}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MinPartitionVRAM}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MaxPartitionVRAM}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${OptimalPartitionVRAM}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MinPartitionEncode}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MaxPartitionEncode}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${OptimalPartitionEncode}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MinPartitionDecode}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MaxPartitionDecode}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${OptimalPartitionDecode}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MinPartitionCompute}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${MaxPartitionCompute}, + + [ValidateNotNull()] + [System.Nullable[uint64]] + ${OptimalPartitionCompute} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMHardDiskDrive { + <# + .SYNOPSIS + Configures a virtual hard disk. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual hard drive is to be configured. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMHardDiskDrive + Specifies one or more hard disks to be configured. + .PARAMETER VMName + Specifies the name of the virtual machine on which the virtual hard drive is to be configured. + .PARAMETER ControllerType + Specifies the type of the controller to which the virtual hard drive to be configured is attached. Allowed values are Floppy , IDE , and SCSI . + .PARAMETER ControllerNumber + Specifies the number of the controller to which the virtual hard drive to be configured is attached. If not specified, all hard drives are configured. + .PARAMETER ControllerLocation + Specifies the number of the location on the controller to which the virtual hard drive to be configured is attached. If not specified, all hard drives are configured. + .PARAMETER Path + Specifies the path to media the virtual hard disk is to use. + .PARAMETER ToControllerType + Specifies the type of controller to which this drive should be moved. Allowed values are IDE and SCSI. + .PARAMETER ToControllerNumber + Specifies the controller location to which this drive should be moved. Allowed values are 0 and 1 for IDE controllers, and from 0 to 3 for SCSI controllers. + .PARAMETER ToControllerLocation + Specifies the controller location to which this drive should be moved. Allowed values are 0 and 1 for IDE controllers, and from 0 to 63 for SCSI controllers. + .PARAMETER DiskNumber + Specifies the disk number of the offline physical hard drive that should be connected as a passthrough disk. + .PARAMETER ResourcePoolName + Specifies the name of the virtual hard disk resource pool to which this drive belongs. + .PARAMETER SupportPersistentReservations + Indicates whether the hard disk supports SCSI persistent reservation semantics. Specify this parameter when the hard disk is a shared disk that is used by multiple virtual machines. + .PARAMETER AllowUnverifiedPaths + Specifies that no error is to be thrown if the specified path is not verified as accessible by the cluster. This parameter is applicable to clustered virtual machines. + .PARAMETER MaximumIOPS + Specifies the maximum normalized I/O operations per second (IOPS) for the hard disk. Hyper-V calculates normalized IOPS as the total size of I/O per second divided by 8 KB. + .PARAMETER MinimumIOPS + Specifies the minimum normalized I/O operations per second (IOPS) for the hard disk. Hyper-V calculates normalized IOPS as the total size of I/O per second divided by 8 KB. + .PARAMETER QoSPolicyID + Specifies the ID for a storage QoS policy to associate with the hard disk drive. + .PARAMETER QoSPolicy + Specifies the storage Quality of Service (QoS) policy to associate with the hard disk drive. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.HardDiskDrive object is to be passed through to the pipeline representing the virtual hard drive to be configured. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.HardDiskDrive])] + param ( + [Parameter(ParameterSetName='VMName', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='Object', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Object')] + [Parameter(ParameterSetName='VMName')] + [Alias('PSComputerName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='Object')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Object', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.HardDiskDrive[]] + ${VMHardDiskDrive}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='VMName', Position=1)] + [Microsoft.HyperV.PowerShell.ControllerType] + ${ControllerType}, + + [Parameter(ParameterSetName='VMName', Position=2)] + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerNumber}, + + [Parameter(ParameterSetName='VMName', Position=3)] + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerLocation}, + + [Parameter(Position=4)] + [ValidateNotNullOrEmpty()] + [string] + ${Path}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.ControllerType]] + ${ToControllerType}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${ToControllerNumber}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${ToControllerLocation}, + + [Parameter(ValueFromPipelineByPropertyName=$true)] + [Alias('Number')] + [uint32] + ${DiskNumber}, + + [ValidateNotNull()] + [string] + ${ResourcePoolName}, + + [Alias('ShareVirtualDisk')] + [ValidateNotNullOrEmpty()] + [System.Nullable[bool]] + ${SupportPersistentReservations}, + + [switch] + ${AllowUnverifiedPaths}, + + [System.Nullable[uint64]] + ${MaximumIOPS}, + + [System.Nullable[uint64]] + ${MinimumIOPS}, + + [string] + ${QoSPolicyID}, + + [ciminstance] + ${QoSPolicy}, + + [switch] + ${Passthru}, + + [System.Nullable[Microsoft.HyperV.PowerShell.CacheAttributes]] + ${OverrideCacheAttributes} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMHost { + <# + .SYNOPSIS + Configures a Hyper-V host. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which this cmdlet operates. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .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 VirtualMachineMigrationAuthenticationType + Specifies the type of authentication to be used for live migrations. The acceptable values for this parameter are: Kerberos and CredSSP. + .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. The Get-VMMigrationNetwork cmdlet returns the list of networks that can be used for migration traffic. + .PARAMETER VirtualMachineMigrationPerformanceOption + Specifies the performance option to use for live migration. The acceptable values for this parameter are: + + - Compression. Compress data to speed up live migration on constrained networks. - SMBTransport. Use server message block (SMB) to get the highest throughput possible. - None. Perform standard live migration. + .PARAMETER ResourceMeteringSaveInterval + Specifies how often the Hyper-V host saves the data that tracks resource usage. The range is a minimum of 1 hour to a maximum of 24 hours. Time within that range can be specified using a format of hh:mm:ss, where hh indicates hours, mm indicates minutes, and ss indicates seconds. You also can use a Timespan object to specify the interval. + .PARAMETER VirtualHardDiskPath + Specifies the default folder to store virtual hard disks on the Hyper-V host. + .PARAMETER VirtualMachinePath + Specifies the default folder to store virtual machine configuration files on the Hyper-V host. + .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 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 NumaSpanningEnabled + Specifies whether virtual machines on the Hyper-V host can use resources from more than one NUMA node. + .PARAMETER EnableEnhancedSessionMode + Indicates whether users can use enhanced mode when they connect to virtual machines on this server by using Virtual Machine Connection. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.Host is to be passed through to the pipeline representing the Hyper-V host to be configured. + #> + + [CmdletBinding(DefaultParameterSetName='ComputerName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMHost])] + param ( + [Parameter(ParameterSetName='CimSession', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ComputerName', Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ComputerName', Position=1)] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [uint32] + ${MaximumStorageMigrations}, + + [uint32] + ${MaximumVirtualMachineMigrations}, + + [Microsoft.HyperV.PowerShell.MigrationAuthenticationType] + ${VirtualMachineMigrationAuthenticationType}, + + [bool] + ${UseAnyNetworkForMigration}, + + [Microsoft.HyperV.PowerShell.VMMigrationPerformance] + ${VirtualMachineMigrationPerformanceOption}, + + [ValidateNotNull()] + [System.Nullable[timespan]] + ${ResourceMeteringSaveInterval}, + + [ValidateNotNullOrEmpty()] + [string] + ${VirtualHardDiskPath}, + + [ValidateNotNullOrEmpty()] + [string] + ${VirtualMachinePath}, + + [ValidateNotNullOrEmpty()] + [string] + ${MacAddressMaximum}, + + [ValidateNotNullOrEmpty()] + [string] + ${MacAddressMinimum}, + + [ValidateNotNullOrEmpty()] + [string] + ${FibreChannelWwnn}, + + [ValidateNotNullOrEmpty()] + [string] + ${FibreChannelWwpnMaximum}, + + [ValidateNotNullOrEmpty()] + [string] + ${FibreChannelWwpnMinimum}, + + [System.Nullable[bool]] + ${NumaSpanningEnabled}, + + [System.Nullable[bool]] + ${EnableEnhancedSessionMode}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMHostCluster { + <# + .SYNOPSIS + Configures a virtual machine host cluster. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ClusterName + Specifies an array of names of the virtual machine host clusters that this cmdlet configures. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER InputObject + Specifies an array of virtual machine host clusters that this cmdlet configures. To obtain a VMHostCluster object, use the Get-VMHostCluster cmdlet. + .PARAMETER SharedStoragePath + Specifies the location of the shared storage for the virtual machine host cluster. + .PARAMETER Passthru + Indicates that this cmdlet returns the Microsoft.HyperV.PowerShell.VMHostCluster object that it configures. + #> + + [CmdletBinding(DefaultParameterSetName='ClusterName')] + [OutputType([Microsoft.HyperV.PowerShell.VMHostCluster])] + param ( + [Parameter(ParameterSetName='CimSession', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ClusterName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ClusterName}, + + [Parameter(ParameterSetName='ClusterName', Position=1, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='InputObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMHostCluster[]] + ${InputObject}, + + [ValidateNotNullOrEmpty()] + [string] + ${SharedStoragePath}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMKeyProtector { + <# + .SYNOPSIS + Configures a key protector for a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts to run the cmdlet. NetBIOS names, IP addresses, and fully-qualified domain names are allowable. The default is the local computer. Use "localhost" or a dot (".") to specify the local computer explicitly. + .PARAMETER Credential + Specifies a user account that has permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies one or more virtual machines for which to set a key protector. + .PARAMETER VMName + Specifies the name of one or more virtual machines for which to set a key protector. + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + .PARAMETER KeyProtector + Specifies the key protector to use for the virtual machine. + .PARAMETER NewLocalKeyProtector + Specifies that this cmdlet generates a new local key protector. + .PARAMETER RestoreLastKnownGoodKeyProtector + Indicates that this cmdlet restores the last known good key protector. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='VMName')] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${Passthru}, + + [byte[]] + ${KeyProtector}, + + [switch] + ${NewLocalKeyProtector}, + + [switch] + ${RestoreLastKnownGoodKeyProtector} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMKeyStorageDrive { + <# + .SYNOPSIS + Set-VMKeyStorageDrive [-VMName] [[-ControllerNumber] ] [[-ControllerLocation] ] [-CimSession ] [-ComputerName ] [-Credential ] [-ToControllerNumber ] [-ToControllerLocation ] [-ResourcePoolName ] [-AllowUnverifiedPaths] [-Passthru] [-WhatIf] [-Confirm] [] + +Set-VMKeyStorageDrive [-VMKeyStorageDrive] [-ToControllerNumber ] [-ToControllerLocation ] [-ResourcePoolName ] [-AllowUnverifiedPaths] [-Passthru] [-WhatIf] [-Confirm] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.KeyStorageDrive])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Object', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.KeyStorageDrive[]] + ${VMKeyStorageDrive}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='VMName', Position=1)] + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerNumber}, + + [Parameter(ParameterSetName='VMName', Position=2)] + [ValidateNotNull()] + [System.Nullable[int]] + ${ControllerLocation}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${ToControllerNumber}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${ToControllerLocation}, + + [ValidateNotNullOrEmpty()] + [string] + ${ResourcePoolName}, + + [switch] + ${AllowUnverifiedPaths}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMMemory { + <# + .SYNOPSIS + Configures the memory of a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the memory of a virtual machine is to be configured. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine whose memory is to be configured. + .PARAMETER VM + Specifies the virtual machine whose memory is to be configured. + .PARAMETER VMMemory + Specifies the virtual machine memory to be configured. + .PARAMETER Buffer + Specifies the percentage of memory to reserve as a buffer in the virtual machine to be configured. Allowed values range from 5 to 2000. + .PARAMETER DynamicMemoryEnabled + Specifies whether dynamic memory is to be enabled on the virtual machine to be configured. + .PARAMETER MaximumBytes + Specifies the maximum amount of memory to be used by a virtual machine which has dynamic memory enabled. + .PARAMETER StartupBytes + Specifies the initial amount of memory to be assigned to a virtual machine with dynamic memory enabled, or the total amount of memory to be assigned to a virtual machine with dynamic memory disabled. + .PARAMETER MinimumBytes + Specifies the minimum amount of memory to be used by a virtual machine which has dynamic memory enabled. + .PARAMETER Priority + Sets the priority for memory availability to this virtual machine relative to other virtual machines on the virtual machine host. Allowed values range from 0 to 100. + .PARAMETER MaximumAmountPerNumaNodeBytes + Specifies the maximum amount of memory per NUMA node in the virtual machine to be configured. + .PARAMETER ResourcePoolName + Specifies the name of the memory resource pool for this virtual machine. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.Memory object is to be passed through to the pipeline representing the virtual machine memory to be configured. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMMemory])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMMemory[]] + ${VMMemory}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${Buffer}, + + [bool] + ${DynamicMemoryEnabled}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${MaximumBytes}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${StartupBytes}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${MinimumBytes}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${Priority}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${MaximumAmountPerNumaNodeBytes}, + + [ValidateNotNull()] + [string] + ${ResourcePoolName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMMigrationNetwork { + <# + .SYNOPSIS + Sets the subnet, subnet mask, and/or priority of a migration network. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which this cmdlet operates. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Subnet + Specifies a string representing an IPv4 or IPv6 subnet mask which identifies the migration network whose properties are to be set. Wildcards are allowed. + .PARAMETER NewSubnet + Specifies a string representing the new subnet value to be set on the migration network. + .PARAMETER NewPriority + Specifies the new priority of the virtual machine migration network. Multiple networks can have the same priority. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.MigrationNetwork is to be passed through to the pipeline representing the migration network to be configured. + #> + + [CmdletBinding(DefaultParameterSetName='ComputerName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMMigrationNetwork])] + param ( + [Parameter(ParameterSetName='CimSession', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ComputerName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ComputerName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${Subnet}, + + [Parameter(Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${NewSubnet}, + + [ValidateNotNullOrEmpty()] + [uint32] + ${NewPriority}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMNetworkAdapter { + <# + .SYNOPSIS + Configures features of the virtual network adapter in a virtual machine or the management operating system. + .PARAMETER ManagementOS + Specifies the virtual network adapter in the management operating system to be configured. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which features of the network adapter are to be configured. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine that has the virtual network adapteryou want to configure. + .PARAMETER VMNetworkAdapter + Specifies the virtual network adapter. + .PARAMETER VM + Specifies the virtual machine that has the virtual network you want to configure. + .PARAMETER Name + Specifies the name for the virtual network adapter. The cmdlet changes the name to the value that you specify. + .PARAMETER DynamicMacAddress + Assigns a dynamically generated MAC address to the virtual network adapter.. + .PARAMETER StaticMacAddress + Assigns a specific a MAC addresss to the virtual network adapter. + .PARAMETER MacAddressSpoofing + Specifies whether virtual machines may change the source MAC address in outgoing packets to one not assigned to them. Allowed values are On (allowing the virtual machine to use a different MAC address) and Off (allowing the virtual machine to use only the MAC address assigned to it). + .PARAMETER DhcpGuard + Specifies whether to drop DHCP messages from a virtual machine claiming to be a DHCP server. Allowed values are On , which drops DHCP messages because the virtualized DHCP server is considered untrusted) or Off , which allows the message to be received because the virtualized DHCP server is considered to be trustworthy. + .PARAMETER RouterGuard + Specifies whether to drop Router Advertisement and Redirection messages from unauthorized virtual machines. The value can be either On or Off . If On is specified, such messages are dropped. If Off is specified, such messages are sent. + .PARAMETER PortMirroring + Specifies the port mirroring mode for the network adapter to be configured. Allowed values are None , Source , and Destination . If a virtual network adapter is configured as Source , every packet it sends or receives is copied and forwarded to a virtual network adapter configured to receive the packets. If a virtual network adapter is configured as Destination , it receives copied packets from the source virtual network adapter. The source and destination virtual network adapters must be connected to the same virtual switch. Specify None to disable the feature. + .PARAMETER IeeePriorityTag + Specifies whether IEEE 802.1p tagged packets from the virtual machine should be trusted. The value should be either On (trusted) or Off (not trusted). If it is on, the IEEE 802.1p tagged packets will be let go as is. If it is off, the priority value is reset to 0. + .PARAMETER VmqWeight + Specifies whether virtual machine queue (VMQ) is to be enabled on the virtual network adapter. . The relative weight describes the affinity of the virtual network adapter to use VMQ. The range of value is from 0 through 100. Specify 0 to disable VMQ on the virtual network adapter. + .PARAMETER IovQueuePairsRequested + Specifies the number of hardware queue pairs to be allocated to an SR-IOV virtual function. If receive-side scaling (RSS) is required, and if the physical network adapter that binds to the virtual switch supports RSS on SR-IOV virtual functions, then more than one queue pair is required. Allowed values range from 1 to 4294967295. + .PARAMETER IovInterruptModeration + Specifies the interrupt moderation value for a single-root I/O virtualization (SR-IOV) virtual function assigned to a virtual network adapter. Allowed values are Default , Adaptive , Off , Low , Medium , and High . If Default is chosen, the value is determined by the physical network adapter vendor's setting. If Adaptive is chosen, the interrupt moderation rate will be based on the runtime traffic pattern. + .PARAMETER IovWeight + Specifies whether single-root I/O virtualization (SR-IOV) is to be enabled on this virtual network adapter. The relative weight sets the affinity of the virtual network adapter to the assigned SR-IOV virtual function. The range of the value is from 0 through 100. Specify 0 to disable SR-IOV on the virtual network adapter. + .PARAMETER IPsecOffloadMaximumSecurityAssociation + Specifies the maximum number of security associations that can be offloaded to the physical network adapter that is bound to the virtual switch and that supports IPSec Task Offload. Specify zero to disable the feature. + .PARAMETER MaximumBandwidth + Specifies the maximum bandwidth, in bits per second, for the virtual network adapter. The specified value is rounded to the nearest multiple of eight. Specify zero to disable the feature. + .PARAMETER MinimumBandwidthAbsolute + Specifies the minimum bandwidth, in bits per second, for the virtual network adapter. The specified value is rounded to the nearest multiple of eight. A value larger than 100 Mbps is recommended. + .PARAMETER MinimumBandwidthWeight + Specifies the minimum bandwidth, in terms of relative weight, for the virtual network adapter. The weight describes how much bandwidth to provide to the virtual network adapter relative to other virtual network adapters connected to the same virtual switch. The range of the value is from 0 through 100. Specify 0 to disable the feature. + .PARAMETER MandatoryFeatureId + Specifies the unique identifiers of the virtual switch extension features that are required for this virtual network adapter to operate. + .PARAMETER ResourcePoolName + Specifies the name of the resource pool. + .PARAMETER TestReplicaPoolName + This parameter applies only to virtual machines that are enabled for replication. It specifies the name of the network resource pool that will be used by this virtual network adapter when its virtual machine is created during a test failover. + .PARAMETER TestReplicaSwitchName + This parameter applies only to virtual machines that are enabled for replication. It specifies the name of the virtual switch to which the virtual network adapter should be connected when its virtual machine is created during a test failover. + .PARAMETER VirtualSubnetId + Specifies the virtual subnet ID to use with Hyper-V Network Virtualization. Allowed values range from 4096 to 16777215 (2^24 - 1), in addition to 0. Use 0 to clear this parameter. + .PARAMETER AllowTeaming + Specifies whether the virtual network adapter can be teamed with other network adapters connected to the same virtual switch. The value can be On (allowed) or Off (disallowed). + .PARAMETER NotMonitoredInCluster + Indicates whether to not monitor the network adapter if the virtual machine that it belongs to is part of a cluster. By default, network adapters for clustered virtual machines are monitored. + .PARAMETER StormLimit + Specifies the number of broadcast, multicast, and unknown unicast packets per second a virtual machine is allowed to send through the specified virtual network adapter. Broadcast, multicast, and unknown unicast packets beyond the limit during that one second interval are dropped. A value of zero (0) means there is no limit. + .PARAMETER DynamicIPAddressLimit + Specifies the dynamic IP address limit, an integer. + .PARAMETER DeviceNaming + Specifies whether this adapter uses device naming. + .PARAMETER FixSpeed10G + Specifies whether the adapter uses fix speed of 10G. + .PARAMETER PacketDirectNumProcs + Specifies the number of processors to use for virtual switch processing inside of the host. + .PARAMETER PacketDirectModerationCount + Specifies the number of packets to wait for before signaling an interrupt. + .PARAMETER PacketDirectModerationInterval + Specifies the amount of time, in milliseconds, to wait before signaling an interrupt after a packet arrives. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual network adapter to be configured. This is a Microsoft.HyperV.PowerShell.VMInternalNetworkAdapter object, if ManagementOS is specified; or a Microsoft.HyperV.PowerShell.VMNetworkAdapter object otherwise. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterBase])] + param ( + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine] + ${VM}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [Alias('VMNetworkAdapterName')] + [string] + ${Name}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='ResourceObject')] + [switch] + ${DynamicMacAddress}, + + [ValidateNotNull()] + [uint32] + ${MediaType}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${NumaAwarePlacement}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${InterruptModeration}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ResourceObject')] + [ValidateNotNullOrEmpty()] + [string] + ${StaticMacAddress}, + + [ValidateNotNullOrEmpty()] + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.OnOffState]] + ${MacAddressSpoofing}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.OnOffState]] + ${DhcpGuard}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.OnOffState]] + ${RouterGuard}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.VMNetworkAdapterPortMirroringMode]] + ${PortMirroring}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.OnOffState]] + ${IeeePriorityTag}, + + [ValidateNotNull()] + [System.Nullable[uint32]] + ${VmqWeight}, + + [ValidateNotNull()] + [System.Nullable[uint32]] + ${IovQueuePairsRequested}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.IovInterruptModerationValue]] + ${IovInterruptModeration}, + + [ValidateNotNull()] + [System.Nullable[uint32]] + ${IovWeight}, + + [ValidateNotNull()] + [System.Nullable[uint32]] + ${IPsecOffloadMaximumSecurityAssociation}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${MaximumBandwidth}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${MinimumBandwidthAbsolute}, + + [ValidateNotNull()] + [System.Nullable[uint32]] + ${MinimumBandwidthWeight}, + + [string[]] + ${MandatoryFeatureId}, + + [ValidateNotNullOrEmpty()] + [string] + ${ResourcePoolName}, + + [string] + ${TestReplicaPoolName}, + + [string] + ${TestReplicaSwitchName}, + + [ValidateNotNull()] + [System.Nullable[uint32]] + ${VirtualSubnetId}, + + [ValidateNotNullOrEmpty()] + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.OnOffState]] + ${AllowTeaming}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${NotMonitoredInCluster}, + + [ValidateNotNull()] + [System.Nullable[uint32]] + ${StormLimit}, + + [ValidateNotNull()] + [System.Nullable[uint32]] + ${DynamicIPAddressLimit}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.OnOffState]] + ${DeviceNaming}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.OnOffState]] + ${FixSpeed10G}, + + [ValidateNotNull()] + [System.Nullable[uint32]] + ${PacketDirectNumProcs}, + + [ValidateNotNull()] + [System.Nullable[uint32]] + ${PacketDirectModerationCount}, + + [ValidateNotNull()] + [System.Nullable[uint32]] + ${PacketDirectModerationInterval}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${VrssEnabled}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${VmmqEnabled}, + + [Alias('VmmqQueuePairs')] + [ValidateNotNull()] + [System.Nullable[uint32]] + ${VrssMaxQueuePairs}, + + [ValidateNotNull()] + [System.Nullable[uint32]] + ${VrssMinQueuePairs}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.VrssQueueSchedulingModeType]] + ${VrssQueueSchedulingMode}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${VrssExcludePrimaryProcessor}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${VrssIndependentHostSpreading}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.VrssVmbusChannelAffinityPolicyType]] + ${VrssVmbusChannelAffinityPolicy}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMNetworkAdapterFailoverConfiguration { + <# + .SYNOPSIS + Configures the IP address of a virtual network adapter to be used when a virtual machine fails over. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the IP address configuration of a virtual network adapter is to be set. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMNetworkAdapter + Specifies the virtual network adapter for which you want to configure the IP address. + .PARAMETER VMName + Specifies the friendly name of the virtual machine for which you want to configure the IP address. + .PARAMETER VM + Specifies the virtual machine for which you want to configure the IP address. + .PARAMETER VMNetworkAdapterName + Specifies the name of the virtual network adapter for which you want to set the IP address. + .PARAMETER IPv4Address + Specifies the IPv4 address to set on the VMNetworkAdapter for use on failover of the virtual machine. You must also specify the IPv4SubnetMask parameter when you specify this parameter. + .PARAMETER IPv6Address + Specifies the IPv6 address to be set on VMNetworkAdapter for use on failover of the virtual machine. You must specify the IPv6SubnetPrefixLength parameter when you specify this parameter. + .PARAMETER IPv4SubnetMask + Specifies the IPv4 subnet mask to be set on VMNetworkAdapter for use on failover of the virtual machine. You must specify the IPv4Address parameter when you specify this parameter. + .PARAMETER IPv6SubnetPrefixLength + Specifies the IPv6 subnet prefix length to be set on VMNetworkAdapter for use on failover of the virtual machine. You must specify the IPv6Address parameter when you specify this parameter. + .PARAMETER IPv4PreferredDNSServer + Specifies the IPv4 preferred DNS server to be set on VMNetworkAdapter for use on failover of the virtual machine. + .PARAMETER IPv4AlternateDNSServer + Specifies the IPv4 alternate DNS server to be set on the VMNetworkAdapter for use on failover of the virtual machine. + .PARAMETER IPv6PreferredDNSServer + Specifies the IPv6 preferred DNS server to be set on VMNetworkAdapter for use on failover of the virtual machine. + .PARAMETER IPv6AlternateDNSServer + Specifies the IPv6 alternate DNS server to be set on VMNetworkAdapter for use on failover of the virtual machine. + .PARAMETER IPv4DefaultGateway + Specifies the IPv4 default gateway to be set on VMNetworkAdapter for use on failover of the virtual machine.. + .PARAMETER IPv6DefaultGateway + Specifies the IPv6 default gateway to be set on VMNetworkAdapter for use on failover of the virtual machine. + .PARAMETER ClearFailoverIPv4Settings + Clears the configured IPv4 failover settings. The IPv4 address configured in the primary virtual machine (static or dynamic) will be used by the Replica virtual machine. + .PARAMETER ClearFailoverIPv6Settings + Clears the configured IPv6 failover settings. The IPv6 address configured in the primary virtual machine (static or dynamic) will be used by the Replica virtual machine. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.VMNetworkAdapterFailoverConfiguration object is to be passed through to the pipeline representing the IP address configuration to be set. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterFailoverSetting])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMNetworkAdapter] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine] + ${VM}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [string] + ${VMNetworkAdapterName}, + + [string] + ${IPv4Address}, + + [string] + ${IPv6Address}, + + [string] + ${IPv4SubnetMask}, + + [ValidateRange(0, 128)] + [System.Nullable[int]] + ${IPv6SubnetPrefixLength}, + + [string] + ${IPv4PreferredDNSServer}, + + [string] + ${IPv4AlternateDNSServer}, + + [string] + ${IPv6PreferredDNSServer}, + + [string] + ${IPv6AlternateDNSServer}, + + [string] + ${IPv4DefaultGateway}, + + [string] + ${IPv6DefaultGateway}, + + [ValidateNotNull()] + [switch] + ${ClearFailoverIPv4Settings}, + + [ValidateNotNull()] + [switch] + ${ClearFailoverIPv6Settings}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMNetworkAdapterIsolation { + <# + .SYNOPSIS + Modifies isolation settings for a virtual network adapter. + .PARAMETER VMNetworkAdapter + Specifies an array VM network adapters as VMNetworkAdapterBase objects. The cmdlet modifies isolation settings for the adapters that you specify. To obtain a network adapter, use the Get-VMNetworkAdapter cmdlet. + .PARAMETER ManagementOS + Indicates that the cmdlet operates on the parent or host operating system. If you specify this parameter, this cmdlet modifies isolation settings for the parent or host operating system. + .PARAMETER VMNetworkAdapterName + Specifies the name of a virtual network adapter. The cmdlet modifies isolation settings for the adapters that you specify. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies an array of Hyper-V hosts. The cmdlet modifies isolation settings for virtual machines hosted by the computers that you specify. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies an array of names of virtual machines. The cmdlet modifies isolation settings for adapters that belong to the virtual machines that you specify. + .PARAMETER VM + Specifies an array of virtual machine objects. The cmdlet modifies isolation settings for adapters that belong to the virtual machines that you specify. To obtain a virtual machine object, use the Get-VM cmdlet. + .PARAMETER IsolationMode + Specifies the isolation mode for the adapter. The acceptable values for this parameter are: + + - NativeVirtualSubnet. Hyper-V Network Virtualization. - ExternalVirtualSubnet. A third party network virtualization solution. - VLAN. + + - None. + + If you specify a value of None, the network adapter uses its default isolation mode. Set the default isolation mode by using the Set-VMNetworkAdapterVlan cmdlet or the Set-VMNetworkAdapter cmdlet. + + .PARAMETER AllowUntaggedTraffic + Indicates whether the virtual machine sends and receives untagged traffic. + .PARAMETER DefaultIsolationID + Specifies the ID of the network for traffic to the default compartment on virtual machines that have multitenancy enabled. The value that you specify applies only to untagged traffic. This parameter has an effect only if you specify a value of $True for the AllowUntaggedTraffic parameter. + .PARAMETER MultiTenantStack + Specifies whether to use multiple isolation IDs for the virtual machine. The acceptable values for this parameter are: + + - On. Indicate isolation IDs so that the virtual machine provides services to multiple tenants on different isolation subnets. - Off. Do not indicate isolation IDs to virtual machine. + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterIsolationSetting])] + param ( + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.VMNetworkAdapterIsolationMode]] + ${IsolationMode}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${AllowUntaggedTraffic}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${DefaultIsolationID}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.OnOffState]] + ${MultiTenantStack}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMNetworkAdapterRdma { + <# + .SYNOPSIS + Set-VMNetworkAdapterRdma [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [-Name ] [-RdmaWeight ] [-Passthru] [-WhatIf] [-Confirm] [] + +Set-VMNetworkAdapterRdma -ManagementOS [-CimSession ] [-ComputerName ] [-Credential ] [-Name ] [-RdmaWeight ] [-Passthru] [-WhatIf] [-Confirm] [] + +Set-VMNetworkAdapterRdma [-VMNetworkAdapter] [-RdmaWeight ] [-Passthru] [-WhatIf] [-Confirm] [] + +Set-VMNetworkAdapterRdma [-VM] [-Name ] [-RdmaWeight ] [-Passthru] [-WhatIf] [-Confirm] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterRdmaSetting])] + param ( + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine] + ${VM}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [Alias('VMNetworkAdapterName')] + [string] + ${Name}, + + [ValidateNotNull()] + [System.Nullable[uint32]] + ${RdmaWeight}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMNetworkAdapterRoutingDomainMapping { + <# + .SYNOPSIS + Sets virtual subnets on a routing domain. + .PARAMETER VMNetworkAdapter + Specifies an array of virtual network adapters as a VMNetworkAdapterBase object. The cmdlet adds the virtual subnets to the routing domain on the adapters that you specify. To obtain a network adapter, use the Get-VMNetworkAdapter cmdlet. + .PARAMETER ManagementOS + Indicates that the cmdlet operates on the parent partition or host operating system. + .PARAMETER VMNetworkAdapterName + Specifies the name of a virtual network adapter. The cmdlet adds the virtual subnets to the routing domain on the adapter that you specify. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies an array of Hyper-V hosts. The cmdlet adds the virtual subnets to the routing domain on the Hyper-V hosts that you specify. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies an array of names of virtual machines. The cmdlet adds the virtual subnets to the routing domain from the network interfaces that belong to the virtual machines that you specify. To obtain a virtual machine object, use the Get-VM cmdlet. + .PARAMETER VM + Specifies an array of virtual machine objects. The cmdlet adds the virtual subnets to the routing domain from the network interfaces that belong to the virtual machines that you specify. To obtain a virtual machine object, use the Get-VM cmdlet. + .PARAMETER InputObject + Specifies the input to this cmdlet. You can use this parameter, or you can pipe the input to this cmdlet. + .PARAMETER RoutingDomainID + Specifies the ID of a routing domain. The ID of a routing domain is a system-assigned GUID. The cmdlet adds the virtual subnets to the routing domain that you specify. + .PARAMETER RoutingDomainName + Specifies the name of a routing domain. The cmdlet adds the virtual subnets to the routing domain that you specify. + .PARAMETER NewRoutingDomainName + Specifies a new name for the routing domain. + .PARAMETER IsolationID + Specifies an array of IDs of virtual subnets. The cmdlet adds the virtual subnets that you specify to the routing domain. The subnets use VLAN or Hyper-V Network Virtualization. For more information about isolation IDs, see the Set-VmNetworkAdapterIsolation cmdlet. + .PARAMETER IsolationName + Specifies an array of names of virtual subnets. The cmdlet adds the virtual subnets that you specify to the routing domain. The subnets use VLAN or Hyper-V Network Virtualization. + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterRoutingDomainSetting])] + param ( + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='InputObjectParameter', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterRoutingDomainSetting] + ${InputObject}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='ResourceObject')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [guid] + ${RoutingDomainID}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ResourceObject')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string] + ${RoutingDomainName}, + + [ValidateNotNullOrEmpty()] + [string] + ${NewRoutingDomainName}, + + [ValidateNotNullOrEmpty()] + [int[]] + ${IsolationID}, + + [string[]] + ${IsolationName}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMNetworkAdapterTeamMapping { + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterTeamMappingSetting])] + param ( + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ManagementOS')] + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine] + ${VM}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string] + ${SwitchName}, + + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${PhysicalNetAdapterName}, + + [ValidateNotNullOrEmpty()] + [Microsoft.Virtualization.Client.Management.DisableOnFailoverFeature] + ${DisableOnFailover}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMNetworkAdapterVlan { + <# + .SYNOPSIS + Configures the virtual LAN settings for the traffic through a virtual network adapter. + .PARAMETER VMNetworkAdapter + Specifies the virtual machine network adapter. + .PARAMETER ManagementOS + Specifies the management (e.g. parent or host) operating system. + .PARAMETER VMNetworkAdapterName + Specifies the name of the virtual machine network adapter. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual LAN settings on a virtual machine network adapter are to be configured. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine. + .PARAMETER VM + Specifies the virtual machine. + .PARAMETER Untagged + Specifies Untagged mode for the virtual machine network adapter. + .PARAMETER Access + Specifies Access mode for the virtual machine network adapter. This parameter must be specified in conjunction with parameter VlanId . + .PARAMETER VlanId + Specifies the virtual LAN identifier of a virtual machine network adapter. This parameter must be specified in conjunction with switch parameter Access . + .PARAMETER Trunk + Specifies Trunk mode for the virtual machine network adapter. This parameter must be used in conjunction with parameters AllowedVlanIdList and NativeVlanId . + .PARAMETER NativeVlanId + Specifies the native virtual LAN identifier for a virtual machine network adapter. This parameter must be specified in conjunction with the switch parameter Trunk . + .PARAMETER AllowedVlanIdList + Specifies a list of virtual LANs allowed on a virtual machine network adapter. This parameter must be specified in conjunction with the switch parameter Trunk . + .PARAMETER Isolated + Specifies Isolated mode for the virtual machine network adapter to be configured. This parameter must be specified in conjunction with parameters PrimaryVlanId and SecondaryVlanId . + .PARAMETER Community + Specifies Community mode for the virtual machine network adapter to be configured. This parameter must be specified in conjunction with parameters PrimaryVlanId and SecondaryVlanId . + .PARAMETER Promiscuous + Specifies Promiscuous mode for the virtual machine network adapter. + + This parameter must be specified in conjunction with parameters PrimaryVlanId and SecondaryVlanIdList . + .PARAMETER PrimaryVlanId + Specifies the primary virtual LAN identifier for a virtual network adapter in Community , Isolated , or Promiscuous mode. + + This parameter must be specified in conjunction with parameter SecondaryVlanId if the virtual machine network adapter is in Community or Isolated mode. It must be used in conjunction with parameter SecondaryVlanIdList if the virtual machine network adapter is in Promiscuous mode. + .PARAMETER SecondaryVlanId + Specifies the secondary virtual LAN identifier for a virtual network adapter in Community or Isolated mode. + + This parameter must be specified in conjunction with parameter PrimaryVlanId , along with switch parameter Community or Isolated . + .PARAMETER SecondaryVlanIdList + Specifies a list of private virtual LAN secondary virtual LANs on a virtual machine network adapter.This parameter must be specified in conjunction with parameter PrimaryVlanId and switch parameter Promiscuous . + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.VMNetworkAdapterVlanSetting object is to be passed through to the pipeline representing the virtual machine network adapter virtual LAN settings to be configured. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterVlanSetting])] + param ( + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='ManagementOS', Mandatory=$true)] + [switch] + ${ManagementOS}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [string] + ${VMNetworkAdapterName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ManagementOS')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Alias('u')] + [switch] + ${Untagged}, + + [Alias('a')] + [switch] + ${Access}, + + [Alias('AccessVlanId')] + [ValidateNotNull()] + [System.Nullable[int]] + ${VlanId}, + + [Alias('t')] + [switch] + ${Trunk}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${NativeVlanId}, + + [string] + ${AllowedVlanIdList}, + + [Alias('i')] + [switch] + ${Isolated}, + + [Alias('c')] + [switch] + ${Community}, + + [Alias('p')] + [switch] + ${Promiscuous}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${PrimaryVlanId}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${SecondaryVlanId}, + + [string] + ${SecondaryVlanIdList}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMPartitionableGpu { + <# + .SYNOPSIS + Set-VMPartitionableGpu [[-ComputerName] ] [[-Credential] ] [-Passthru] [-PartitionCount ] [] + +Set-VMPartitionableGpu [-CimSession] [-Passthru] [-PartitionCount ] [] + +Set-VMPartitionableGpu [-PartitionableGpu] [-Passthru] [-PartitionCount ] [] + +Set-VMPartitionableGpu [-Passthru] [-Name ] [-PartitionCount ] [] + #> + + [CmdletBinding(DefaultParameterSetName='ComputerName')] + [OutputType([Microsoft.HyperV.PowerShell.VMPartitionableGpu])] + param ( + [Parameter(ParameterSetName='CimSession', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='ComputerName', Position=0)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='ComputerName', Position=1)] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Object', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMPartitionableGpu[]] + ${PartitionableGpu}, + + [switch] + ${Passthru}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [ValidateNotNullOrEmpty()] + [System.Nullable[uint16]] + ${PartitionCount} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMProcessor { + <# + .SYNOPSIS + Configures one or more processors of a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which processors are to be configured. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine on which the processor is to be configured. + .PARAMETER VM + Specifies the virtual machine on which the processor is to be configured. + .PARAMETER VMProcessor + Specifies the virtual machine processor to be configured. + .PARAMETER Count + Specifies the number of processors for the virtual machine. + .PARAMETER CompatibilityForMigrationEnabled + Specifies whether the virtual processor's 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 Maximum + Specifies the maximum percentage of resources available to the virtual machine processor to be configured. Allowed values range from 0 to 100. + .PARAMETER Reserve + Specifies the percentage of processor resources to be reserved for this virtual machine. Allowed values range from 0 to 100. + .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 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 ResourcePoolName + Specifies the name of the processor resource pool to be used. + .PARAMETER EnableHostResourceProtection + Specifies whether to enable host resource protection. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.Processor is to be passed through to the pipeline representing the processor to be configured. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMProcessor])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMProcessor', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMProcessor[]] + ${VMProcessor}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${Count}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${CompatibilityForMigrationEnabled}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${CompatibilityForOlderOperatingSystemsEnabled}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${HwThreadCountPerCore}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${Maximum}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${Reserve}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${RelativeWeight}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${MaximumCountPerNumaNode}, + + [ValidateNotNull()] + [System.Nullable[int]] + ${MaximumCountPerNumaSocket}, + + [ValidateNotNull()] + [string] + ${ResourcePoolName}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${EnableHostResourceProtection}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${ExposeVirtualizationExtensions}, + + [string[]] + ${Perfmon}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${EnableLegacyApicMode}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${AllowACountMCount}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMRemoteFx3dVideoAdapter { + <# + .SYNOPSIS + Configures the RemoteFX 3D video adapter of a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the RemoteFX 3D video adapter is to be configured. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine on which the adapter is to be configured. + .PARAMETER VM + Specifies the virtual machine on which the adapter is to be configured. + .PARAMETER VMRemoteFx3dVideoAdapter + Specifies the adapter to be configured. + .PARAMETER MonitorCount + Specifies the maximum number of monitors supported by this adapter. + .PARAMETER MaximumResolution + Specifies the maximum resolution supported by this adapter. + .PARAMETER VRAMSizeBytes + Specifies the size, in bytes, of VRAM supported that this adapter supports. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.RemoteFxVideoAdapter object is to be passed through to the pipeline representing the adapter to be configured. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMRemoteFx3DVideoAdapter])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='Object', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMRemoteFx3DVideoAdapter[]] + ${VMRemoteFx3dVideoAdapter}, + + [Parameter(Position=1)] + [ValidateNotNull()] + [System.Nullable[byte]] + ${MonitorCount}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${MaximumResolution}, + + [Parameter(Position=3)] + [ValidateNotNull()] + [System.Nullable[uint64]] + ${VRAMSizeBytes}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMReplication { + <# + .SYNOPSIS + Modifies the replication settings of a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which replication is to be enabled. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine for which the replication configuration is to be set. + .PARAMETER VM + Specifies the virtual machine for which the replication configuration is to be set. + .PARAMETER VMReplication + Specifies a virtual machine replication object for which the configuration is to be set. + .PARAMETER ReplicaServerName + Specifies the name of the Replica server to which this virtual machine will be replicated. + .PARAMETER ReplicaServerPort + Specifies the port on the Replica server to use for replication traffic. Make sure you specify a port that is configured on the Replica server to support the same authentication type you specify using the AuthenticationType parameter in this cmdlet. Run the Get-VMReplicationServer cmdlet on the Replica server to check the configuration of the port, or contact the administrator of the specified Replica server. + .PARAMETER AuthenticationType + Specifies the authentication type to use for virtual machine replication, either Kerberos or Certificate. The specified Replica server must support the chosen authentication type. Run the Get-VMReplicationServer cmdlet to verify the authentication configured for the specified Replica server, or contact the administrator of the specified Replica server. + .PARAMETER CertificateThumbprint + Specifies the certificate to use for mutual authentication of the replication data. This parameter is required only when "Certificate" is specified as the type of authentication. Specify the thumbprint of a valid computer certificate from the Personal store. + + The certificate must have all of the following properties to be valid: + + - It must not be expired. + + - It must include both client and server authentication extensions for extended key usage (EKU), and an associated private key. + + - It must terminate at a valid root certificate. + + - The requirement for the subject common name (CN) differs depending on whether the virtual machine belongs to a cluster. For virtual machines that do not belong to a cluster, the subject common name (CN) must be equal to, or subject alternative name (DNS Name) should contain, the FQDN of the host. For virtual machines that belong to a cluster, the subject common name (CN) must be equal to, or subject alternative name (DNS Name) must contain, the and fully-qualified domain name (FQDN) of the Hyper-V Replica Broker. + + To display a list of certificates in the computer's My store and the thumbprint of each certificate, type the following: + + `PS C:\> cd cert:\LocalMachine\My` + + `PS C:\> dir | format-list` + For more information about certificate stores, see http://technet.microsoft.com//library/cc757138.aspx (http://technet.microsoft.com//library/cc757138.aspx). + + .PARAMETER CompressionEnabled + Specifies whether replication data sent over the network is to be compressed. + .PARAMETER ReplicateHostKvpItems + Specifies whether to replicate host-only key value pairs (KVP) for this virtual machine. + .PARAMETER BypassProxyServer + Specifies whether to bypass a proxy server while replicating data to the Replica server. + .PARAMETER EnableWriteOrderPreservationAcrossDisks + Determines whether all virtual hard disks selected for replication are replicated to the same point in time. This is useful if the virtual machine runs an application that saves data across virtual hard disks (for example, one virtual hard disk dedicated for application data, and another virtual hard disk dedicated for application log files). + .PARAMETER InitialReplicationStartTime + Specifies the time to start the initial replication, when scheduling initial replication to occur later. You can specify a time up to 7 days later. When this parameter is not specified, initial replication occurs immediately. + .PARAMETER DisableVSSSnapshotReplication + Specifies whether to replicate volume shadow copy service (VSS) snapshots. + .PARAMETER VSSSnapshotFrequencyHour + Specifies the frequency, in hours, at which Volume Shadow Copy Service (VSS) performs a snapshot backup of the virtual machines. Specify this parameter only if application-consistent replication is enabled for the virtual is and the value you set for the RecoveryHistory parameter is not zero. The cmdlet sets a value of zero for this parameter if application-consistent replication is disabled. Do not specify this parameter if you are extending replication from the Replica virtual machine. + .PARAMETER RecoveryHistory + Specifies whether to store additional recovery points on the Replica virtual machine. Storing more than the most recent recovery point of the primary virtual machine allows you to recover to an earlier point in time. However, storing additional recovery points requires more storage and processing resources. You can configure as many as 24 recovery points to be stored. + .PARAMETER ReplicationFrequencySec + Specifies the frequency, in seconds, at which Hyper-V replicates changes to the Replica server. + .PARAMETER ReplicatedDisks + Specifies all virtual hard disks to include for replication. This parameter can include all the VHDs attached to the virtual mahine or a subset. Be sure to include virtual hard disks that are critical to the ability of the virtual machine to start, such as the guest operating system disk. Excluding a critical disk from this list could prevent the replica virtual machine from starting properly. + .PARAMETER ReplicatedDiskPaths + Specifies the fully qualified path names of all the virtual hard disks to include for replication. Be sure to include virtual hard disks that are critical to the ability of the virtual machine to start, such as the guest operating system disk. Excluding a critical disk from this list could prevent the replica virtual machine from starting properly. + .PARAMETER Reverse + Reverses the replication of the virtual machine, switching it from a primary virtual machine to a Replica virtual machine, or from a Replica virtual machine to a primary virtual machine. + .PARAMETER AutoResynchronizeEnabled + Enables replicating virtual machines that require resynchronization to be resynchronized automatically. (For example, a virtual machine requires resynchronization if the primary server shuts down abruptly). Resynchronization requires significant storage and processing resources. We recommended scheduling resynchronization during off-peak hours to reduce the impact to the host and other virtual machines running on the host. Use the AutoResynchronizeIntervalStart and AutoResynchronizeIntervalEnd parameters to specify an off-peak time to start the automatic resynchronization. + .PARAMETER AutoResynchronizeIntervalStart + Specifies the start of the time period in which you want resynchronization to start automatically. + .PARAMETER AutoResynchronizeIntervalEnd + Specifies the end of the time period in which you want resynchronization to start automatically. + .PARAMETER AsReplica + Specifies that the virtual machine is a replica virtual machine, enabling it to be used as the source for the initial replication of the primary virtual machine. + .PARAMETER UseBackup + Specifies that a restored copy of the virtual machine on the Replica server is to be used as the source of the initial replication. + .PARAMETER AllowedPrimaryServer + When you use the AsReplica parameter to specify a virtual machine as a Replica virtual machine, this parameter determines which primary servers can send replication to the Replica virtual machine. Replication is accepted only from the server specified in the chosen authentication entry, or any other authentication entry that has the same trust group. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that a VMReplication object is to be passed through to the pipeline representing the replication configuration to be set. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplication])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMReplication', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMReplication[]] + ${VMReplication}, + + [Parameter(Position=1)] + [Alias('ReplicaServer')] + [ValidateNotNullOrEmpty()] + [string] + ${ReplicaServerName}, + + [Parameter(Position=2)] + [Alias('ReplicaPort')] + [ValidateNotNull()] + [ValidateRange(1, 65535)] + [System.Nullable[int]] + ${ReplicaServerPort}, + + [Parameter(Position=3)] + [Alias('AuthType')] + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.ReplicationAuthenticationType]] + ${AuthenticationType}, + + [Parameter(ValueFromPipelineByPropertyName=$true)] + [Alias('Thumbprint','Cert')] + [string] + ${CertificateThumbprint}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${CompressionEnabled}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${ReplicateHostKvpItems}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${BypassProxyServer}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${EnableWriteOrderPreservationAcrossDisks}, + + [Alias('IRTime')] + [ValidateNotNull()] + [System.Nullable[datetime]] + ${InitialReplicationStartTime}, + + [Alias('DisableVSS')] + [switch] + ${DisableVSSSnapshotReplication}, + + [Alias('VSSFreq')] + [ValidateRange(1, 12)] + [ValidateNotNull()] + [System.Nullable[int]] + ${VSSSnapshotFrequencyHour}, + + [Alias('RecHist')] + [ValidateRange(0, 24)] + [ValidateNotNull()] + [System.Nullable[int]] + ${RecoveryHistory}, + + [Alias('RepFreq')] + [ValidateRange(30, 900)] + [System.Nullable[int]] + ${ReplicationFrequencySec}, + + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.HardDiskDrive[]] + ${ReplicatedDisks}, + + [ValidateNotNull()] + [string[]] + ${ReplicatedDiskPaths}, + + [switch] + ${Reverse}, + + [Alias('AutoResync')] + [ValidateNotNull()] + [System.Nullable[bool]] + ${AutoResynchronizeEnabled}, + + [Alias('AutoResyncStart')] + [ValidateNotNull()] + [System.Nullable[timespan]] + ${AutoResynchronizeIntervalStart}, + + [Alias('AutoResyncEnd')] + [ValidateNotNull()] + [System.Nullable[timespan]] + ${AutoResynchronizeIntervalEnd}, + + [switch] + ${AsReplica}, + + [switch] + ${UseBackup}, + + [Parameter(ValueFromPipelineByPropertyName=$true)] + [Alias('AllowedPS')] + [string] + ${AllowedPrimaryServer}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMReplicationAuthorizationEntry { + <# + .SYNOPSIS + Modifies an authorization entry on a Replica server. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the authorization entry is to be set. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMReplicationAuthorizationEntry + Specifies the authorization entry to be set. + .PARAMETER AllowedPrimaryServer + Specifies the allowed primary server of the authorization entry to be modified. + .PARAMETER ReplicaStorageLocation + Specifies the location to store the Replica virtual hard disk files from the allowed server when a new Replica virtual machine is created. Modifying this location does not affect any existing virtual hard disk files on the Replica server. + .PARAMETER TrustGroup + Identifies a group of primary servers within which a given primary virtual machine can move so replications of the primary virtual machine are accepted by the Replica server only from primary servers that belong to the trust group. You can use any string to create a new trust group. Ensure all primary servers within a specific trust group use the same string as the value you specify for this parameter. + + Use of a trust group can help you keep virtual machines isolated by maintaining control over which primary servers are trusted to provide replication, while also allowing the virtual machines to move from one primary server to another (such as through live migration or failover from a cluster node). + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the replication authorization entry to be set. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplicationAuthorizationEntry])] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Object', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMRepAuthEntry')] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMReplicationAuthorizationEntry[]] + ${VMReplicationAuthorizationEntry}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('AllowedPS')] + [ValidateNotNullOrEmpty()] + [string] + ${AllowedPrimaryServer}, + + [Parameter(Position=1)] + [Alias('StorageLoc')] + [ValidateNotNullOrEmpty()] + [string] + ${ReplicaStorageLocation}, + + [Parameter(Position=2)] + [ValidateNotNullOrEmpty()] + [string] + ${TrustGroup}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMReplicationServer { + <# + .SYNOPSIS + Configures a host as a Replica server. + .PARAMETER ReplicationEnabled + Specifies whether the host is enabled as a Replica server. + .PARAMETER AllowedAuthenticationType + Specifies which authentication types the Replica server will use. Allowed values are Kerberos, Certificate, or CertificateAndKerberos. + .PARAMETER ReplicationAllowedFromAnyServer + Specifies whether to accept replication requests from any server. When specified as true , DefaultStorageLocation must also be specified. The default storage location and DEFAULT trust group tag are used for virtual machine replicas. + .PARAMETER CertificateThumbprint + Specifies the certificate to use for mutual authentication of the replication data. This parameter is required only when Certificate is specified as the type of authentication. Specify the thumbprint of a valid computer certificate from the Personal store. + + The certificate must have all of the following properties to be valid: + + - It must not be expired. + + - It must include both client and server authentication extensions for extended key usage (EKU), and an associated private key. + + - It must terminate at a valid root certificate. + + - It must meet the requirements for the subject common name (CN): + + - For servers that are not clustered, the subject common name (CN) must be equal to, or subject alternative name (DNS Name) should contain, the FQDN of the host. - For servers that are clustered, each node must have two certificates - one in which the subject common name (CN) or subject alternative name (DNS Name) is the name of the node, and the other in which subject common name (CN) or subject alternative name (DNS Name) is FQDN of the Hyper-V Replica Broker. + + To display a list of certificates in the computer's My store and the thumbprint of each certificate, run the following commands: + + `PS C:\> cd cert:\LocalMachine\My` + + `PS C:\> dir | format-list` + + For more information about certificate stores, see http://technet.microsoft.com//library/cc757138.aspx (http://technet.microsoft.com//library/cc757138.aspx). + .PARAMETER DefaultStorageLocation + Specifies the default location to store the virtual hard disk files when a Replica virtual machine is created. You must specify this parameter when ReplicationAllowedFromAnyServer is True. + .PARAMETER KerberosAuthenticationPort + Specifies the port that the HTTP listener uses on the Replica server host. + .PARAMETER CertificateAuthenticationPort + Specifies the port on which the Replica server will receive replication data using certificate-based authentication. This parameter can be set only when the value of the AllowedAuthType parameter is Certificate or CertificateAndKerberos. + .PARAMETER KerberosAuthenticationPortMapping + When using Hyper-V Replica with failover clustering and Kerberos authorization, you can use this parameter to specify a different port for each node of the cluster to receive replication. We recommend that you specify a unique port for each node of the cluster, and one unique port for the Hyper-V Replica Broker. This parameter can be set only when the Replica server is configured with an authentication type of either Kerberos or CertificateAndKerberos. + .PARAMETER CertificateAuthenticationPortMapping + When using Hyper-V Replica with failover clustering and certificate-based authorization, you can use this parameter to specify a different port for each node of the cluster to receive replication. We recommend that you specify a unique port for each node of the cluster, and one unique port for the Hyper-V Replica Broker. This parameter can be set only when the Replica server is configured with an authentication type of Certificate or CertificateAndKerberos. + .PARAMETER MonitoringInterval + Specifies how often (the monitoring interval) replication statistics are computed. Valid values are: 1 hour, 2 hours, 3 hours, 4 hours, 6 hours, 8 hours, 12 hours, 24 hours, 2 days, 3 days, 4 days, 5 days, 6 days, 7 days. Specify in the format days:hours:minutes:seconds, such as 01:00:00 for 1 hour, or 1.00:00:00 for 1 day. + .PARAMETER MonitoringStartTime + Specifies when the monitoring interval starts. + .PARAMETER Force + Specifies whether the command runs without requiring confirmation. + .PARAMETER Passthru + Specifies that a VMReplicationServer object is to be passed through to the pipeline representing the replication settings of the Replica server. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Configures Replica server settings for one or more Hyper-V hosts. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='AuthenticationPort', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplicationServer])] + param ( + [Parameter(Position=0)] + [Alias('RepEnabled')] + [ValidateNotNull()] + [System.Nullable[bool]] + ${ReplicationEnabled}, + + [Parameter(Position=1)] + [Alias('AuthType')] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.RecoveryAuthenticationType] + ${AllowedAuthenticationType}, + + [Parameter(Position=2)] + [Alias('AllowAnyServer')] + [ValidateNotNull()] + [System.Nullable[bool]] + ${ReplicationAllowedFromAnyServer}, + + [Parameter(ValueFromPipelineByPropertyName=$true)] + [Alias('Thumbprint')] + [ValidateNotNullOrEmpty()] + [string] + ${CertificateThumbprint}, + + [Alias('StorageLoc')] + [ValidateNotNullOrEmpty()] + [string] + ${DefaultStorageLocation}, + + [Parameter(ParameterSetName='AuthenticationPort')] + [Alias('KerbAuthPort')] + [ValidateRange(1, 65535)] + [ValidateNotNull()] + [System.Nullable[int]] + ${KerberosAuthenticationPort}, + + [Parameter(ParameterSetName='AuthenticationPort')] + [Alias('CertAuthPort')] + [ValidateRange(1, 65535)] + [ValidateNotNull()] + [System.Nullable[int]] + ${CertificateAuthenticationPort}, + + [Parameter(ParameterSetName='AuthenticationPortMapping')] + [ValidateNotNull()] + [hashtable] + ${KerberosAuthenticationPortMapping}, + + [Parameter(ParameterSetName='AuthenticationPortMapping')] + [ValidateNotNull()] + [hashtable] + ${CertificateAuthenticationPortMapping}, + + [ValidateNotNull()] + [System.Nullable[timespan]] + ${MonitoringInterval}, + + [ValidateNotNull()] + [System.Nullable[timespan]] + ${MonitoringStartTime}, + + [switch] + ${Force}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMResourcePool { + <# + .SYNOPSIS + Sets the parent resource pool for a selected resource pool. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Name + Specifies the resource pool whose parent resource pool is to be set. + .PARAMETER ResourcePoolType + Specifies the type of the resource pool whose parent is to be set. + .PARAMETER ParentName + Specifies the name of the resource pool to be set as a parent. + .PARAMETER Passthru + Specifies that a VMResourcePool object is to be passed through to the pipeline representing the resource pool whose parent is to be set. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a resource pool's parent is to be set. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMResourcePool])] + param ( + [Parameter(ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(Mandatory=$true, Position=1, ValueFromPipelineByPropertyName=$true)] + [Microsoft.HyperV.PowerShell.VMResourcePoolType] + ${ResourcePoolType}, + + [Parameter(Mandatory=$true, Position=2)] + [ValidateNotNullOrEmpty()] + [string[]] + ${ParentName}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMSan { + <# + .SYNOPSIS + Configures a virtual storage area network (SAN) on one or more Hyper-V hosts. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual storage area network (SAN) is to be configured. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies the name of the virtual storage area network (SAN) to be configured. + .PARAMETER HostBusAdapter + Specifies the host bus adapter (HBA) to associate with the virtual storage area network (SAN). You can use the Get-InitiatorPort cmdlet to get this object. + .PARAMETER WorldWideNodeName + The World Wide Node name of the Fibre Channel host bus adapter to be associated with this virtual storage area network (SAN). + .PARAMETER WorldWidePortName + The World Wide Port name of the Fibre Channel host bus adapter to be associated with this virtual storage area network (SAN). + .PARAMETER Note + Specifies the note to be associated with the virtual storage area network (SAN). + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the configured virtual storage area network (SAN). + #> + + [CmdletBinding(DefaultParameterSetName='HbaObject', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSan])] + param ( + [Parameter(ParameterSetName='StringWwn', ValueFromPipelineByPropertyName=$true)] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='StringWwn')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='StringWwn')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)] + [Alias('SanName')] + [ValidateNotNullOrEmpty()] + [string] + ${Name}, + + [Parameter(ParameterSetName='HbaObject')] + [ValidateNotNullOrEmpty()] + [ciminstance[]] + ${HostBusAdapter}, + + [Parameter(ParameterSetName='StringWwn', Mandatory=$true)] + [Alias('Wwnn','NodeName','Wwnns','NodeNames','WorldWideNodeNames','NodeAddress')] + [ValidateNotNullOrEmpty()] + [string[]] + ${WorldWideNodeName}, + + [Parameter(ParameterSetName='StringWwn', Mandatory=$true)] + [Alias('Wwpn','PortName','Wwpns','PortNames','WorldWidePortNames','PortAddress')] + [ValidateNotNullOrEmpty()] + [string[]] + ${WorldWidePortName}, + + [ValidateNotNull()] + [string] + ${Note}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMSecurity { + <# + .SYNOPSIS + Configures security settings for a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts to run the cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies a user account that has permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies an array of virtual machines. + .PARAMETER VMName + Specifies an array of virtual machine names. + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + .PARAMETER EncryptStateAndVmMigrationTraffic + Indicates that this cmdlet enables encryption of virtual machine state and migration traffic. + .PARAMETER VirtualizationBasedSecurityOptOut + Specifies whether to opt the virtual machine out of virtualization-based security. Specify a value of $True to opt out of virtualization-based security. If the guest operating system supports virtualization-based security, a value of $False allows it. The default value is $False. + + To change this setting, the virtual machine must be off. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='VMName')] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${Passthru}, + + [bool] + ${EncryptStateAndVmMigrationTraffic}, + + [bool] + ${VirtualizationBasedSecurityOptOut} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMSecurityPolicy { + <# + .SYNOPSIS + Configures the security policy for a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts to on which to configure security policy. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that has permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies an array of virtual machine objects. This cmdlet configures the security policy for these objects. To obtain a virtual machine object, use the Get-VM cmdlet. + .PARAMETER VMName + Specifies an array of virtual machine names. This cmdlet configures the security policy for these virtual machines. + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + .PARAMETER Shielded + Configures the virtual machine as shielded. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='VMName')] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${Passthru}, + + [bool] + ${Shielded}, + + [bool] + ${BindToHostTpm} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMStorageSettings { + <# + .SYNOPSIS + Set-VMStorageSettings [-VMName] [-CimSession ] [-ComputerName ] [-Credential ] [-Passthru] [-DisableInterruptBatching ] [-ThreadCountPerChannel ] [-VirtualProcessorsPerChannel ] [-WhatIf] [-Confirm] [] + +Set-VMStorageSettings [-VM] [-Passthru] [-DisableInterruptBatching ] [-ThreadCountPerChannel ] [-VirtualProcessorsPerChannel ] [-WhatIf] [-Confirm] [] + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='VMName')] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [switch] + ${Passthru}, + + [bool] + ${DisableInterruptBatching}, + + [Microsoft.HyperV.PowerShell.ThreadCount] + ${ThreadCountPerChannel}, + + [uint16] + ${VirtualProcessorsPerChannel} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMSwitch { + <# + .SYNOPSIS + Configures a virtual switch. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual switch is to be configured. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMSwitch + Specifies the virtual switch to be configured. + .PARAMETER Name + Specifies the name of the virtual switch to be configured. + .PARAMETER NetAdapterName + Specifies the name of the physical network adapter to which an external virtual switch should be bound. If you specify this parameter to convert a virtual switch, the external virtual switch is configured to allow the management operating system to share access to the physical network adapter. To override this behavior, include AllowManagementOs $false in the command + .PARAMETER NetAdapterInterfaceDescription + Specifies the interface description of the physical network adapter to which an external virtual switch should be bound. If you specify this parameter to convert a virtual switch, the external virtual switch is configured to allow the management operating system to share access to the physical network adapter. To override this behavior, include AllowManagementOs $false in the command + .PARAMETER SwitchType + Converts a virtual switch from one type to another. Allowed values are Internal or Private . You can convert an internal or private virtual switch to an external virtual switch, by including either the NetAdapterInterfaceDescription or NetAdapterName parameter in the command. If you do this, the external virtual switch is configured to allow the management operating system to share access to the physical network adapter. To override this behavior, include AllowManagementOs $false in the command. + .PARAMETER AllowManagementOS + Specifies whether the management operating system can use the physical network adapter that is bound to the external virtual switch. + .PARAMETER DefaultFlowMinimumBandwidthAbsolute + Specifies the minimum bandwidth, in bits per second, that is allocated to a special category called "default flow." Any traffic sent by a virtual network adapter that is connected to this virtual switch and does not have minimum bandwidth allocated is filtered into this category. Specify a value for this parameter only if the minimum bandwidth mode on this virtual switch is absolute (See the New-VMSwitch cmdlet). By default, the virtual switch allocates 10% of the total bandwidth, which depends on the physical network adapter it binds to, to this category. For example, if a virtual switch binds to a 1 GbE network adapter, this special category can use at least 100 Mbps. If the value is not a multiple of 8, the value is rounded down to the nearest number that is a multiple of 8. For example, a value input as 1234567 is converted to 1234560. + .PARAMETER DefaultFlowMinimumBandwidthWeight + Specifies the minimum bandwidth, in relative weight, that is allocated to a special category called "default flow". Any traffic sent by a virtual network adapter that is connected to this virtual switch and doesn't have minimum bandwidth allocated is filtered into this category. Specify a value for this parameter only if the minimum bandwidth mode on this virtual switch is weight (See the New-VMSwitch cmdlet). By default, this special category has a weight of 1. + .PARAMETER Extensions + Specifies an ordered list of network extensions used to reorder the bindings on the virtual switch. + .PARAMETER Notes + Specifies notes to be associated with the virtual switch. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.EthernetSwitch object is to be passed through to the pipeline representing the virtual switch to be configured. + #> + + [CmdletBinding(DefaultParameterSetName='SwitchName_SwitchType', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitch])] + param ( + [Parameter(ParameterSetName='SwitchName_SwitchType', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='SwitchName_NetAdapterInterfaceDescription', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='SwitchName_NetAdapterName', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='SwitchObject_NetAdapterInterfaceDescription')] + [Parameter(ParameterSetName='SwitchObject_NetAdapterName')] + [Parameter(ParameterSetName='SwitchObject_SwitchType')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='SwitchName_SwitchType')] + [Parameter(ParameterSetName='SwitchName_NetAdapterInterfaceDescription')] + [Parameter(ParameterSetName='SwitchName_NetAdapterName')] + [Parameter(ParameterSetName='SwitchObject_NetAdapterInterfaceDescription')] + [Parameter(ParameterSetName='SwitchObject_NetAdapterName')] + [Parameter(ParameterSetName='SwitchObject_SwitchType')] + [Alias('PSComputerName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='SwitchObject_NetAdapterInterfaceDescription')] + [Parameter(ParameterSetName='SwitchName_SwitchType')] + [Parameter(ParameterSetName='SwitchName_NetAdapterInterfaceDescription')] + [Parameter(ParameterSetName='SwitchName_NetAdapterName')] + [Parameter(ParameterSetName='SwitchObject_NetAdapterName')] + [Parameter(ParameterSetName='SwitchObject_SwitchType')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='SwitchObject_SwitchType', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='SwitchObject_NetAdapterName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='SwitchObject_NetAdapterInterfaceDescription', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMSwitch[]] + ${VMSwitch}, + + [Parameter(ParameterSetName='SwitchName_SwitchType', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='SwitchName_NetAdapterInterfaceDescription', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='SwitchName_NetAdapterName', Mandatory=$true, Position=0)] + [Alias('SwitchName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='SwitchName_NetAdapterName', Mandatory=$true, Position=1, ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='SwitchObject_NetAdapterName', Mandatory=$true, Position=1, ValueFromPipelineByPropertyName=$true)] + [Alias('InterfaceAlias')] + [ValidateNotNullOrEmpty()] + [string] + ${NetAdapterName}, + + [Parameter(ParameterSetName='SwitchName_NetAdapterInterfaceDescription', Mandatory=$true, Position=1)] + [Parameter(ParameterSetName='SwitchObject_NetAdapterInterfaceDescription', Mandatory=$true, Position=1)] + [ValidateNotNullOrEmpty()] + [string] + ${NetAdapterInterfaceDescription}, + + [Parameter(ParameterSetName='SwitchName_SwitchType')] + [Parameter(ParameterSetName='SwitchObject_SwitchType')] + [System.Nullable[Microsoft.HyperV.PowerShell.VMSwitchType]] + ${SwitchType}, + + [System.Nullable[bool]] + ${AllowManagementOS}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${DefaultFlowMinimumBandwidthAbsolute}, + + [ValidateNotNull()] + [System.Nullable[long]] + ${DefaultFlowMinimumBandwidthWeight}, + + [System.Nullable[bool]] + ${DefaultQueueVrssEnabled}, + + [System.Nullable[bool]] + ${DefaultQueueVmmqEnabled}, + + [Alias('DefaultQueueVmmqQueuePairs')] + [ValidateNotNull()] + [System.Nullable[uint32]] + ${DefaultQueueVrssMaxQueuePairs}, + + [ValidateNotNull()] + [System.Nullable[uint32]] + ${DefaultQueueVrssMinQueuePairs}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.VrssQueueSchedulingModeType]] + ${DefaultQueueVrssQueueSchedulingMode}, + + [System.Nullable[bool]] + ${DefaultQueueVrssExcludePrimaryProcessor}, + + [System.Nullable[bool]] + ${EnableSoftwareRsc}, + + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitchExtension[]] + ${Extensions}, + + [ValidateNotNull()] + [string] + ${Notes}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMSwitchExtensionPortFeature { + <# + .SYNOPSIS + Configures a feature on a virtual network adapter. + .PARAMETER VMSwitchExtensionFeature + Specifies the feature to be configured. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.VMSwitchExtensionPortFeature object is to be passed through to the pipeline representing the feature to be configured. + .PARAMETER VMName + Specifies the name of the virtual machine on which the feature is to be configured. + .PARAMETER VMNetworkAdapter + Specifies the virtual network adapter. + .PARAMETER ManagementOS + Specifies the management (e.g. parent, or host) operating system. + .PARAMETER ExternalPort + Specifies the virtual switch port connected to the external network adapter. + .PARAMETER SwitchName + Specifies the name of the virtual switch. + .PARAMETER VMNetworkAdapterName + Specifies the name of the virtual network adapter. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which this cmdlet operates. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER VM + Specifies the virtual machine on which the feature is to be configured. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchExtensionPortFeature])] + param ( + [Parameter(Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitchExtensionPortFeature[]] + ${VMSwitchExtensionFeature}, + + [switch] + ${Passthru}, + + [string[]] + ${VMName}, + + [Microsoft.HyperV.PowerShell.VMNetworkAdapterBase[]] + ${VMNetworkAdapter}, + + [switch] + ${ManagementOS}, + + [switch] + ${ExternalPort}, + + [string] + ${SwitchName}, + + [string] + ${VMNetworkAdapterName}, + + [string[]] + ${ComputerName}, + + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMSwitchExtensionSwitchFeature { + <# + .SYNOPSIS + Configures a feature on a virtual switch. + .PARAMETER VMSwitchExtensionFeature + Specifies the feature to be configured. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.VMSwitchExtensionSwitchFeature is to be passed through to the pipeline representing the feature to be configured. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which this cmdlet operates. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER SwitchName + Specifies the name of the virtual switch. + .PARAMETER VMSwitch + Specifies the virtual switch. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitchExtensionSwitchFeature])] + param ( + [Parameter(Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitchExtensionSwitchFeature[]] + ${VMSwitchExtensionFeature}, + + [switch] + ${Passthru}, + + [string[]] + ${ComputerName}, + + [string[]] + ${SwitchName}, + + [Microsoft.HyperV.PowerShell.VMSwitch[]] + ${VMSwitch}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMSwitchTeam { + <# + .SYNOPSIS + Configures a virtual switch team. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER VMSwitch + Specifies an array of virtual switches that this cmdlet configures for teaming. To obtain a VMSwitch object, use the Get-VMSwitch cmdlet. + .PARAMETER Name + Specifies an array of names of virtual switches that this cmdlet configures for teaming. + .PARAMETER NetAdapterName + Specifies an array of names of the virtual network adapters that this cmdlet includes in the switch team. This value replaces the existing members. + .PARAMETER NetAdapterInterfaceDescription + Specifies an array of interface descriptions of the virtual network adapters that this cmdlet includes in the switch team. This value replaces the existing members. + .PARAMETER TeamingMode + Specifies the teaming mode. Currently, the only option is SwitchIndependent. + .PARAMETER LoadBalancingAlgorithm + Specifies the load balancing algorithm that this switch team uses. The acceptable values for this parameter are: Dynamic and HyperVPort. The default value is Dynamic. + .PARAMETER Passthru + Indicates that this cmdlet returns the Microsoft.HyperV.PowerShell.VMSwitch object that it configures. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='SwitchName_NetAdapterName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMSwitch])] + param ( + [Parameter(ParameterSetName='SwitchName_NetAdapterInterfaceDescription', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='SwitchName_NetAdapterName', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='SwitchObject_NetAdapterInterfaceDescription', ValueFromPipelineByPropertyName=$true)] + [Parameter(ParameterSetName='SwitchObject_NetAdapterName', ValueFromPipelineByPropertyName=$true)] + [Alias('PSComputerName')] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='SwitchObject_NetAdapterName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='SwitchObject_NetAdapterInterfaceDescription', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMSwitch[]] + ${VMSwitch}, + + [Parameter(ParameterSetName='SwitchName_NetAdapterInterfaceDescription', Mandatory=$true, Position=0)] + [Parameter(ParameterSetName='SwitchName_NetAdapterName', Mandatory=$true, Position=0)] + [Alias('SwitchName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='SwitchObject_NetAdapterName')] + [Parameter(ParameterSetName='SwitchName_NetAdapterName')] + [Alias('InterfaceAlias')] + [string[]] + ${NetAdapterName}, + + [Parameter(ParameterSetName='SwitchName_NetAdapterInterfaceDescription')] + [Parameter(ParameterSetName='SwitchObject_NetAdapterInterfaceDescription')] + [string[]] + ${NetAdapterInterfaceDescription}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.VMSwitchTeamingMode]] + ${TeamingMode}, + + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.VMSwitchLoadBalancingAlgorithm]] + ${LoadBalancingAlgorithm}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Set-VMVideo { + <# + .SYNOPSIS + Configures video settings for virtual machines. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies an array of names of virtual machines for which this cmdlet configures video settings. + .PARAMETER VM + Specifies an array of virtual machines for which this cmdlet configures video settings. To obtain a VirtualMachine object, use the Get-VM cmdlet. + .PARAMETER VMVideo + Specifies an array of virtual machine video settings that this cmdlet configures. To obtain a VMVideo object, use the Get-VMVideo cmdlet. + .PARAMETER ResolutionType + Specifies the resolution type for the virtual machine display. The acceptable values for this parameter are: + + - Maximum. The input HorizontalResolution * VerticalResolution is the maximum supported resolution. All standard resolutions smaller than HorizontalResolution * VerticalResolution are also supported. - Single. The input HorizontalResolution * VerticalResolution is the only supported resolution. - Default. The supported resolutions are those in the list of standard resolutions. Input HorizontalResolution * VerticalResolution is ignored. + .PARAMETER HorizontalResolution + Specifies the horizontal resolution for the virtual machine display. + .PARAMETER VerticalResolution + Specifies the vertical resolution for the virtual machine display. + .PARAMETER Passthru + Indicates that this cmdlet returns the Microsoft.HyperV.PowerShell.VMVideo object that it modifies. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMVideo])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMVideo', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VMVideo[]] + ${VMVideo}, + + [Parameter(Position=1)] + [ValidateNotNull()] + [System.Nullable[Microsoft.HyperV.PowerShell.ResolutionType]] + ${ResolutionType}, + + [Parameter(Position=2)] + [ValidateNotNull()] + [System.Nullable[uint16]] + ${HorizontalResolution}, + + [Parameter(Position=3)] + [ValidateNotNull()] + [System.Nullable[uint16]] + ${VerticalResolution}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Start-VM { + <# + .SYNOPSIS + Starts a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a virtual machine is to be started. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine to be started. + .PARAMETER Name + Specifies the name of the virtual machine to be started. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.VirtualMachine object is to be passed through to the pipeline representing the virtual machine to be started. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Start-VMFailover { + <# + .SYNOPSIS + Starts failover on a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which failover is to be started. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine for which failover is to be started. + .PARAMETER VM + Specifies the virtual machine for which failover is to be started. + .PARAMETER VMRecoverySnapshot + Specifies the recovery snapshot to use during a failover. (This parameter is not required for a planned failover.) + .PARAMETER AsTest + Creates a test virtual machine using the chosen recovery point. You can use a test virtual machine to validate a Replica virtual machine. To stop a test failover, use the Stop-VMFailover cmdlet. + .PARAMETER Prepare + Starts the planned failover on the primary virtual machine and replicates any pending changes. To complete the planned failover, use the Set-VMReplication and Start-VM cmdlets as shown in Example 4. + + Note: The primary virtual machine must be shut down to prepare it for failover. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that a virtual machine object is to be passed through to the pipeline representing the virtual machine on which failover is to be started. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='High')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMName_Test')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMName_Test')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMName_Test')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMName_Test', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject_Test', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMSnapshot', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Parameter(ParameterSetName='VMSnapshot_Test', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMRecoveryCheckpoint')] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMSnapshot] + ${VMRecoverySnapshot}, + + [Parameter(ParameterSetName='VMName_Test', Mandatory=$true)] + [Parameter(ParameterSetName='VMObject_Test', Mandatory=$true)] + [Parameter(ParameterSetName='VMSnapshot_Test', Mandatory=$true)] + [switch] + ${AsTest}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [switch] + ${Prepare}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Start-VMInitialReplication { + <# + .SYNOPSIS + Starts replication of a virtual machine. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which replication of a virtual machine is to be started. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER VMName + Specifies the name of the virtual machine on which replication is to be started. + .PARAMETER VM + Specifies the virtual machine on which replication is to be started. + .PARAMETER VMReplication + Specifies an object that represents the replication to be started. You can get this object from the Get-VMReplication cmdlet. + .PARAMETER DestinationPath + Specifies the path to use when copying the files for initial replication; assumes use of external media as the method for initial replication. External media is typically a removable drive that is shipped to the location of the Replica server. When the external media arrives at the Replica site, use the Import-InitialVMReplication cmdlet on the Replica virtual machine to copy the files. + .PARAMETER InitialReplicationStartTime + Specifies the time to start the initial replication, when scheduling initial replication to occur later. You can specify a time up to 7 days later. When this parameter is not specified, initial replication occurs immediately. + .PARAMETER UseBackup + Indicates that you want to use a copy of this virtual machine on the Replica server as the basis for the initial replication. Specify this option only if it was specified when replication was enabled on the primary virtual machine. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that a virtual machine object is to be passed through to the pipeline representing the virtual machine on which replication is to be started. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplication])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMReplication', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMReplication[]] + ${VMReplication}, + + [Alias('IRLoc')] + [ValidateNotNullOrEmpty()] + [string] + ${DestinationPath}, + + [Alias('IRTime')] + [ValidateNotNullOrEmpty()] + [System.Nullable[datetime]] + ${InitialReplicationStartTime}, + + [switch] + ${UseBackup}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Start-VMTrace { + <# + .SYNOPSIS + Starts tracing to a file. + .PARAMETER Level + Specifies the level of tracing. The acceptable values for this parameter are: + + - Off + + - Error + + - Warning + + - Info + + - Verbose + .PARAMETER TraceVerboseObjects + Specifies that tracing uses verbose objects. + .PARAMETER Path + Specifies the path of the file where this cmdlet stores the trace information. + #> + + [CmdletBinding()] + param ( + [Parameter(Mandatory=$true, Position=0)] + [ValidateSet('Error','Warning','Info','Verbose')] + [System.Diagnostics.TraceLevel] + ${Level}, + + [switch] + ${TraceVerboseObjects}, + + [string] + ${Path} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Stop-VM { + <# + .SYNOPSIS + Shuts down, turns off, or saves a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a virtual machine is to be shut down. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine to be shut down. + .PARAMETER Name + Specifies the name of the virtual machine to be shut down. + .PARAMETER Save + Specifies that the virtual machine is to be saved. + .PARAMETER TurnOff + Specifies that the virtual machine is to be turned off. + .PARAMETER Force + Specifies that the shutdown of the virtual machine is to be forced. If the virtual machine has applications with unsaved data, the virtual machine has five minutes to save data and shut down. If the virtual machine is locked, it is shut down immediately. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.VirtualMachine object is to be passed through to the pipeline representing the virtual machine to be shut down. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [switch] + ${Save}, + + [switch] + ${TurnOff}, + + [switch] + ${Force}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Stop-VMFailover { + <# + .SYNOPSIS + Stops failover of a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more hosts on which to cancel the failover of a virtual machine. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine whose you want to cancel. + .PARAMETER VM + Specifies the virtual machine whose failover you want to cancel. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual machine whose initial replication is to be stopped. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Stop-VMInitialReplication { + <# + .SYNOPSIS + Stops an ongoing initial replication. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which an ongoing initial replication is to be stopped. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER VMName + Specifies the name of the virtual machine whose initial replication is to be stopped. + .PARAMETER VM + Specifies the virtual machine whose initial replication is to be stopped. + .PARAMETER VMReplication + Specifies the virtual machine replication to be stopped. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual machine whose initial replication is to be stopped. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplication])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMReplication', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMReplication[]] + ${VMReplication}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Stop-VMReplication { + <# + .SYNOPSIS + Cancels an ongoing virtual machine resynchronization. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the ongoing virtual machine resynchronization is to be stopped. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER VMName + Specifies the name of the virtual machine whose resynchronization is to be stopped. + .PARAMETER VM + Specifies the virtual machine whose resychronization is to be stopped. + .PARAMETER VMReplication + Specifies the resynchronization to be stopped. + .PARAMETER ReplicationRelationshipType + Specifies the replication relationship type of the virtual machine. Specify whether the replication relationship is a simple primary to replica or is an extended replication chain. The cmdlet cancels the ongoing resynchronization of the virtual machines that have the replication type that you specify. + .PARAMETER Passthru + Specifies that an object is to be passed through to the pipeline representing the virtual machine on which the ongoing virtual machine resynchronization is to be stopped. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplication])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMReplication', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMReplication[]] + ${VMReplication}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Alias('Relationship')] + [System.Nullable[Microsoft.HyperV.PowerShell.VMReplicationRelationshipType]] + ${ReplicationRelationshipType}, + + [switch] + ${Passthru}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Stop-VMTrace { + <# + .SYNOPSIS + Stops tracing to file. + #> + + [CmdletBinding()] + param ( ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Suspend-VM { + <# + .SYNOPSIS + Suspends, or pauses, a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which a virtual machine is to be suspended. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VM + Specifies the virtual machine to be suspended. + .PARAMETER Name + Specifies the name of the virtual machine to be suspended. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Specifies that a Microsoft.HyperV.PowerShell.VirtualMachine object is to be passed through to the pipeline representing the virtual machine to be suspended. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Suspend-VMReplication { + <# + .SYNOPSIS + Suspends replication of a virtual machine. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which replication of a virtual machine is to be suspended. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of the virtual machine whose replication is to be suspended. + .PARAMETER VM + Specifies the virtual machine whose replication is to be suspended. + .PARAMETER VMReplication + Specifies the virtual machine replication to be suspended. + .PARAMETER ReplicationRelationshipType + Specifies the replication relationship type of the virtual machine. Specify whether the replication relationship is a simple primary to replica or is an extended replication chain. The cmdlet suspends replication of the virtual machines that have the replication type that you specify. + .PARAMETER Passthru + Specifies that a VMReplication object is to be passed through to the pipeline representing the replication to be suspended. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMReplication])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string[]] + ${VMName}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='VMReplication', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNull()] + [Microsoft.HyperV.PowerShell.VMReplication[]] + ${VMReplication}, + + [Parameter(ParameterSetName='VMName')] + [Alias('Relationship')] + [System.Nullable[Microsoft.HyperV.PowerShell.VMReplicationRelationshipType]] + ${ReplicationRelationshipType}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Test-VHD { + <# + .SYNOPSIS + Tests a virtual hard disk for any problems that would make it unusable. + .PARAMETER Path + Specifies the path to the virtual hard disk file of the virtual hard disk to be tested. If a filename or relative path is specified, the new virtual hard disk path is calculated relative to the current working directory. + .PARAMETER SupportPersistentReservations + Indicates that the cmdlet tests for SCSI persistent reservation support semantics. Specify this parameter to test whether a virtual hard disk or path supports shared virtual disks. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which the virtual hard disk is to be tested. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding(DefaultParameterSetName='ExistingVHD')] + [OutputType([System.Boolean])] + param ( + [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('FullName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='SharedDisk', Mandatory=$true)] + [Alias('ShareVirtualDisk')] + [switch] + ${SupportPersistentReservations}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Test-VMNetworkAdapter { + <# + .SYNOPSIS + Tests connectivity between virtual machines. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts on which this cmdlet operates. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER VMName + Specifies the name of a virtual machine. + .PARAMETER VMNetworkAdapter + Specifies a virtual machine network adapter as a VMNetworkAdapterBase object. The cmdlet tests connectivity for the adapters that you specify. To obtain a network adapter, use the Get-VMNetworkAdapter cmdlet. + .PARAMETER VM + Specifies a virtual machine. The cmdlet tests connectivity for adapters that belong to the virtual machines that you specify. + .PARAMETER Name + Specifies the name of the virtual machine. + .PARAMETER Sender + Indicates that the cmdlet targets the sender virtual machine. + .PARAMETER Receiver + Indicates that the cmdlet targets the receiver virtual machine. + .PARAMETER SenderIPAddress + Specifies the IP address of the sender virtual machine. + .PARAMETER ReceiverIPAddress + Specifies the IP address of the receiver virtual machine. + .PARAMETER NextHopMacAddress + Specified the MAC address for the next hop VM required for non-Hyper-V Network Virtualization configurations. + .PARAMETER IsolationId + Specifies the ID of a virtual subnet. + .PARAMETER SequenceNumber + Specifies the sequence number to use to generate ICMP Ping packets. The default value is 100. + .PARAMETER Passthru + Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + #> + + [CmdletBinding(DefaultParameterSetName='VMName', SupportsShouldProcess=$true, ConfirmImpact='Medium')] + [OutputType([Microsoft.HyperV.PowerShell.VMNetworkAdapterConnectionTestResult])] + param ( + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='VMName')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMName', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${VMName}, + + [Parameter(ParameterSetName='ResourceObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Microsoft.HyperV.PowerShell.VMNetworkAdapter] + ${VMNetworkAdapter}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine] + ${VM}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Alias('VMNetworkAdapterName')] + [string] + ${Name}, + + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='ResourceObject')] + [switch] + ${Sender}, + + [Parameter(ParameterSetName='VMObject')] + [Parameter(ParameterSetName='VMName')] + [Parameter(ParameterSetName='ResourceObject')] + [switch] + ${Receiver}, + + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${SenderIPAddress}, + + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + ${ReceiverIPAddress}, + + [string] + ${NextHopMacAddress}, + + [System.Nullable[int]] + ${IsolationId}, + + [Parameter(Mandatory=$true)] + [int] + ${SequenceNumber}, + + [System.Nullable[int]] + ${PayloadSize}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Test-VMReplicationConnection { + <# + .SYNOPSIS + Tests the connection between a primary server and a Replica server. + .PARAMETER ReplicaServerName + Specifies the name of the Replica server to test for connectivity with the virtual machine to be replicated. + .PARAMETER ReplicaServerPort + Specifies the port on the Replica server to use to test connectivity. Make sure you specify a port that is configured on the Replica server to support the same authentication type you specify using the AuthenticationType parameter in this cmdlet. Run the Get-VMReplicationServer cmdlet on the Replica server to check the configuration of the port, or contact the administrator of the specified Replica server. + .PARAMETER AuthenticationType + Specifies the authentication type to use to test the connection, either "Kerberos" or "Certificate". The specified Replica server must support the chosen authentication type. Run the Get-VMReplicationServer cmdlet to verify the authentication configured for the specified Replica server, or contact the administrator of the specified Replica server. + .PARAMETER CertificateThumbprint + Specifies the certificate to use for mutual authentication of the replication data. This parameter is required only when "Certificate" is the specified as the type of authentication. Specify the thumbprint of a valid computer certificate from the Personal store. + + The certificate must have all of the following properties to be valid: + + It must not be expired. + + It must include both client and server authentication extensions for extended key usage (EKU), and an associated private key. + + It must terminate at a valid root certificate. + + The requirement for the subject common name (CN) differs depending on whether the virtual machine belongs to a cluster. For virtual machines that do not belong to a cluster, the subject common name (CN) must be equal to, or subject alternative name (DNS Name) should contain, the FQDN of the host. For virtual machines that belong to a cluster, the subject common name (CN) must be equal to, or subject alternative name (DNS Name) must contain, the FQDN of the Hyper-V Replica Broker. + + To display a list certificates in the computer's My store and the thumbprint of each certificate, type the following: + + `PS C:\> cd cert:\LocalMachine\My` + + `PS C:\> dir | format-list` + + For more information about certificate stores, see http://technet.microsoft.com//library/cc757138.aspx (http://technet.microsoft.com//library/cc757138.aspx). + .PARAMETER BypassProxyServer + Specifies whether to bypass a proxy server when testing the connectivity. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that have the virtual machines for which you want to test the connection for replication. NetBIOS names, IP addresses, and fully qualified domain names (FQDN) are allowed. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + #> + + [CmdletBinding()] + [OutputType([System.String])] + param ( + [Parameter(Mandatory=$true, Position=0)] + [Alias('ReplicaServer')] + [ValidateNotNullOrEmpty()] + [string] + ${ReplicaServerName}, + + [Parameter(Mandatory=$true, Position=1)] + [Alias('ReplicaPort')] + [ValidateRange(1, 65535)] + [int] + ${ReplicaServerPort}, + + [Parameter(Mandatory=$true, Position=2)] + [Alias('AuthType')] + [Microsoft.HyperV.PowerShell.ReplicationAuthenticationType] + ${AuthenticationType}, + + [Parameter(Position=3, ValueFromPipelineByPropertyName=$true)] + [Alias('Thumbprint')] + [ValidateNotNullOrEmpty()] + [string] + ${CertificateThumbprint}, + + [ValidateNotNull()] + [System.Nullable[bool]] + ${BypassProxyServer}, + + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Update-VMVersion { + <# + .SYNOPSIS + Updates the version of virtual machines. + .PARAMETER CimSession + Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession (http://go.microsoft.com/fwlink/p/?LinkId=227967) or [Get-CimSession](http://go.microsoft.com/fwlink/p/?LinkId=227966)cmdlet. The default is the current session on the local computer. + .PARAMETER ComputerName + Specifies one or more Hyper-V hosts that run this cmdlet. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly. + .PARAMETER Credential + Specifies one or more user accounts that have permission to perform this action. The default is the current user. + .PARAMETER Name + Specifies an array of names of the virtual machines that this cmdlet updates. + .PARAMETER VM + Specifies an array of virtual machines that this cmdlet updates. To obtain a VirtualMachine object, use the Get-VM cmdlet. + .PARAMETER Force + Forces the command to run without asking for user confirmation. + .PARAMETER AsJob + Runs the cmdlet as a background job. + .PARAMETER Passthru + Indicates that this cmdlet returns the Microsoft.HyperV.VirtualMachine object that it modifies. + #> + + [CmdletBinding(DefaultParameterSetName='Name', SupportsShouldProcess=$true, ConfirmImpact='High')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [switch] + ${Force}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + +function Wait-VM { + <# + .SYNOPSIS + Wait-VM [-Name] [-CimSession ] [-ComputerName ] [-Credential ] [-AsJob] [-Passthru] [-For ] [-Delay ] [-Timeout ] [] + +Wait-VM [-VM] [-AsJob] [-Passthru] [-For ] [-Delay ] [-Timeout ] [] + #> + + [CmdletBinding(DefaultParameterSetName='Name')] + [OutputType([Microsoft.HyperV.PowerShell.VirtualMachine])] + param ( + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [CimSession[]] + ${CimSession}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [string[]] + ${ComputerName}, + + [Parameter(ParameterSetName='Name')] + [ValidateNotNullOrEmpty()] + [pscredential[]] + ${Credential}, + + [Parameter(ParameterSetName='VMObject', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [ValidateNotNullOrEmpty()] + [Microsoft.HyperV.PowerShell.VirtualMachine[]] + ${VM}, + + [Parameter(ParameterSetName='Name', Mandatory=$true, Position=0, ValueFromPipeline=$true)] + [Alias('VMName')] + [ValidateNotNullOrEmpty()] + [string[]] + ${Name}, + + [switch] + ${AsJob}, + + [switch] + ${Passthru}, + + [Microsoft.HyperV.PowerShell.WaitVMTypes] + ${For}, + + [ValidateRange(1, 65535)] + [uint16] + ${Delay}, + + [Alias('TimeoutSec')] + [ValidateRange(-1, 2147483647)] + [int] + ${Timeout} + ) + end { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand + } +} + diff --git a/tests/Unit/Stubs/README.md b/tests/Unit/Stubs/README.md new file mode 100644 index 0000000..4ce2d1e --- /dev/null +++ b/tests/Unit/Stubs/README.md @@ -0,0 +1,124 @@ +# Stubs + +A stub function is function with just the skeleton of the original function +or cmdlet. Pester can use a stub function to have something to hook into +when a mock of a cmdlet or function is needed in a unit test. Stub functions +make it possible to run unit tests without having the actual module with +the cmdlet or function installed. + +## How to + +Install the module `Indented.StubCommand` which is used to generate the +stub module. + +```powershell +Install-Module Indented.StubCommand -Scope CurrentUser +``` + +Install the necessary feature to get the module to create stubs from. + +For Windows Server: + +```powershell +Install-WindowsFeature -Name 'Hyper-V-PowerShell' +``` + +For Windows Client: + +```powershell +Enable-WindowsOptionalFeature -FeatureName 'Microsoft-Hyper-V-Management-PowerShell' -Online +``` + +Create the stub modules in output folder 'c:\projects\stub' (can be any +folder). + +```powershell +$destinationFolder = 'c:\projects\stubs\' + +$functionBody = { + throw '{0}: StubNotImplemented' -f $MyInvocation.MyCommand +} + +New-StubModule -FromModule 'Hyper-V' -Path $destinationFolder -FunctionBody $functionBody +``` + +>**NOTE:** It was a problem with the module Hyper-V and specifically the +>cmdlet `Set-VMProcessor` when running `New-StubModule`. When `New-StubCommand` +>is called for the cmdlet `Set-VMProcessor` this error is thrown: +> +>```plaintext +>New-StubCommand : Cannot compare "System.Management.Automation.ParameterMetadata" because it is not IComparable. +>At +>C:\Users\johlju\Documents\WindowsPowerShell\Modules\Indented.StubCommand\1.4.0\Indented.StubCommand.psm1:747 +>char:24 +>+ $_.Group | New-StubCommand @StubCommandSplat +>+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +> + CategoryInfo : InvalidOperation: (:) [Write-Error], RuntimeException +> + FullyQualifiedErrorId : NotIcomparable,New-StubCommand +>``` +> +>To workaround this, in the cmdlet `New-StubCommand` the following line +>must be changed. +> +>```powershell +>if ($CommandInfo.CmdletBinding -or $CommandInfo.Parameters.Count -gt 0) { +>``` +> +>The line should be changed to: +> +>```powershell +>if ($CommandInfo.CmdletBinding -or $CommandInfo.Parameters.Keys.Count -gt 0) { +>``` +> +>For some reason the property `Count` did not return the number of parameters +>but instead returned an object of `System.Management.Automation.ParameterMetadata`, +>by instead counting the number of keys we worked around this issue. +> +>```plaintext +>Name : Count +>ParameterType : System.Nullable`1[System.Int64] +>ParameterSets : {[__AllParameterSets, System.Management.Automation.ParameterSetMetadata]} +>IsDynamic : False +>Aliases : {} +>Attributes : {System.Management.Automation.ValidateNotNullAttribute, __AllParameterSets} +>SwitchParameter : False +>``` + +## Post-changes + +Must add a reference to the namespace `Microsoft.Management.Infrastructure` for +the type `Microsoft.Management.Infrastructure.CimSession` to work. +Add the following parameter to the `Add-Type` call at the top of the stub file. + +```powershell +Add-Type -IgnoreWarnings -ReferencedAssemblies 'C:\Program Files (x86)\Reference Assemblies\Microsoft\WMI\v1.0\Microsoft.Management.Infrastructure.dll' -TypeDefinition @' + +-ReferencedAssemblies 'C:\Program Files (x86)\Reference Assemblies\Microsoft\WMI\v1.0\Microsoft.Management.Infrastructure.dll' +``` + +One of the namespaces for `Microsoft.HyperV.PowerShell.Commands` is wrongly +generated twice. Remove the duplicate namespace and make sure the enums +`WaitVMTypes` and `RestartType` is moved _inside_ the class `RestartVM`. + +The property `MacAddress` is not added to the class `VMNetworkAdapterBase` +and is needed for the resource unit test `xVMNetworkAdapter`. +Normally the class `VMNetworkAdapter` probably inherits from `VMNetworkAdapterBase` +and the class `VMNetworkAdapter` should be used in the unit test instead +of `VMNetworkAdapterBase` but instead of trying to solve the inheritance +issue this property was just added to the class `VMNetworkAdapterBase`. + +```csharp + public class VMNetworkAdapterBase + { + // Manually added properties + public System.String MacAddress { get; set; } + + ... + } +``` + +The class `HardDiskDrive` should inherit from the class `Drive`. + +```csharp +public class HardDiskDrive : Drive +``` diff --git a/xHyper-V.psd1 b/xHyper-V.psd1 deleted file mode 100644 index e4809a6..0000000 --- a/xHyper-V.psd1 +++ /dev/null @@ -1,75 +0,0 @@ -@{ -# Version number of this module. -moduleVersion = '3.17.0.0' - -# ID used to uniquely identify this module -GUID = 'f5a5f169-7026-4053-932a-19a7c37b1ca5' - -# Author of this module -Author = 'Microsoft Corporation' - -# Company or vendor of this module -CompanyName = 'Microsoft Corporation' - -# Copyright statement for this module -Copyright = '(c) 2017 Microsoft Corporation. All rights reserved.' - -# Description of the functionality provided by this module -Description = 'Module with DSC Resources for Hyper-V area' - -# 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 = '*' - -# 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 = @('DesiredStateConfiguration', 'DSC', 'DSCResourceKit', 'DSCResource') - - # A URL to the license for this module. - LicenseUri = 'https://github.com/PowerShell/xHyper-V/blob/master/LICENSE' - - # A URL to the main website for this project. - ProjectUri = 'https://github.com/PowerShell/xHyper-V' - - # A URL to an icon representing this module. - # IconUri = '' - - # ReleaseNotes of this module - ReleaseNotes = '* MSFT_xVMNetworkAdapter: - * Added NetworkSettings to be able to statically set IPAddress. - * Added option for Vlan tagging. You can now setup a Network Adapeter as an access switch on a specific Vlan. - -' - - } # End of PSData hashtable - -} # End of PrivateData hashtable -} - - - - - - - - - - - - - - - -