Merge pull request #2 from vmware/master

Update Fork
This commit is contained in:
Kyle Ruddy
2019-06-14 08:21:43 -04:00
committed by GitHub
12 changed files with 2669 additions and 228 deletions

View File

@@ -710,3 +710,71 @@ Function New-VMFromVMTX {
Write-Host "`nDeploying new VM $NewVMName from VMTX Template $VMTXName ..." Write-Host "`nDeploying new VM $NewVMName from VMTX Template $VMTXName ..."
$results = $vmtxService.deploy($vmtxId,$vmtxDeploySpec) $results = $vmtxService.deploy($vmtxId,$vmtxDeploySpec)
} }
Function New-SubscribedContentLibrary {
<#
.NOTES
===========================================================================
Created by: William Lam
Organization: VMware
Blog: www.virtuallyghetto.com
Twitter: @lamw
===========================================================================
.DESCRIPTION
This function creates a new Subscriber Content Library from Subscription URL
.PARAMETER LibraryName
The name of the new vSphere Content Library
.PARAMETER DatastoreName
The name of the vSphere Datastore to store the Content Library
.PARAMETER SubscriptionURL
The URL of the published Content Library
.PARAMETER SubscriptionThumbprint
The SSL Thumbprint for the published Content Library
.PARAMETER OnDemand
Specifies whether content is downloaded on-demand (e.g. no immediately)
.PARAMETER AutomaticSync
Specifies whether automatic synchronization with the external content library is enabled
.EXAMPLE
New-SubscribedContentLibrary -LibraryName NestedESXi -DatastoreName vsanDatastore -SubscriptionURL https://download3.vmware.com/software/vmw-tools/lib.json -SubscriptionThumbprint "7a:c4:08:2d:d3:55:56:af:9f:26:43:65:d0:31:99:0b:d2:f3:d8:69" -AutomaticSync
.EXAMPLE
New-SubscribedContentLibrary -LibraryName NestedESXi -DatastoreName vsanDatastore -SubscriptionURL https://download3.vmware.com/software/vmw-tools/lib.json -SubscriptionThumbprint "7a:c4:08:2d:d3:55:56:af:9f:26:43:65:d0:31:99:0b:d2:f3:d8:69" -OnDemand
#>
param(
[Parameter(Mandatory=$true)][String]$LibraryName,
[Parameter(Mandatory=$true)][String]$DatastoreName,
[Parameter(Mandatory=$true)][String]$SubscriptionURL,
[Parameter(Mandatory=$true)][String]$SubscriptionThumbprint,
[Parameter(Mandatory=$false)][Switch]$OnDemand,
[Parameter(Mandatory=$false)][Switch]$AutomaticSync
)
$datastore = Get-Datastore -Name $DatastoreName
if($datastore) {
$datastoreId = $datastore.ExtensionData.MoRef.Value
$subscribeLibraryService = Get-CisService -Name "com.vmware.content.subscribed_library"
$StorageSpec = [pscustomobject] @{
datastore_id = $datastoreId;
type = "DATASTORE";
}
$UniqueChangeId = [guid]::NewGuid().tostring()
$createSpec = $subscribeLibraryService.help.create.create_spec.create()
$createSpec.name = $LibraryName
$createSpec.type = "SUBSCRIBED"
$addResults = $createSpec.storage_backings.Add($StorageSpec)
if($OnDemand) { $OnDemandFlag = $true } else { $OnDemandFlag = $false }
if($AutomaticSync) { $AutomaticSyncFlag = $true } else { $AutomaticSyncFlag = $false }
$createSpec.subscription_info.on_demand = $OnDemandFlag
$createSpec.subscription_info.automatic_sync_enabled = $AutomaticSyncFlag
$createSpec.subscription_info.subscription_url = $SubscriptionURL
$createSpec.subscription_info.authentication_method = "NONE"
$createSpec.subscription_info.ssl_thumbprint = $SubscriptionThumbprint
Write-Host "Creating new Subscribed Content Library called $LibraryName ..."
$library = $subscribeLibraryService.create($UniqueChangeId, $createSpec)
}
}

View File

@@ -152,10 +152,12 @@ Function New-XVCMRequest {
The name of the source vSphere Datacenter The name of the source vSphere Datacenter
.PARAMETER DstDatacenter .PARAMETER DstDatacenter
The name of the destination vSphere Datacenter The name of the destination vSphere Datacenter
.PARAMETER SrcCluster
<Not needed for v2.0,removed from code>
.PARAMETER DstCluster .PARAMETER DstCluster
The name of the destination vSphere Cluster, set to null if DstHost is defined The name of the destination vSphere Cluster, set to null if DstHost is defined
.PARAMETER DstPool
The name of the destination vSphere Resource Pool
.PARAMETER DstFolder
The name of the destination vSphere Folder
.PARAMETER DstDatastore .PARAMETER DstDatastore
The name of the destination Datastore The name of the destination Datastore
.PARAMETER DstHost .PARAMETER DstHost
@@ -171,6 +173,15 @@ Function New-XVCMRequest {
-DstDatastore vsanDatastore ` -DstDatastore vsanDatastore `
-srcVMs @("PhotonOS-01","PhotonOS-02","PhotonOS-03","PhotonOS-04") ` -srcVMs @("PhotonOS-01","PhotonOS-02","PhotonOS-03","PhotonOS-04") `
-NetworkMapping @{"DVPG-VM Network 1"="DVPG-Internal Network";"DVPG-VM Network 2"="DVPG-External Network"} -NetworkMapping @{"DVPG-VM Network 1"="DVPG-Internal Network";"DVPG-VM Network 2"="DVPG-External Network"}
.EXAMPLE
New-XVCMRequest -opType Clone -SrcSite OREGON -DstSite CALIF `
-SrcDatacenter SDDC-Datacenter -srcVMs @(“DUDE-ubuntu”) `
-DstDatacenter SDDC-Datacenter `
-DstCluster "Cluster-1" -DstHost $null `
-DstPool Compute-ResourcePool `
-DstFolder Workloads `
-DstDatastore WorkloadDatastore `
-NetworkMapping @{"OREGON-VMs-sddc"="CALIF-sddc-VMs"}
#> #>
param( param(
[Parameter(Mandatory=$true)][String]$opType, #Added by CPM for 2.0 [Parameter(Mandatory=$true)][String]$opType, #Added by CPM for 2.0
@@ -178,8 +189,9 @@ Function New-XVCMRequest {
[Parameter(Mandatory=$true)][String]$DstSite, [Parameter(Mandatory=$true)][String]$DstSite,
[Parameter(Mandatory=$true)][String]$SrcDatacenter, [Parameter(Mandatory=$true)][String]$SrcDatacenter,
[Parameter(Mandatory=$true)][String]$DstDatacenter, [Parameter(Mandatory=$true)][String]$DstDatacenter,
#[Parameter(Mandatory=$true)][String]$SrcCluster, #Removed by CPM for 2.0
[Parameter(Mandatory=$true)][AllowNull()] $DstCluster, #Added [AllowNull()], removed [String] by CPM for 2.0 [Parameter(Mandatory=$true)][AllowNull()] $DstCluster, #Added [AllowNull()], removed [String] by CPM for 2.0
[Parameter(Mandatory=$true)][String]$DstPool,
[Parameter(Mandatory=$true)][String]$DstFolder,
[Parameter(Mandatory=$true)][String]$DstDatastore, [Parameter(Mandatory=$true)][String]$DstDatastore,
[Parameter(Mandatory=$true)][AllowNull()] $DstHost, #Added by CPM for 2.0 [Parameter(Mandatory=$true)][AllowNull()] $DstHost, #Added by CPM for 2.0
[Parameter(Mandatory=$true)][String[]]$srcVMs, [Parameter(Mandatory=$true)][String[]]$srcVMs,
@@ -193,7 +205,8 @@ Function New-XVCMRequest {
"targetSite"=$DstSite; "targetSite"=$DstSite;
"sourceDatacenter"=$SrcDatacenter; "sourceDatacenter"=$SrcDatacenter;
"targetDatacenter"=$dstDatacenter; "targetDatacenter"=$dstDatacenter;
#"sourceCluster"=$SrcCluster; #Removed by CPM for 2.0 "targetPool"=$DstPool;
"targetFolder"=$DstFolder;
"targetCluster"=$DstCluster; "targetCluster"=$DstCluster;
"targetDatastore"=$DstDatastore; "targetDatastore"=$DstDatastore;
"targetHost"=$DstHost; #Added by CPM for 2.0 "targetHost"=$DstHost; #Added by CPM for 2.0

Binary file not shown.

View File

@@ -0,0 +1,256 @@
Function Connect-DRaas {
<#
.NOTES
===========================================================================
Created by: William Lam
Date: 05/23/2019
Organization: VMware
Blog: http://www.virtuallyghetto.com
Twitter: @lamw
===========================================================================
.SYNOPSIS
This cmdlet creates $global:draasConnection object containing the DRaaS URL along with CSP Token Header
.DESCRIPTION
This cmdlet creates $global:draasConnection object containing the DRaaS URL along with CSP Token Header
.EXAMPLE
Connect-DRaaS -RefreshToken $RefreshToken -OrgName $OrgName -SDDCName $SDDCName
.NOTES
You must be logged into VMC using Connect-VmcServer cmdlet
#>
Param (
[Parameter(Mandatory=$true)][String]$RefreshToken,
[Parameter(Mandatory=$true)][String]$OrgName,
[Parameter(Mandatory=$true)][String]$SDDCName
)
If (-Not $global:DefaultVMCServers.IsConnected) { Write-error "No valid VMC Connection found, please use the Connect-VMC to connect"; break } Else {
$sddcService = Get-VmcService "com.vmware.vmc.orgs.sddcs"
$orgId = (Get-VMCOrg -Name $OrgName).Id
$sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
$sddc = $sddcService.get($orgId,$sddcId)
}
$results = Invoke-WebRequest -Uri "https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize?refresh_token=$RefreshToken" -Method POST -ContentType "application/json" -UseBasicParsing -Headers @{"csp-auth-token"="$RefreshToken"}
if($results.StatusCode -ne 200) {
Write-Host -ForegroundColor Red "Failed to retrieve Access Token, please ensure your VMC Refresh Token is valid and try again"
break
}
$accessToken = ($results | ConvertFrom-Json).access_token
$headers = @{
"csp-auth-token"="$accessToken"
"Content-Type"="application/json"
"Accept"="application/json"
}
$global:draasConnection = new-object PSObject -Property @{
'Server' = "https://vmc.vmware.com/vmc/draas/api/orgs/$orgId/sddcs/$sddcId/site-recovery"
'headers' = $headers
}
$global:draasConnection
}
Function Get-DRaas {
<#
.NOTES
===========================================================================
Created by: William Lam
Date: 05/23/2019
Organization: VMware
Blog: http://www.virtuallyghetto.com
Twitter: @lamw
===========================================================================
.SYNOPSIS
Returns information about DRaaS configuration for a given SDDC
.DESCRIPTION
This cmdlet returns information about DRaaS configuration for a given SDDC. Can be used to monitor both activate and deactivate operations.
.EXAMPLE
Get-DRaas
#>
Param (
[Switch]$Troubleshoot
)
If (-Not $global:draasConnection) { Write-error "No DRaaS Connection found, please use Connect-DRaaS" } Else {
$method = "GET"
$draasUrl = $global:draasConnection.Server
$draasVersionUrl = $global:draasConnection.Server + "/versions"
if($Troubleshoot) {
Write-Host -ForegroundColor cyan "`n[DEBUG] - $METHOD`n$draasUrl`n"
}
try {
if($PSVersionTable.PSEdition -eq "Core") {
$requests = Invoke-WebRequest -Uri $draasUrl -Method $method -Headers $global:draasConnection.headers -SkipCertificateCheck
} else {
$requests = Invoke-WebRequest -Uri $draasUrl -Method $method -Headers $global:draasConnection.headers
}
} catch {
if($_.Exception.Response.StatusCode -eq "Unauthorized") {
Write-Host -ForegroundColor Red "`nThe CSP session is no longer valid, please re-run the Connect-DRaaS cmdlet to retrieve a new token`n"
break
} else {
Write-Error "Error in retrieving DRaaS Information"
Write-Error "`n($_.Exception.Message)`n"
break
}
}
if($requests.StatusCode -eq 200) {
$json = ($requests.Content | ConvertFrom-Json)
$draasId = $json.id;
$draasState = $json.site_recovery_state;
$srmNode = $json.srm_node.ip_address;
$srmNodeState = $json.site_recovery_state;
$vrNode = $json.vr_node.ip_address;
$vrNodeState = $json.vr_node.state;
$draasUrl = $json.draas_h5_url;
if($srmNodeState -eq "ACTIVATED") {
if($Troubleshoot) {
Write-Host -ForegroundColor cyan "`n[DEBUG] - $METHOD`n$draasVersionUrl`n"
}
try {
if($PSVersionTable.PSEdition -eq "Core") {
$requests = Invoke-WebRequest -Uri $draasVersionUrl -Method $method -Headers $global:draasConnection.headers -SkipCertificateCheck
} else {
$requests = Invoke-WebRequest -Uri $draasVersionUrl -Method $method -Headers $global:draasConnection.headers
}
} catch {
if($_.Exception.Response.StatusCode -eq "Unauthorized") {
Write-Host -ForegroundColor Red "`nThe CSP session is no longer valid, please re-run the Connect-DRaaS cmdlet to retrieve a new token`n"
break
} else {
Write-Error "Error in retrieving DRaaS Information"
Write-Error "`n($_.Exception.Message)`n"
break
}
}
if($requests.StatusCode -eq 200) {
$json = ($requests.Content | ConvertFrom-Json).node_versions
$srmVersion,$srmDescription = ($json | where {$_.node_ip -eq $srmNode}).full_version.split("`n")
$vrVersion,$vrDescription = ($json | where {$_.node_ip -eq $vrNode}).full_version.split("`n")
$results = [pscustomobject] @{
ID = $draasId;
DRaaSState = $draasState;
SRMNode = $srmNode;
SRMVersion = $srmVersion;
SRMNodeState = $srmNodeState;
VRNode = $vrNode;
VRVersion = $vrVersion;
VRNodeState = $vrNodeState;
DRaaSURL = $draasUrl;
}
$results
}
} elseif ($srmNodeState -eq "ACTIVATING" -or $srmNodeState -eq "DEACTIVATING") {
$results = [pscustomobject] @{
ID = $draasId;
DRaaSState = $draasState;
SRMNode = $srmNode;
SRMNodeState = $srmNodeState;
VRNode = $vrNode;
VRNodeState = $vrNodeState;
DRaaSURL = $draasUrl;
}
$results
} else {
Write-Host "`nDRaaS is currently deactivated, please run Set-DRaas -Activate`n"
}
} else {
Write-Host "`nDRaaS has not been activated before, please run Set-DRaas -Activate`n"
}
}
}
Function Set-DRaas {
<#
.NOTES
===========================================================================
Created by: William Lam
Date: 05/23/2019
Organization: VMware
Blog: http://www.virtuallyghetto.com
Twitter: @lamw
===========================================================================
.SYNOPSIS
Activate or deactivate DRaaS for a given SDDC
.DESCRIPTION
This cmdlet activates or deactivates DRaaS for a given SDDC
.EXAMPLE
Get-DRaas
#>
Param (
[Switch]$Activate,
[Switch]$Deactivate,
[Switch]$Troubleshoot
)
If (-Not $global:draasConnection) { Write-error "No DRaaS Connection found, please use Connect-DRaaS" } Else {
$draasUrl = $global:draasConnection.server
if($Activate) {
$method = "POST"
if($Troubleshoot) {
Write-Host -ForegroundColor cyan "`n[DEBUG] - $METHOD`n$draasUrl`n"
}
try {
if($PSVersionTable.PSEdition -eq "Core") {
$requests = Invoke-WebRequest -Uri $draasUrl -Method $method -Headers $global:draasConnection.headers -SkipCertificateCheck
} else {
$requests = Invoke-WebRequest -Uri $draasUrl -Method $method -Headers $global:draasConnection.headers
}
} catch {
if($_.Exception.Response.StatusCode -eq "Unauthorized") {
Write-Host -ForegroundColor Red "`nThe CSP session is no longer valid, please re-run the Connect-DRaaS cmdlet to retrieve a new token`n"
break
} else {
Write-Error "Error in activating DRaaS"
Write-Error "`n($_.Exception.Message)`n"
break
}
}
Write-Host "`nActivating DRaaS, this will take some time and you can monitor the progress using Get-DRaaS or using the VMC Console UI`n"
} elseif ($Deactivate) {
$method = "DELETE"
if($Troubleshoot) {
Write-Host -ForegroundColor cyan "`n[DEBUG] - $METHOD`n$draasUrl`n"
}
try {
if($PSVersionTable.PSEdition -eq "Core") {
$requests = Invoke-WebRequest -Uri $draasUrl -Method $method -Headers $global:draasConnection.headers -SkipCertificateCheck
} else {
$requests = Invoke-WebRequest -Uri $draasUrl -Method $method -Headers $global:draasConnection.headers
}
} catch {
if($_.Exception.Response.StatusCode -eq "Unauthorized") {
Write-Host -ForegroundColor Red "`nThe CSP session is no longer valid, please re-run the Connect-DRaaS cmdlet to retrieve a new token`n"
break
} else {
Write-Error "Error in deactivating DRaaS"
Write-Error "`n($_.Exception.Message)`n"
break
}
}
Write-Host "`nDeactivating DRaaS, this will take some time and you can monitor the progress using Get-DRaaS or the VMC Console UI`n"
} else {
Write-Error "Invalid Operation"
}
}
}

View File

@@ -36,7 +36,7 @@ Description = 'PowerShell Module for Managing Hybrid Cloud Extension (HCX) on VM
PowerShellVersion = '6.0' 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. # 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' 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', 'Get-HcxLicense'
# 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. # 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 = @() CmdletsToExport = @()

View File

@@ -453,12 +453,23 @@ Function Get-HcxMigration {
Get-HcxMigration -MigrationId <MigrationID> Get-HcxMigration -MigrationId <MigrationID>
#> #>
Param ( Param (
[Parameter(Mandatory=$false)][String]$MigrationId, [Parameter(Mandatory=$false)][String[]]$MigrationId,
[Switch]$RunningMigrations [Switch]$RunningMigrations
) )
If (-Not $global:hcxConnection) { Write-error "HCX Auth Token not found, please run Connect-HcxManager " } Else { If (-Not $global:hcxConnection) { Write-error "HCX Auth Token not found, please run Connect-HcxManager " } Else {
If($PSBoundParameters.ContainsKey("MigrationId")){
$spec = @{
filter = @{
migrationId = $MigrationId
}
paging =@{
pageSize = $MigrationId.Count
}
}
} Else {
$spec = @{} $spec = @{}
}
$body = $spec | ConvertTo-Json $body = $spec | ConvertTo-Json
$hcxQueryUrl = $global:hcxConnection.Server + "/migrations?action=query" $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 $requests = Invoke-WebRequest -Uri $hcxQueryUrl -Method POST -Headers $global:hcxConnection.headers -UseBasicParsing
} }
$migrations = ($requests.content | ConvertFrom-Json).rows
if($PSBoundParameters.ContainsKey("MigrationId")){ 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){ 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 { 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" $vcConfigUrl = $global:hcxVAMIConnection.Server + "/api/admin/global/config/vcenter"
$pscConfigUrl = $global:hcxVAMIConnection.Server + "/api/admin/global/config/lookupservice"
if($PSVersionTable.PSEdition -eq "Core") { if($PSVersionTable.PSEdition -eq "Core") {
$vcRequests = Invoke-WebRequest -Uri $vcConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing -SkipCertificateCheck $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 { } else {
$vcRequests = Invoke-WebRequest -Uri $vcConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing $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 $vcData = ($vcRequests.content | ConvertFrom-Json).data.items
$ssoData = ($ssoRequests.content | ConvertFrom-Json).data.items
$tmp = [pscustomobject] @{ $tmp = [pscustomobject] @{
Name = $vcData.config.name; Name = $vcData.config.name;
UserName = $vcData.Config.userName
LookupServiceUrl = $ssoData.config.lookupServiceUrl
Version = $vcData.config.version; Version = $vcData.config.version;
Build = $vcData.config.buildNumber; Build = $vcData.config.buildNumber;
UUID = $vcData.config.vcuuid; 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 { Function Set-HcxLicense {
<# <#
.NOTES .NOTES
@@ -789,6 +838,7 @@ Function Get-HcxNSXConfig {
$tmp = [pscustomobject] @{ $tmp = [pscustomobject] @{
Name = $nsxData.config.url; Name = $nsxData.config.url;
UserName = $nsxData.config.userName
Version = $nsxData.config.version; Version = $nsxData.config.version;
HCXUUID = $nsxData.config.uuid; HCXUUID = $nsxData.config.uuid;
} }
@@ -1200,6 +1250,7 @@ Function Set-HcxProxy {
[Parameter(Mandatory=$True)]$ProxyPort, [Parameter(Mandatory=$True)]$ProxyPort,
[Parameter(Mandatory=$False)]$ProxyUser, [Parameter(Mandatory=$False)]$ProxyUser,
[Parameter(Mandatory=$False)]$ProxyPassword, [Parameter(Mandatory=$False)]$ProxyPassword,
[Parameter(Mandatory=$False)]$ProxyExclusions,
[Switch]$Troubleshoot [Switch]$Troubleshoot
) )
@@ -1214,7 +1265,7 @@ Function Set-HcxProxy {
config = @{ config = @{
proxyHost = "$ProxyServer"; proxyHost = "$ProxyServer";
proxyPort = "$ProxyPort"; proxyPort = "$ProxyPort";
nonProxyHosts = ""; nonProxyHosts = "$ProxyExclusions";
userName = "$ProxyUser"; userName = "$ProxyUser";
password = "$ProxyPassword"; password = "$ProxyPassword";
} }

File diff suppressed because it is too large Load Diff

View File

@@ -36,7 +36,13 @@ Description = 'PowerShell Module for Managing NSX-T on VMware Cloud on AWS'
PowerShellVersion = '6.0' 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. # 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-NSXTProxy', 'Get-NSXTSegment', 'New-NSXTSegment', 'Remove-NSXTSegment', 'Get-NSXTGroup', 'New-NSXTGroup', 'Remove-NSXTGroup', 'Get-NSXTService', 'New-NSXTService', 'Get-NSXTFirewall', 'New-NSXTFirewall', 'Remove-NSXTFirewall', 'Get-NSXTDistFirewallSection', 'Get-NSXTDistFirewall', 'New-NSXTDistFirewall', 'Remove-NSXTDistFirewall', 'Get-NSXTRouteTable', 'Get-NSXTOverviewInfo' FunctionsToExport = 'Connect-NSXTProxy', 'Get-NSXTSegment', 'New-NSXTSegment', 'Remove-NSXTSegment', `
'Get-NSXTGroup', 'New-NSXTGroup', 'Remove-NSXTGroup', 'Get-NSXTService', 'New-NSXTService', `
'Get-NSXTFirewall', 'New-NSXTFirewall', 'Remove-NSXTFirewall', 'Get-NSXTDistFirewallSection', `
'Get-NSXTDistFirewall', 'New-NSXTDistFirewall', 'Remove-NSXTDistFirewall', 'Get-NSXTRouteTable', `
'Get-NSXTOverviewInfo', 'Get-NSXTInfraScope', 'Get-NSXTInfraGroup', 'New-NSXTRouteBasedVPN', `
'Get-NSXTRouteBasedVPN', 'Remove-NSXTRouteBasedVPN', 'Remove-NSXTService', 'New-NSXTDistFirewallSection', 'Get-NSXTDistFirewallSection', `
'New-NSXTPolicyBasedVPN', 'Get-NSXTPolicyBasedVPN', 'Remove-NSXTPolicyBasedVPN', 'Get-NSXTDNS', 'Set-NSXTDNS'
# 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. # 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 = @() CmdletsToExport = @()

File diff suppressed because it is too large Load Diff

View File

@@ -874,8 +874,8 @@ Function Get-VMCSDDCSummary {
Get-VMCSDDCSummary -Name <SDDC Name> -Org <Org Name> Get-VMCSDDCSummary -Name <SDDC Name> -Org <Org Name>
#> #>
Param ( Param (
[Parameter(Mandatory=$True)]$OrgName, [Parameter(Mandatory=$True)]$Org,
[Parameter(Mandatory=$True)]$SDDCName [Parameter(Mandatory=$True)]$Name
) )
If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else {
@@ -895,6 +895,7 @@ Function Get-VMCSDDCSummary {
InstanceType = $sddc.resource_config.sddc_manifest.esx_ami.instance_type; InstanceType = $sddc.resource_config.sddc_manifest.esx_ami.instance_type;
VpcCIDR = $sddc.resource_config.vpc_info.vpc_cidr; VpcCIDR = $sddc.resource_config.vpc_info.vpc_cidr;
NSXT = $sddc.resource_config.nsxt; NSXT = $sddc.resource_config.nsxt;
VPC_VGW = $sddc.resource_config.vpc_info.vgw_id;
} }
$results $results
} }
@@ -903,7 +904,7 @@ Function Get-VMCPublicIP {
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created by: William Lam Created by: William LamVPC_VGW
Date: 09/12/2018 Date: 09/12/2018
Organization: VMware Organization: VMware
Blog: http://www.virtuallyghetto.com Blog: http://www.virtuallyghetto.com

View 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
}

View File

@@ -1,27 +1,30 @@
function Save-PowerCLI { function Save-PowerCLI {
<# <#
.SYNOPSIS .SYNOPSIS
Advanced function which can be used to easily download specific versions of PowerCLI from an online gallery Advanced function which can be used to easily download specific versions of PowerCLI from an online gallery
.DESCRIPTION .DESCRIPTION
Downloads a specific version of PowerCLI and all the dependencies at the appropriate version Downloads a specific version of PowerCLI and all the dependencies at the appropriate version
.NOTES .NOTES
Author: 1.0 - Dimitar Milov Author: 1.0 - Dimitar Milov
Author: 2.0 - Kyle Ruddy, @kmruddy Author: 2.0 - Kyle Ruddy, @kmruddy
.PARAMETER RequiredVersion 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 Dynamic parameter used to specify the PowerCLI version
.PARAMETER Path .PARAMETER Path
Directory path where the modules should be downloaded Directory path where the modules should be downloaded
.PARAMETER Repository .PARAMETER Repository
Repository to access the PowerCLI modules Repository to access the PowerCLI modules
.PARAMETER Simple .PARAMETER Simple
Switch used to specify the nested version folders should be removed (therefore adding PowerShell 3/4 compatibility) Switch used to specify the nested version folders should be removed (therefore adding PowerShell 3/4 compatibility)
.EXAMPLE .EXAMPLE
Save-PowerCLI -RequiredVersion '10.0.0.7895300' -Path .\Downloads\ Save-PowerCLI -RequiredVersion '10.0.0.7895300' -Path .\Downloads\
Downloads PowerCLI 10.0.0 to the Downloads folder Downloads PowerCLI 10.0.0 to the Downloads folder
.EXAMPLE .EXAMPLE
Save-PowerCLI -RequiredVersion '6.5.2.6268016' -Path .\Downloads\ -Simple 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 Downloads PowerCLI 6.5.2 to the Downloads folder and removes the nested version folders
#> #>
[CmdletBinding(SupportsShouldProcess = $True)] [CmdletBinding(SupportsShouldProcess = $True)]
param( param(
[Parameter(Mandatory = $true, Position = 1)] [Parameter(Mandatory = $true, Position = 1)]
@@ -62,14 +65,14 @@ function Save-PowerCLI {
$AttributeCollection.Add($ValidateSetAttribute) $AttributeCollection.Add($ValidateSetAttribute)
# Create and return the dynamic parameter # Create and return the dynamic parameter
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection) $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [String], $AttributeCollection)
$RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter) $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
return $RuntimeParameterDictionary return $RuntimeParameterDictionary
} }
begin { begin {
$powercliModuleName = 'VMware.PowerCLI' $powercliModuleName = 'VMware.PowerCLI'
$desiredPowerCLIModule = Find-Module -Name $powercliModuleName -RequiredVersion $RequiredVersion -Repository $Repository $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' $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 = @() $orderedDependencies = @()
@@ -94,14 +97,23 @@ function Save-PowerCLI {
if (Get-ChildItem -Path (Join-Path $path $dependency.Name) | Where-Object {$_.Name -ne $dependency.MinimumVersion}) { if (Get-ChildItem -Path (Join-Path $path $dependency.Name) | Where-Object {$_.Name -ne $dependency.MinimumVersion}) {
# Save dependencies with minimum version # Save dependencies with minimum version
Find-Module $dependency.Name -RequiredVersion $dependency.MinimumVersion | Save-Module -Path $Path 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 { 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
}
}
}
if ($Simple) { if ($Simple) {
function FolderCleanup { function FolderCleanup {
@@ -142,6 +154,5 @@ function Save-PowerCLI {
} }
} }
}
} }
}