From 5f6294cf6744880cea834fcfe87e910b86ce6415 Mon Sep 17 00:00:00 2001 From: seanpmassey Date: Mon, 5 Aug 2019 01:16:33 -0500 Subject: [PATCH 01/10] Update VMware.VMC.psm1 Add switch to Connect-VMCVIServer to allow the use of the management IP Address instead of the Public IP address. This would be used when the DNS resolution for the VMC vCenter is set to the private IP. --- Modules/VMware.VMC/VMware.VMC.psm1 | 945 +++-------------------------- 1 file changed, 94 insertions(+), 851 deletions(-) diff --git a/Modules/VMware.VMC/VMware.VMC.psm1 b/Modules/VMware.VMC/VMware.VMC.psm1 index 88eaa28..91b7cff 100644 --- a/Modules/VMware.VMC/VMware.VMC.psm1 +++ b/Modules/VMware.VMC/VMware.VMC.psm1 @@ -47,15 +47,22 @@ Function Connect-VMCVIServer { Param ( [Parameter(Mandatory=$true)]$Org, [Parameter(Mandatory=$true)]$Sddc, - [switch]$Autologin + [switch]$Autologin, + [switch]$UseManagementIP ) If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { $creds = Get-VMCSDDCDefaultCredential -Org $Org -Sddc $Sddc - Write-Host "Connecting to VMC vCenter Server" $creds.vc_public_ip - Connect-VIServer -Server $creds.vc_public_ip -User $creds.cloud_username -Password $creds.cloud_password | Add-Member -MemberType Noteproperty -Name Location -Value "VMC" - Write-Host "Connecting to VMC CIS Endpoint" $creds.vc_public_ip - Connect-CisServer -Server $creds.vc_public_ip -User $creds.cloud_username -Password $creds.cloud_password | Add-Member -MemberType Noteproperty -Name Location -Value "VMC" + If($UseManagementIP){ + $Server = $creds.vc_management_ip + }Else{ + $Server = $creds.vc_public_ip + } + + Write-Host "Connecting to VMC vCenter Server" $Server + Connect-VIServer -Server $Server -User $creds.cloud_username -Password $creds.cloud_password | Add-Member -MemberType Noteproperty -Name Location -Value "VMC" + Write-Host "Connecting to VMC CIS Endpoint" $Server + Connect-CisServer -Server $Server -User $creds.cloud_username -Password $creds.cloud_password | Add-Member -MemberType Noteproperty -Name Location -Value "VMC" } } Function Get-VMCOrg { @@ -81,13 +88,13 @@ Function Get-VMCOrg { Return all the info about the orgs you are a part of #> Param ( - [Parameter(Mandatory=$false)]$Name + [Parameter(Mandatory=$false)]$Name ) If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use Connect-VMC to connect" } Else { $orgService = Get-VMCService com.vmware.vmc.orgs if ($PSBoundParameters.ContainsKey("Name")){ - $orgs = $orgService.list() | Where {$_.display_name -eq $Name} + $orgs = $orgService.list() | Where {$_.display_name -match $Name} } Else { $orgs = $orgService.list() } @@ -130,7 +137,7 @@ Function Get-VMCSDDC { $orgID = $org.ID $sddcService = Get-VMCService com.vmware.vmc.orgs.sddcs if ($PSBoundParameters.ContainsKey("Name")){ - $sddcService.list($OrgID) | Where {$_.name -eq $Name} + $sddcService.list($OrgID) | Where {$_.name -match $Name} } Else { $sddcService.list($OrgID) } @@ -320,6 +327,7 @@ Function Get-VMCSDDCVersion { } } } + Function Get-VMCFirewallRule { <# .NOTES @@ -393,8 +401,9 @@ Function Get-VMCFirewallRule { } $results } -Function Export-VMCFirewallRule { -<# + + Function Export-VMCFirewallRule { + <# .NOTES =========================================================================== Created by: William Lam @@ -411,45 +420,45 @@ Function Export-VMCFirewallRule { .EXAMPLE Export-VMCFirewallRule -OrgName -SDDCName -GatewayType -Path "C:\Users\lamw\Desktop\VMCFirewallRules.json" #> - param( + param( [Parameter(Mandatory=$false)][String]$SDDCName, [Parameter(Mandatory=$false)][String]$OrgName, [Parameter(Mandatory=$true)][ValidateSet("MGW","CGW")][String]$GatewayType, [Parameter(Mandatory=$false)][String]$Path ) - if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } + if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } - if($GatewayType -eq "MGW") { + if($GatewayType -eq "MGW") { $EdgeId = "edge-1" } else { $EdgeId = "edge-2" } - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - if(-not $orgId) { + if(-not $orgId) { Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input" break } - if(-not $sddcId) { + if(-not $sddcId) { Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input" break } - $firewallConfigService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config + $firewallConfigService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config - $firewallRules = ($firewallConfigService.get($orgId, $sddcId, $EdgeId)).firewall_rules.firewall_rules - if(-not $ShowAll) { + $firewallRules = ($firewallConfigService.get($orgId, $sddcId, $EdgeId)).firewall_rules.firewall_rules + if(-not $ShowAll) { $firewallRules = $firewallRules | where { $_.rule_type -ne "default_policy" -and $_.rule_type -ne "internal_high" -and $_.name -ne "vSphere Cluster HA" -and $_.name -ne "Outbound Access" } | Sort-Object -Property rule_tag } else { $firewallRules = $firewallRules | Sort-Object -Property rule_tag } - $results = @() - $count = 0 - foreach ($firewallRule in $firewallRules) { + $results = @() + $count = 0 + foreach ($firewallRule in $firewallRules) { if($firewallRule.source.ip_address.Count -ne 0) { $source = $firewallRule.source.ip_address } else { @@ -471,15 +480,16 @@ Function Export-VMCFirewallRule { $count+=1 $results+=$tmp } - if($Path) { + if($Path) { Write-Host -ForegroundColor Green "Exporting $count VMC Firewall Rules to $Path ..." $results | ConvertTo-Json | Out-File $Path } else { $results | ConvertTo-Json } -} -Function Import-VMCFirewallRule { -<# + } + + Function Import-VMCFirewallRule { + <# .NOTES =========================================================================== Created by: William Lam @@ -496,43 +506,43 @@ Function Import-VMCFirewallRule { .EXAMPLE Import-VMCFirewallRule -OrgName -SDDCName -GatewayType -Path "C:\Users\lamw\Desktop\VMCFirewallRules.json" #> - param( + param( [Parameter(Mandatory=$false)][String]$SDDCName, [Parameter(Mandatory=$false)][String]$OrgName, [Parameter(Mandatory=$true)][ValidateSet("MGW","CGW")][String]$GatewayType, [Parameter(Mandatory=$false)][String]$Path ) - if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } + if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } - if($GatewayType -eq "MGW") { + if($GatewayType -eq "MGW") { $EdgeId = "edge-1" } else { $EdgeId = "edge-2" } - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - if(-not $orgId) { + if(-not $orgId) { Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input" break } - if(-not $sddcId) { + if(-not $sddcId) { Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input" break } - $firewallService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config.rules + $firewallService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config.rules - $vmcFirewallRulesJSON = Get-Content -Raw $Path | ConvertFrom-Json + $vmcFirewallRulesJSON = Get-Content -Raw $Path | ConvertFrom-Json - # Create top level Firewall Rules Object - $firewallRules = $firewallService.Help.add.firewall_rules.Create() - # Create top top level Firewall Rule Spec which will be an array of individual Firewall rules as we process them in next section - $ruleSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Create() + # Create top level Firewall Rules Object + $firewallRules = $firewallService.Help.add.firewall_rules.Create() + # Create top top level Firewall Rule Spec which will be an array of individual Firewall rules as we process them in next section + $ruleSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Create() - foreach ($vmcFirewallRule in $vmcFirewallRulesJSON) { + foreach ($vmcFirewallRule in $vmcFirewallRulesJSON) { # Create Individual Firewall Rule Element Spec $ruleElementSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.Create() @@ -629,13 +639,14 @@ Function Import-VMCFirewallRule { Write-host "Creating VMC Firewall Rule Spec:" $vmcFirewallRule.Name "..." $ruleSpecAdd = $ruleSpec.Add($ruleElementSpec) } - $firewallRules.firewall_rules = $ruleSpec + $firewallRules.firewall_rules = $ruleSpec - Write-host "Adding VMC Firewall Rules ..." - $firewallRuleAdd = $firewallService.add($orgId,$sddcId,$EdgeId,$firewallRules) -} -Function Remove-VMCFirewallRule { -<# + Write-host "Adding VMC Firewall Rules ..." + $firewallRuleAdd = $firewallService.add($orgId,$sddcId,$EdgeId,$firewallRules) + } + + Function Remove-VMCFirewallRule { + <# .NOTES =========================================================================== Created by: William Lam @@ -652,37 +663,38 @@ Function Remove-VMCFirewallRule { .EXAMPLE Remove-VMCFirewallRule -OrgName -SDDCName -GatewayType -RuleId #> - param( + param( [Parameter(Mandatory=$false)][String]$SDDCName, [Parameter(Mandatory=$false)][String]$OrgName, [Parameter(Mandatory=$true)][ValidateSet("MGW","CGW")][String]$GatewayType, [Parameter(Mandatory=$false)][String]$RuleId ) - if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } + if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } - if($GatewayType -eq "MGW") { + if($GatewayType -eq "MGW") { $EdgeId = "edge-1" } else { $EdgeId = "edge-2" } - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - if(-not $orgId) { + if(-not $orgId) { Write-Host -ForegroundColor red "Unable to find Org $OrgName, please verify input" break } - if(-not $sddcId) { + if(-not $sddcId) { Write-Host -ForegroundColor red "Unable to find SDDC $SDDCName, please verify input" break } - $firewallService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config.rules - Write-Host "Removing VMC Firewall Rule Id $RuleId ..." - $firewallService.delete($orgId,$sddcId,$EdgeId,$RuleId) -} + $firewallService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config.rules + Write-Host "Removing VMC Firewall Rule Id $RuleId ..." + $firewallService.delete($orgId,$sddcId,$EdgeId,$RuleId) + } + Function Get-VMCLogicalNetwork { <# .NOTES @@ -690,7 +702,7 @@ Function Get-VMCLogicalNetwork { Created by: Kyle Ruddy Date: 03/06/2018 Organization: VMware - Blog: https://www.kmruddy.com + Blog: https://thatcouldbeaproblem.com Twitter: @kmruddy =========================================================================== @@ -722,17 +734,9 @@ Function Get-VMCLogicalNetwork { break } - # @LucD22 - 21/10/18 - Fix for issue #176 VMware.VMC module only lists firts 20 Logical networks - # Loop until entries (total_count) are returned + $logicalNetworkService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.logical - $index = [long]0 - - $logicalNetworks = do{ - $netData = $logicalNetworkService.get_0($orgId,$sddcId,$pagesize,$index) - $netData.data | Sort-Object -Property id - $index = $index + $netdata.paging_info.page_size - } - until($index -ge $netData.paging_info.total_count) + $logicalNetworks = ($logicalNetworkService.get_0($orgId, $sddcId)).data | Sort-Object -Property id if($LogicalNetworkName) { $logicalNetworks = $logicalNetworks | Where-Object {$_.Name -eq $LogicalNetworkName} @@ -754,6 +758,7 @@ Function Get-VMCLogicalNetwork { } $results } + Function Remove-VMCLogicalNetwork { <# .NOTES @@ -761,7 +766,7 @@ Function Remove-VMCLogicalNetwork { Created by: Kyle Ruddy Date: 03/06/2018 Organization: VMware - Blog: https://www.kmruddy.com + Blog: https://thatcouldbeaproblem.com Twitter: @kmruddy =========================================================================== @@ -801,24 +806,25 @@ Function Remove-VMCLogicalNetwork { $logicalNetworkService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.logical $logicalNetworkService.delete($orgId,$sddcId,$lsId) } -Function New-VMCLogicalNetwork { -<# - .NOTES - =========================================================================== - Created by: Kyle Ruddy - Date: 03/06/2018 - Organization: VMware - Blog: https://www.kmruddy.com - Twitter: @kmruddy - =========================================================================== - .SYNOPSIS - Creates a new Logical Network - .DESCRIPTION - Creates a new Logical Network - .EXAMPLE - New-VMCLogicalNetwork -OrgName -SDDCName -LogicalNetworkName -SubnetMask -Gateway -#> +Function New-VMCLogicalNetwork { + <# + .NOTES + =========================================================================== + Created by: Kyle Ruddy + Date: 03/06/2018 + Organization: VMware + Blog: https://thatcouldbeaproblem.com + Twitter: @kmruddy + =========================================================================== + + .SYNOPSIS + Creates a new Logical Network + .DESCRIPTION + Creates a new Logical Network + .EXAMPLE + New-VMCLogicalNetwork -OrgName -SDDCName -LogicalNetworkName -SubnetMask -Gateway + #> [cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact='High')] param( [Parameter(Mandatory=$true)][String]$SDDCName, @@ -855,768 +861,5 @@ Function New-VMCLogicalNetwork { $logicalNetworkService.create($orgId, $sddcId, $logicalNetworkSpec) Get-VMCLogicalNetwork -OrgName $OrgName -SDDCName $SDDCName -LogicalNetworkName $LogicalNetworkName } -Function Get-VMCSDDCSummary { - <# - .NOTES - =========================================================================== - Created by: VMware - Date: 09/04/18 - Organization: VMware - Blog: https://www.virtuallyghetto.com - Twitter: @lamw - =========================================================================== - .SYNOPSIS - Returns a number of useful informational data about a given SDDC within VMC Org - .DESCRIPTION - Returns Version, Create/Expiration Date, Deployment Type, Region, AZ, Instance Type, VPC CIDR & NSX-T - .EXAMPLE - Get-VMCSDDCSummary -Name -Org - #> - Param ( - [Parameter(Mandatory=$True)]$Org, - [Parameter(Mandatory=$True)]$Name - ) - - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - $orgId = (Get-VMCOrg -Name $Org).Id - $sddcId = (Get-VMCSDDC -Name $Name -Org $Org).Id - - $sddcService = Get-VmcService "com.vmware.vmc.orgs.sddcs" - $sddc = $sddcService.get($orgId,$sddcId) - - $results = [pscustomobject] @{ - Version = $sddc.resource_config.sddc_manifest.vmc_version; - CreateDate = $sddc.created; - ExpirationDate = $sddc.expiration_date; - DeploymentType = $sddc.resource_config.deployment_type; - Region = $sddc.resource_config.region; - AvailabilityZone = $sddc.resource_config.availability_zones; - InstanceType = $sddc.resource_config.sddc_manifest.esx_ami.instance_type; - VpcCIDR = $sddc.resource_config.vpc_info.vpc_cidr; - NSXT = $sddc.resource_config.nsxt; - VPC_VGW = $sddc.resource_config.vpc_info.vgw_id; - } - $results - } -} -Function Get-VMCPublicIP { - <# - .NOTES - =========================================================================== - Created by: William LamVPC_VGW - Date: 09/12/2018 - Organization: VMware - Blog: http://www.virtuallyghetto.com - Twitter: @lamw - =========================================================================== - - .SYNOPSIS - Retrieves all public IP Addresses for a given SDDC - .DESCRIPTION - This cmdlet retrieves all public IP Address for a given SDDC - .EXAMPLE - Get-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName - #> - Param ( - [Parameter(Mandatory=$True)]$OrgName, - [Parameter(Mandatory=$True)]$SDDCName - ) - - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - - $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" - $publicIPs = $publicIPService.list($orgId,$sddcId) - - $publicIPs | select public_ip, name, allocation_id - } -} - -Function New-VMCPublicIP { - <# - .NOTES - =========================================================================== - Created by: William Lam - Date: 09/12/2018 - Organization: VMware - Blog: http://www.virtuallyghetto.com - Twitter: @lamw - =========================================================================== - - .SYNOPSIS - Request a new public IP Address for a given SDDC - .DESCRIPTION - This cmdlet requests a new public IP Address for a given SDDC - .EXAMPLE - New-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName -Description "Test for Randy" - #> - Param ( - [Parameter(Mandatory=$True)]$OrgName, - [Parameter(Mandatory=$True)]$SDDCName, - [Parameter(Mandatory=$False)]$Description - ) - - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - - $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" - - $publicIPSpec = $publicIPService.Help.create.spec.Create() - $publicIPSpec.count = 1 - $publicIPSpec.names = @($Description) - - Write-Host "Requesting a new public IP Address for your SDDC ..." - $results = $publicIPService.create($orgId,$sddcId,$publicIPSpec) - } -} - -Function Remove-VMCPublicIP { - <# - .NOTES - =========================================================================== - Created by: William Lam - Date: 09/12/2018 - Organization: VMware - Blog: http://www.virtuallyghetto.com - Twitter: @lamw - =========================================================================== - - .SYNOPSIS - Removes a specific public IP Addresses for a given SDDC - .DESCRIPTION - This cmdlet removes a specific public IP Address for a given SDDC - .EXAMPLE - Remove-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName -AllocationId "eipalloc-0567acf34e436c01f" - #> - Param ( - [Parameter(Mandatory=$True)]$OrgName, - [Parameter(Mandatory=$True)]$SDDCName, - [Parameter(Mandatory=$True)]$AllocationId - ) - - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - - $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" - - Write-Host "Deleting public IP Address with ID $AllocationId ..." - $results = $publicIPService.delete($orgId,$sddcId,$AllocationId) - } -} - -Function Set-VMCSDDC { - <# - .NOTES - =========================================================================== - Created by: William Lam - Date: 01/12/2019 - Organization: VMware - Blog: http://www.virtuallyghetto.com - Twitter: @lamw - =========================================================================== - - .SYNOPSIS - Rename an SDDC - .DESCRIPTION - This cmdlet renames an SDDC - .EXAMPLE - Set-VMCSDDC -SDDC $SDDCName -OrgName $OrgName -Name $NewSDDCName - #> - Param ( - [Parameter(Mandatory=$True)]$SDDCName, - [Parameter(Mandatory=$True)]$OrgName, - [Parameter(Mandatory=$True)]$Name - ) - - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - $sddc = Get-VMCSDDC -Org $OrgName -Name $SDDCName - if($sddc) { - $sddcService = Get-VmcService com.vmware.vmc.orgs.sddcs - $renameSpec = $sddcService.help.patch.sddc_patch_request.Create() - $renameSpec.name = $Name - - Write-Host "`nRenaming SDDC `'$SDDCName`' to `'$Name`' ...`n" - $results = $sddcService.patch($sddc.org_id,$sddc.id,$renameSpec) - } - } -} - -Function New-VMCPublicIP { -<# - .NOTES - =========================================================================== - Created by: William Lam - Date: 09/12/2018 - Organization: VMware - Blog: http://www.virtuallyghetto.com - Twitter: @lamw - =========================================================================== - - .SYNOPSIS - Request a new public IP Address for a given SDDC - .DESCRIPTION - This cmdlet requests a new public IP Address for a given SDDC - .EXAMPLE - New-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName -Description "Test for Randy" -#> - Param ( - [Parameter(Mandatory=$True)]$OrgName, - [Parameter(Mandatory=$True)]$SDDCName, - [Parameter(Mandatory=$False)]$Description - ) - - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - - $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" - - $publicIPSpec = $publicIPService.Help.create.spec.Create() - $publicIPSpec.count = 1 - $publicIPSpec.names = @($Description) - - Write-Host "Requesting a new public IP Address for your SDDC ..." - $results = $publicIPService.create($orgId,$sddcId,$publicIPSpec) - } -} - -Function Remove-VMCPublicIP { -<# - .NOTES - =========================================================================== - Created by: William Lam - Date: 09/12/2018 - Organization: VMware - Blog: http://www.virtuallyghetto.com - Twitter: @lamw - =========================================================================== - - .SYNOPSIS - Removes a specific public IP Addresses for a given SDDC - .DESCRIPTION - This cmdlet removes a specific public IP Address for a given SDDC - .EXAMPLE - Remove-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName -AllocationId "eipalloc-0567acf34e436c01f" -#> - Param ( - [Parameter(Mandatory=$True)]$OrgName, - [Parameter(Mandatory=$True)]$SDDCName, - [Parameter(Mandatory=$True)]$AllocationId - ) - - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - - $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" - - Write-Host "Deleting public IP Address with ID $AllocationId ..." - $results = $publicIPService.delete($orgId,$sddcId,$AllocationId) - } -} - -Function Get-VMCEdge { -<# -.NOTES -=========================================================================== -Created by: Luc Dekens -Date: 23/10/2018 -Organization: Community -Blog: http://lucd.info -Twitter: @LucD22 -=========================================================================== - -.SYNOPSIS - Returns all the VMC Edges -.DESCRIPTION - Returns all the VMC Edges -.EXAMPLE - Get-VMCEdge -OrgName $orgName -SddcName $SDDCName -EdgeType gatewayServices -#> - Param ( - [Parameter(Mandatory=$True)] - [string]$OrgName, - [Parameter(Mandatory=$True)] - [string]$SDDCName, - [ValidateSet('gatewayServices','distributedRouter')] - [string]$EdgeType = '' - ) - - If (-Not $global:DefaultVMCServers) { - Write-error "No VMC Connection found, please use the Connect-VMC to connect" - } - Else { - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - - $edgeService = Get-VmcService -Name 'com.vmware.vmc.orgs.sddcs.networks.edges' - $index = [long]0 - $edges = do{ - $edgeData = $edgeService.get($orgId,$sddcId,$EdgeType,'',$index) - $edgeData.edge_page.data | Sort-Object -Property id - $index = $index + $edgeData.edge_page.paging_info.page_size - } - until($index -ge $edgeData.paging_info.total_count) - $edges | %{ - [pscustomobject]@{ - Name = $_.Name - Id = $_.id - Type = $_.edge_type - State = $_.state - Status = $_.edge_status - VNics = $_.number_of_connected_vnics - TenantId = $_.tenant_id - } - } - } -} - -Function Get-VMCEdgeStatus { -<# -.NOTES -=========================================================================== -Created by: Luc Dekens -Date: 23/10/2018 -Organization: Community -Blog: http://lucd.info -Twitter: @LucD22 -=========================================================================== - -.SYNOPSIS - Returns the status of the gateway -.DESCRIPTION - Retrieve the status of the specified management or compute gateway (NSX Edge). -.EXAMPLE - Get-VMCEdgeStatus -OrgName $orgName -SddcName $SDDCName -Edge $EdgeName -#> - Param ( - [Parameter(Mandatory=$True)] - [string]$OrgName, - [Parameter(Mandatory=$True)] - [string]$SDDCName, - [Parameter(Mandatory=$True)] - [string]$EdgeName - ) - - If (-Not $global:DefaultVMCServers) { - Write-error "No VMC Connection found, please use the Connect-VMC to connect" - } - Else { - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - $edgeId = Get-VMCEdge -SDDCName $SDDCName -Org $OrgName | where{$_.Name -eq $EdgeName} | select -ExpandProperty Id - - $statusService = Get-VmcService -Name 'com.vmware.vmc.orgs.sddcs.networks.edges.status' - $status = $statusService.get($orgId,$sddcId,$edgeId) - - $vmStatus = $status.edge_vm_status | %{ - [pscustomobject]@{ - Name = $_.name - State = $_.edge_VM_status - HAState = $_.ha_state - Index = $_.index - } - } - $featureStatus = $status.feature_statuses | %{ - [pscustomobject]@{ - Service = $_.service - Status = $_.status - } - } - [pscustomobject]@{ - Time = [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($status.timestamp/1000)) - Status = $status.edge_status - PublishStatus = $status.publish_status - SystemStatus = $_.system_status - NicInUse = $status.ha_vnic_in_use - } - } -} - -Function Get-VMCEdgeNic { -<# -.NOTES -=========================================================================== -Created by: Luc Dekens -Date: 23/10/2018 -Organization: Community -Blog: http://lucd.info -Twitter: @LucD22 -=========================================================================== - -.SYNOPSIS - Returns all interfaces for the gateway -.DESCRIPTION - Retrieve all interfaces for the specified management or compute gateway (NSX Edge). -.EXAMPLE - Get-VMCEdgeNic -OrgName $orgName -SddcName $SDDCName -Edge $EdgeName -#> - Param ( - [Parameter(Mandatory=$True)] - [string]$OrgName, - [Parameter(Mandatory=$True)] - [string]$SDDCName, - [Parameter(Mandatory=$True)] - [string]$EdgeName - ) - - If (-Not $global:DefaultVMCServers) { - Write-error "No VMC Connection found, please use the Connect-VMC to connect" - } - Else { - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - $edgeId = Get-VMCEdge -SDDCName $SDDCName -Org $OrgName | where{$_.Name -eq $EdgeName} | select -ExpandProperty Id - - $vnicService = Get-VmcService -Name 'com.vmware.vmc.orgs.sddcs.networks.edges.vnics' - $vnicService.get($orgId,$sddcId,$edgeId) | select -ExpandProperty vnics | %{ - [pscustomobject]@{ - Label = $_.label - Name = $_.Name - Type = $_.type - Index = $_.index - IsConnected = $_.is_connected - Portgroup = $_.portgroup_name - } - } - } -} - -Function Get-VMCEdgeNicStat { -<# -.NOTES -=========================================================================== -Created by: Luc Dekens -Date: 23/10/2018 -Organization: Community -Blog: http://lucd.info -Twitter: @LucD22 -=========================================================================== - -.SYNOPSIS - Returns statistics for the gateway interfaces -.DESCRIPTION - Retrieve interface statistics for a management or compute gateway (NSX Edge). -.EXAMPLE - Get-VMCEdgeNicStat -OrgName $orgName -SddcName $SDDCName -Edge $EdgeName -#> - [CmdletBinding(DefaultParameterSetName='Default')] - Param ( - [Parameter(Mandatory=$True)] - [string]$OrgName, - [Parameter(Mandatory=$True)] - [string]$SDDCName, - [Parameter(Mandatory=$True)] - [string]$EdgeName -# [DateTime]$Start, -# [DateTime]$Finish - ) - - If (-Not $global:DefaultVMCServers) { - Write-error "No VMC Connection found, please use the Connect-VMC to connect" - } - Else { - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - $edgeId = Get-VMCEdge -SDDCName $SDDCName -Org $OrgName | where{$_.Name -eq $EdgeName} | select -ExpandProperty Id - -# $epoch = Get-Date 01/01/1970 -# -# if($start){ -# $startEpoch = (New-TimeSpan -Start $epoch -End $Start.ToUniversalTime()).TotalMilliseconds -# } -# if($Finish){ -# $finishEpoch = (New-TimeSpan -Start $epoch -End $Finish.ToUniversalTime()).TotalMilliseconds -# } - - $vnicStatService = Get-VmcService -Name 'com.vmware.vmc.orgs.sddcs.networks.edges.statistics.interfaces' -# $stats = $vnicStatService.get($orgId,$sddcId,$edgeId,[long]$startEpoch,[long]$finishEpoch) - $stats = $vnicStatService.get($orgId,$sddcId,$edgeId) - - $stats.data_dto | Get-Member -MemberType NoteProperty | where{$_.Name -ne 'Help'} | %{$_.Name} | %{ - $stats.data_dto."$_" | %{ - [pscustomobject]@{ - vNIC = $_.vnic - Timestamp = [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($_.timestamp)) - In = $_.in - Out = $_.out - Unit = 'Kbps' - Interval = $stats.meta_dto.interval - } - } - } - } -} - -Function Get-VMCEdgeUplinkStat { -<# -.NOTES -=========================================================================== -Created by: Luc Dekens -Date: 23/10/2018 -Organization: Community -Blog: http://lucd.info -Twitter: @LucD22 -=========================================================================== - -.SYNOPSIS - Returns statistics for the uplink interfaces -.DESCRIPTION - Retrieve uplink interface statistics for a management or compute gateway (NSX Edge). -.EXAMPLE - Get-VMCEdgeUplinkStat -OrgName $orgName -SddcName $SDDCName -Edge $EdgeName -#> - Param ( - [Parameter(Mandatory=$True)] - [string]$OrgName, - [Parameter(Mandatory=$True)] - [string]$SDDCName, - [Parameter(Mandatory=$True)] - [string]$EdgeName -# [DateTime]$Start, -# [DateTime]$Finish - ) - - If (-Not $global:DefaultVMCServers) { - Write-error "No VMC Connection found, please use the Connect-VMC to connect" - } - Else { - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - $edgeId = Get-VMCEdge -SDDCName $SDDCName -Org $OrgName | where{$_.Name -eq $EdgeName} | select -ExpandProperty Id - -# $epoch = Get-Date 01/01/1970 -# -# if($start){ -# $startEpoch = (New-TimeSpan -Start $epoch -End $Start.ToUniversalTime()).TotalMilliseconds -# } -# if($Finish){ -# $finishEpoch = (New-TimeSpan -Start $epoch -End $Finish.ToUniversalTime()).TotalMilliseconds -# } - - $uplinkStatService = Get-VmcService -Name 'com.vmware.vmc.orgs.sddcs.networks.edges.statistics.interfaces.uplink' -# $stats = $uplinkStatService.get($orgId,$sddcId,$edgeId,[long]$startEpoch,[long]$finishEpoch) - $stats = $uplinkStatService.get($orgId,$sddcId,$edgeId) - - $stats.data_dto | Get-Member -MemberType NoteProperty | where{$_.Name -ne 'Help'} | %{$_.Name} | %{ - if($stats.data_dto."$_".Count -ne 0){ - $stats.data_dto."$_" | %{ - [pscustomobject]@{ - vNIC = $_.vnic - Timestamp = [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($_.timestamp)) - In = $_.in - Out = $_.out - Unit = 'Kbps' - Interval = $stats.meta_dto.interval - } - } - } - } - } -} -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 -SDDCName -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 -SDDCName -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 -SDDCName -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 -SDDCName -Cluster - #> - [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-VMCSDDCCluster', 'New-VMCSDDCCluster', 'Remove-VMCSDDCCluster' \ No newline at end of file +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' \ No newline at end of file From 5325596b2fab2bbfeddb957f525ba74d76ccd9ce Mon Sep 17 00:00:00 2001 From: seanpmassey Date: Wed, 7 Aug 2019 15:17:43 -0500 Subject: [PATCH 02/10] Delete VMware.VMC.psm1 --- Modules/VMware.VMC/VMware.VMC.psm1 | 865 ----------------------------- 1 file changed, 865 deletions(-) delete mode 100644 Modules/VMware.VMC/VMware.VMC.psm1 diff --git a/Modules/VMware.VMC/VMware.VMC.psm1 b/Modules/VMware.VMC/VMware.VMC.psm1 deleted file mode 100644 index 91b7cff..0000000 --- a/Modules/VMware.VMC/VMware.VMC.psm1 +++ /dev/null @@ -1,865 +0,0 @@ -Function Get-VMCCommand { -<# - .NOTES - =========================================================================== - Created by: VMware - Date: 11/17/2017 - Organization: VMware - Blog: http://vmware.com/go/powercli - Twitter: @powercli - =========================================================================== - - .SYNOPSIS - Returns all cmdlets for VMware Cloud on AWS - .DESCRIPTION - This cmdlet will allow you to return all cmdlets included in the VMC module - .EXAMPLE - Get-VMCCommand - .EXAMPLE - Get-Command -Module VMware.VMC - .NOTES - You can either use this cmdlet or the Get-Command cmdlet as seen in Example 2 -#> - Get-command -Module VMware.VimAutomation.Vmc - Get-Command -Module VMware.VMC - -} -Function Connect-VMCVIServer { -<# - .NOTES - =========================================================================== - Created by: VMware - Date: 11/17/2017 - Organization: VMware - Blog: http://vmware.com/go/powercli - Twitter: @powercli - =========================================================================== - - .SYNOPSIS - Cmdlet to connect to your VMC vCenter Server - .DESCRIPTION - This will connect you to both the VMC ViServer as well as the CiSServer at the same time. - .EXAMPLE - Connect-VMCVIServer -Server -User -Password - .NOTES - Easiest way is to pipe through your credentials from Get-VMCSDDCDefaultCredential -#> - Param ( - [Parameter(Mandatory=$true)]$Org, - [Parameter(Mandatory=$true)]$Sddc, - [switch]$Autologin, - [switch]$UseManagementIP - ) - - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - $creds = Get-VMCSDDCDefaultCredential -Org $Org -Sddc $Sddc - If($UseManagementIP){ - $Server = $creds.vc_management_ip - }Else{ - $Server = $creds.vc_public_ip - } - - Write-Host "Connecting to VMC vCenter Server" $Server - Connect-VIServer -Server $Server -User $creds.cloud_username -Password $creds.cloud_password | Add-Member -MemberType Noteproperty -Name Location -Value "VMC" - Write-Host "Connecting to VMC CIS Endpoint" $Server - Connect-CisServer -Server $Server -User $creds.cloud_username -Password $creds.cloud_password | Add-Member -MemberType Noteproperty -Name Location -Value "VMC" - } -} -Function Get-VMCOrg { -<# - .NOTES - =========================================================================== - Created by: VMware - Date: 11/17/2017 - Organization: VMware - Blog: http://vmware.com/go/powercli - Twitter: @powercli - =========================================================================== - - .SYNOPSIS - Return the Orgs that you are a part of - .DESCRIPTION - Depending on what you've purchased, you may be a part of one or more VMC Orgs. This will return your orgs - .EXAMPLE - Get-VMCOrg - .EXAMPLE - Get-VMCOrg -Name - .NOTES - Return all the info about the orgs you are a part of -#> - Param ( - [Parameter(Mandatory=$false)]$Name - ) - - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use Connect-VMC to connect" } Else { - $orgService = Get-VMCService com.vmware.vmc.orgs - if ($PSBoundParameters.ContainsKey("Name")){ - $orgs = $orgService.list() | Where {$_.display_name -match $Name} - } Else { - $orgs = $orgService.list() - } - $Orgs | Select display_name, name, user_name, created, id - } -} -Function Get-VMCSDDC { -<# - .NOTES - =========================================================================== - Created by: VMware - Date: 11/17/2017 - Organization: VMware - Blog: http://vmware.com/go/powercli - Twitter: @powercli - =========================================================================== - - .SYNOPSIS - Returns all of the SDDCs you are associated to - .DESCRIPTION - Returns all of the SDDCs ayou are associated to - .EXAMPLE - Get-VMCSDDC -Org - .EXAMPLE - Get-VMCSDDC -Name -Org -#> - Param ( - [Parameter(Mandatory=$True)]$Org, - [Parameter(Mandatory=$false)]$Name - ) - - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - if ($PSBoundParameters.ContainsKey("Org")){ - $orgs = Get-VMCOrg -Name $Org - } else { - $orgs = Get-VMCOrg - } - - foreach ($org in $orgs) { - $orgID = $org.ID - $sddcService = Get-VMCService com.vmware.vmc.orgs.sddcs - if ($PSBoundParameters.ContainsKey("Name")){ - $sddcService.list($OrgID) | Where {$_.name -match $Name} - } Else { - $sddcService.list($OrgID) - } - } - } -} -Function Get-VMCTask { -<# - .NOTES - =========================================================================== - Created by: VMware - Date: 11/17/2017 - Organization: VMware - Blog: http://vmware.com/go/powercli - Twitter: @powercli - =========================================================================== - - .SYNOPSIS - Returns all of the VMC Tasks - .DESCRIPTION - Returns all of the VMC Tasks that have either occurred or are in process - .EXAMPLE - Get-VMCTask -#> - Param ( - [Parameter(Mandatory=$True)]$Org - ) - - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - if ($PSBoundParameters.ContainsKey("Org")){ - $orgs = Get-VMCOrg -Name $Org - } else { - $orgs = Get-VMCOrg - } - - foreach ($org in $orgs) { - $orgID = $org.ID - $taskService = Get-VMCService com.vmware.vmc.orgs.tasks - $taskService.list($OrgID) | Select * -ExcludeProperty Help - } - } -} -Function Get-VMCSDDCDefaultCredential { -<# - .NOTES - =========================================================================== - Created by: VMware - Date: 11/17/2017 - Organization: VMware - Blog: http://vmware.com/go/powercli - Twitter: @powercli - =========================================================================== - - .SYNOPSIS - Returns the default credential for the SDDC - .DESCRIPTION - Returns the default credential for the sddc - .EXAMPLE - Get-VMCSDDCDefaultCredential -Org - .EXAMPLE - Get-VMCSDDCDefaultCredential -Sddc -Org -#> - Param ( - [Parameter(Mandatory=$true)]$Org, - [Parameter(Mandatory=$false)]$Sddc - ) - - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - if ($PSBoundParameters.ContainsKey("Sddc")){ - $sddcs = Get-VMCSDDC -Name $Sddc -Org $Org - } else { - $sddcs = Get-VMCSDDC -Org $Org - } - - foreach ($sddc in $sddcs) { - $sddc.resource_config | Select-object vc_url, vc_management_ip, vc_public_ip, cloud_username, cloud_password - } - } -} -Function Get-VMCSDDCPublicIP { -<# - .NOTES - =========================================================================== - Created by: VMware - Date: 11/17/2017 - Organization: VMware - Blog: http://vmware.com/go/powercli - Twitter: @powercli - =========================================================================== - - .SYNOPSIS - Returns your Public IPs - .DESCRIPTION - Returns your Public IPs - .EXAMPLE - Get-VMCSDDCPublicIP -Org - .EXAMPLE - Get-VMCSDDCPublicIP -Sddc -Org - .NOTES - Return your Public IPs that you have assigned to your account -#> - Param ( - [Parameter(Mandatory=$true)]$Org, - [Parameter(Mandatory=$false)]$Sddc - ) - - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - if ($PSBoundParameters.ContainsKey("Sddc")){ - $sddcs = Get-VMCSDDC -Name $Sddc -Org $Org - } else { - $sddcs = Get-VMCSDDC -Org $Org - } - - foreach ($sddc in $sddcs) { - $sddc.resource_config.Public_ip_pool - } - } -} -Function Get-VMCVMHost { - Param ( - [Parameter(Mandatory=$false)]$Sddc, - [Parameter(Mandatory=$true)]$Org - ) - - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - if ($PSBoundParameters.ContainsKey("Sddc")){ - $sddcs = Get-VMCSDDC -Name $Sddc -Org $Org - } else { - $sddcs = Get-VMCSDDC -Org $Org - } - - $results = @() - foreach ($sddc in $sddcs) { - foreach ($vmhost in $sddc.resource_config.esx_hosts) { - $tmp = [pscustomobject] @{ - esx_id = $vmhost.esx_id; - name = $vmhost.name; - hostname = $vmhost.hostname; - esx_state = $vmhost.esx_state; - sddc_id = $sddc.id; - org_id = $sddc.org_id; - } - $results += $tmp - } - $results - } - } -} -Function Get-VMCSDDCVersion { -<# - .NOTES - =========================================================================== - Created by: VMware - Date: 11/17/2017 - Organization: VMware - Blog: http://vmware.com/go/powercli - Twitter: @powercli - =========================================================================== - - .SYNOPSIS - Returns SDDC Version - .DESCRIPTION - Returns Version of the SDDC - .EXAMPLE - Get-VMCSDDCVersion -Name -Org -#> - Param ( - [Parameter(Mandatory=$True)]$Org, - [Parameter(Mandatory=$false)]$Name - ) - - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - if ($PSBoundParameters.ContainsKey("Org")){ - $orgs = Get-VMCOrg -Name $Org - } else { - $orgs = Get-VMCOrg - } - - foreach ($org in $orgs) { - $orgID = $org.ID - $sddcService = Get-VMCService com.vmware.vmc.orgs.sddcs - if ($PSBoundParameters.ContainsKey("Name")){ - ($sddcService.list($OrgID) | Where {$_.name -match $Name}).resource_config.sddc_manifest | Select *version - } Else { - ($sddcService.list($OrgID)).resource_config.sddc_manifest | Select *version - } - } - } -} - -Function Get-VMCFirewallRule { - <# - .NOTES - =========================================================================== - Created by: William Lam - Date: 11/19/2017 - Organization: VMware - Blog: https://www.virtuallyghetto.com - Twitter: @lamw - =========================================================================== - - .SYNOPSIS - Retruns VMC Firewall Rules for a given Gateway (MGW or CGW) - .DESCRIPTION - Retruns VMC Firewall Rules for a given Gateway (MGW or CGW) - .EXAMPLE - Get-VMCFirewallRule -OrgName -SDDCName -GatewayType - .EXAMPLE - Get-VMCFirewallRule -OrgName -SDDCName -GatewayType -ShowAll - #> - param( - [Parameter(Mandatory=$false)][String]$SDDCName, - [Parameter(Mandatory=$false)][String]$OrgName, - [Parameter(Mandatory=$false)][Switch]$ShowAll, - [Parameter(Mandatory=$true)][ValidateSet("MGW","CGW")][String]$GatewayType - ) - - if($GatewayType -eq "MGW") { - $EdgeId = "edge-1" - } else { - $EdgeId = "edge-2" - } - - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - - $firewallConfigService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config - - $firewallRules = ($firewallConfigService.get($orgId, $sddcId, $EdgeId)).firewall_rules.firewall_rules - if(-not $ShowAll) { - $firewallRules = $firewallRules | where { $_.rule_type -ne "default_policy" -and $_.rule_type -ne "internal_high" -and $_.name -ne "vSphere Cluster HA" -and $_.name -ne "Outbound Access" } | Sort-Object -Property rule_tag - } else { - $firewallRules = $firewallRules | Sort-Object -Property rule_tag - } - - $results = @() - foreach ($firewallRule in $firewallRules) { - if($firewallRule.source.ip_address.Count -ne 0) { - $source = $firewallRule.source.ip_address - } else { $source = "ANY" } - - if($firewallRule.application.service.protocol -ne $null) { - $protocol = $firewallRule.application.service.protocol - } else { $protocol = "ANY" } - - if($firewallRule.application.service.port -ne $null) { - $port = $firewallRule.application.service.port - } else { $port = "ANY" } - - $tmp = [pscustomobject] @{ - ID = $firewallRule.rule_id; - Name = $firewallRule.name; - Type = $firewallRule.rule_type; - Action = $firewallRule.action; - Protocol = $protocol; - Port = $port; - SourceAddress = $source - DestinationAddress = $firewallRule.destination.ip_address; - } - $results+=$tmp - } - $results - } - - Function Export-VMCFirewallRule { - <# - .NOTES - =========================================================================== - Created by: William Lam - Date: 11/19/2017 - Organization: VMware - Blog: https://www.virtuallyghetto.com - Twitter: @lamw - =========================================================================== - - .SYNOPSIS - Exports all "customer" created VMC Firewall Rules to JSON file - .DESCRIPTION - Exports all "customer" created VMC Firewall Rules to JSON file - .EXAMPLE - Export-VMCFirewallRule -OrgName -SDDCName -GatewayType -Path "C:\Users\lamw\Desktop\VMCFirewallRules.json" - #> - param( - [Parameter(Mandatory=$false)][String]$SDDCName, - [Parameter(Mandatory=$false)][String]$OrgName, - [Parameter(Mandatory=$true)][ValidateSet("MGW","CGW")][String]$GatewayType, - [Parameter(Mandatory=$false)][String]$Path - ) - - if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } - - if($GatewayType -eq "MGW") { - $EdgeId = "edge-1" - } else { - $EdgeId = "edge-2" - } - - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).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 - } - - $firewallConfigService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config - - $firewallRules = ($firewallConfigService.get($orgId, $sddcId, $EdgeId)).firewall_rules.firewall_rules - if(-not $ShowAll) { - $firewallRules = $firewallRules | where { $_.rule_type -ne "default_policy" -and $_.rule_type -ne "internal_high" -and $_.name -ne "vSphere Cluster HA" -and $_.name -ne "Outbound Access" } | Sort-Object -Property rule_tag - } else { - $firewallRules = $firewallRules | Sort-Object -Property rule_tag - } - - $results = @() - $count = 0 - foreach ($firewallRule in $firewallRules) { - if($firewallRule.source.ip_address.Count -ne 0) { - $source = $firewallRule.source.ip_address - } else { - $source = "ANY" - } - - $tmp = [pscustomobject] @{ - Name = $firewallRule.name; - Action = $firewallRule.action; - Protocol = $firewallRule.application.service.protocol; - Port = $firewallRule.application.service.port; - SourcePort = $firewallRule.application.service.source_port; - ICMPType = $firewallRule.application.service.icmp_type; - SourceAddress = $firewallRule.source.ip_address; - DestinationAddress = $firewallRule.destination.ip_address; - Enabled = $firewallRule.enabled; - Logging = $firewallRule.logging_enabled; - } - $count+=1 - $results+=$tmp - } - if($Path) { - Write-Host -ForegroundColor Green "Exporting $count VMC Firewall Rules to $Path ..." - $results | ConvertTo-Json | Out-File $Path - } else { - $results | ConvertTo-Json - } - } - - Function Import-VMCFirewallRule { - <# - .NOTES - =========================================================================== - Created by: William Lam - Date: 11/19/2017 - Organization: VMware - Blog: https://www.virtuallyghetto.com - Twitter: @lamw - =========================================================================== - - .SYNOPSIS - Imports VMC Firewall Rules from exported JSON configuration file - .DESCRIPTION - Imports VMC Firewall Rules from exported JSON configuration file - .EXAMPLE - Import-VMCFirewallRule -OrgName -SDDCName -GatewayType -Path "C:\Users\lamw\Desktop\VMCFirewallRules.json" - #> - param( - [Parameter(Mandatory=$false)][String]$SDDCName, - [Parameter(Mandatory=$false)][String]$OrgName, - [Parameter(Mandatory=$true)][ValidateSet("MGW","CGW")][String]$GatewayType, - [Parameter(Mandatory=$false)][String]$Path - ) - - if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } - - if($GatewayType -eq "MGW") { - $EdgeId = "edge-1" - } else { - $EdgeId = "edge-2" - } - - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).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 - } - - $firewallService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config.rules - - $vmcFirewallRulesJSON = Get-Content -Raw $Path | ConvertFrom-Json - - # Create top level Firewall Rules Object - $firewallRules = $firewallService.Help.add.firewall_rules.Create() - # Create top top level Firewall Rule Spec which will be an array of individual Firewall rules as we process them in next section - $ruleSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Create() - - foreach ($vmcFirewallRule in $vmcFirewallRulesJSON) { - # Create Individual Firewall Rule Element Spec - $ruleElementSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.Create() - - # AppSpec - $appSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.application.Create() - # ServiceSpec - $serviceSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.application.service.Element.Create() - - $protocol = $null - if($vmcFirewallRule.Protocol -ne $null) { - $protocol = $vmcFirewallRule.Protocol - } - $serviceSpec.protocol = $protocol - - # Process ICMP Type from JSON - $icmpType = $null - if($vmcFirewallRule.ICMPType -ne $null) { - $icmpType = $vmcFirewallRule.ICMPType - } - $serviceSpec.icmp_type = $icmpType - - # Process Source Ports from JSON - $sourcePorts = @() - if($vmcFirewallRule.SourcePort -eq "any" -or $vmcFirewallRule.SourcePort -ne $null) { - foreach ($port in $vmcFirewallRule.SourcePort) { - $sourcePorts+=$port - } - } else { - $sourcePorts = @("any") - } - $serviceSpec.source_port = $sourcePorts - - # Process Ports from JSON - $ports = @() - if($vmcFirewallRule.Port -ne "null") { - foreach ($port in $vmcFirewallRule.Port) { - $ports+=$port - } - } - $serviceSpec.port = $ports - $addSpec = $appSpec.service.Add($serviceSpec) - - # Create Source Spec - $srcSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.source.Create() - $srcSpec.exclude = $false - # Process Source Address from JSON - $sourceAddess = @() - if($vmcFirewallRule.SourceAddress -ne "null") { - foreach ($address in $vmcFirewallRule.SourceAddress) { - $sourceAddess+=$address - } - } - $srcSpec.ip_address = $sourceAddess; - - # Create Destination Spec - $destSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.destination.Create() - $destSpec.exclude = $false - # Process Destination Address from JSON - $destinationAddess = @() - if($vmcFirewallRule.DestinationAddress -ne "null") { - foreach ($address in $vmcFirewallRule.DestinationAddress) { - $destinationAddess+=$address - } - } - $destSpec.ip_address = $destinationAddess - - # Add various specs - if($vmcFirewallRule.Protocol -ne $null -and $vmcFirewallRule.port -ne $null) { - $ruleElementSpec.application = $appSpec - } - - $ruleElementSpec.source = $srcSpec - $ruleElementSpec.destination = $destSpec - $ruleElementSpec.rule_type = "user" - - # Process Enabled from JSON - $fwEnabled = $false - if($vmcFirewallRule.Enabled -eq "true") { - $fwEnabled = $true - } - $ruleElementSpec.enabled = $fwEnabled - - # Process Logging from JSON - $loggingEnabled = $false - if($vmcFirewallRule.Logging -eq "true") { - $loggingEnabled = $true - } - $ruleElementSpec.logging_enabled = $loggingEnabled - - $ruleElementSpec.action = $vmcFirewallRule.Action - $ruleElementSpec.name = $vmcFirewallRule.Name - - # Add the individual FW rule spec into our overall firewall rules array - Write-host "Creating VMC Firewall Rule Spec:" $vmcFirewallRule.Name "..." - $ruleSpecAdd = $ruleSpec.Add($ruleElementSpec) - } - $firewallRules.firewall_rules = $ruleSpec - - Write-host "Adding VMC Firewall Rules ..." - $firewallRuleAdd = $firewallService.add($orgId,$sddcId,$EdgeId,$firewallRules) - } - - Function Remove-VMCFirewallRule { - <# - .NOTES - =========================================================================== - Created by: William Lam - Date: 11/19/2017 - Organization: VMware - Blog: https://www.virtuallyghetto.com - Twitter: @lamw - =========================================================================== - - .SYNOPSIS - Removes VMC Firewall Rule given Rule Id - .DESCRIPTION - Removes VMC Firewall Rule given Rule Id - .EXAMPLE - Remove-VMCFirewallRule -OrgName -SDDCName -GatewayType -RuleId - #> - param( - [Parameter(Mandatory=$false)][String]$SDDCName, - [Parameter(Mandatory=$false)][String]$OrgName, - [Parameter(Mandatory=$true)][ValidateSet("MGW","CGW")][String]$GatewayType, - [Parameter(Mandatory=$false)][String]$RuleId - ) - - if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } - - if($GatewayType -eq "MGW") { - $EdgeId = "edge-1" - } else { - $EdgeId = "edge-2" - } - - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).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 - } - - $firewallService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config.rules - Write-Host "Removing VMC Firewall Rule Id $RuleId ..." - $firewallService.delete($orgId,$sddcId,$EdgeId,$RuleId) - } - -Function Get-VMCLogicalNetwork { - <# - .NOTES - =========================================================================== - Created by: Kyle Ruddy - Date: 03/06/2018 - Organization: VMware - Blog: https://thatcouldbeaproblem.com - Twitter: @kmruddy - =========================================================================== - - .SYNOPSIS - Retruns VMC Logical Networks for a given SDDC - .DESCRIPTION - Retruns VMC Logical Networks for a given SDDC - .EXAMPLE - Get-VMCLogicalNetwork -OrgName -SDDCName - .EXAMPLE - Get-VMCLogicalNetwork -OrgName -SDDCName -LogicalNetworkName - #> - param( - [Parameter(Mandatory=$true)][String]$SDDCName, - [Parameter(Mandatory=$true)][String]$OrgName, - [Parameter(Mandatory=$false)][String]$LogicalNetworkName - - ) - - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).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 - } - - $logicalNetworkService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.logical - - $logicalNetworks = ($logicalNetworkService.get_0($orgId, $sddcId)).data | Sort-Object -Property id - - if($LogicalNetworkName) { - $logicalNetworks = $logicalNetworks | Where-Object {$_.Name -eq $LogicalNetworkName} - } - - $results = @() - foreach ($logicalNetwork in $logicalNetworks) { - $tmp = [pscustomobject] @{ - ID = $logicalNetwork.id; - Name = $logicalNetwork.name; - SubnetMask = $logicalNetwork.subnets.address_groups.prefix_length; - Gateway = $logicalNetwork.subnets.address_groups.primary_address; - DHCPipRange = $logicalNetwork.dhcp_configs.ip_pools.ip_range; - DHCPdomain = $logicalNetwork.dhcp_configs.ip_pools.domain_name; - CGatewayID = $logicalNetwork.cgw_id; - CGateway = $logicalNetwork.cgw_name; - } - $results+=$tmp - } - $results -} - -Function Remove-VMCLogicalNetwork { - <# - .NOTES - =========================================================================== - Created by: Kyle Ruddy - Date: 03/06/2018 - Organization: VMware - Blog: https://thatcouldbeaproblem.com - Twitter: @kmruddy - =========================================================================== - - .SYNOPSIS - Removes Logical Network given ID - .DESCRIPTION - Removes Logical Network given ID - .EXAMPLE - Remove-VMCLogicalNetwork -OrgName -SDDCName -LogicalNetworkName - #> - [cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact='High')] - param( - [Parameter(Mandatory=$true)][String]$SDDCName, - [Parameter(Mandatory=$true)][String]$OrgName, - [Parameter(Mandatory=$true)][String]$LogicalNetworkName - ) - - if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } - - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id - $lsId = (Get-VMCLogicalNetwork -OrgName $OrgName -SDDCName $SDDCName -LogicalNetworkName $LogicalNetworkName).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 $lsId) { - Write-Host -ForegroundColor red "Unable to find SDDC $LogicalNetworkName, please verify input" - break - } - - $logicalNetworkService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.logical - $logicalNetworkService.delete($orgId,$sddcId,$lsId) -} - -Function New-VMCLogicalNetwork { - <# - .NOTES - =========================================================================== - Created by: Kyle Ruddy - Date: 03/06/2018 - Organization: VMware - Blog: https://thatcouldbeaproblem.com - Twitter: @kmruddy - =========================================================================== - - .SYNOPSIS - Creates a new Logical Network - .DESCRIPTION - Creates a new Logical Network - .EXAMPLE - New-VMCLogicalNetwork -OrgName -SDDCName -LogicalNetworkName -SubnetMask -Gateway - #> - [cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact='High')] - param( - [Parameter(Mandatory=$true)][String]$SDDCName, - [Parameter(Mandatory=$true)][String]$OrgName, - [Parameter(Mandatory=$true)][String]$LogicalNetworkName, - [Parameter(Mandatory=$true)][String]$SubnetMask, - [Parameter(Mandatory=$true)][String]$Gateway - ) - - if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } - - $orgId = (Get-VMCOrg -Name $OrgName).Id - $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).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 - } - - $logicalNetworkService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.logical - $logicalNetworkSpec = $logicalNetworkService.Help.create.sddc_network.Create() - $logicalNetworkSpec.name = $LogicalNetworkName - $logicalNetworkSpec.cgw_id = "edge-2" - $logicalNetworkSpec.cgw_name = "SDDC-CGW-1" - $logicalNetworkAddressGroupSpec = $logicalNetworkService.Help.create.sddc_network.subnets.address_groups.Element.Create() - $logicalNetworkAddressGroupSpec.prefix_length = $SubnetMask - $logicalNetworkAddressGroupSpec.primary_address = $Gateway - - $logicalNetworkSpec.subnets.address_groups.Add($logicalNetworkAddressGroupSpec) | Out-Null - $logicalNetworkService.create($orgId, $sddcId, $logicalNetworkSpec) - Get-VMCLogicalNetwork -OrgName $OrgName -SDDCName $SDDCName -LogicalNetworkName $LogicalNetworkName -} - -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' \ No newline at end of file From 2c79a86531df8c20a51041185db34d68fd42cb85 Mon Sep 17 00:00:00 2001 From: seanpmassey Date: Wed, 7 Aug 2019 15:22:51 -0500 Subject: [PATCH 03/10] Create VMware.VMC.psm1 --- Modules/VMware.VMC/VMware.VMC.psm1 | 1629 ++++++++++++++++++++++++++++ 1 file changed, 1629 insertions(+) create mode 100644 Modules/VMware.VMC/VMware.VMC.psm1 diff --git a/Modules/VMware.VMC/VMware.VMC.psm1 b/Modules/VMware.VMC/VMware.VMC.psm1 new file mode 100644 index 0000000..dd74f2a --- /dev/null +++ b/Modules/VMware.VMC/VMware.VMC.psm1 @@ -0,0 +1,1629 @@ +Function Get-VMCCommand { +<# + .NOTES + =========================================================================== + Created by: VMware + Date: 11/17/2017 + Organization: VMware + Blog: http://vmware.com/go/powercli + Twitter: @powercli + =========================================================================== + + .SYNOPSIS + Returns all cmdlets for VMware Cloud on AWS + .DESCRIPTION + This cmdlet will allow you to return all cmdlets included in the VMC module + .EXAMPLE + Get-VMCCommand + .EXAMPLE + Get-Command -Module VMware.VMC + .NOTES + You can either use this cmdlet or the Get-Command cmdlet as seen in Example 2 +#> + Get-command -Module VMware.VimAutomation.Vmc + Get-Command -Module VMware.VMC + +} +Function Connect-VMCVIServer { + <# + .NOTES + =========================================================================== + Created by: VMware + Date: 11/17/2017 + Organization: VMware + Blog: http://vmware.com/go/powercli + Twitter: @powercli + =========================================================================== + + .SYNOPSIS + Cmdlet to connect to your VMC vCenter Server + .DESCRIPTION + This will connect you to both the VMC ViServer as well as the CiSServer at the same time. + .EXAMPLE + Connect-VMCVIServer -Server -User -Password + .NOTES + Easiest way is to pipe through your credentials from Get-VMCSDDCDefaultCredential + #> + Param ( + [Parameter(Mandatory=$true)]$Org, + [Parameter(Mandatory=$true)]$Sddc, + [switch]$Autologin, + [switch]$UseManagementIP + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + $creds = Get-VMCSDDCDefaultCredential -Org $Org -Sddc $Sddc + If($UseManagementIP){ + $Server = $creds.vc_management_ip + }Else{ + $Server = $creds.vc_public_ip + } + + Write-Host "Connecting to VMC vCenter Server" $Server + Connect-VIServer -Server $Server -User $creds.cloud_username -Password $creds.cloud_password | Add-Member -MemberType Noteproperty -Name Location -Value "VMC" + Write-Host "Connecting to VMC CIS Endpoint" $Server + Connect-CisServer -Server $Server -User $creds.cloud_username -Password $creds.cloud_password | Add-Member -MemberType Noteproperty -Name Location -Value "VMC" + } + } +Function Get-VMCOrg { +<# + .NOTES + =========================================================================== + Created by: VMware + Date: 11/17/2017 + Organization: VMware + Blog: http://vmware.com/go/powercli + Twitter: @powercli + =========================================================================== + + .SYNOPSIS + Return the Orgs that you are a part of + .DESCRIPTION + Depending on what you've purchased, you may be a part of one or more VMC Orgs. This will return your orgs + .EXAMPLE + Get-VMCOrg + .EXAMPLE + Get-VMCOrg -Name + .NOTES + Return all the info about the orgs you are a part of +#> + Param ( + [Parameter(Mandatory=$false)]$Name + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use Connect-VMC to connect" } Else { + $orgService = Get-VMCService com.vmware.vmc.orgs + if ($PSBoundParameters.ContainsKey("Name")){ + $orgs = $orgService.list() | Where {$_.display_name -eq $Name} + } Else { + $orgs = $orgService.list() + } + $Orgs | Select display_name, name, user_name, created, id + } +} +Function Get-VMCSDDC { +<# + .NOTES + =========================================================================== + Created by: VMware + Date: 11/17/2017 + Organization: VMware + Blog: http://vmware.com/go/powercli + Twitter: @powercli + =========================================================================== + + .SYNOPSIS + Returns all of the SDDCs you are associated to + .DESCRIPTION + Returns all of the SDDCs ayou are associated to + .EXAMPLE + Get-VMCSDDC -Org + .EXAMPLE + Get-VMCSDDC -Name -Org +#> + Param ( + [Parameter(Mandatory=$True)]$Org, + [Parameter(Mandatory=$false)]$Name + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + if ($PSBoundParameters.ContainsKey("Org")){ + $orgs = Get-VMCOrg -Name $Org + } else { + $orgs = Get-VMCOrg + } + + foreach ($org in $orgs) { + $orgID = $org.ID + $sddcService = Get-VMCService com.vmware.vmc.orgs.sddcs + if ($PSBoundParameters.ContainsKey("Name")){ + $sddcService.list($OrgID) | Where {$_.name -eq $Name} + } Else { + $sddcService.list($OrgID) + } + } + } +} +Function Get-VMCTask { +<# + .NOTES + =========================================================================== + Created by: VMware + Date: 11/17/2017 + Organization: VMware + Blog: http://vmware.com/go/powercli + Twitter: @powercli + =========================================================================== + + .SYNOPSIS + Returns all of the VMC Tasks + .DESCRIPTION + Returns all of the VMC Tasks that have either occurred or are in process + .EXAMPLE + Get-VMCTask +#> + Param ( + [Parameter(Mandatory=$True)]$Org + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + if ($PSBoundParameters.ContainsKey("Org")){ + $orgs = Get-VMCOrg -Name $Org + } else { + $orgs = Get-VMCOrg + } + + foreach ($org in $orgs) { + $orgID = $org.ID + $taskService = Get-VMCService com.vmware.vmc.orgs.tasks + $taskService.list($OrgID) | Select * -ExcludeProperty Help + } + } +} +Function Get-VMCSDDCDefaultCredential { +<# + .NOTES + =========================================================================== + Created by: VMware + Date: 11/17/2017 + Organization: VMware + Blog: http://vmware.com/go/powercli + Twitter: @powercli + =========================================================================== + + .SYNOPSIS + Returns the default credential for the SDDC + .DESCRIPTION + Returns the default credential for the sddc + .EXAMPLE + Get-VMCSDDCDefaultCredential -Org + .EXAMPLE + Get-VMCSDDCDefaultCredential -Sddc -Org +#> + Param ( + [Parameter(Mandatory=$true)]$Org, + [Parameter(Mandatory=$false)]$Sddc + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + if ($PSBoundParameters.ContainsKey("Sddc")){ + $sddcs = Get-VMCSDDC -Name $Sddc -Org $Org + } else { + $sddcs = Get-VMCSDDC -Org $Org + } + + foreach ($sddc in $sddcs) { + $sddc.resource_config | Select-object vc_url, vc_management_ip, vc_public_ip, cloud_username, cloud_password + } + } +} +Function Get-VMCSDDCPublicIP { +<# + .NOTES + =========================================================================== + Created by: VMware + Date: 11/17/2017 + Organization: VMware + Blog: http://vmware.com/go/powercli + Twitter: @powercli + =========================================================================== + + .SYNOPSIS + Returns your Public IPs + .DESCRIPTION + Returns your Public IPs + .EXAMPLE + Get-VMCSDDCPublicIP -Org + .EXAMPLE + Get-VMCSDDCPublicIP -Sddc -Org + .NOTES + Return your Public IPs that you have assigned to your account +#> + Param ( + [Parameter(Mandatory=$true)]$Org, + [Parameter(Mandatory=$false)]$Sddc + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + if ($PSBoundParameters.ContainsKey("Sddc")){ + $sddcs = Get-VMCSDDC -Name $Sddc -Org $Org + } else { + $sddcs = Get-VMCSDDC -Org $Org + } + + foreach ($sddc in $sddcs) { + $sddc.resource_config.Public_ip_pool + } + } +} +Function Get-VMCVMHost { + Param ( + [Parameter(Mandatory=$false)]$Sddc, + [Parameter(Mandatory=$true)]$Org + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + if ($PSBoundParameters.ContainsKey("Sddc")){ + $sddcs = Get-VMCSDDC -Name $Sddc -Org $Org + } else { + $sddcs = Get-VMCSDDC -Org $Org + } + + $results = @() + foreach ($sddc in $sddcs) { + foreach ($vmhost in $sddc.resource_config.esx_hosts) { + $tmp = [pscustomobject] @{ + esx_id = $vmhost.esx_id; + name = $vmhost.name; + hostname = $vmhost.hostname; + esx_state = $vmhost.esx_state; + sddc_id = $sddc.id; + org_id = $sddc.org_id; + } + $results += $tmp + } + $results + } + } +} +Function Get-VMCSDDCVersion { +<# + .NOTES + =========================================================================== + Created by: VMware + Date: 11/17/2017 + Organization: VMware + Blog: http://vmware.com/go/powercli + Twitter: @powercli + =========================================================================== + + .SYNOPSIS + Returns SDDC Version + .DESCRIPTION + Returns Version of the SDDC + .EXAMPLE + Get-VMCSDDCVersion -Name -Org +#> + Param ( + [Parameter(Mandatory=$True)]$Org, + [Parameter(Mandatory=$false)]$Name + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + if ($PSBoundParameters.ContainsKey("Org")){ + $orgs = Get-VMCOrg -Name $Org + } else { + $orgs = Get-VMCOrg + } + + foreach ($org in $orgs) { + $orgID = $org.ID + $sddcService = Get-VMCService com.vmware.vmc.orgs.sddcs + if ($PSBoundParameters.ContainsKey("Name")){ + ($sddcService.list($OrgID) | Where {$_.name -match $Name}).resource_config.sddc_manifest | Select *version + } Else { + ($sddcService.list($OrgID)).resource_config.sddc_manifest | Select *version + } + } + } +} +Function Get-VMCFirewallRule { + <# + .NOTES + =========================================================================== + Created by: William Lam + Date: 11/19/2017 + Organization: VMware + Blog: https://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Retruns VMC Firewall Rules for a given Gateway (MGW or CGW) + .DESCRIPTION + Retruns VMC Firewall Rules for a given Gateway (MGW or CGW) + .EXAMPLE + Get-VMCFirewallRule -OrgName -SDDCName -GatewayType + .EXAMPLE + Get-VMCFirewallRule -OrgName -SDDCName -GatewayType -ShowAll + #> + param( + [Parameter(Mandatory=$false)][String]$SDDCName, + [Parameter(Mandatory=$false)][String]$OrgName, + [Parameter(Mandatory=$false)][Switch]$ShowAll, + [Parameter(Mandatory=$true)][ValidateSet("MGW","CGW")][String]$GatewayType + ) + + if($GatewayType -eq "MGW") { + $EdgeId = "edge-1" + } else { + $EdgeId = "edge-2" + } + + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + + $firewallConfigService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config + + $firewallRules = ($firewallConfigService.get($orgId, $sddcId, $EdgeId)).firewall_rules.firewall_rules + if(-not $ShowAll) { + $firewallRules = $firewallRules | where { $_.rule_type -ne "default_policy" -and $_.rule_type -ne "internal_high" -and $_.name -ne "vSphere Cluster HA" -and $_.name -ne "Outbound Access" } | Sort-Object -Property rule_tag + } else { + $firewallRules = $firewallRules | Sort-Object -Property rule_tag + } + + $results = @() + foreach ($firewallRule in $firewallRules) { + if($firewallRule.source.ip_address.Count -ne 0) { + $source = $firewallRule.source.ip_address + } else { $source = "ANY" } + + if($firewallRule.application.service.protocol -ne $null) { + $protocol = $firewallRule.application.service.protocol + } else { $protocol = "ANY" } + + if($firewallRule.application.service.port -ne $null) { + $port = $firewallRule.application.service.port + } else { $port = "ANY" } + + $tmp = [pscustomobject] @{ + ID = $firewallRule.rule_id; + Name = $firewallRule.name; + Type = $firewallRule.rule_type; + Action = $firewallRule.action; + Protocol = $protocol; + Port = $port; + SourceAddress = $source + DestinationAddress = $firewallRule.destination.ip_address; + } + $results+=$tmp + } + $results + } +Function Export-VMCFirewallRule { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: 11/19/2017 + Organization: VMware + Blog: https://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Exports all "customer" created VMC Firewall Rules to JSON file + .DESCRIPTION + Exports all "customer" created VMC Firewall Rules to JSON file + .EXAMPLE + Export-VMCFirewallRule -OrgName -SDDCName -GatewayType -Path "C:\Users\lamw\Desktop\VMCFirewallRules.json" + #> + param( + [Parameter(Mandatory=$false)][String]$SDDCName, + [Parameter(Mandatory=$false)][String]$OrgName, + [Parameter(Mandatory=$true)][ValidateSet("MGW","CGW")][String]$GatewayType, + [Parameter(Mandatory=$false)][String]$Path + ) + + if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } + + if($GatewayType -eq "MGW") { + $EdgeId = "edge-1" + } else { + $EdgeId = "edge-2" + } + + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).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 + } + + $firewallConfigService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config + + $firewallRules = ($firewallConfigService.get($orgId, $sddcId, $EdgeId)).firewall_rules.firewall_rules + if(-not $ShowAll) { + $firewallRules = $firewallRules | where { $_.rule_type -ne "default_policy" -and $_.rule_type -ne "internal_high" -and $_.name -ne "vSphere Cluster HA" -and $_.name -ne "Outbound Access" } | Sort-Object -Property rule_tag + } else { + $firewallRules = $firewallRules | Sort-Object -Property rule_tag + } + + $results = @() + $count = 0 + foreach ($firewallRule in $firewallRules) { + if($firewallRule.source.ip_address.Count -ne 0) { + $source = $firewallRule.source.ip_address + } else { + $source = "ANY" + } + + $tmp = [pscustomobject] @{ + Name = $firewallRule.name; + Action = $firewallRule.action; + Protocol = $firewallRule.application.service.protocol; + Port = $firewallRule.application.service.port; + SourcePort = $firewallRule.application.service.source_port; + ICMPType = $firewallRule.application.service.icmp_type; + SourceAddress = $firewallRule.source.ip_address; + DestinationAddress = $firewallRule.destination.ip_address; + Enabled = $firewallRule.enabled; + Logging = $firewallRule.logging_enabled; + } + $count+=1 + $results+=$tmp + } + if($Path) { + Write-Host -ForegroundColor Green "Exporting $count VMC Firewall Rules to $Path ..." + $results | ConvertTo-Json | Out-File $Path + } else { + $results | ConvertTo-Json + } +} +Function Import-VMCFirewallRule { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: 11/19/2017 + Organization: VMware + Blog: https://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Imports VMC Firewall Rules from exported JSON configuration file + .DESCRIPTION + Imports VMC Firewall Rules from exported JSON configuration file + .EXAMPLE + Import-VMCFirewallRule -OrgName -SDDCName -GatewayType -Path "C:\Users\lamw\Desktop\VMCFirewallRules.json" + #> + param( + [Parameter(Mandatory=$false)][String]$SDDCName, + [Parameter(Mandatory=$false)][String]$OrgName, + [Parameter(Mandatory=$true)][ValidateSet("MGW","CGW")][String]$GatewayType, + [Parameter(Mandatory=$false)][String]$Path + ) + + if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } + + if($GatewayType -eq "MGW") { + $EdgeId = "edge-1" + } else { + $EdgeId = "edge-2" + } + + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).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 + } + + $firewallService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config.rules + + $vmcFirewallRulesJSON = Get-Content -Raw $Path | ConvertFrom-Json + + # Create top level Firewall Rules Object + $firewallRules = $firewallService.Help.add.firewall_rules.Create() + # Create top top level Firewall Rule Spec which will be an array of individual Firewall rules as we process them in next section + $ruleSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Create() + + foreach ($vmcFirewallRule in $vmcFirewallRulesJSON) { + # Create Individual Firewall Rule Element Spec + $ruleElementSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.Create() + + # AppSpec + $appSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.application.Create() + # ServiceSpec + $serviceSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.application.service.Element.Create() + + $protocol = $null + if($vmcFirewallRule.Protocol -ne $null) { + $protocol = $vmcFirewallRule.Protocol + } + $serviceSpec.protocol = $protocol + + # Process ICMP Type from JSON + $icmpType = $null + if($vmcFirewallRule.ICMPType -ne $null) { + $icmpType = $vmcFirewallRule.ICMPType + } + $serviceSpec.icmp_type = $icmpType + + # Process Source Ports from JSON + $sourcePorts = @() + if($vmcFirewallRule.SourcePort -eq "any" -or $vmcFirewallRule.SourcePort -ne $null) { + foreach ($port in $vmcFirewallRule.SourcePort) { + $sourcePorts+=$port + } + } else { + $sourcePorts = @("any") + } + $serviceSpec.source_port = $sourcePorts + + # Process Ports from JSON + $ports = @() + if($vmcFirewallRule.Port -ne "null") { + foreach ($port in $vmcFirewallRule.Port) { + $ports+=$port + } + } + $serviceSpec.port = $ports + $addSpec = $appSpec.service.Add($serviceSpec) + + # Create Source Spec + $srcSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.source.Create() + $srcSpec.exclude = $false + # Process Source Address from JSON + $sourceAddess = @() + if($vmcFirewallRule.SourceAddress -ne "null") { + foreach ($address in $vmcFirewallRule.SourceAddress) { + $sourceAddess+=$address + } + } + $srcSpec.ip_address = $sourceAddess; + + # Create Destination Spec + $destSpec = $firewallService.Help.add.firewall_rules.firewall_rules.Element.destination.Create() + $destSpec.exclude = $false + # Process Destination Address from JSON + $destinationAddess = @() + if($vmcFirewallRule.DestinationAddress -ne "null") { + foreach ($address in $vmcFirewallRule.DestinationAddress) { + $destinationAddess+=$address + } + } + $destSpec.ip_address = $destinationAddess + + # Add various specs + if($vmcFirewallRule.Protocol -ne $null -and $vmcFirewallRule.port -ne $null) { + $ruleElementSpec.application = $appSpec + } + + $ruleElementSpec.source = $srcSpec + $ruleElementSpec.destination = $destSpec + $ruleElementSpec.rule_type = "user" + + # Process Enabled from JSON + $fwEnabled = $false + if($vmcFirewallRule.Enabled -eq "true") { + $fwEnabled = $true + } + $ruleElementSpec.enabled = $fwEnabled + + # Process Logging from JSON + $loggingEnabled = $false + if($vmcFirewallRule.Logging -eq "true") { + $loggingEnabled = $true + } + $ruleElementSpec.logging_enabled = $loggingEnabled + + $ruleElementSpec.action = $vmcFirewallRule.Action + $ruleElementSpec.name = $vmcFirewallRule.Name + + # Add the individual FW rule spec into our overall firewall rules array + Write-host "Creating VMC Firewall Rule Spec:" $vmcFirewallRule.Name "..." + $ruleSpecAdd = $ruleSpec.Add($ruleElementSpec) + } + $firewallRules.firewall_rules = $ruleSpec + + Write-host "Adding VMC Firewall Rules ..." + $firewallRuleAdd = $firewallService.add($orgId,$sddcId,$EdgeId,$firewallRules) +} +Function Remove-VMCFirewallRule { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: 11/19/2017 + Organization: VMware + Blog: https://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Removes VMC Firewall Rule given Rule Id + .DESCRIPTION + Removes VMC Firewall Rule given Rule Id + .EXAMPLE + Remove-VMCFirewallRule -OrgName -SDDCName -GatewayType -RuleId + #> + param( + [Parameter(Mandatory=$false)][String]$SDDCName, + [Parameter(Mandatory=$false)][String]$OrgName, + [Parameter(Mandatory=$true)][ValidateSet("MGW","CGW")][String]$GatewayType, + [Parameter(Mandatory=$false)][String]$RuleId + ) + + if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } + + if($GatewayType -eq "MGW") { + $EdgeId = "edge-1" + } else { + $EdgeId = "edge-2" + } + + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).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 + } + + $firewallService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.edges.firewall.config.rules + Write-Host "Removing VMC Firewall Rule Id $RuleId ..." + $firewallService.delete($orgId,$sddcId,$EdgeId,$RuleId) +} +Function Get-VMCLogicalNetwork { + <# + .NOTES + =========================================================================== + Created by: Kyle Ruddy + Date: 03/06/2018 + Organization: VMware + Blog: https://www.kmruddy.com + Twitter: @kmruddy + =========================================================================== + + .SYNOPSIS + Retruns VMC Logical Networks for a given SDDC + .DESCRIPTION + Retruns VMC Logical Networks for a given SDDC + .EXAMPLE + Get-VMCLogicalNetwork -OrgName -SDDCName + .EXAMPLE + Get-VMCLogicalNetwork -OrgName -SDDCName -LogicalNetworkName + #> + param( + [Parameter(Mandatory=$true)][String]$SDDCName, + [Parameter(Mandatory=$true)][String]$OrgName, + [Parameter(Mandatory=$false)][String]$LogicalNetworkName + + ) + + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).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 + } + + # @LucD22 - 21/10/18 - Fix for issue #176 VMware.VMC module only lists firts 20 Logical networks + # Loop until entries (total_count) are returned + + $index = [long]0 + + $logicalNetworks = do{ + $netData = $logicalNetworkService.get_0($orgId,$sddcId,$pagesize,$index) + $netData.data | Sort-Object -Property id + $index = $index + $netdata.paging_info.page_size + } + until($index -ge $netData.paging_info.total_count) + + if($LogicalNetworkName) { + $logicalNetworks = $logicalNetworks | Where-Object {$_.Name -eq $LogicalNetworkName} + } + + $results = @() + foreach ($logicalNetwork in $logicalNetworks) { + $tmp = [pscustomobject] @{ + ID = $logicalNetwork.id; + Name = $logicalNetwork.name; + SubnetMask = $logicalNetwork.subnets.address_groups.prefix_length; + Gateway = $logicalNetwork.subnets.address_groups.primary_address; + DHCPipRange = $logicalNetwork.dhcp_configs.ip_pools.ip_range; + DHCPdomain = $logicalNetwork.dhcp_configs.ip_pools.domain_name; + CGatewayID = $logicalNetwork.cgw_id; + CGateway = $logicalNetwork.cgw_name; + } + $results+=$tmp + } + $results +} +Function Remove-VMCLogicalNetwork { + <# + .NOTES + =========================================================================== + Created by: Kyle Ruddy + Date: 03/06/2018 + Organization: VMware + Blog: https://www.kmruddy.com + Twitter: @kmruddy + =========================================================================== + + .SYNOPSIS + Removes Logical Network given ID + .DESCRIPTION + Removes Logical Network given ID + .EXAMPLE + Remove-VMCLogicalNetwork -OrgName -SDDCName -LogicalNetworkName + #> + [cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact='High')] + param( + [Parameter(Mandatory=$true)][String]$SDDCName, + [Parameter(Mandatory=$true)][String]$OrgName, + [Parameter(Mandatory=$true)][String]$LogicalNetworkName + ) + + if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } + + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + $lsId = (Get-VMCLogicalNetwork -OrgName $OrgName -SDDCName $SDDCName -LogicalNetworkName $LogicalNetworkName).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 $lsId) { + Write-Host -ForegroundColor red "Unable to find SDDC $LogicalNetworkName, please verify input" + break + } + + $logicalNetworkService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.logical + $logicalNetworkService.delete($orgId,$sddcId,$lsId) +} +Function New-VMCLogicalNetwork { +<# + .NOTES + =========================================================================== + Created by: Kyle Ruddy + Date: 03/06/2018 + Organization: VMware + Blog: https://www.kmruddy.com + Twitter: @kmruddy + =========================================================================== + + .SYNOPSIS + Creates a new Logical Network + .DESCRIPTION + Creates a new Logical Network + .EXAMPLE + New-VMCLogicalNetwork -OrgName -SDDCName -LogicalNetworkName -SubnetMask -Gateway +#> + [cmdletbinding(SupportsShouldProcess = $true,ConfirmImpact='High')] + param( + [Parameter(Mandatory=$true)][String]$SDDCName, + [Parameter(Mandatory=$true)][String]$OrgName, + [Parameter(Mandatory=$true)][String]$LogicalNetworkName, + [Parameter(Mandatory=$true)][String]$SubnetMask, + [Parameter(Mandatory=$true)][String]$Gateway + ) + + if (-not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect"; break } + + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).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 + } + + $logicalNetworkService = Get-VmcService com.vmware.vmc.orgs.sddcs.networks.logical + $logicalNetworkSpec = $logicalNetworkService.Help.create.sddc_network.Create() + $logicalNetworkSpec.name = $LogicalNetworkName + $logicalNetworkSpec.cgw_id = "edge-2" + $logicalNetworkSpec.cgw_name = "SDDC-CGW-1" + $logicalNetworkAddressGroupSpec = $logicalNetworkService.Help.create.sddc_network.subnets.address_groups.Element.Create() + $logicalNetworkAddressGroupSpec.prefix_length = $SubnetMask + $logicalNetworkAddressGroupSpec.primary_address = $Gateway + + $logicalNetworkSpec.subnets.address_groups.Add($logicalNetworkAddressGroupSpec) | Out-Null + $logicalNetworkService.create($orgId, $sddcId, $logicalNetworkSpec) + Get-VMCLogicalNetwork -OrgName $OrgName -SDDCName $SDDCName -LogicalNetworkName $LogicalNetworkName +} +Function Get-VMCSDDCSummary { + <# + .NOTES + =========================================================================== + Created by: VMware + Date: 09/04/18 + Organization: VMware + Blog: https://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Returns a number of useful informational data about a given SDDC within VMC Org + .DESCRIPTION + Returns Version, Create/Expiration Date, Deployment Type, Region, AZ, Instance Type, VPC CIDR & NSX-T + .EXAMPLE + Get-VMCSDDCSummary -Name -Org + #> + Param ( + [Parameter(Mandatory=$True)]$Org, + [Parameter(Mandatory=$True)]$Name + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + $orgId = (Get-VMCOrg -Name $Org).Id + $sddcId = (Get-VMCSDDC -Name $Name -Org $Org).Id + + $sddcService = Get-VmcService "com.vmware.vmc.orgs.sddcs" + $sddc = $sddcService.get($orgId,$sddcId) + + $results = [pscustomobject] @{ + Version = $sddc.resource_config.sddc_manifest.vmc_version; + CreateDate = $sddc.created; + ExpirationDate = $sddc.expiration_date; + DeploymentType = $sddc.resource_config.deployment_type; + Region = $sddc.resource_config.region; + AvailabilityZone = $sddc.resource_config.availability_zones; + InstanceType = $sddc.resource_config.sddc_manifest.esx_ami.instance_type; + VpcCIDR = $sddc.resource_config.vpc_info.vpc_cidr; + NSXT = $sddc.resource_config.nsxt; + VPC_VGW = $sddc.resource_config.vpc_info.vgw_id; + } + $results + } +} +Function Get-VMCPublicIP { + <# + .NOTES + =========================================================================== + Created by: William LamVPC_VGW + Date: 09/12/2018 + Organization: VMware + Blog: http://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Retrieves all public IP Addresses for a given SDDC + .DESCRIPTION + This cmdlet retrieves all public IP Address for a given SDDC + .EXAMPLE + Get-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName + #> + Param ( + [Parameter(Mandatory=$True)]$OrgName, + [Parameter(Mandatory=$True)]$SDDCName + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + + $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" + $publicIPs = $publicIPService.list($orgId,$sddcId) + + $publicIPs | select public_ip, name, allocation_id + } +} + +Function New-VMCPublicIP { + <# + .NOTES + =========================================================================== + Created by: William Lam + Date: 09/12/2018 + Organization: VMware + Blog: http://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Request a new public IP Address for a given SDDC + .DESCRIPTION + This cmdlet requests a new public IP Address for a given SDDC + .EXAMPLE + New-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName -Description "Test for Randy" + #> + Param ( + [Parameter(Mandatory=$True)]$OrgName, + [Parameter(Mandatory=$True)]$SDDCName, + [Parameter(Mandatory=$False)]$Description + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + + $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" + + $publicIPSpec = $publicIPService.Help.create.spec.Create() + $publicIPSpec.count = 1 + $publicIPSpec.names = @($Description) + + Write-Host "Requesting a new public IP Address for your SDDC ..." + $results = $publicIPService.create($orgId,$sddcId,$publicIPSpec) + } +} + +Function Remove-VMCPublicIP { + <# + .NOTES + =========================================================================== + Created by: William Lam + Date: 09/12/2018 + Organization: VMware + Blog: http://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Removes a specific public IP Addresses for a given SDDC + .DESCRIPTION + This cmdlet removes a specific public IP Address for a given SDDC + .EXAMPLE + Remove-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName -AllocationId "eipalloc-0567acf34e436c01f" + #> + Param ( + [Parameter(Mandatory=$True)]$OrgName, + [Parameter(Mandatory=$True)]$SDDCName, + [Parameter(Mandatory=$True)]$AllocationId + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + + $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" + + Write-Host "Deleting public IP Address with ID $AllocationId ..." + $results = $publicIPService.delete($orgId,$sddcId,$AllocationId) + } +} + +Function Set-VMCSDDC { + <# + .NOTES + =========================================================================== + Created by: William Lam + Date: 01/12/2019 + Organization: VMware + Blog: http://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Rename an SDDC + .DESCRIPTION + This cmdlet renames an SDDC + .EXAMPLE + Set-VMCSDDC -SDDC $SDDCName -OrgName $OrgName -Name $NewSDDCName + #> + Param ( + [Parameter(Mandatory=$True)]$SDDCName, + [Parameter(Mandatory=$True)]$OrgName, + [Parameter(Mandatory=$True)]$Name + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + $sddc = Get-VMCSDDC -Org $OrgName -Name $SDDCName + if($sddc) { + $sddcService = Get-VmcService com.vmware.vmc.orgs.sddcs + $renameSpec = $sddcService.help.patch.sddc_patch_request.Create() + $renameSpec.name = $Name + + Write-Host "`nRenaming SDDC `'$SDDCName`' to `'$Name`' ...`n" + $results = $sddcService.patch($sddc.org_id,$sddc.id,$renameSpec) + } + } +} + +Function New-VMCPublicIP { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: 09/12/2018 + Organization: VMware + Blog: http://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Request a new public IP Address for a given SDDC + .DESCRIPTION + This cmdlet requests a new public IP Address for a given SDDC + .EXAMPLE + New-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName -Description "Test for Randy" +#> + Param ( + [Parameter(Mandatory=$True)]$OrgName, + [Parameter(Mandatory=$True)]$SDDCName, + [Parameter(Mandatory=$False)]$Description + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + + $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" + + $publicIPSpec = $publicIPService.Help.create.spec.Create() + $publicIPSpec.count = 1 + $publicIPSpec.names = @($Description) + + Write-Host "Requesting a new public IP Address for your SDDC ..." + $results = $publicIPService.create($orgId,$sddcId,$publicIPSpec) + } +} + +Function Remove-VMCPublicIP { +<# + .NOTES + =========================================================================== + Created by: William Lam + Date: 09/12/2018 + Organization: VMware + Blog: http://www.virtuallyghetto.com + Twitter: @lamw + =========================================================================== + + .SYNOPSIS + Removes a specific public IP Addresses for a given SDDC + .DESCRIPTION + This cmdlet removes a specific public IP Address for a given SDDC + .EXAMPLE + Remove-VMCPublicIP -OrgName $OrgName -SDDCName $SDDCName -AllocationId "eipalloc-0567acf34e436c01f" +#> + Param ( + [Parameter(Mandatory=$True)]$OrgName, + [Parameter(Mandatory=$True)]$SDDCName, + [Parameter(Mandatory=$True)]$AllocationId + ) + + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + + $publicIPService = Get-VmcService "com.vmware.vmc.orgs.sddcs.publicips" + + Write-Host "Deleting public IP Address with ID $AllocationId ..." + $results = $publicIPService.delete($orgId,$sddcId,$AllocationId) + } +} + +Function Get-VMCEdge { +<# +.NOTES +=========================================================================== +Created by: Luc Dekens +Date: 23/10/2018 +Organization: Community +Blog: http://lucd.info +Twitter: @LucD22 +=========================================================================== + +.SYNOPSIS + Returns all the VMC Edges +.DESCRIPTION + Returns all the VMC Edges +.EXAMPLE + Get-VMCEdge -OrgName $orgName -SddcName $SDDCName -EdgeType gatewayServices +#> + Param ( + [Parameter(Mandatory=$True)] + [string]$OrgName, + [Parameter(Mandatory=$True)] + [string]$SDDCName, + [ValidateSet('gatewayServices','distributedRouter')] + [string]$EdgeType = '' + ) + + If (-Not $global:DefaultVMCServers) { + Write-error "No VMC Connection found, please use the Connect-VMC to connect" + } + Else { + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + + $edgeService = Get-VmcService -Name 'com.vmware.vmc.orgs.sddcs.networks.edges' + $index = [long]0 + $edges = do{ + $edgeData = $edgeService.get($orgId,$sddcId,$EdgeType,'',$index) + $edgeData.edge_page.data | Sort-Object -Property id + $index = $index + $edgeData.edge_page.paging_info.page_size + } + until($index -ge $edgeData.paging_info.total_count) + $edges | %{ + [pscustomobject]@{ + Name = $_.Name + Id = $_.id + Type = $_.edge_type + State = $_.state + Status = $_.edge_status + VNics = $_.number_of_connected_vnics + TenantId = $_.tenant_id + } + } + } +} + +Function Get-VMCEdgeStatus { +<# +.NOTES +=========================================================================== +Created by: Luc Dekens +Date: 23/10/2018 +Organization: Community +Blog: http://lucd.info +Twitter: @LucD22 +=========================================================================== + +.SYNOPSIS + Returns the status of the gateway +.DESCRIPTION + Retrieve the status of the specified management or compute gateway (NSX Edge). +.EXAMPLE + Get-VMCEdgeStatus -OrgName $orgName -SddcName $SDDCName -Edge $EdgeName +#> + Param ( + [Parameter(Mandatory=$True)] + [string]$OrgName, + [Parameter(Mandatory=$True)] + [string]$SDDCName, + [Parameter(Mandatory=$True)] + [string]$EdgeName + ) + + If (-Not $global:DefaultVMCServers) { + Write-error "No VMC Connection found, please use the Connect-VMC to connect" + } + Else { + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + $edgeId = Get-VMCEdge -SDDCName $SDDCName -Org $OrgName | where{$_.Name -eq $EdgeName} | select -ExpandProperty Id + + $statusService = Get-VmcService -Name 'com.vmware.vmc.orgs.sddcs.networks.edges.status' + $status = $statusService.get($orgId,$sddcId,$edgeId) + + $vmStatus = $status.edge_vm_status | %{ + [pscustomobject]@{ + Name = $_.name + State = $_.edge_VM_status + HAState = $_.ha_state + Index = $_.index + } + } + $featureStatus = $status.feature_statuses | %{ + [pscustomobject]@{ + Service = $_.service + Status = $_.status + } + } + [pscustomobject]@{ + Time = [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($status.timestamp/1000)) + Status = $status.edge_status + PublishStatus = $status.publish_status + SystemStatus = $_.system_status + NicInUse = $status.ha_vnic_in_use + } + } +} + +Function Get-VMCEdgeNic { +<# +.NOTES +=========================================================================== +Created by: Luc Dekens +Date: 23/10/2018 +Organization: Community +Blog: http://lucd.info +Twitter: @LucD22 +=========================================================================== + +.SYNOPSIS + Returns all interfaces for the gateway +.DESCRIPTION + Retrieve all interfaces for the specified management or compute gateway (NSX Edge). +.EXAMPLE + Get-VMCEdgeNic -OrgName $orgName -SddcName $SDDCName -Edge $EdgeName +#> + Param ( + [Parameter(Mandatory=$True)] + [string]$OrgName, + [Parameter(Mandatory=$True)] + [string]$SDDCName, + [Parameter(Mandatory=$True)] + [string]$EdgeName + ) + + If (-Not $global:DefaultVMCServers) { + Write-error "No VMC Connection found, please use the Connect-VMC to connect" + } + Else { + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + $edgeId = Get-VMCEdge -SDDCName $SDDCName -Org $OrgName | where{$_.Name -eq $EdgeName} | select -ExpandProperty Id + + $vnicService = Get-VmcService -Name 'com.vmware.vmc.orgs.sddcs.networks.edges.vnics' + $vnicService.get($orgId,$sddcId,$edgeId) | select -ExpandProperty vnics | %{ + [pscustomobject]@{ + Label = $_.label + Name = $_.Name + Type = $_.type + Index = $_.index + IsConnected = $_.is_connected + Portgroup = $_.portgroup_name + } + } + } +} + +Function Get-VMCEdgeNicStat { +<# +.NOTES +=========================================================================== +Created by: Luc Dekens +Date: 23/10/2018 +Organization: Community +Blog: http://lucd.info +Twitter: @LucD22 +=========================================================================== + +.SYNOPSIS + Returns statistics for the gateway interfaces +.DESCRIPTION + Retrieve interface statistics for a management or compute gateway (NSX Edge). +.EXAMPLE + Get-VMCEdgeNicStat -OrgName $orgName -SddcName $SDDCName -Edge $EdgeName +#> + [CmdletBinding(DefaultParameterSetName='Default')] + Param ( + [Parameter(Mandatory=$True)] + [string]$OrgName, + [Parameter(Mandatory=$True)] + [string]$SDDCName, + [Parameter(Mandatory=$True)] + [string]$EdgeName +# [DateTime]$Start, +# [DateTime]$Finish + ) + + If (-Not $global:DefaultVMCServers) { + Write-error "No VMC Connection found, please use the Connect-VMC to connect" + } + Else { + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + $edgeId = Get-VMCEdge -SDDCName $SDDCName -Org $OrgName | where{$_.Name -eq $EdgeName} | select -ExpandProperty Id + +# $epoch = Get-Date 01/01/1970 +# +# if($start){ +# $startEpoch = (New-TimeSpan -Start $epoch -End $Start.ToUniversalTime()).TotalMilliseconds +# } +# if($Finish){ +# $finishEpoch = (New-TimeSpan -Start $epoch -End $Finish.ToUniversalTime()).TotalMilliseconds +# } + + $vnicStatService = Get-VmcService -Name 'com.vmware.vmc.orgs.sddcs.networks.edges.statistics.interfaces' +# $stats = $vnicStatService.get($orgId,$sddcId,$edgeId,[long]$startEpoch,[long]$finishEpoch) + $stats = $vnicStatService.get($orgId,$sddcId,$edgeId) + + $stats.data_dto | Get-Member -MemberType NoteProperty | where{$_.Name -ne 'Help'} | %{$_.Name} | %{ + $stats.data_dto."$_" | %{ + [pscustomobject]@{ + vNIC = $_.vnic + Timestamp = [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($_.timestamp)) + In = $_.in + Out = $_.out + Unit = 'Kbps' + Interval = $stats.meta_dto.interval + } + } + } + } +} + +Function Get-VMCEdgeUplinkStat { +<# +.NOTES +=========================================================================== +Created by: Luc Dekens +Date: 23/10/2018 +Organization: Community +Blog: http://lucd.info +Twitter: @LucD22 +=========================================================================== + +.SYNOPSIS + Returns statistics for the uplink interfaces +.DESCRIPTION + Retrieve uplink interface statistics for a management or compute gateway (NSX Edge). +.EXAMPLE + Get-VMCEdgeUplinkStat -OrgName $orgName -SddcName $SDDCName -Edge $EdgeName +#> + Param ( + [Parameter(Mandatory=$True)] + [string]$OrgName, + [Parameter(Mandatory=$True)] + [string]$SDDCName, + [Parameter(Mandatory=$True)] + [string]$EdgeName +# [DateTime]$Start, +# [DateTime]$Finish + ) + + If (-Not $global:DefaultVMCServers) { + Write-error "No VMC Connection found, please use the Connect-VMC to connect" + } + Else { + $orgId = (Get-VMCOrg -Name $OrgName).Id + $sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id + $edgeId = Get-VMCEdge -SDDCName $SDDCName -Org $OrgName | where{$_.Name -eq $EdgeName} | select -ExpandProperty Id + +# $epoch = Get-Date 01/01/1970 +# +# if($start){ +# $startEpoch = (New-TimeSpan -Start $epoch -End $Start.ToUniversalTime()).TotalMilliseconds +# } +# if($Finish){ +# $finishEpoch = (New-TimeSpan -Start $epoch -End $Finish.ToUniversalTime()).TotalMilliseconds +# } + + $uplinkStatService = Get-VmcService -Name 'com.vmware.vmc.orgs.sddcs.networks.edges.statistics.interfaces.uplink' +# $stats = $uplinkStatService.get($orgId,$sddcId,$edgeId,[long]$startEpoch,[long]$finishEpoch) + $stats = $uplinkStatService.get($orgId,$sddcId,$edgeId) + + $stats.data_dto | Get-Member -MemberType NoteProperty | where{$_.Name -ne 'Help'} | %{$_.Name} | %{ + if($stats.data_dto."$_".Count -ne 0){ + $stats.data_dto."$_" | %{ + [pscustomobject]@{ + vNIC = $_.vnic + Timestamp = [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($_.timestamp)) + In = $_.in + Out = $_.out + Unit = 'Kbps' + Interval = $stats.meta_dto.interval + } + } + } + } + } +} +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 -SDDCName -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 -SDDCName -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 -SDDCName -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 -SDDCName -Cluster + #> + [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-VMCSDDCCluster', 'New-VMCSDDCCluster', 'Remove-VMCSDDCCluster' \ No newline at end of file From 0ba0b870afcadecfaeb0baa5fd8fc20cb55f5c8c Mon Sep 17 00:00:00 2001 From: seanpmassey Date: Wed, 7 Aug 2019 15:27:37 -0500 Subject: [PATCH 04/10] Update VMware.VMC.psm1 --- Modules/VMware.VMC/VMware.VMC.psm1 | 73 +++++++++++++++--------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/Modules/VMware.VMC/VMware.VMC.psm1 b/Modules/VMware.VMC/VMware.VMC.psm1 index dd74f2a..7914c64 100644 --- a/Modules/VMware.VMC/VMware.VMC.psm1 +++ b/Modules/VMware.VMC/VMware.VMC.psm1 @@ -25,46 +25,47 @@ Function Get-VMCCommand { } Function Connect-VMCVIServer { - <# - .NOTES - =========================================================================== - Created by: VMware - Date: 11/17/2017 - Organization: VMware - Blog: http://vmware.com/go/powercli - Twitter: @powercli - =========================================================================== +<# + .NOTES + =========================================================================== + Created by: VMware + Date: 11/17/2017 + Organization: VMware + Blog: http://vmware.com/go/powercli + Twitter: @powercli + =========================================================================== - .SYNOPSIS - Cmdlet to connect to your VMC vCenter Server - .DESCRIPTION - This will connect you to both the VMC ViServer as well as the CiSServer at the same time. - .EXAMPLE - Connect-VMCVIServer -Server -User -Password - .NOTES - Easiest way is to pipe through your credentials from Get-VMCSDDCDefaultCredential - #> - Param ( - [Parameter(Mandatory=$true)]$Org, - [Parameter(Mandatory=$true)]$Sddc, - [switch]$Autologin, - [switch]$UseManagementIP - ) + .SYNOPSIS + Cmdlet to connect to your VMC vCenter Server + .DESCRIPTION + This will connect you to both the VMC ViServer as well as the CiSServer at the same time. + .EXAMPLE + Connect-VMCVIServer -Server -User -Password + .NOTES + Easiest way is to pipe through your credentials from Get-VMCSDDCDefaultCredential +#> + Param ( + [Parameter(Mandatory=$true)]$Org, + [Parameter(Mandatory=$true)]$Sddc, + [switch]$Autologin, + [switch]$UseManagementIP + ) - If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { - $creds = Get-VMCSDDCDefaultCredential -Org $Org -Sddc $Sddc - If($UseManagementIP){ - $Server = $creds.vc_management_ip - }Else{ - $Server = $creds.vc_public_ip - } - - Write-Host "Connecting to VMC vCenter Server" $Server - Connect-VIServer -Server $Server -User $creds.cloud_username -Password $creds.cloud_password | Add-Member -MemberType Noteproperty -Name Location -Value "VMC" - Write-Host "Connecting to VMC CIS Endpoint" $Server - Connect-CisServer -Server $Server -User $creds.cloud_username -Password $creds.cloud_password | Add-Member -MemberType Noteproperty -Name Location -Value "VMC" + If (-Not $global:DefaultVMCServers) { Write-error "No VMC Connection found, please use the Connect-VMC to connect" } Else { + $creds = Get-VMCSDDCDefaultCredential -Org $Org -Sddc $Sddc + If($UseManagementIP){ + $Server = $creds.vc_management_ip + }Else{ + $Server = $creds.vc_public_ip } + + Write-Host "Connecting to VMC vCenter Server" $Server + Connect-VIServer -Server $Server -User $creds.cloud_username -Password $creds.cloud_password | Add-Member -MemberType Noteproperty -Name Location -Value "VMC" + Write-Host "Connecting to VMC CIS Endpoint" $Server + Connect-CisServer -Server $Server -User $creds.cloud_username -Password $creds.cloud_password | Add-Member -MemberType Noteproperty -Name Location -Value "VMC" } +} + Function Get-VMCOrg { <# .NOTES From 9de3195b324620ca15725c1b0aca56d32199c30c Mon Sep 17 00:00:00 2001 From: Bill Wall Date: Thu, 8 Aug 2019 09:30:43 -0500 Subject: [PATCH 05/10] Add Tag Assigments option Added the optional ability to export/import tag assignments. --- Scripts/ExportImportTags.ps1 | 40 +++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/Scripts/ExportImportTags.ps1 b/Scripts/ExportImportTags.ps1 index e6a1ec7..27b8ae1 100644 --- a/Scripts/ExportImportTags.ps1 +++ b/Scripts/ExportImportTags.ps1 @@ -5,15 +5,23 @@ function Export-Tag { [VMware.VimAutomation.ViCore.Types.V1.VIServer]$Server, [Parameter(Mandatory = $True, Position = 2)] - [string]$Destination + [string]$Destination, + + [Parameter(Mandatory = $False, Position = 3)] + [boolean]$ExportAssignments ) # Retrieve all categories $categoryList = Get-TagCategory -Server $server # Retrieve all tags $tagList = Get-Tag -Server $server - # Store the tags and categories in a list to export them at once - $export = @($categoryList, $tagList) + # Store the tags, categories and assignments (if selected) in a list to export them at once + If ($ExportAssignments) { + $tagAssignments = Get-TagAssignment -Server $server + $export = @($categoryList, $tagList, $tagAssignments) + } else { + $export = @($categoryList, $tagList) + } # Export the tags and categories to the specified destination Export-Clixml -InputObject $export -Path $destination } @@ -25,7 +33,10 @@ function Import-Tag { [VMware.VimAutomation.ViCore.Types.V1.VIServer]$Server, [Parameter(Mandatory = $True, Position = 2)] - [string]$Source + [string]$Source, + + [Parameter(Mandatory = $False, Position = 3)] + [boolean]$ImportAssignments ) # Import the tags and categories from the specified source @@ -62,4 +73,23 @@ function Import-Tag { -Server $server ` | Out-Null } -} \ No newline at end of file + + # Restore the assignments if selected + If ($ImportAssignments) { + # Check for assignments in the file + If ($import[2]) { + # If tags were found, assign them + $tagAssignments = $import[2] + ForEach ($assignment in $tagAssignments) { + New-TagAssignment ` + -Tag (Get-Tag -Server $server -Name $assignment.Tag.Name -Category $assignment.Tag.Category) ` + -Entity (Get-VIObjectByVIView -MORef $assignment.Entity.id) ` + -Server $server ` + | Out-Null + } + } else { + # If no assignments were found, output warning + Write-Warning "Source file does not contain tag assignments." + } + } +} From fef2f32adfe53dc9069728be2d92f2e7834dc8d5 Mon Sep 17 00:00:00 2001 From: Thibaut Noben Date: Mon, 26 Aug 2019 11:42:01 +0200 Subject: [PATCH 06/10] Added vgpu support to new-hvfarm --- .../Farm/AutomatedLinkedCloneFarm vGPU.json | 97 +++++++++++++++++++ .../VMware.Hv.Helper/VMware.HV.Helper.psm1 | 26 +++++ 2 files changed, 123 insertions(+) create mode 100644 Modules/VMware.Hv.Helper/Json/Farm/AutomatedLinkedCloneFarm vGPU.json diff --git a/Modules/VMware.Hv.Helper/Json/Farm/AutomatedLinkedCloneFarm vGPU.json b/Modules/VMware.Hv.Helper/Json/Farm/AutomatedLinkedCloneFarm vGPU.json new file mode 100644 index 0000000..ecec6ea --- /dev/null +++ b/Modules/VMware.Hv.Helper/Json/Farm/AutomatedLinkedCloneFarm vGPU.json @@ -0,0 +1,97 @@ +{ + "Type": "AUTOMATED", + "Data": { + "Name": "LCFarmJson", + "DisplayName": "FarmJsonTest", + "AccessGroup": "Root", + "Description": "created LC Farm from PS via JSON with NVIDIA GRID VGPU", + "Enabled": null, + "Deleting": false, + "Settings": { + "DisconnectedSessionTimeoutPolicy": "NEVER", + "DisconnectedSessionTimeoutMinutes": 1, + "EmptySessionTimeoutPolicy": "AFTER", + "EmptySessionTimeoutMinutes": 1, + "LogoffAfterTimeout": false + }, + "Desktop": null, + "DisplayProtocolSettings": { + "DefaultDisplayProtocol": "PCOIP", + "AllowDisplayProtocolOverride": false, + "EnableHTMLAccess": false, + "EnableCollaboration": false, + "EnableGRIDvGPUs": true, + "VGPUGridProfile": "grid_m10-8a" + }, + "ServerErrorThreshold": null, + "MirageConfigurationOverrides": { + "OverrideGlobalSetting": false, + "Enabled": false, + "Url": null + } + }, + "AutomatedFarmSpec": { + "ProvisioningType": "VIEW_COMPOSER", + "VirtualCenter": null, + "RdsServerNamingSpec": { + "NamingMethod": "PATTERN", + "PatternNamingSettings": { + "NamingPattern": "LCFarmVMPS", + "MaxNumberOfRDSServers": 1 + } + }, + "VirtualCenterProvisioningSettings": { + "EnableProvisioning": true, + "StopProvisioningOnError": true, + "MinReadyVMsOnVComposerMaintenance": 0, + "VirtualCenterProvisioningData": { + "ParentVm": "RDSServer", + "Snapshot": "RDS_SNAP1", + "Datacenter": null, + "VmFolder": "Praveen", + "HostOrCluster": "CS-1", + "ResourcePool": "CS-1" + }, + "VirtualCenterStorageSettings": { + "Datastores": [ + { + "Datastore": "Datastore1", + "StorageOvercommit": "UNBOUNDED" + } + ], + "UseVSan": false, + "ViewComposerStorageSettings": { + "UseSeparateDatastoresReplicaAndOSDisks": false, + "ReplicaDiskDatastore": null, + "UseNativeSnapshots": false, + "SpaceReclamationSettings": { + "ReclaimVmDiskSpace": false, + "ReclamationThresholdGB": null, + "BlackoutTimes": null + } + } + }, + "VirtualCenterNetworkingSettings": { + "Nics": null + } + }, + "VirtualCenterManagedCommonSettings": { + "TransparentPageSharingScope": "VM" + }, + "CustomizationSettings": { + "CustomizationType": "SYS_PREP", + "DomainAdministrator": null, + "AdContainer": "CN=Computers", + "ReusePreExistingAccounts": false, + "SysprepCustomizationSettings": { + "CustomizationSpec": "PraveenCust" + } + }, + "RdsServerMaxSessionsData": { + "MaxSessionsType": "UNLIMITED", + "MaxSessions": null + } + }, + "ManualFarmSpec": null, + "NetBiosName": "adviewdev" +} \ No newline at end of file diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 index f5921d6..67a99cd 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 @@ -2243,6 +2243,21 @@ function New-HVFarm { [boolean] $EnableHTMLAccess = $false, + #farmSpec.data.displayProtocolSettings.EnableCollaboration + [Parameter(Mandatory = $false)] + [boolean] + $EnableCollaboration = $false, + + #farmSpec.data.displayProtocolSettings.EnableGRIDvGPUs + [Parameter(Mandatory = $false)] + [boolean] + $EnableGRIDvGPUs = $false, + + #farmSpec.data.displayProtocolSettings.VGPUGridProfile + [Parameter(Mandatory = $false)] + [string] + $VGPUGridProfile, + #farmSpec.data.serverErrorThreshold [Parameter(Mandatory = $false)] [ValidateRange(0,[Int]::MaxValue)] @@ -2659,6 +2674,12 @@ function New-HVFarm { $defaultDisplayProtocol = $jsonObject.Data.DisplayProtocolSettings.DefaultDisplayProtocol $allowDisplayProtocolOverride = $jsonObject.Data.DisplayProtocolSettings.AllowDisplayProtocolOverride $enableHTMLAccess = $jsonObject.Data.DisplayProtocolSettings.EnableHTMLAccess + $EnableCollaboration = $jsonObject.Data.DisplayProtocolSettings.EnableCollaboration + + if ($null -ne $jsonObject.Data.DisplayProtocolSettings.VGPUGridProfile) { + $EnableGRIDvGPUs = $jsonObject.Data.DisplayProtocolSettings.EnableGRIDvGPUs + $VGPUGridProfile = $jsonObject.Data.DisplayProtocolSettings.VGPUGridProfile + } } if ($null -ne $jsonObject.Data.serverErrorThreshold) { $serverErrorThreshold = $jsonObject.Data.serverErrorThreshold @@ -2802,6 +2823,11 @@ function New-HVFarm { $farmData.DisplayProtocolSettings.DefaultDisplayProtocol = $defaultDisplayProtocol $farmData.DisplayProtocolSettings.AllowDisplayProtocolOverride = $AllowDisplayProtocolOverride $farmData.DisplayProtocolSettings.EnableHTMLAccess = $enableHTMLAccess + $farmData.DisplayProtocolSettings.EnableCollaboration = $EnableCollaboration + if($VGPUGridProfile -ne $false){ + $farmData.DisplayProtocolSettings.EnableGRIDvGPUs = $EnableGRIDvGPUs + $farmData.DisplayProtocolSettings.VGPUGridProfile = $VGPUGridProfile + } } if ($farmData.MirageConfigurationOverrides){ $farmData.MirageConfigurationOverrides.OverrideGlobalSetting = $overrideGlobalSetting From 3653dd09bc6c44c87be79fcdb1d453ab81a9b635 Mon Sep 17 00:00:00 2001 From: Thibaut Noben Date: Tue, 27 Aug 2019 12:14:00 +0200 Subject: [PATCH 07/10] Removed spaces from name json file --- ...inkedCloneFarm vGPU.json => AutomatedLinkedCloneFarmVGPU.json} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Modules/VMware.Hv.Helper/Json/Farm/{AutomatedLinkedCloneFarm vGPU.json => AutomatedLinkedCloneFarmVGPU.json} (100%) diff --git a/Modules/VMware.Hv.Helper/Json/Farm/AutomatedLinkedCloneFarm vGPU.json b/Modules/VMware.Hv.Helper/Json/Farm/AutomatedLinkedCloneFarmVGPU.json similarity index 100% rename from Modules/VMware.Hv.Helper/Json/Farm/AutomatedLinkedCloneFarm vGPU.json rename to Modules/VMware.Hv.Helper/Json/Farm/AutomatedLinkedCloneFarmVGPU.json From 323b9e88f7ea5e03b5c6ea3893ad4cd45b6324f5 Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Tue, 10 Sep 2019 21:35:12 -0400 Subject: [PATCH 08/10] Update NewProfile.ps1 Removed redundant display (Core) in the console as it's displayed in the Title --- Scripts/At_Your_Fingertips/NewProfile.ps1 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Scripts/At_Your_Fingertips/NewProfile.ps1 b/Scripts/At_Your_Fingertips/NewProfile.ps1 index d4f2608..7fc2f05 100644 --- a/Scripts/At_Your_Fingertips/NewProfile.ps1 +++ b/Scripts/At_Your_Fingertips/NewProfile.ps1 @@ -8,7 +8,6 @@ # Added PowerShell-Core compatibility # # 1) PS prompt -# - detect pwsh-core # - current (local) time # - execution time of the previous command # - shortened PWD @@ -21,10 +20,6 @@ function prompt { - # Detect PS-Core - If ($PSVersionTable.PSEdition -eq 'Core') { - Write-Host '(Core) ' -NoNewLine - } # Current time $date = (Get-Date).ToString('HH:mm:ss') Write-Host -Object '[' -NoNewLine From 46db5d0f50aed4e76e41f9595a0d59b3548fdaee Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Tue, 10 Sep 2019 21:42:15 -0400 Subject: [PATCH 09/10] Revert "Update NewProfile.ps1" This reverts commit 323b9e88f7ea5e03b5c6ea3893ad4cd45b6324f5. --- Scripts/At_Your_Fingertips/NewProfile.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Scripts/At_Your_Fingertips/NewProfile.ps1 b/Scripts/At_Your_Fingertips/NewProfile.ps1 index 7fc2f05..d4f2608 100644 --- a/Scripts/At_Your_Fingertips/NewProfile.ps1 +++ b/Scripts/At_Your_Fingertips/NewProfile.ps1 @@ -8,6 +8,7 @@ # Added PowerShell-Core compatibility # # 1) PS prompt +# - detect pwsh-core # - current (local) time # - execution time of the previous command # - shortened PWD @@ -20,6 +21,10 @@ function prompt { + # Detect PS-Core + If ($PSVersionTable.PSEdition -eq 'Core') { + Write-Host '(Core) ' -NoNewLine + } # Current time $date = (Get-Date).ToString('HH:mm:ss') Write-Host -Object '[' -NoNewLine From 35095fbea71bc09aebe0ad2c31f9055f956dcfb5 Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Tue, 10 Sep 2019 21:46:44 -0400 Subject: [PATCH 10/10] Update NewProfile.ps1 Removed redundant display of (Core) in the console as it's displayed in the Title; minor cleanup. --- Scripts/At_Your_Fingertips/NewProfile.ps1 | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Scripts/At_Your_Fingertips/NewProfile.ps1 b/Scripts/At_Your_Fingertips/NewProfile.ps1 index d4f2608..a4b9f8d 100644 --- a/Scripts/At_Your_Fingertips/NewProfile.ps1 +++ b/Scripts/At_Your_Fingertips/NewProfile.ps1 @@ -8,7 +8,6 @@ # Added PowerShell-Core compatibility # # 1) PS prompt -# - detect pwsh-core # - current (local) time # - execution time of the previous command # - shortened PWD @@ -21,10 +20,6 @@ function prompt { - # Detect PS-Core - If ($PSVersionTable.PSEdition -eq 'Core') { - Write-Host '(Core) ' -NoNewLine - } # Current time $date = (Get-Date).ToString('HH:mm:ss') Write-Host -Object '[' -NoNewLine @@ -60,7 +55,7 @@ function prompt function Set-Title { # Running as Administrator or a regular user - If (($PSVersionTable.PSEdition -eq 'Core') -and ($IsWindows -eq 'True') -or ($PSVersionTable.PSEdition -ine 'Core')) + If (($PSEdition -eq 'Core') -and ($IsWindows -eq 'True') -or ($PSEdition -ine 'Core')) { $userInfo = [Security.Principal.WindowsIdentity]::GetCurrent() if ((New-Object Security.Principal.WindowsPrincipal $userInfo).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) @@ -74,7 +69,7 @@ function Set-Title } # Usertype user@hostname - If (($PSVersionTable.PSEdition -eq 'Core') -and ($IsWindows -ine 'True')) { + If (($PSEdition -eq 'Core') -and ($IsWindows -ine 'True')) { $env:computername = hostname $user = "$($env:user)@$($env:computername)" }