Merge branch 'master' of https://github.com/kmruddy/PowerCLI-Example-Scripts
This commit is contained in:
@@ -190,7 +190,7 @@ Function Get-ContentLibraryItemFiles {
|
||||
$itemIds = $contentLibraryItemService.list($libraryID)
|
||||
$DatastoreID = $library.storage_backings.datastore_id.Value
|
||||
$Datastore = get-datastore -id "Datastore-$DatastoreID"
|
||||
|
||||
|
||||
foreach($itemId in $itemIds) {
|
||||
$itemName = ($contentLibraryItemService.get($itemId)).name
|
||||
$contentLibraryItemFileSerice = Get-CisService com.vmware.content.library.item.file
|
||||
@@ -205,7 +205,7 @@ Function Get-ContentLibraryItemFiles {
|
||||
else{
|
||||
$fullfilepath = "UNKNOWN"
|
||||
}
|
||||
|
||||
|
||||
if(!$LibraryItemName) {
|
||||
$fileResult = [pscustomobject] @{
|
||||
Name = $file.name;
|
||||
@@ -709,4 +709,72 @@ Function New-VMFromVMTX {
|
||||
|
||||
Write-Host "`nDeploying new VM $NewVMName from VMTX Template $VMTXName ..."
|
||||
$results = $vmtxService.deploy($vmtxId,$vmtxDeploySpec)
|
||||
}
|
||||
}
|
||||
|
||||
Function New-SubscribedContentLibrary {
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Created by: William Lam
|
||||
Organization: VMware
|
||||
Blog: www.virtuallyghetto.com
|
||||
Twitter: @lamw
|
||||
===========================================================================
|
||||
.DESCRIPTION
|
||||
This function creates a new Subscriber Content Library from Subscription URL
|
||||
.PARAMETER LibraryName
|
||||
The name of the new vSphere Content Library
|
||||
.PARAMETER DatastoreName
|
||||
The name of the vSphere Datastore to store the Content Library
|
||||
.PARAMETER SubscriptionURL
|
||||
The URL of the published Content Library
|
||||
.PARAMETER SubscriptionThumbprint
|
||||
The SSL Thumbprint for the published Content Library
|
||||
.PARAMETER OnDemand
|
||||
Specifies whether content is downloaded on-demand (e.g. no immediately)
|
||||
.PARAMETER AutomaticSync
|
||||
Specifies whether automatic synchronization with the external content library is enabled
|
||||
.EXAMPLE
|
||||
New-SubscribedContentLibrary -LibraryName NestedESXi -DatastoreName vsanDatastore -SubscriptionURL https://download3.vmware.com/software/vmw-tools/lib.json -SubscriptionThumbprint "7a:c4:08:2d:d3:55:56:af:9f:26:43:65:d0:31:99:0b:d2:f3:d8:69" -AutomaticSync
|
||||
.EXAMPLE
|
||||
New-SubscribedContentLibrary -LibraryName NestedESXi -DatastoreName vsanDatastore -SubscriptionURL https://download3.vmware.com/software/vmw-tools/lib.json -SubscriptionThumbprint "7a:c4:08:2d:d3:55:56:af:9f:26:43:65:d0:31:99:0b:d2:f3:d8:69" -OnDemand
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][String]$LibraryName,
|
||||
[Parameter(Mandatory=$true)][String]$DatastoreName,
|
||||
[Parameter(Mandatory=$true)][String]$SubscriptionURL,
|
||||
[Parameter(Mandatory=$true)][String]$SubscriptionThumbprint,
|
||||
[Parameter(Mandatory=$false)][Switch]$OnDemand,
|
||||
[Parameter(Mandatory=$false)][Switch]$AutomaticSync
|
||||
)
|
||||
|
||||
$datastore = Get-Datastore -Name $DatastoreName
|
||||
|
||||
if($datastore) {
|
||||
$datastoreId = $datastore.ExtensionData.MoRef.Value
|
||||
$subscribeLibraryService = Get-CisService -Name "com.vmware.content.subscribed_library"
|
||||
|
||||
$StorageSpec = [pscustomobject] @{
|
||||
datastore_id = $datastoreId;
|
||||
type = "DATASTORE";
|
||||
}
|
||||
|
||||
$UniqueChangeId = [guid]::NewGuid().tostring()
|
||||
|
||||
$createSpec = $subscribeLibraryService.help.create.create_spec.create()
|
||||
$createSpec.name = $LibraryName
|
||||
$createSpec.type = "SUBSCRIBED"
|
||||
$addResults = $createSpec.storage_backings.Add($StorageSpec)
|
||||
|
||||
if($OnDemand) { $OnDemandFlag = $true } else { $OnDemandFlag = $false }
|
||||
if($AutomaticSync) { $AutomaticSyncFlag = $true } else { $AutomaticSyncFlag = $false }
|
||||
$createSpec.subscription_info.on_demand = $OnDemandFlag
|
||||
$createSpec.subscription_info.automatic_sync_enabled = $AutomaticSyncFlag
|
||||
$createSpec.subscription_info.subscription_url = $SubscriptionURL
|
||||
$createSpec.subscription_info.authentication_method = "NONE"
|
||||
$createSpec.subscription_info.ssl_thumbprint = $SubscriptionThumbprint
|
||||
|
||||
Write-Host "Creating new Subscribed Content Library called $LibraryName ..."
|
||||
$library = $subscribeLibraryService.create($UniqueChangeId, $createSpec)
|
||||
}
|
||||
}
|
||||
@@ -152,10 +152,12 @@ Function New-XVCMRequest {
|
||||
The name of the source vSphere Datacenter
|
||||
.PARAMETER DstDatacenter
|
||||
The name of the destination vSphere Datacenter
|
||||
.PARAMETER SrcCluster
|
||||
<Not needed for v2.0,removed from code>
|
||||
.PARAMETER DstCluster
|
||||
The name of the destination vSphere Cluster, set to null if DstHost is defined
|
||||
.PARAMETER DstPool
|
||||
The name of the destination vSphere Resource Pool
|
||||
.PARAMETER DstFolder
|
||||
The name of the destination vSphere Folder
|
||||
.PARAMETER DstDatastore
|
||||
The name of the destination Datastore
|
||||
.PARAMETER DstHost
|
||||
@@ -171,6 +173,15 @@ Function New-XVCMRequest {
|
||||
-DstDatastore vsanDatastore `
|
||||
-srcVMs @("PhotonOS-01","PhotonOS-02","PhotonOS-03","PhotonOS-04") `
|
||||
-NetworkMapping @{"DVPG-VM Network 1"="DVPG-Internal Network";"DVPG-VM Network 2"="DVPG-External Network"}
|
||||
.EXAMPLE
|
||||
New-XVCMRequest -opType Clone -SrcSite OREGON -DstSite CALIF `
|
||||
-SrcDatacenter SDDC-Datacenter -srcVMs @(“DUDE-ubuntu”) `
|
||||
-DstDatacenter SDDC-Datacenter `
|
||||
-DstCluster "Cluster-1" -DstHost $null `
|
||||
-DstPool Compute-ResourcePool `
|
||||
-DstFolder Workloads `
|
||||
-DstDatastore WorkloadDatastore `
|
||||
-NetworkMapping @{"OREGON-VMs-sddc"="CALIF-sddc-VMs"}
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][String]$opType, #Added by CPM for 2.0
|
||||
@@ -178,8 +189,9 @@ Function New-XVCMRequest {
|
||||
[Parameter(Mandatory=$true)][String]$DstSite,
|
||||
[Parameter(Mandatory=$true)][String]$SrcDatacenter,
|
||||
[Parameter(Mandatory=$true)][String]$DstDatacenter,
|
||||
#[Parameter(Mandatory=$true)][String]$SrcCluster, #Removed by CPM for 2.0
|
||||
[Parameter(Mandatory=$true)][AllowNull()] $DstCluster, #Added [AllowNull()], removed [String] by CPM for 2.0
|
||||
[Parameter(Mandatory=$true)][String]$DstPool,
|
||||
[Parameter(Mandatory=$true)][String]$DstFolder,
|
||||
[Parameter(Mandatory=$true)][String]$DstDatastore,
|
||||
[Parameter(Mandatory=$true)][AllowNull()] $DstHost, #Added by CPM for 2.0
|
||||
[Parameter(Mandatory=$true)][String[]]$srcVMs,
|
||||
@@ -193,7 +205,8 @@ Function New-XVCMRequest {
|
||||
"targetSite"=$DstSite;
|
||||
"sourceDatacenter"=$SrcDatacenter;
|
||||
"targetDatacenter"=$dstDatacenter;
|
||||
#"sourceCluster"=$SrcCluster; #Removed by CPM for 2.0
|
||||
"targetPool"=$DstPool;
|
||||
"targetFolder"=$DstFolder;
|
||||
"targetCluster"=$DstCluster;
|
||||
"targetDatastore"=$DstDatastore;
|
||||
"targetHost"=$DstHost; #Added by CPM for 2.0
|
||||
|
||||
BIN
Modules/VMware.DRaaS/VMware.DRaaS.psd1
Executable file
BIN
Modules/VMware.DRaaS/VMware.DRaaS.psd1
Executable file
Binary file not shown.
256
Modules/VMware.DRaaS/VMware.DRaaS.psm1
Normal file
256
Modules/VMware.DRaaS/VMware.DRaaS.psm1
Normal file
@@ -0,0 +1,256 @@
|
||||
Function Connect-DRaas {
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Created by: William Lam
|
||||
Date: 05/23/2019
|
||||
Organization: VMware
|
||||
Blog: http://www.virtuallyghetto.com
|
||||
Twitter: @lamw
|
||||
===========================================================================
|
||||
|
||||
.SYNOPSIS
|
||||
This cmdlet creates $global:draasConnection object containing the DRaaS URL along with CSP Token Header
|
||||
.DESCRIPTION
|
||||
This cmdlet creates $global:draasConnection object containing the DRaaS URL along with CSP Token Header
|
||||
.EXAMPLE
|
||||
Connect-DRaaS -RefreshToken $RefreshToken -OrgName $OrgName -SDDCName $SDDCName
|
||||
.NOTES
|
||||
You must be logged into VMC using Connect-VmcServer cmdlet
|
||||
#>
|
||||
Param (
|
||||
[Parameter(Mandatory=$true)][String]$RefreshToken,
|
||||
[Parameter(Mandatory=$true)][String]$OrgName,
|
||||
[Parameter(Mandatory=$true)][String]$SDDCName
|
||||
)
|
||||
|
||||
If (-Not $global:DefaultVMCServers.IsConnected) { Write-error "No valid VMC Connection found, please use the Connect-VMC to connect"; break } Else {
|
||||
$sddcService = Get-VmcService "com.vmware.vmc.orgs.sddcs"
|
||||
$orgId = (Get-VMCOrg -Name $OrgName).Id
|
||||
$sddcId = (Get-VMCSDDC -Name $SDDCName -Org $OrgName).Id
|
||||
$sddc = $sddcService.get($orgId,$sddcId)
|
||||
|
||||
}
|
||||
|
||||
$results = Invoke-WebRequest -Uri "https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize?refresh_token=$RefreshToken" -Method POST -ContentType "application/json" -UseBasicParsing -Headers @{"csp-auth-token"="$RefreshToken"}
|
||||
if($results.StatusCode -ne 200) {
|
||||
Write-Host -ForegroundColor Red "Failed to retrieve Access Token, please ensure your VMC Refresh Token is valid and try again"
|
||||
break
|
||||
}
|
||||
$accessToken = ($results | ConvertFrom-Json).access_token
|
||||
|
||||
$headers = @{
|
||||
"csp-auth-token"="$accessToken"
|
||||
"Content-Type"="application/json"
|
||||
"Accept"="application/json"
|
||||
}
|
||||
$global:draasConnection = new-object PSObject -Property @{
|
||||
'Server' = "https://vmc.vmware.com/vmc/draas/api/orgs/$orgId/sddcs/$sddcId/site-recovery"
|
||||
'headers' = $headers
|
||||
}
|
||||
$global:draasConnection
|
||||
}
|
||||
|
||||
Function Get-DRaas {
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Created by: William Lam
|
||||
Date: 05/23/2019
|
||||
Organization: VMware
|
||||
Blog: http://www.virtuallyghetto.com
|
||||
Twitter: @lamw
|
||||
===========================================================================
|
||||
|
||||
.SYNOPSIS
|
||||
Returns information about DRaaS configuration for a given SDDC
|
||||
.DESCRIPTION
|
||||
This cmdlet returns information about DRaaS configuration for a given SDDC. Can be used to monitor both activate and deactivate operations.
|
||||
.EXAMPLE
|
||||
Get-DRaas
|
||||
#>
|
||||
Param (
|
||||
[Switch]$Troubleshoot
|
||||
)
|
||||
|
||||
If (-Not $global:draasConnection) { Write-error "No DRaaS Connection found, please use Connect-DRaaS" } Else {
|
||||
$method = "GET"
|
||||
$draasUrl = $global:draasConnection.Server
|
||||
$draasVersionUrl = $global:draasConnection.Server + "/versions"
|
||||
|
||||
if($Troubleshoot) {
|
||||
Write-Host -ForegroundColor cyan "`n[DEBUG] - $METHOD`n$draasUrl`n"
|
||||
}
|
||||
|
||||
try {
|
||||
if($PSVersionTable.PSEdition -eq "Core") {
|
||||
$requests = Invoke-WebRequest -Uri $draasUrl -Method $method -Headers $global:draasConnection.headers -SkipCertificateCheck
|
||||
} else {
|
||||
$requests = Invoke-WebRequest -Uri $draasUrl -Method $method -Headers $global:draasConnection.headers
|
||||
}
|
||||
} catch {
|
||||
if($_.Exception.Response.StatusCode -eq "Unauthorized") {
|
||||
Write-Host -ForegroundColor Red "`nThe CSP session is no longer valid, please re-run the Connect-DRaaS cmdlet to retrieve a new token`n"
|
||||
break
|
||||
} else {
|
||||
Write-Error "Error in retrieving DRaaS Information"
|
||||
Write-Error "`n($_.Exception.Message)`n"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if($requests.StatusCode -eq 200) {
|
||||
$json = ($requests.Content | ConvertFrom-Json)
|
||||
|
||||
$draasId = $json.id;
|
||||
$draasState = $json.site_recovery_state;
|
||||
$srmNode = $json.srm_node.ip_address;
|
||||
$srmNodeState = $json.site_recovery_state;
|
||||
$vrNode = $json.vr_node.ip_address;
|
||||
$vrNodeState = $json.vr_node.state;
|
||||
$draasUrl = $json.draas_h5_url;
|
||||
|
||||
if($srmNodeState -eq "ACTIVATED") {
|
||||
if($Troubleshoot) {
|
||||
Write-Host -ForegroundColor cyan "`n[DEBUG] - $METHOD`n$draasVersionUrl`n"
|
||||
}
|
||||
|
||||
try {
|
||||
if($PSVersionTable.PSEdition -eq "Core") {
|
||||
$requests = Invoke-WebRequest -Uri $draasVersionUrl -Method $method -Headers $global:draasConnection.headers -SkipCertificateCheck
|
||||
} else {
|
||||
$requests = Invoke-WebRequest -Uri $draasVersionUrl -Method $method -Headers $global:draasConnection.headers
|
||||
}
|
||||
} catch {
|
||||
if($_.Exception.Response.StatusCode -eq "Unauthorized") {
|
||||
Write-Host -ForegroundColor Red "`nThe CSP session is no longer valid, please re-run the Connect-DRaaS cmdlet to retrieve a new token`n"
|
||||
break
|
||||
} else {
|
||||
Write-Error "Error in retrieving DRaaS Information"
|
||||
Write-Error "`n($_.Exception.Message)`n"
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if($requests.StatusCode -eq 200) {
|
||||
$json = ($requests.Content | ConvertFrom-Json).node_versions
|
||||
|
||||
$srmVersion,$srmDescription = ($json | where {$_.node_ip -eq $srmNode}).full_version.split("`n")
|
||||
$vrVersion,$vrDescription = ($json | where {$_.node_ip -eq $vrNode}).full_version.split("`n")
|
||||
|
||||
$results = [pscustomobject] @{
|
||||
ID = $draasId;
|
||||
DRaaSState = $draasState;
|
||||
SRMNode = $srmNode;
|
||||
SRMVersion = $srmVersion;
|
||||
SRMNodeState = $srmNodeState;
|
||||
VRNode = $vrNode;
|
||||
VRVersion = $vrVersion;
|
||||
VRNodeState = $vrNodeState;
|
||||
DRaaSURL = $draasUrl;
|
||||
}
|
||||
|
||||
$results
|
||||
}
|
||||
} elseif ($srmNodeState -eq "ACTIVATING" -or $srmNodeState -eq "DEACTIVATING") {
|
||||
$results = [pscustomobject] @{
|
||||
ID = $draasId;
|
||||
DRaaSState = $draasState;
|
||||
SRMNode = $srmNode;
|
||||
SRMNodeState = $srmNodeState;
|
||||
VRNode = $vrNode;
|
||||
VRNodeState = $vrNodeState;
|
||||
DRaaSURL = $draasUrl;
|
||||
}
|
||||
|
||||
$results
|
||||
} else {
|
||||
Write-Host "`nDRaaS is currently deactivated, please run Set-DRaas -Activate`n"
|
||||
}
|
||||
} else {
|
||||
Write-Host "`nDRaaS has not been activated before, please run Set-DRaas -Activate`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Function Set-DRaas {
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Created by: William Lam
|
||||
Date: 05/23/2019
|
||||
Organization: VMware
|
||||
Blog: http://www.virtuallyghetto.com
|
||||
Twitter: @lamw
|
||||
===========================================================================
|
||||
|
||||
.SYNOPSIS
|
||||
Activate or deactivate DRaaS for a given SDDC
|
||||
.DESCRIPTION
|
||||
This cmdlet activates or deactivates DRaaS for a given SDDC
|
||||
.EXAMPLE
|
||||
Get-DRaas
|
||||
#>
|
||||
Param (
|
||||
[Switch]$Activate,
|
||||
[Switch]$Deactivate,
|
||||
[Switch]$Troubleshoot
|
||||
)
|
||||
|
||||
If (-Not $global:draasConnection) { Write-error "No DRaaS Connection found, please use Connect-DRaaS" } Else {
|
||||
$draasUrl = $global:draasConnection.server
|
||||
|
||||
if($Activate) {
|
||||
$method = "POST"
|
||||
|
||||
if($Troubleshoot) {
|
||||
Write-Host -ForegroundColor cyan "`n[DEBUG] - $METHOD`n$draasUrl`n"
|
||||
}
|
||||
|
||||
try {
|
||||
if($PSVersionTable.PSEdition -eq "Core") {
|
||||
$requests = Invoke-WebRequest -Uri $draasUrl -Method $method -Headers $global:draasConnection.headers -SkipCertificateCheck
|
||||
} else {
|
||||
$requests = Invoke-WebRequest -Uri $draasUrl -Method $method -Headers $global:draasConnection.headers
|
||||
}
|
||||
} catch {
|
||||
if($_.Exception.Response.StatusCode -eq "Unauthorized") {
|
||||
Write-Host -ForegroundColor Red "`nThe CSP session is no longer valid, please re-run the Connect-DRaaS cmdlet to retrieve a new token`n"
|
||||
break
|
||||
} else {
|
||||
Write-Error "Error in activating DRaaS"
|
||||
Write-Error "`n($_.Exception.Message)`n"
|
||||
break
|
||||
}
|
||||
}
|
||||
Write-Host "`nActivating DRaaS, this will take some time and you can monitor the progress using Get-DRaaS or using the VMC Console UI`n"
|
||||
} elseif ($Deactivate) {
|
||||
$method = "DELETE"
|
||||
|
||||
if($Troubleshoot) {
|
||||
Write-Host -ForegroundColor cyan "`n[DEBUG] - $METHOD`n$draasUrl`n"
|
||||
}
|
||||
|
||||
try {
|
||||
if($PSVersionTable.PSEdition -eq "Core") {
|
||||
$requests = Invoke-WebRequest -Uri $draasUrl -Method $method -Headers $global:draasConnection.headers -SkipCertificateCheck
|
||||
} else {
|
||||
$requests = Invoke-WebRequest -Uri $draasUrl -Method $method -Headers $global:draasConnection.headers
|
||||
}
|
||||
} catch {
|
||||
if($_.Exception.Response.StatusCode -eq "Unauthorized") {
|
||||
Write-Host -ForegroundColor Red "`nThe CSP session is no longer valid, please re-run the Connect-DRaaS cmdlet to retrieve a new token`n"
|
||||
break
|
||||
} else {
|
||||
Write-Error "Error in deactivating DRaaS"
|
||||
Write-Error "`n($_.Exception.Message)`n"
|
||||
break
|
||||
}
|
||||
}
|
||||
Write-Host "`nDeactivating DRaaS, this will take some time and you can monitor the progress using Get-DRaaS or the VMC Console UI`n"
|
||||
} else {
|
||||
Write-Error "Invalid Operation"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ Description = 'PowerShell Module for Managing Hybrid Cloud Extension (HCX) on VM
|
||||
PowerShellVersion = '6.0'
|
||||
|
||||
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
|
||||
FunctionsToExport = 'Connect-HcxServer', 'Get-HcxCloudConfig', 'Get-HcxEndpoint', 'New-HcxMigration', 'Get-HcxMigration', 'Connect-HcxVAMI', 'Get-HcxVCConfig', 'Set-HcxLicense', 'Set-HcxVCConfig', 'Get-HcxNSXConfig', 'Set-HcxNSXConfig', 'Get-HcxCity', 'Get-HcxLocation', 'Set-HcxLocation', 'Get-HcxRoleMapping', 'Set-HcxRoleMapping', 'Get-HcxProxy', 'Set-HcxProxy', 'Remove-HcxProxy'
|
||||
FunctionsToExport = 'Connect-HcxServer', 'Get-HcxCloudConfig', 'Get-HcxEndpoint', 'New-HcxMigration', 'Get-HcxMigration', 'Connect-HcxVAMI', 'Get-HcxVCConfig', 'Set-HcxLicense', 'Set-HcxVCConfig', 'Get-HcxNSXConfig', 'Set-HcxNSXConfig', 'Get-HcxCity', 'Get-HcxLocation', 'Set-HcxLocation', 'Get-HcxRoleMapping', 'Set-HcxRoleMapping', 'Get-HcxProxy', 'Set-HcxProxy', 'Remove-HcxProxy', 'Get-HcxLicense'
|
||||
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
||||
CmdletsToExport = @()
|
||||
|
||||
|
||||
@@ -453,12 +453,23 @@ Function Get-HcxMigration {
|
||||
Get-HcxMigration -MigrationId <MigrationID>
|
||||
#>
|
||||
Param (
|
||||
[Parameter(Mandatory=$false)][String]$MigrationId,
|
||||
[Parameter(Mandatory=$false)][String[]]$MigrationId,
|
||||
[Switch]$RunningMigrations
|
||||
)
|
||||
|
||||
If (-Not $global:hcxConnection) { Write-error "HCX Auth Token not found, please run Connect-HcxManager " } Else {
|
||||
$spec = @{}
|
||||
If($PSBoundParameters.ContainsKey("MigrationId")){
|
||||
$spec = @{
|
||||
filter = @{
|
||||
migrationId = $MigrationId
|
||||
}
|
||||
paging =@{
|
||||
pageSize = $MigrationId.Count
|
||||
}
|
||||
}
|
||||
} Else {
|
||||
$spec = @{}
|
||||
}
|
||||
$body = $spec | ConvertTo-Json
|
||||
|
||||
$hcxQueryUrl = $global:hcxConnection.Server + "/migrations?action=query"
|
||||
@@ -468,10 +479,10 @@ Function Get-HcxMigration {
|
||||
$requests = Invoke-WebRequest -Uri $hcxQueryUrl -Method POST -Headers $global:hcxConnection.headers -UseBasicParsing
|
||||
}
|
||||
|
||||
$migrations = ($requests.content | ConvertFrom-Json).rows
|
||||
|
||||
if($PSBoundParameters.ContainsKey("MigrationId")){
|
||||
$migrations = $migrations | where { $_.migrationId -eq $MigrationId }
|
||||
$migrations = ($requests.content | ConvertFrom-Json).items
|
||||
} else {
|
||||
$migrations = ($requests.content | ConvertFrom-Json).rows
|
||||
}
|
||||
|
||||
if($RunningMigrations){
|
||||
@@ -559,16 +570,22 @@ Function Get-HcxVCConfig {
|
||||
#>
|
||||
If (-Not $global:hcxVAMIConnection) { Write-error "HCX Auth Token not found, please run Connect-HcxVAMI " } Else {
|
||||
$vcConfigUrl = $global:hcxVAMIConnection.Server + "/api/admin/global/config/vcenter"
|
||||
$pscConfigUrl = $global:hcxVAMIConnection.Server + "/api/admin/global/config/lookupservice"
|
||||
|
||||
if($PSVersionTable.PSEdition -eq "Core") {
|
||||
$vcRequests = Invoke-WebRequest -Uri $vcConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing -SkipCertificateCheck
|
||||
$ssoRequests = Invoke-WebRequest -Uri $pscConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing -SkipCertificateCheck
|
||||
} else {
|
||||
$vcRequests = Invoke-WebRequest -Uri $vcConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing
|
||||
$ssoRequests = Invoke-WebRequest -Uri $pscConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing
|
||||
}
|
||||
$vcData = ($vcRequests.content | ConvertFrom-Json).data.items
|
||||
$ssoData = ($ssoRequests.content | ConvertFrom-Json).data.items
|
||||
|
||||
$tmp = [pscustomobject] @{
|
||||
Name = $vcData.config.name;
|
||||
UserName = $vcData.Config.userName
|
||||
LookupServiceUrl = $ssoData.config.lookupServiceUrl
|
||||
Version = $vcData.config.version;
|
||||
Build = $vcData.config.buildNumber;
|
||||
UUID = $vcData.config.vcuuid;
|
||||
@@ -578,6 +595,38 @@ Function Get-HcxVCConfig {
|
||||
}
|
||||
}
|
||||
|
||||
Function Get-HcxLicense {
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Created by: Mark McGilly
|
||||
Date: 4/29/2019
|
||||
Organization: Liberty Mutual Insurance
|
||||
===========================================================================
|
||||
|
||||
.SYNOPSIS
|
||||
Returns the license key that is registered with HCX Manager
|
||||
.DESCRIPTION
|
||||
This cmdlet returns the license key registered with HCX Manager
|
||||
.EXAMPLE
|
||||
Get-HcxLicense
|
||||
#>
|
||||
|
||||
If (-Not $global:hcxVAMIConnection) { Write-error "HCX Auth Token not found, please run Connect-HcxVAMI " } Else {
|
||||
$hcxConfigUrl = $global:hcxVAMIConnection.Server + "/api/admin/global/config/hcx"
|
||||
|
||||
if($PSVersionTable.PSEdition -eq "Core") {
|
||||
$licenseRequests = Invoke-WebRequest -Uri $hcxConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing -SkipCertificateCheck
|
||||
} else {
|
||||
$licenseRequests = Invoke-WebRequest -Uri $hcxConfigUrl -Method GET -Headers $global:hcxVAMIConnection.headers -UseBasicParsing
|
||||
}
|
||||
$license = ($licenseRequests.content | ConvertFrom-Json).data.items
|
||||
if($licenseRequests) {
|
||||
$license.config.activationKey
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Function Set-HcxLicense {
|
||||
<#
|
||||
.NOTES
|
||||
@@ -789,6 +838,7 @@ Function Get-HcxNSXConfig {
|
||||
|
||||
$tmp = [pscustomobject] @{
|
||||
Name = $nsxData.config.url;
|
||||
UserName = $nsxData.config.userName
|
||||
Version = $nsxData.config.version;
|
||||
HCXUUID = $nsxData.config.uuid;
|
||||
}
|
||||
@@ -1200,6 +1250,7 @@ Function Set-HcxProxy {
|
||||
[Parameter(Mandatory=$True)]$ProxyPort,
|
||||
[Parameter(Mandatory=$False)]$ProxyUser,
|
||||
[Parameter(Mandatory=$False)]$ProxyPassword,
|
||||
[Parameter(Mandatory=$False)]$ProxyExclusions,
|
||||
[Switch]$Troubleshoot
|
||||
)
|
||||
|
||||
@@ -1214,7 +1265,7 @@ Function Set-HcxProxy {
|
||||
config = @{
|
||||
proxyHost = "$ProxyServer";
|
||||
proxyPort = "$ProxyPort";
|
||||
nonProxyHosts = "";
|
||||
nonProxyHosts = "$ProxyExclusions";
|
||||
userName = "$ProxyUser";
|
||||
password = "$ProxyPassword";
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -36,7 +36,13 @@ Description = 'PowerShell Module for Managing NSX-T on VMware Cloud on AWS'
|
||||
PowerShellVersion = '6.0'
|
||||
|
||||
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
|
||||
FunctionsToExport = 'Connect-NSXTProxy', 'Get-NSXTSegment', 'New-NSXTSegment', 'Remove-NSXTSegment', 'Get-NSXTGroup', 'New-NSXTGroup', 'Remove-NSXTGroup', 'Get-NSXTService', 'New-NSXTService', 'Get-NSXTFirewall', 'New-NSXTFirewall', 'Remove-NSXTFirewall', 'Get-NSXTDistFirewallSection', 'Get-NSXTDistFirewall', 'New-NSXTDistFirewall', 'Remove-NSXTDistFirewall', 'Get-NSXTRouteTable', 'Get-NSXTOverviewInfo'
|
||||
FunctionsToExport = 'Connect-NSXTProxy', 'Get-NSXTSegment', 'New-NSXTSegment', 'Remove-NSXTSegment', `
|
||||
'Get-NSXTGroup', 'New-NSXTGroup', 'Remove-NSXTGroup', 'Get-NSXTService', 'New-NSXTService', `
|
||||
'Get-NSXTFirewall', 'New-NSXTFirewall', 'Remove-NSXTFirewall', 'Get-NSXTDistFirewallSection', `
|
||||
'Get-NSXTDistFirewall', 'New-NSXTDistFirewall', 'Remove-NSXTDistFirewall', 'Get-NSXTRouteTable', `
|
||||
'Get-NSXTOverviewInfo', 'Get-NSXTInfraScope', 'Get-NSXTInfraGroup', 'New-NSXTRouteBasedVPN', `
|
||||
'Get-NSXTRouteBasedVPN', 'Remove-NSXTRouteBasedVPN', 'Remove-NSXTService', 'New-NSXTDistFirewallSection', 'Get-NSXTDistFirewallSection', `
|
||||
'New-NSXTPolicyBasedVPN', 'Get-NSXTPolicyBasedVPN', 'Remove-NSXTPolicyBasedVPN', 'Get-NSXTDNS', 'Set-NSXTDNS'
|
||||
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
||||
CmdletsToExport = @()
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -874,8 +874,8 @@ Function Get-VMCSDDCSummary {
|
||||
Get-VMCSDDCSummary -Name <SDDC Name> -Org <Org Name>
|
||||
#>
|
||||
Param (
|
||||
[Parameter(Mandatory=$True)]$OrgName,
|
||||
[Parameter(Mandatory=$True)]$SDDCName
|
||||
[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 {
|
||||
@@ -895,6 +895,7 @@ Function Get-VMCSDDCSummary {
|
||||
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
|
||||
}
|
||||
@@ -903,7 +904,7 @@ Function Get-VMCPublicIP {
|
||||
<#
|
||||
.NOTES
|
||||
===========================================================================
|
||||
Created by: William Lam
|
||||
Created by: William LamVPC_VGW
|
||||
Date: 09/12/2018
|
||||
Organization: VMware
|
||||
Blog: http://www.virtuallyghetto.com
|
||||
|
||||
12
Scripts/Get-Migrations.ps1
Normal file
12
Scripts/Get-Migrations.ps1
Normal file
@@ -0,0 +1,12 @@
|
||||
<#
|
||||
Script name: get-migrations.ps1
|
||||
Created on: 20/12/2018
|
||||
Author: Chris Bradshaw @aldershotchris
|
||||
Description: The purpose of the script is to list the currently running + recently finished VM migrations.
|
||||
Dependencies: None known
|
||||
#>
|
||||
Function Get-Migrations{
|
||||
Get-Task |
|
||||
Where-Object{$_.Name -eq "RelocateVM_Task"} |
|
||||
Select-Object @{Name="VM";Expression={Get-VM -Id $_.ObjectID}}, State, @{Name="% Complete";Expression={$_.PercentComplete}},StartTime
|
||||
}
|
||||
@@ -1,147 +1,158 @@
|
||||
function Save-PowerCLI {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Advanced function which can be used to easily download specific versions of PowerCLI from an online gallery
|
||||
.DESCRIPTION
|
||||
Downloads a specific version of PowerCLI and all the dependencies at the appropriate version
|
||||
.NOTES
|
||||
Author: 1.0 - Dimitar Milov
|
||||
Author: 2.0 - Kyle Ruddy, @kmruddy
|
||||
.PARAMETER RequiredVersion
|
||||
Dynamic parameter used to specify the PowerCLI version
|
||||
.PARAMETER Path
|
||||
Directory path where the modules should be downloaded
|
||||
.PARAMETER Repository
|
||||
Repository to access the PowerCLI modules
|
||||
.PARAMETER Simple
|
||||
Switch used to specify the nested version folders should be removed (therefore adding PowerShell 3/4 compatibility)
|
||||
.EXAMPLE
|
||||
Save-PowerCLI -RequiredVersion '10.0.0.7895300' -Path .\Downloads\
|
||||
Downloads PowerCLI 10.0.0 to the Downloads folder
|
||||
.EXAMPLE
|
||||
Save-PowerCLI -RequiredVersion '6.5.2.6268016' -Path .\Downloads\ -Simple
|
||||
Downloads PowerCLI 6.5.2 to the Downloads folder and removes the nested version folders
|
||||
#>
|
||||
[CmdletBinding(SupportsShouldProcess = $True)]
|
||||
param(
|
||||
[Parameter(Mandatory = $true, Position = 1)]
|
||||
[ValidateScript( { Test-Path $_} )]
|
||||
$Path,
|
||||
[Parameter(Mandatory = $false, Position = 2)]
|
||||
[string]$Repository = 'PSGallery',
|
||||
[Parameter(Mandatory = $false, Position = 3)]
|
||||
[Switch]$Simple
|
||||
)
|
||||
DynamicParam
|
||||
{
|
||||
# Set the dynamic parameters name
|
||||
$ParameterName = 'RequiredVersion'
|
||||
|
||||
# Create the dictionary
|
||||
$RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
|
||||
|
||||
# Create the collection of attributes
|
||||
$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
|
||||
|
||||
# Create and set the parameters' attributes
|
||||
$ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
|
||||
$ParameterAttribute.ValueFromPipeline = $true
|
||||
$ParameterAttribute.ValueFromPipelineByPropertyName = $true
|
||||
$ParameterAttribute.Mandatory = $true
|
||||
$ParameterAttribute.Position = 0
|
||||
|
||||
# Add the attributes to the attributes collection
|
||||
$AttributeCollection.Add($ParameterAttribute)
|
||||
|
||||
# Generate and set the ValidateSet
|
||||
$pcliVersions = Find-Module -Name 'VMware.PowerCLI' -AllVersions
|
||||
$arrSet = $pcliVersions | select-Object -ExpandProperty Version
|
||||
$ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)
|
||||
|
||||
# Add the ValidateSet to the attributes collection
|
||||
$AttributeCollection.Add($ValidateSetAttribute)
|
||||
|
||||
# Create and return the dynamic parameter
|
||||
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
|
||||
$RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
|
||||
return $RuntimeParameterDictionary
|
||||
function Save-PowerCLI {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Advanced function which can be used to easily download specific versions of PowerCLI from an online gallery
|
||||
.DESCRIPTION
|
||||
Downloads a specific version of PowerCLI and all the dependencies at the appropriate version
|
||||
.NOTES
|
||||
Author: 1.0 - Dimitar Milov
|
||||
Author: 2.0 - Kyle Ruddy, @kmruddy
|
||||
Author: 2.1 - Luc Dekens, @LucD22
|
||||
- fixed issue with downloading the correct versions
|
||||
- added a working cleanup of unwanted versions
|
||||
.PARAMETER RequiredVersion
|
||||
Dynamic parameter used to specify the PowerCLI version
|
||||
.PARAMETER Path
|
||||
Directory path where the modules should be downloaded
|
||||
.PARAMETER Repository
|
||||
Repository to access the PowerCLI modules
|
||||
.PARAMETER Simple
|
||||
Switch used to specify the nested version folders should be removed (therefore adding PowerShell 3/4 compatibility)
|
||||
.EXAMPLE
|
||||
Save-PowerCLI -RequiredVersion '10.0.0.7895300' -Path .\Downloads\
|
||||
Downloads PowerCLI 10.0.0 to the Downloads folder
|
||||
.EXAMPLE
|
||||
Save-PowerCLI -RequiredVersion '6.5.2.6268016' -Path .\Downloads\ -Simple
|
||||
Downloads PowerCLI 6.5.2 to the Downloads folder and removes the nested version folders
|
||||
#>
|
||||
[CmdletBinding(SupportsShouldProcess = $True)]
|
||||
param(
|
||||
[Parameter(Mandatory = $true, Position = 1)]
|
||||
[ValidateScript( { Test-Path $_} )]
|
||||
$Path,
|
||||
[Parameter(Mandatory = $false, Position = 2)]
|
||||
[string]$Repository = 'PSGallery',
|
||||
[Parameter(Mandatory = $false, Position = 3)]
|
||||
[Switch]$Simple
|
||||
)
|
||||
DynamicParam
|
||||
{
|
||||
# Set the dynamic parameters name
|
||||
$ParameterName = 'RequiredVersion'
|
||||
|
||||
# Create the dictionary
|
||||
$RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
|
||||
|
||||
# Create the collection of attributes
|
||||
$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
|
||||
|
||||
# Create and set the parameters' attributes
|
||||
$ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
|
||||
$ParameterAttribute.ValueFromPipeline = $true
|
||||
$ParameterAttribute.ValueFromPipelineByPropertyName = $true
|
||||
$ParameterAttribute.Mandatory = $true
|
||||
$ParameterAttribute.Position = 0
|
||||
|
||||
# Add the attributes to the attributes collection
|
||||
$AttributeCollection.Add($ParameterAttribute)
|
||||
|
||||
# Generate and set the ValidateSet
|
||||
$pcliVersions = Find-Module -Name 'VMware.PowerCLI' -AllVersions
|
||||
$arrSet = $pcliVersions | select-Object -ExpandProperty Version
|
||||
$ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)
|
||||
|
||||
# Add the ValidateSet to the attributes collection
|
||||
$AttributeCollection.Add($ValidateSetAttribute)
|
||||
|
||||
# Create and return the dynamic parameter
|
||||
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [String], $AttributeCollection)
|
||||
$RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
|
||||
return $RuntimeParameterDictionary
|
||||
}
|
||||
|
||||
begin {
|
||||
$powercliModuleName = 'VMware.PowerCLI'
|
||||
$desiredPowerCLIModule = Find-Module -Name $powercliModuleName -RequiredVersion $PSBoundParameters.RequiredVersion -Repository $Repository
|
||||
|
||||
$depsOrder = 'VMware.VimAutomation.Sdk', 'VMware.VimAutomation.Common', 'VMware.Vim', 'VMware.VimAutomation.Cis.Core', 'VMware.VimAutomation.Core', 'VMware.VimAutomation.Nsxt', 'VMware.VimAutomation.Vmc', 'VMware.VimAutomation.Vds', 'VMware.VimAutomation.Srm', 'VMware.ImageBuilder', 'VMware.VimAutomation.Storage', 'VMware.VimAutomation.StorageUtility', 'VMware.VimAutomation.License', 'VMware.VumAutomation', 'VMware.VimAutomation.HorizonView', 'VMware.DeployAutomation', 'VMware.VimAutomation.vROps', 'VMware.VimAutomation.PCloud'
|
||||
$orderedDependencies = @()
|
||||
foreach ($depModuleName in $depsOrder) {
|
||||
$orderedDependencies += $desiredPowerCLIModule.Dependencies | Where-Object {$_.Name -eq $depModuleName}
|
||||
}
|
||||
|
||||
begin {
|
||||
$powercliModuleName = 'VMware.PowerCLI'
|
||||
$desiredPowerCLIModule = Find-Module -Name $powercliModuleName -RequiredVersion $RequiredVersion -Repository $Repository
|
||||
|
||||
$depsOrder = 'VMware.VimAutomation.Sdk', 'VMware.VimAutomation.Common', 'VMware.Vim', 'VMware.VimAutomation.Cis.Core', 'VMware.VimAutomation.Core', 'VMware.VimAutomation.Nsxt', 'VMware.VimAutomation.Vmc', 'VMware.VimAutomation.Vds', 'VMware.VimAutomation.Srm', 'VMware.ImageBuilder', 'VMware.VimAutomation.Storage', 'VMware.VimAutomation.StorageUtility', 'VMware.VimAutomation.License', 'VMware.VumAutomation', 'VMware.VimAutomation.HorizonView', 'VMware.DeployAutomation', 'VMware.VimAutomation.vROps', 'VMware.VimAutomation.PCloud'
|
||||
$orderedDependencies = @()
|
||||
foreach ($depModuleName in $depsOrder) {
|
||||
$orderedDependencies += $desiredPowerCLIModule.Dependencies | Where-Object {$_.Name -eq $depModuleName}
|
||||
|
||||
foreach ($remainingDep in $desiredPowerCLIModule.Dependencies) {
|
||||
if ($orderedDependencies.Name -notcontains $remainingDep.Name) {
|
||||
$orderedDependencies += $remainingDep
|
||||
}
|
||||
|
||||
foreach ($remainingDep in $desiredPowerCLIModule.Dependencies) {
|
||||
if ($orderedDependencies.Name -notcontains $remainingDep.Name) {
|
||||
$orderedDependencies += $remainingDep
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
# Save PowerCLI Module Version
|
||||
$desiredPowerCLIModule | Save-Module -Path $Path
|
||||
|
||||
# Working with the depenent modules
|
||||
foreach ($dependency in $orderedDependencies) {
|
||||
if (Get-ChildItem -Path (Join-Path $path $dependency.Name) | Where-Object {$_.Name -ne $dependency.MinimumVersion}) {
|
||||
# Save dependencies with minimum version
|
||||
Find-Module $dependency.Name -RequiredVersion $dependency.MinimumVersion | Save-Module -Path $Path
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
# Save PowerCLI Module Version
|
||||
$desiredPowerCLIModule | Save-Module -Path $Path
|
||||
|
||||
# Working with the depenent modules
|
||||
foreach ($dependency in $orderedDependencies) {
|
||||
if (Get-ChildItem -Path (Join-Path $path $dependency.Name) | Where-Object {$_.Name -ne $dependency.MinimumVersion}) {
|
||||
# Save dependencies with minimum version
|
||||
Find-Module $dependency.Name -RequiredVersion $dependency.MinimumVersion | Save-Module -Path $Path
|
||||
|
||||
# Remove newer dependencies version
|
||||
Get-ChildItem -Path (Join-Path $path $dependency.Name) | Where-Object {$_.Name -ne $dependency.MinimumVersion} | Remove-Item -Confirm:$false -Force -Recurse
|
||||
}
|
||||
|
||||
end {
|
||||
Get-Item -Path "$($Path)\*" -PipelineVariable dir |
|
||||
ForEach-Object -Process {
|
||||
$children = Get-ChildItem -Path $dir.FullName -Directory
|
||||
if($children.Count -gt 1){
|
||||
$tgtVersion = $orderedDependencies.GetEnumerator() | where {$_.Name -eq $dir.Name}
|
||||
$children | where{$_.Name -ne $tgtVersion.MinimumVersion} |
|
||||
ForEach-Object -Process {
|
||||
Remove-Item -Path $_.FullName -Recurse -Force -Confirm:$false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
if ($Simple) {
|
||||
|
||||
function FolderCleanup {
|
||||
param(
|
||||
[Parameter(Mandatory = $true, Position = 0)]
|
||||
[ValidateScript( { Test-Path $_} )]
|
||||
$ParentFolder,
|
||||
[Parameter(Mandatory = $true, Position = 1)]
|
||||
[String]$ModuleName,
|
||||
[Parameter(Mandatory = $true, Position = 2)]
|
||||
$Version
|
||||
)
|
||||
|
||||
|
||||
$topFolder = Get-Item -Path (Join-Path $ParentFolder $ModuleName)
|
||||
$versionFolder = $topFolder | Get-ChildItem -Directory | Where-Object {$_.Name -eq $Version}
|
||||
$versionFolder | Get-ChildItem | Copy-Item -Destination $topFolder
|
||||
|
||||
# Checking for any nested folders within the PowerCLI module version folder
|
||||
if ($versionFolder| Get-ChildItem -Directory) {
|
||||
|
||||
# Obtaining and storing the child items to a variable, then copying the items to the parent folder's nested folder
|
||||
$nestFolder = $versionFolder| Get-ChildItem -Directory
|
||||
foreach ($nestDir in $nestFolder) {
|
||||
$nestDir | Get-ChildItem | Copy-Item -Destination (Join-Path $topFolder $nestDir.Name)
|
||||
}
|
||||
|
||||
|
||||
if ($Simple) {
|
||||
|
||||
function FolderCleanup {
|
||||
param(
|
||||
[Parameter(Mandatory = $true, Position = 0)]
|
||||
[ValidateScript( { Test-Path $_} )]
|
||||
$ParentFolder,
|
||||
[Parameter(Mandatory = $true, Position = 1)]
|
||||
[String]$ModuleName,
|
||||
[Parameter(Mandatory = $true, Position = 2)]
|
||||
$Version
|
||||
)
|
||||
|
||||
|
||||
$topFolder = Get-Item -Path (Join-Path $ParentFolder $ModuleName)
|
||||
$versionFolder = $topFolder | Get-ChildItem -Directory | Where-Object {$_.Name -eq $Version}
|
||||
$versionFolder | Get-ChildItem | Copy-Item -Destination $topFolder
|
||||
|
||||
# Checking for any nested folders within the PowerCLI module version folder
|
||||
if ($versionFolder| Get-ChildItem -Directory) {
|
||||
|
||||
# Obtaining and storing the child items to a variable, then copying the items to the parent folder's nested folder
|
||||
$nestFolder = $versionFolder| Get-ChildItem -Directory
|
||||
foreach ($nestDir in $nestFolder) {
|
||||
$nestDir | Get-ChildItem | Copy-Item -Destination (Join-Path $topFolder $nestDir.Name)
|
||||
}
|
||||
|
||||
# Removing any of the former, no longer needed, directory structure
|
||||
$versionFolder| Remove-Item -Recurse -Force
|
||||
|
||||
}
|
||||
|
||||
FolderCleanup -ParentFolder $Path -ModuleName $desiredPowerCLIModule.Name -Version $desiredPowerCLIModule.Version
|
||||
foreach ($cleanUp in $orderedDependencies) {
|
||||
|
||||
FolderCleanup -ParentFolder $Path -ModuleName $cleanUp.Name -Version $cleanUp.MinimumVersion
|
||||
}
|
||||
|
||||
|
||||
# Removing any of the former, no longer needed, directory structure
|
||||
$versionFolder| Remove-Item -Recurse -Force
|
||||
}
|
||||
|
||||
|
||||
FolderCleanup -ParentFolder $Path -ModuleName $desiredPowerCLIModule.Name -Version $desiredPowerCLIModule.Version
|
||||
foreach ($cleanUp in $orderedDependencies) {
|
||||
|
||||
FolderCleanup -ParentFolder $Path -ModuleName $cleanUp.Name -Version $cleanUp.MinimumVersion
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user