This commit is contained in:
Kyle Ruddy
2019-06-14 10:10:26 -04:00
12 changed files with 2669 additions and 228 deletions

View File

@@ -190,7 +190,7 @@ Function Get-ContentLibraryItemFiles {
$itemIds = $contentLibraryItemService.list($libraryID) $itemIds = $contentLibraryItemService.list($libraryID)
$DatastoreID = $library.storage_backings.datastore_id.Value $DatastoreID = $library.storage_backings.datastore_id.Value
$Datastore = get-datastore -id "Datastore-$DatastoreID" $Datastore = get-datastore -id "Datastore-$DatastoreID"
foreach($itemId in $itemIds) { foreach($itemId in $itemIds) {
$itemName = ($contentLibraryItemService.get($itemId)).name $itemName = ($contentLibraryItemService.get($itemId)).name
$contentLibraryItemFileSerice = Get-CisService com.vmware.content.library.item.file $contentLibraryItemFileSerice = Get-CisService com.vmware.content.library.item.file
@@ -205,7 +205,7 @@ Function Get-ContentLibraryItemFiles {
else{ else{
$fullfilepath = "UNKNOWN" $fullfilepath = "UNKNOWN"
} }
if(!$LibraryItemName) { if(!$LibraryItemName) {
$fileResult = [pscustomobject] @{ $fileResult = [pscustomobject] @{
Name = $file.name; Name = $file.name;
@@ -709,4 +709,72 @@ 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 {
$spec = @{} If($PSBoundParameters.ContainsKey("MigrationId")){
$spec = @{
filter = @{
migrationId = $MigrationId
}
paging =@{
pageSize = $MigrationId.Count
}
}
} Else {
$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,147 +1,158 @@
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
Dynamic parameter used to specify the PowerCLI version - fixed issue with downloading the correct versions
.PARAMETER Path - added a working cleanup of unwanted versions
Directory path where the modules should be downloaded .PARAMETER RequiredVersion
.PARAMETER Repository Dynamic parameter used to specify the PowerCLI version
Repository to access the PowerCLI modules .PARAMETER Path
.PARAMETER Simple Directory path where the modules should be downloaded
Switch used to specify the nested version folders should be removed (therefore adding PowerShell 3/4 compatibility) .PARAMETER Repository
.EXAMPLE Repository to access the PowerCLI modules
Save-PowerCLI -RequiredVersion '10.0.0.7895300' -Path .\Downloads\ .PARAMETER Simple
Downloads PowerCLI 10.0.0 to the Downloads folder Switch used to specify the nested version folders should be removed (therefore adding PowerShell 3/4 compatibility)
.EXAMPLE .EXAMPLE
Save-PowerCLI -RequiredVersion '6.5.2.6268016' -Path .\Downloads\ -Simple Save-PowerCLI -RequiredVersion '10.0.0.7895300' -Path .\Downloads\
Downloads PowerCLI 6.5.2 to the Downloads folder and removes the nested version folders Downloads PowerCLI 10.0.0 to the Downloads folder
#> .EXAMPLE
[CmdletBinding(SupportsShouldProcess = $True)] Save-PowerCLI -RequiredVersion '6.5.2.6268016' -Path .\Downloads\ -Simple
param( Downloads PowerCLI 6.5.2 to the Downloads folder and removes the nested version folders
[Parameter(Mandatory = $true, Position = 1)] #>
[ValidateScript( { Test-Path $_} )] [CmdletBinding(SupportsShouldProcess = $True)]
$Path, param(
[Parameter(Mandatory = $false, Position = 2)] [Parameter(Mandatory = $true, Position = 1)]
[string]$Repository = 'PSGallery', [ValidateScript( { Test-Path $_} )]
[Parameter(Mandatory = $false, Position = 3)] $Path,
[Switch]$Simple [Parameter(Mandatory = $false, Position = 2)]
) [string]$Repository = 'PSGallery',
DynamicParam [Parameter(Mandatory = $false, Position = 3)]
{ [Switch]$Simple
# Set the dynamic parameters name )
$ParameterName = 'RequiredVersion' DynamicParam
{
# Create the dictionary # Set the dynamic parameters name
$RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary $ParameterName = 'RequiredVersion'
# Create the collection of attributes # Create the dictionary
$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
# Create and set the parameters' attributes # Create the collection of attributes
$ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
$ParameterAttribute.ValueFromPipeline = $true
$ParameterAttribute.ValueFromPipelineByPropertyName = $true # Create and set the parameters' attributes
$ParameterAttribute.Mandatory = $true $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
$ParameterAttribute.Position = 0 $ParameterAttribute.ValueFromPipeline = $true
$ParameterAttribute.ValueFromPipelineByPropertyName = $true
# Add the attributes to the attributes collection $ParameterAttribute.Mandatory = $true
$AttributeCollection.Add($ParameterAttribute) $ParameterAttribute.Position = 0
# Generate and set the ValidateSet # Add the attributes to the attributes collection
$pcliVersions = Find-Module -Name 'VMware.PowerCLI' -AllVersions $AttributeCollection.Add($ParameterAttribute)
$arrSet = $pcliVersions | select-Object -ExpandProperty Version
$ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) # Generate and set the ValidateSet
$pcliVersions = Find-Module -Name 'VMware.PowerCLI' -AllVersions
# Add the ValidateSet to the attributes collection $arrSet = $pcliVersions | select-Object -ExpandProperty Version
$AttributeCollection.Add($ValidateSetAttribute) $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)
# Create and return the dynamic parameter # Add the ValidateSet to the attributes collection
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection) $AttributeCollection.Add($ValidateSetAttribute)
$RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
return $RuntimeParameterDictionary # 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 { foreach ($remainingDep in $desiredPowerCLIModule.Dependencies) {
$powercliModuleName = 'VMware.PowerCLI' if ($orderedDependencies.Name -notcontains $remainingDep.Name) {
$desiredPowerCLIModule = Find-Module -Name $powercliModuleName -RequiredVersion $RequiredVersion -Repository $Repository $orderedDependencies += $remainingDep
$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
} 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 end {
$desiredPowerCLIModule | Save-Module -Path $Path Get-Item -Path "$($Path)\*" -PipelineVariable dir |
ForEach-Object -Process {
# Working with the depenent modules $children = Get-ChildItem -Path $dir.FullName -Directory
foreach ($dependency in $orderedDependencies) { if($children.Count -gt 1){
if (Get-ChildItem -Path (Join-Path $path $dependency.Name) | Where-Object {$_.Name -ne $dependency.MinimumVersion}) { $tgtVersion = $orderedDependencies.GetEnumerator() | where {$_.Name -eq $dir.Name}
# Save dependencies with minimum version $children | where{$_.Name -ne $tgtVersion.MinimumVersion} |
Find-Module $dependency.Name -RequiredVersion $dependency.MinimumVersion | Save-Module -Path $Path ForEach-Object -Process {
Remove-Item -Path $_.FullName -Recurse -Force -Confirm:$false
# 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 { if ($Simple) {
if ($Simple) {
function FolderCleanup {
function FolderCleanup { param(
param( [Parameter(Mandatory = $true, Position = 0)]
[Parameter(Mandatory = $true, Position = 0)] [ValidateScript( { Test-Path $_} )]
[ValidateScript( { Test-Path $_} )] $ParentFolder,
$ParentFolder, [Parameter(Mandatory = $true, Position = 1)]
[Parameter(Mandatory = $true, Position = 1)] [String]$ModuleName,
[String]$ModuleName, [Parameter(Mandatory = $true, Position = 2)]
[Parameter(Mandatory = $true, Position = 2)] $Version
$Version )
)
$topFolder = Get-Item -Path (Join-Path $ParentFolder $ModuleName)
$topFolder = Get-Item -Path (Join-Path $ParentFolder $ModuleName) $versionFolder = $topFolder | Get-ChildItem -Directory | Where-Object {$_.Name -eq $Version}
$versionFolder = $topFolder | Get-ChildItem -Directory | Where-Object {$_.Name -eq $Version} $versionFolder | Get-ChildItem | Copy-Item -Destination $topFolder
$versionFolder | Get-ChildItem | Copy-Item -Destination $topFolder
# Checking for any nested folders within the PowerCLI module version folder
# Checking for any nested folders within the PowerCLI module version folder if ($versionFolder| Get-ChildItem -Directory) {
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
# 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
$nestFolder = $versionFolder| Get-ChildItem -Directory foreach ($nestDir in $nestFolder) {
foreach ($nestDir in $nestFolder) { $nestDir | Get-ChildItem | Copy-Item -Destination (Join-Path $topFolder $nestDir.Name)
$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 # Removing any of the former, no longer needed, directory structure
foreach ($cleanUp in $orderedDependencies) { $versionFolder| Remove-Item -Recurse -Force
FolderCleanup -ParentFolder $Path -ModuleName $cleanUp.Name -Version $cleanUp.MinimumVersion
}
} }
FolderCleanup -ParentFolder $Path -ModuleName $desiredPowerCLIModule.Name -Version $desiredPowerCLIModule.Version
foreach ($cleanUp in $orderedDependencies) {
FolderCleanup -ParentFolder $Path -ModuleName $cleanUp.Name -Version $cleanUp.MinimumVersion
}
} }
} }
}