Merge branch 'master' into master
This commit is contained in:
@@ -36,6 +36,7 @@ Description = 'PowerShell Module for Managing Hybrid Cloud Extension (HCX) on VM
|
||||
PowerShellVersion = '6.0'
|
||||
|
||||
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
|
||||
|
||||
FunctionsToExport = 'Connect-HcxServer', 'Get-HcxCloudConfig', 'Get-HcxEndpoint', 'New-HcxMigration', 'Get-HcxMigration', 'Connect-HcxVAMI',
|
||||
'Get-HcxVCConfig', 'Set-HcxLicense', 'Set-HcxVCConfig', 'Get-HcxNSXConfig', 'Set-HcxNSXConfig', 'Get-HcxCity', 'Get-HcxLocation', 'Set-HcxLocation',
|
||||
'Get-HcxRoleMapping', 'Set-HcxRoleMapping', 'Get-HcxProxy', 'Set-HcxProxy', 'Remove-HcxProxy', 'Connect-HcxCloudServer', 'Get-HCXCloudActivationKey',
|
||||
|
||||
@@ -453,12 +453,23 @@ Function Get-HcxMigration {
|
||||
Get-HcxMigration -MigrationId <MigrationID>
|
||||
#>
|
||||
Param (
|
||||
[Parameter(Mandatory=$false)][String]$MigrationId,
|
||||
[Parameter(Mandatory=$false)][String[]]$MigrationId,
|
||||
[Switch]$RunningMigrations
|
||||
)
|
||||
|
||||
If (-Not $global:hcxConnection) { Write-error "HCX Auth Token not found, please run Connect-HcxManager " } Else {
|
||||
$spec = @{}
|
||||
If($PSBoundParameters.ContainsKey("MigrationId")){
|
||||
$spec = @{
|
||||
filter = @{
|
||||
migrationId = $MigrationId
|
||||
}
|
||||
paging =@{
|
||||
pageSize = $MigrationId.Count
|
||||
}
|
||||
}
|
||||
} Else {
|
||||
$spec = @{}
|
||||
}
|
||||
$body = $spec | ConvertTo-Json
|
||||
|
||||
$hcxQueryUrl = $global:hcxConnection.Server + "/migrations?action=query"
|
||||
@@ -468,10 +479,10 @@ Function Get-HcxMigration {
|
||||
$requests = Invoke-WebRequest -Uri $hcxQueryUrl -Method POST -Headers $global:hcxConnection.headers -UseBasicParsing
|
||||
}
|
||||
|
||||
$migrations = ($requests.content | ConvertFrom-Json).rows
|
||||
|
||||
if($PSBoundParameters.ContainsKey("MigrationId")){
|
||||
$migrations = $migrations | where { $_.migrationId -eq $MigrationId }
|
||||
$migrations = ($requests.content | ConvertFrom-Json).items
|
||||
} else {
|
||||
$migrations = ($requests.content | ConvertFrom-Json).rows
|
||||
}
|
||||
|
||||
if($RunningMigrations){
|
||||
@@ -559,16 +570,22 @@ Function Get-HcxVCConfig {
|
||||
#>
|
||||
If (-Not $global:hcxVAMIConnection) { Write-error "HCX Auth Token not found, please run Connect-HcxVAMI " } Else {
|
||||
$vcConfigUrl = $global:hcxVAMIConnection.Server + "/api/admin/global/config/vcenter"
|
||||
$pscConfigUrl = $global:hcxVAMIConnection.Server + "/api/admin/global/config/lookupservice"
|
||||
|
||||
if($PSVersionTable.PSEdition -eq "Core") {
|
||||
$vcRequests = Invoke-WebRequest -Uri $vcConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing -SkipCertificateCheck
|
||||
$ssoRequests = Invoke-WebRequest -Uri $pscConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing -SkipCertificateCheck
|
||||
} else {
|
||||
$vcRequests = Invoke-WebRequest -Uri $vcConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing
|
||||
$ssoRequests = Invoke-WebRequest -Uri $pscConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing
|
||||
}
|
||||
$vcData = ($vcRequests.content | ConvertFrom-Json).data.items
|
||||
$ssoData = ($ssoRequests.content | ConvertFrom-Json).data.items
|
||||
|
||||
$tmp = [pscustomobject] @{
|
||||
Name = $vcData.config.name;
|
||||
UserName = $vcData.Config.userName
|
||||
LookupServiceUrl = $ssoData.config.lookupServiceUrl
|
||||
Version = $vcData.config.version;
|
||||
Build = $vcData.config.buildNumber;
|
||||
UUID = $vcData.config.vcuuid;
|
||||
@@ -578,6 +595,38 @@ Function Get-HcxVCConfig {
|
||||
}
|
||||
}
|
||||
|
||||
Function Get-HcxLicense {
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Created by: Mark McGilly
|
||||
Date: 4/29/2019
|
||||
Organization: Liberty Mutual Insurance
|
||||
===========================================================================
|
||||
|
||||
.SYNOPSIS
|
||||
Returns the license key that is registered with HCX Manager
|
||||
.DESCRIPTION
|
||||
This cmdlet returns the license key registered with HCX Manager
|
||||
.EXAMPLE
|
||||
Get-HcxLicense
|
||||
#>
|
||||
|
||||
If (-Not $global:hcxVAMIConnection) { Write-error "HCX Auth Token not found, please run Connect-HcxVAMI " } Else {
|
||||
$hcxConfigUrl = $global:hcxVAMIConnection.Server + "/api/admin/global/config/hcx"
|
||||
|
||||
if($PSVersionTable.PSEdition -eq "Core") {
|
||||
$licenseRequests = Invoke-WebRequest -Uri $hcxConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing -SkipCertificateCheck
|
||||
} else {
|
||||
$licenseRequests = Invoke-WebRequest -Uri $hcxConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing
|
||||
}
|
||||
$license = ($licenseRequests.content | ConvertFrom-Json).data.items
|
||||
if($licenseRequests) {
|
||||
$license.config.activationKey
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Function Set-HcxLicense {
|
||||
<#
|
||||
.NOTES
|
||||
@@ -789,6 +838,7 @@ Function Get-HcxNSXConfig {
|
||||
|
||||
$tmp = [pscustomobject] @{
|
||||
Name = $nsxData.config.url;
|
||||
UserName = $nsxData.config.userName
|
||||
Version = $nsxData.config.version;
|
||||
HCXUUID = $nsxData.config.uuid;
|
||||
}
|
||||
@@ -1200,6 +1250,7 @@ Function Set-HcxProxy {
|
||||
[Parameter(Mandatory=$True)]$ProxyPort,
|
||||
[Parameter(Mandatory=$False)]$ProxyUser,
|
||||
[Parameter(Mandatory=$False)]$ProxyPassword,
|
||||
[Parameter(Mandatory=$False)]$ProxyExclusions,
|
||||
[Switch]$Troubleshoot
|
||||
)
|
||||
|
||||
@@ -1214,7 +1265,7 @@ Function Set-HcxProxy {
|
||||
config = @{
|
||||
proxyHost = "$ProxyServer";
|
||||
proxyPort = "$ProxyPort";
|
||||
nonProxyHosts = "";
|
||||
nonProxyHosts = "$ProxyExclusions";
|
||||
userName = "$ProxyUser";
|
||||
password = "$ProxyPassword";
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -690,7 +690,7 @@ Function Get-VMCLogicalNetwork {
|
||||
Created by: Kyle Ruddy
|
||||
Date: 03/06/2018
|
||||
Organization: VMware
|
||||
Blog: https://thatcouldbeaproblem.com
|
||||
Blog: https://www.kmruddy.com
|
||||
Twitter: @kmruddy
|
||||
===========================================================================
|
||||
|
||||
@@ -761,7 +761,7 @@ Function Remove-VMCLogicalNetwork {
|
||||
Created by: Kyle Ruddy
|
||||
Date: 03/06/2018
|
||||
Organization: VMware
|
||||
Blog: https://thatcouldbeaproblem.com
|
||||
Blog: https://www.kmruddy.com
|
||||
Twitter: @kmruddy
|
||||
===========================================================================
|
||||
|
||||
@@ -808,7 +808,7 @@ Function New-VMCLogicalNetwork {
|
||||
Created by: Kyle Ruddy
|
||||
Date: 03/06/2018
|
||||
Organization: VMware
|
||||
Blog: https://thatcouldbeaproblem.com
|
||||
Blog: https://www.kmruddy.com
|
||||
Twitter: @kmruddy
|
||||
===========================================================================
|
||||
|
||||
@@ -1418,11 +1418,205 @@ Twitter: @LucD22
|
||||
}
|
||||
}
|
||||
}
|
||||
Function New-VMCSDDCCluster {
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Created by: Kyle Ruddy
|
||||
Date: 03/16/2019
|
||||
Organization: VMware
|
||||
Blog: https://www.kmruddy.com
|
||||
Twitter: @kmruddy
|
||||
===========================================================================
|
||||
|
||||
.SYNOPSIS
|
||||
Creates a new cluster for the designated SDDC
|
||||
.DESCRIPTION
|
||||
Creates a new cluster
|
||||
.EXAMPLE
|
||||
New-VMCSDDCCluster -OrgName <Org Name> -SDDCName <SDDC Name> -HostCount 1 -CPUCoreCount 8
|
||||
#>
|
||||
[cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact='High')]
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][String]$OrgName,
|
||||
[Parameter(Mandatory=$true)][String]$SDDCName,
|
||||
[Parameter(Mandatory=$true)][Int]$HostCount,
|
||||
[Parameter(Mandatory=$true)][ValidateSet("8","16","32")]$CPUCoreCount
|
||||
)
|
||||
|
||||
if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break }
|
||||
|
||||
$orgId = Get-VMCOrg -Name $OrgName | Select-Object -ExpandProperty Id
|
||||
$sddcId = Get-VMCSDDC -Name $SDDCName -Org $OrgName | Select-Object -ExpandProperty Id
|
||||
|
||||
if(-not $orgId) {
|
||||
Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input"
|
||||
break
|
||||
}
|
||||
if(-not $sddcId) {
|
||||
Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input"
|
||||
break
|
||||
}
|
||||
|
||||
$sddcClusterSvc = Get-VmcService -Name com.vmware.vmc.orgs.sddcs.clusters
|
||||
|
||||
$sddcClusterCreateSpec = $sddcClusterSvc.Help.create.cluster_config.Create()
|
||||
$sddcClusterCreateSpec.host_cpu_cores_count = $CPUCoreCount
|
||||
$sddcClusterCreateSpec.num_hosts = $HostCount
|
||||
|
||||
$sddcClusterTask = $sddcClusterSvc.Create($org.Id, $sddc.Id, $sddcClusterCreateSpec)
|
||||
$sddcClusterTask | Select-Object Id,Task_Type,Status,Created | Format-Table
|
||||
}
|
||||
Function Get-VMCSDDCCluster {
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Created by: Kyle Ruddy
|
||||
Date: 03/16/2019
|
||||
Organization: VMware
|
||||
Blog: https://www.kmruddy.com
|
||||
Twitter: @kmruddy
|
||||
===========================================================================
|
||||
|
||||
.SYNOPSIS
|
||||
Retreives cluster information for the designated SDDC
|
||||
.DESCRIPTION
|
||||
Lists cluster information for an SDDC
|
||||
.EXAMPLE
|
||||
Get-VMCSDDCCluster -OrgName <Org Name> -SDDCName <SDDC Name> -HostCount 1 -CPUCoreCount 8
|
||||
#>
|
||||
[cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact='Low')]
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][String]$OrgName,
|
||||
[Parameter(Mandatory=$true)][String]$SddcName
|
||||
)
|
||||
|
||||
if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break }
|
||||
|
||||
$orgId = Get-VMCOrg -Name $OrgName | Select-Object -ExpandProperty Id
|
||||
$sddcId = Get-VMCSDDC -Name $SDDCName -Org $OrgName | Select-Object -ExpandProperty Id
|
||||
|
||||
if(-not $orgId) {
|
||||
Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input"
|
||||
break
|
||||
}
|
||||
if(-not $sddcId) {
|
||||
Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input"
|
||||
break
|
||||
}
|
||||
|
||||
$clusterOutput = @()
|
||||
$sddcClusters = Get-VMCSDDC -Org $OrgName -Name $SDDCName | Select-Object -ExpandProperty resource_config | Select-Object -ExpandProperty clusters
|
||||
foreach ($c in $sddcClusters) {
|
||||
$tempCluster = "" | Select-Object Id, Name, State
|
||||
$tempCluster.Id = $c.cluster_id
|
||||
$tempCluster.Name = $c.cluster_name
|
||||
$tempCluster.State = $c.cluster_state
|
||||
$clusterOutput += $tempCluster
|
||||
}
|
||||
return $clusterOutput
|
||||
}
|
||||
Function New-VMCSDDCCluster {
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Created by: Kyle Ruddy
|
||||
Date: 03/16/2019
|
||||
Organization: VMware
|
||||
Blog: https://www.kmruddy.com
|
||||
Twitter: @kmruddy
|
||||
===========================================================================
|
||||
|
||||
.SYNOPSIS
|
||||
Creates a new cluster for the designated SDDC
|
||||
.DESCRIPTION
|
||||
Creates a new cluster
|
||||
.EXAMPLE
|
||||
New-VMCSDDCCluster -OrgName <Org Name> -SDDCName <SDDC Name> -HostCount 1 -CPUCoreCount 8
|
||||
#>
|
||||
[cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact='High')]
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][String]$OrgName,
|
||||
[Parameter(Mandatory=$true)][String]$SddcName,
|
||||
[Parameter(Mandatory=$true)][Int]$HostCount,
|
||||
[Parameter(Mandatory=$false)][ValidateSet("8","16","36","48")]$CPUCoreCount
|
||||
)
|
||||
|
||||
if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break }
|
||||
|
||||
$orgId = Get-VMCOrg -Name $OrgName | Select-Object -ExpandProperty Id
|
||||
$sddcId = Get-VMCSDDC -Name $SDDCName -Org $OrgName | Select-Object -ExpandProperty Id
|
||||
|
||||
if(-not $orgId) {
|
||||
Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input"
|
||||
break
|
||||
}
|
||||
if(-not $sddcId) {
|
||||
Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input"
|
||||
break
|
||||
}
|
||||
|
||||
$sddcClusterSvc = Get-VmcService -Name com.vmware.vmc.orgs.sddcs.clusters
|
||||
|
||||
$sddcClusterCreateSpec = $sddcClusterSvc.Help.create.cluster_config.Create()
|
||||
$sddcClusterCreateSpec.host_cpu_cores_count = $CPUCoreCount
|
||||
$sddcClusterCreateSpec.num_hosts = $HostCount
|
||||
|
||||
$sddcClusterTask = $sddcClusterSvc.Create($org.Id, $sddc.Id, $sddcClusterCreateSpec)
|
||||
$sddcClusterTask | Select-Object Id,Task_Type,Status,Created | Format-Table
|
||||
}
|
||||
Function Remove-VMCSDDCCluster {
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Created by: Kyle Ruddy
|
||||
Date: 03/16/2019
|
||||
Organization: VMware
|
||||
Blog: https://www.kmruddy.com
|
||||
Twitter: @kmruddy
|
||||
===========================================================================
|
||||
|
||||
.SYNOPSIS
|
||||
Removes a specified cluster from the designated SDDC
|
||||
.DESCRIPTION
|
||||
Deletes a cluster from an SDDC
|
||||
.EXAMPLE
|
||||
Remove-VMCSDDCCluster -OrgName <Org Name> -SDDCName <SDDC Name> -Cluster <Cluster Name>
|
||||
#>
|
||||
[cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact='High')]
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][String]$OrgName,
|
||||
[Parameter(Mandatory=$true)][String]$SDDCName,
|
||||
[Parameter(Mandatory=$true)][String]$ClusterName
|
||||
)
|
||||
|
||||
if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break }
|
||||
|
||||
$orgId = Get-VMCOrg -Name $OrgName | Select-Object -ExpandProperty Id
|
||||
$sddcId = Get-VMCSDDC -Name $SDDCName -Org $OrgName | Select-Object -ExpandProperty Id
|
||||
$clusterId = Get-VMCSDDCCluster -SddcName $SDDCName -OrgName $OrgName | Where-Object {$_.Name -eq $ClusterName} | Select-Object -ExpandProperty Id
|
||||
|
||||
if(-not $orgId) {
|
||||
Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input"
|
||||
break
|
||||
}
|
||||
if(-not $sddcId) {
|
||||
Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input"
|
||||
break
|
||||
}
|
||||
if(-not $clusterId) {
|
||||
Write-Host -ForegroundColor red "Unable to find cluster $ClusterName, please verify input"
|
||||
break
|
||||
}
|
||||
|
||||
$sddcClusterTask = $sddcClusterSvc.Delete($orgId, $sddcId, $clusterId)
|
||||
$sddcClusterTask | Select-Object Id,Task_Type,Status,Created | Format-Table
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function 'Get-VMCCommand', 'Connect-VMCVIServer', 'Get-VMCOrg', 'Get-VMCSDDC',
|
||||
'Get-VMCTask', 'Get-VMCSDDCDefaultCredential', 'Get-VMCSDDCPublicIP', 'Get-VMCVMHost',
|
||||
'Get-VMCSDDCVersion', 'Get-VMCFirewallRule', 'Export-VMCFirewallRule', 'Import-VMCFirewallRule',
|
||||
'Remove-VMCFirewallRule', 'Get-VMCLogicalNetwork', 'Remove-VMCLogicalNetwork', 'New-VMCLogicalNetwork',
|
||||
'Get-VMCSDDCSummary', 'Get-VMCPublicIP', 'New-VMCPublicIP', 'Remove-VMCPublicIP', 'Set-VMCSDDC',
|
||||
'Get-VMCEdge', 'Get-VMCEdgeNic', 'Get-VMCEdgeStatus', 'Get-VMCEdgeNicStat', 'Get-VMCEdgeUplinkStat'
|
||||
|
||||
'Get-VMCEdge', 'Get-VMCEdgeNic', 'Get-VMCEdgeStatus', 'Get-VMCEdgeNicStat', 'Get-VMCEdgeUplinkStat',
|
||||
'Get-VMCSDDCCluster', 'New-VMCSDDCCluster', 'Remove-VMCSDDCCluster'
|
||||
12
Scripts/Get-Migrations.ps1
Normal file
12
Scripts/Get-Migrations.ps1
Normal file
@@ -0,0 +1,12 @@
|
||||
<#
|
||||
Script name: get-migrations.ps1
|
||||
Created on: 20/12/2018
|
||||
Author: Chris Bradshaw @aldershotchris
|
||||
Description: The purpose of the script is to list the currently running + recently finished VM migrations.
|
||||
Dependencies: None known
|
||||
#>
|
||||
Function Get-Migrations{
|
||||
Get-Task |
|
||||
Where-Object{$_.Name -eq "RelocateVM_Task"} |
|
||||
Select-Object @{Name="VM";Expression={Get-VM -Id $_.ObjectID}}, State, @{Name="% Complete";Expression={$_.PercentComplete}},StartTime
|
||||
}
|
||||
34
Scripts/Move-DatastoreCluster.ps1
Normal file
34
Scripts/Move-DatastoreCluster.ps1
Normal file
@@ -0,0 +1,34 @@
|
||||
function Move-DatastoreCluster {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Moves a datastore cluster to a new location
|
||||
.DESCRIPTION
|
||||
Will move a datastore cluster to a new location
|
||||
.NOTES
|
||||
Author: Kyle Ruddy, @kmruddy
|
||||
.PARAMETER DatastoreCluster
|
||||
Specifies the datastore cluster you want to move.
|
||||
.PARAMETER Destination
|
||||
Specifies a destination where you want to place the datastore cluster
|
||||
.EXAMPLE
|
||||
Move-DatastoreCluster -DatastoreCluster $DSCluster -Destination $DSClusterFolder
|
||||
Moves the $DSCluster datastore cluster to the specified $DSClusterFolder folder.
|
||||
#>
|
||||
[CmdletBinding(SupportsShouldProcess = $True)]
|
||||
param(
|
||||
[Parameter(Mandatory=$false,Position=0,ValueFromPipelineByPropertyName=$true)]
|
||||
[VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.DatastoreCluster]$DatastoreCluster,
|
||||
[Parameter(Mandatory=$false,Position=1,ValueFromPipelineByPropertyName=$true)]
|
||||
[VMware.VimAutomation.ViCore.Types.V1.Inventory.Folder]$Destination
|
||||
)
|
||||
|
||||
if ($Global:DefaultVIServer.IsConnected -eq $false) {
|
||||
Write-Warning -Message "No vCenter Server connection found."
|
||||
break
|
||||
}
|
||||
|
||||
If ($Pscmdlet.ShouldProcess($DatastoreCluster,"Move Datastore Cluster")) {
|
||||
$Destination.ExtensionData.MoveIntoFolder($DatastoreCluster.ExtensionData.MoRef)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,147 +1,158 @@
|
||||
function Save-PowerCLI {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Advanced function which can be used to easily download specific versions of PowerCLI from an online gallery
|
||||
.DESCRIPTION
|
||||
Downloads a specific version of PowerCLI and all the dependencies at the appropriate version
|
||||
.NOTES
|
||||
Author: 1.0 - Dimitar Milov
|
||||
Author: 2.0 - Kyle Ruddy, @kmruddy
|
||||
.PARAMETER RequiredVersion
|
||||
Dynamic parameter used to specify the PowerCLI version
|
||||
.PARAMETER Path
|
||||
Directory path where the modules should be downloaded
|
||||
.PARAMETER Repository
|
||||
Repository to access the PowerCLI modules
|
||||
.PARAMETER Simple
|
||||
Switch used to specify the nested version folders should be removed (therefore adding PowerShell 3/4 compatibility)
|
||||
.EXAMPLE
|
||||
Save-PowerCLI -RequiredVersion '10.0.0.7895300' -Path .\Downloads\
|
||||
Downloads PowerCLI 10.0.0 to the Downloads folder
|
||||
.EXAMPLE
|
||||
Save-PowerCLI -RequiredVersion '6.5.2.6268016' -Path .\Downloads\ -Simple
|
||||
Downloads PowerCLI 6.5.2 to the Downloads folder and removes the nested version folders
|
||||
#>
|
||||
[CmdletBinding(SupportsShouldProcess = $True)]
|
||||
param(
|
||||
[Parameter(Mandatory = $true, Position = 1)]
|
||||
[ValidateScript( { Test-Path $_} )]
|
||||
$Path,
|
||||
[Parameter(Mandatory = $false, Position = 2)]
|
||||
[string]$Repository = 'PSGallery',
|
||||
[Parameter(Mandatory = $false, Position = 3)]
|
||||
[Switch]$Simple
|
||||
)
|
||||
DynamicParam
|
||||
{
|
||||
# Set the dynamic parameters name
|
||||
$ParameterName = 'RequiredVersion'
|
||||
|
||||
# Create the dictionary
|
||||
$RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
|
||||
|
||||
# Create the collection of attributes
|
||||
$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
|
||||
|
||||
# Create and set the parameters' attributes
|
||||
$ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
|
||||
$ParameterAttribute.ValueFromPipeline = $true
|
||||
$ParameterAttribute.ValueFromPipelineByPropertyName = $true
|
||||
$ParameterAttribute.Mandatory = $true
|
||||
$ParameterAttribute.Position = 0
|
||||
|
||||
# Add the attributes to the attributes collection
|
||||
$AttributeCollection.Add($ParameterAttribute)
|
||||
|
||||
# Generate and set the ValidateSet
|
||||
$pcliVersions = Find-Module -Name 'VMware.PowerCLI' -AllVersions
|
||||
$arrSet = $pcliVersions | select-Object -ExpandProperty Version
|
||||
$ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)
|
||||
|
||||
# Add the ValidateSet to the attributes collection
|
||||
$AttributeCollection.Add($ValidateSetAttribute)
|
||||
|
||||
# Create and return the dynamic parameter
|
||||
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
|
||||
$RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
|
||||
return $RuntimeParameterDictionary
|
||||
function Save-PowerCLI {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Advanced function which can be used to easily download specific versions of PowerCLI from an online gallery
|
||||
.DESCRIPTION
|
||||
Downloads a specific version of PowerCLI and all the dependencies at the appropriate version
|
||||
.NOTES
|
||||
Author: 1.0 - Dimitar Milov
|
||||
Author: 2.0 - Kyle Ruddy, @kmruddy
|
||||
Author: 2.1 - Luc Dekens, @LucD22
|
||||
- fixed issue with downloading the correct versions
|
||||
- added a working cleanup of unwanted versions
|
||||
.PARAMETER RequiredVersion
|
||||
Dynamic parameter used to specify the PowerCLI version
|
||||
.PARAMETER Path
|
||||
Directory path where the modules should be downloaded
|
||||
.PARAMETER Repository
|
||||
Repository to access the PowerCLI modules
|
||||
.PARAMETER Simple
|
||||
Switch used to specify the nested version folders should be removed (therefore adding PowerShell 3/4 compatibility)
|
||||
.EXAMPLE
|
||||
Save-PowerCLI -RequiredVersion '10.0.0.7895300' -Path .\Downloads\
|
||||
Downloads PowerCLI 10.0.0 to the Downloads folder
|
||||
.EXAMPLE
|
||||
Save-PowerCLI -RequiredVersion '6.5.2.6268016' -Path .\Downloads\ -Simple
|
||||
Downloads PowerCLI 6.5.2 to the Downloads folder and removes the nested version folders
|
||||
#>
|
||||
[CmdletBinding(SupportsShouldProcess = $True)]
|
||||
param(
|
||||
[Parameter(Mandatory = $true, Position = 1)]
|
||||
[ValidateScript( { Test-Path $_} )]
|
||||
$Path,
|
||||
[Parameter(Mandatory = $false, Position = 2)]
|
||||
[string]$Repository = 'PSGallery',
|
||||
[Parameter(Mandatory = $false, Position = 3)]
|
||||
[Switch]$Simple
|
||||
)
|
||||
DynamicParam
|
||||
{
|
||||
# Set the dynamic parameters name
|
||||
$ParameterName = 'RequiredVersion'
|
||||
|
||||
# Create the dictionary
|
||||
$RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
|
||||
|
||||
# Create the collection of attributes
|
||||
$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
|
||||
|
||||
# Create and set the parameters' attributes
|
||||
$ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
|
||||
$ParameterAttribute.ValueFromPipeline = $true
|
||||
$ParameterAttribute.ValueFromPipelineByPropertyName = $true
|
||||
$ParameterAttribute.Mandatory = $true
|
||||
$ParameterAttribute.Position = 0
|
||||
|
||||
# Add the attributes to the attributes collection
|
||||
$AttributeCollection.Add($ParameterAttribute)
|
||||
|
||||
# Generate and set the ValidateSet
|
||||
$pcliVersions = Find-Module -Name 'VMware.PowerCLI' -AllVersions
|
||||
$arrSet = $pcliVersions | select-Object -ExpandProperty Version
|
||||
$ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)
|
||||
|
||||
# Add the ValidateSet to the attributes collection
|
||||
$AttributeCollection.Add($ValidateSetAttribute)
|
||||
|
||||
# Create and return the dynamic parameter
|
||||
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [String], $AttributeCollection)
|
||||
$RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
|
||||
return $RuntimeParameterDictionary
|
||||
}
|
||||
|
||||
begin {
|
||||
$powercliModuleName = 'VMware.PowerCLI'
|
||||
$desiredPowerCLIModule = Find-Module -Name $powercliModuleName -RequiredVersion $PSBoundParameters.RequiredVersion -Repository $Repository
|
||||
|
||||
$depsOrder = 'VMware.VimAutomation.Sdk', 'VMware.VimAutomation.Common', 'VMware.Vim', 'VMware.VimAutomation.Cis.Core', 'VMware.VimAutomation.Core', 'VMware.VimAutomation.Nsxt', 'VMware.VimAutomation.Vmc', 'VMware.VimAutomation.Vds', 'VMware.VimAutomation.Srm', 'VMware.ImageBuilder', 'VMware.VimAutomation.Storage', 'VMware.VimAutomation.StorageUtility', 'VMware.VimAutomation.License', 'VMware.VumAutomation', 'VMware.VimAutomation.HorizonView', 'VMware.DeployAutomation', 'VMware.VimAutomation.vROps', 'VMware.VimAutomation.PCloud'
|
||||
$orderedDependencies = @()
|
||||
foreach ($depModuleName in $depsOrder) {
|
||||
$orderedDependencies += $desiredPowerCLIModule.Dependencies | Where-Object {$_.Name -eq $depModuleName}
|
||||
}
|
||||
|
||||
begin {
|
||||
$powercliModuleName = 'VMware.PowerCLI'
|
||||
$desiredPowerCLIModule = Find-Module -Name $powercliModuleName -RequiredVersion $RequiredVersion -Repository $Repository
|
||||
|
||||
$depsOrder = 'VMware.VimAutomation.Sdk', 'VMware.VimAutomation.Common', 'VMware.Vim', 'VMware.VimAutomation.Cis.Core', 'VMware.VimAutomation.Core', 'VMware.VimAutomation.Nsxt', 'VMware.VimAutomation.Vmc', 'VMware.VimAutomation.Vds', 'VMware.VimAutomation.Srm', 'VMware.ImageBuilder', 'VMware.VimAutomation.Storage', 'VMware.VimAutomation.StorageUtility', 'VMware.VimAutomation.License', 'VMware.VumAutomation', 'VMware.VimAutomation.HorizonView', 'VMware.DeployAutomation', 'VMware.VimAutomation.vROps', 'VMware.VimAutomation.PCloud'
|
||||
$orderedDependencies = @()
|
||||
foreach ($depModuleName in $depsOrder) {
|
||||
$orderedDependencies += $desiredPowerCLIModule.Dependencies | Where-Object {$_.Name -eq $depModuleName}
|
||||
|
||||
foreach ($remainingDep in $desiredPowerCLIModule.Dependencies) {
|
||||
if ($orderedDependencies.Name -notcontains $remainingDep.Name) {
|
||||
$orderedDependencies += $remainingDep
|
||||
}
|
||||
|
||||
foreach ($remainingDep in $desiredPowerCLIModule.Dependencies) {
|
||||
if ($orderedDependencies.Name -notcontains $remainingDep.Name) {
|
||||
$orderedDependencies += $remainingDep
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
# Save PowerCLI Module Version
|
||||
$desiredPowerCLIModule | Save-Module -Path $Path
|
||||
|
||||
# Working with the depenent modules
|
||||
foreach ($dependency in $orderedDependencies) {
|
||||
if (Get-ChildItem -Path (Join-Path $path $dependency.Name) | Where-Object {$_.Name -ne $dependency.MinimumVersion}) {
|
||||
# Save dependencies with minimum version
|
||||
Find-Module $dependency.Name -RequiredVersion $dependency.MinimumVersion | Save-Module -Path $Path
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
# Save PowerCLI Module Version
|
||||
$desiredPowerCLIModule | Save-Module -Path $Path
|
||||
|
||||
# Working with the depenent modules
|
||||
foreach ($dependency in $orderedDependencies) {
|
||||
if (Get-ChildItem -Path (Join-Path $path $dependency.Name) | Where-Object {$_.Name -ne $dependency.MinimumVersion}) {
|
||||
# Save dependencies with minimum version
|
||||
Find-Module $dependency.Name -RequiredVersion $dependency.MinimumVersion | Save-Module -Path $Path
|
||||
|
||||
# Remove newer dependencies version
|
||||
Get-ChildItem -Path (Join-Path $path $dependency.Name) | Where-Object {$_.Name -ne $dependency.MinimumVersion} | Remove-Item -Confirm:$false -Force -Recurse
|
||||
}
|
||||
|
||||
end {
|
||||
Get-Item -Path "$($Path)\*" -PipelineVariable dir |
|
||||
ForEach-Object -Process {
|
||||
$children = Get-ChildItem -Path $dir.FullName -Directory
|
||||
if($children.Count -gt 1){
|
||||
$tgtVersion = $orderedDependencies.GetEnumerator() | where {$_.Name -eq $dir.Name}
|
||||
$children | where{$_.Name -ne $tgtVersion.MinimumVersion} |
|
||||
ForEach-Object -Process {
|
||||
Remove-Item -Path $_.FullName -Recurse -Force -Confirm:$false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
if ($Simple) {
|
||||
|
||||
function FolderCleanup {
|
||||
param(
|
||||
[Parameter(Mandatory = $true, Position = 0)]
|
||||
[ValidateScript( { Test-Path $_} )]
|
||||
$ParentFolder,
|
||||
[Parameter(Mandatory = $true, Position = 1)]
|
||||
[String]$ModuleName,
|
||||
[Parameter(Mandatory = $true, Position = 2)]
|
||||
$Version
|
||||
)
|
||||
|
||||
|
||||
$topFolder = Get-Item -Path (Join-Path $ParentFolder $ModuleName)
|
||||
$versionFolder = $topFolder | Get-ChildItem -Directory | Where-Object {$_.Name -eq $Version}
|
||||
$versionFolder | Get-ChildItem | Copy-Item -Destination $topFolder
|
||||
|
||||
# Checking for any nested folders within the PowerCLI module version folder
|
||||
if ($versionFolder| Get-ChildItem -Directory) {
|
||||
|
||||
# Obtaining and storing the child items to a variable, then copying the items to the parent folder's nested folder
|
||||
$nestFolder = $versionFolder| Get-ChildItem -Directory
|
||||
foreach ($nestDir in $nestFolder) {
|
||||
$nestDir | Get-ChildItem | Copy-Item -Destination (Join-Path $topFolder $nestDir.Name)
|
||||
}
|
||||
|
||||
|
||||
if ($Simple) {
|
||||
|
||||
function FolderCleanup {
|
||||
param(
|
||||
[Parameter(Mandatory = $true, Position = 0)]
|
||||
[ValidateScript( { Test-Path $_} )]
|
||||
$ParentFolder,
|
||||
[Parameter(Mandatory = $true, Position = 1)]
|
||||
[String]$ModuleName,
|
||||
[Parameter(Mandatory = $true, Position = 2)]
|
||||
$Version
|
||||
)
|
||||
|
||||
|
||||
$topFolder = Get-Item -Path (Join-Path $ParentFolder $ModuleName)
|
||||
$versionFolder = $topFolder | Get-ChildItem -Directory | Where-Object {$_.Name -eq $Version}
|
||||
$versionFolder | Get-ChildItem | Copy-Item -Destination $topFolder
|
||||
|
||||
# Checking for any nested folders within the PowerCLI module version folder
|
||||
if ($versionFolder| Get-ChildItem -Directory) {
|
||||
|
||||
# Obtaining and storing the child items to a variable, then copying the items to the parent folder's nested folder
|
||||
$nestFolder = $versionFolder| Get-ChildItem -Directory
|
||||
foreach ($nestDir in $nestFolder) {
|
||||
$nestDir | Get-ChildItem | Copy-Item -Destination (Join-Path $topFolder $nestDir.Name)
|
||||
}
|
||||
|
||||
# Removing any of the former, no longer needed, directory structure
|
||||
$versionFolder| Remove-Item -Recurse -Force
|
||||
|
||||
}
|
||||
|
||||
FolderCleanup -ParentFolder $Path -ModuleName $desiredPowerCLIModule.Name -Version $desiredPowerCLIModule.Version
|
||||
foreach ($cleanUp in $orderedDependencies) {
|
||||
|
||||
FolderCleanup -ParentFolder $Path -ModuleName $cleanUp.Name -Version $cleanUp.MinimumVersion
|
||||
}
|
||||
|
||||
|
||||
# Removing any of the former, no longer needed, directory structure
|
||||
$versionFolder| Remove-Item -Recurse -Force
|
||||
}
|
||||
|
||||
|
||||
FolderCleanup -ParentFolder $Path -ModuleName $desiredPowerCLIModule.Name -Version $desiredPowerCLIModule.Version
|
||||
foreach ($cleanUp in $orderedDependencies) {
|
||||
|
||||
FolderCleanup -ParentFolder $Path -ModuleName $cleanUp.Name -Version $cleanUp.MinimumVersion
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
50
Scripts/Set-NetworkAdapterOpaqueNetwork.ps1
Normal file
50
Scripts/Set-NetworkAdapterOpaqueNetwork.ps1
Normal file
@@ -0,0 +1,50 @@
|
||||
function Set-NetworkAdapterOpaqueNetwork {
|
||||
param(
|
||||
[Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 1)]
|
||||
[VMware.VimAutomation.Types.NetworkAdapter]
|
||||
$NetworkAdapter,
|
||||
|
||||
[Parameter(Mandatory = $true, Position = 2)]
|
||||
[string]
|
||||
$OpaqueNetworkName,
|
||||
|
||||
[Parameter()]
|
||||
[switch]
|
||||
$Connected,
|
||||
|
||||
[Parameter()]
|
||||
[switch]
|
||||
$StartConnected
|
||||
)
|
||||
process {
|
||||
$opaqueNetwork = Get-View -ViewType OpaqueNetwork | ? {$_.Name -eq $OpaqueNetworkName}
|
||||
if (-not $opaqueNetwork) {
|
||||
throw "'$OpaqueNetworkName' network not found."
|
||||
}
|
||||
|
||||
$opaqueNetworkBacking = New-Object VMware.Vim.VirtualEthernetCardOpaqueNetworkBackingInfo
|
||||
$opaqueNetworkBacking.OpaqueNetworkId = $opaqueNetwork.Summary.OpaqueNetworkId
|
||||
$opaqueNetworkBacking.OpaqueNetworkType = $opaqueNetwork.Summary.OpaqueNetworkType
|
||||
|
||||
$device = $NetworkAdapter.ExtensionData
|
||||
$device.Backing = $opaqueNetworkBacking
|
||||
|
||||
if ($StartConnected) {
|
||||
$device.Connectable.StartConnected = $true
|
||||
}
|
||||
|
||||
if ($Connected) {
|
||||
$device.Connectable.Connected = $true
|
||||
}
|
||||
|
||||
$spec = New-Object VMware.Vim.VirtualDeviceConfigSpec
|
||||
$spec.Operation = [VMware.Vim.VirtualDeviceConfigSpecOperation]::edit
|
||||
$spec.Device = $device
|
||||
$configSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
|
||||
$configSpec.DeviceChange = @($spec)
|
||||
$NetworkAdapter.Parent.ExtensionData.ReconfigVM($configSpec)
|
||||
|
||||
# Output
|
||||
Get-NetworkAdapter -Id $NetworkAdapter.Id
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user