Hi LucD
Please help me with the following script
Currently you helped me to formulate this array with two fields and it works fine
###############################################################
Reference Table
Source_VLAN | Destination_VLAN |
X1-VLAN-110-ZZZZZZ-VMN | abc01-w03-cl01--pg-vlan-110 |
X1-VLAN-111-ZZZK-VMN | abc01-w03-cl01--pg-vlan-111 |
X1-VLAN-111-ZZZZZZ-VMN | abc01-w03-cl01--pg-vlan-111 |
X1-VLAN-112-ZZZK-VMN | abc01-w03-cl01--pg-vlan-112 |
X1-VLAN-112-ZZZZZZ-VMN | abc01-w03-cl01--pg-vlan-112 |
X1-VLAN-114-ZZZZZZ-VMN | abc01-w03-cl01--pg-vlan-114 |
X1-VLAN-114-ZZZK-VMN | abc01-w03-cl01--pg-vlan-114 |
X1-VLAN-115-ZZZK-VMN | abc01-w03-cl01--pg-vlan-115 |
X1-VLAN-115-ZZZZZZ-VMN | abc01-w03-cl01--pg-vlan-115 |
X1-VLAN-116-ZZZZZZ-VMN | abc01-w03-cl01--pg-vlan-116 |
Try {
$tabvlan =$null
$tabvlan = @{}
Import-Csv -Path "$workingdir\vMotion_VLAN_Reference_Table\vLan_Reference.csv" -Delimiter ";" -PipelineVariable row |
ForEach-Object -Process {
if(-not $tabvlan.($row.SrcDvPG)) {$tabvlan.Add($row.SrcDvPG,$row.DstDvPG)}
}
}
Catch
{
Write-Warning ""
Write-Host "Error Ran into issues: $($PSItem.ToString()) " -ForegroundColor Red
""
Write-Host "Error !!! Check above error for details" -ForegroundColor DarkYellow
}
########################################################################
However I now need reference four columns
Reference Table
Source_cluuster_Name | Source_VLAN | Destination_cluuster_Name | Destination_VLAN |
cluuster005_BAK_Test | VLAN-752-BB-VMN-Test | abc01-w03-clu02 | abc01-w03-clu02--pg-vlan-752 |
cluuster005_BAK_Test | VLAN-753-BB-VMN-Test | abc01-w03-clu02 | abc01-w03-clu02--pg-vlan-753 |
cluuster049_cluU_P2_WNN | P2-VLAN-258-WNN | abc01-w04-clu01 | abc01-w04-clu01--pg-vlan-258
|
Please help me with the code to reference four columns
I am using the following to create a template file
#####################################
## Creating VM Template File ###
#####################################
Try {
Get-cluster $selectedCLuster.name -ErrorAction Stop |Get-VMHost $TemplateDetails.vmHost -ErrorAction Stop |get-vm -ErrorAction Stop|`
#Get-cluster $selectedCLuster.name |Get-VMHost -Name $TemplateDetails.vmHost |get-vm |`
Select-Object @{N= 'Comment' ; E={ '#'}},
@{N= 'VMName' ; E={$_.name }},
@{N= 'NW_Adapter1' ; E={(Get-NetworkAdapter -VM $_)[0].Name }},
@{N= 'Src_NW1' ; E={(get-networkadapter -VM $_)[0].NetworkName}},
@{N= 'SDI_NW1' ; E={ $tabvlan[(Get-NetworkAdapter -VM $_)[0].NetworkName]}},
@{N= 'NW_Adapter2' ; E={(Get-NetworkAdapter -VM $_)[1].Name }},
@{N= 'Src_NW2' ; E={(get-networkadapter -VM $_)[1].NetworkName}},
@{N= 'SDI_NW2' ; E={ $tabvlan[(Get-NetworkAdapter -VM $_)[1].NetworkName]}},
@{N= 'NW_Adapter3' ; E={(Get-NetworkAdapter -VM $_)[2].Name }},
@{N= 'Src_NW3' ; E={(get-networkadapter -VM $_)[2].NetworkName}},
@{N= 'SDI_NW3' ; E= { $tabvlan[(Get-NetworkAdapter -VM $_)[2].NetworkName]}},
@{N= 'NW_Adapter4' ; E={(Get-NetworkAdapter -VM $_)[3].Name }},
@{N= 'Src_NW4' ; E={(get-networkadapter -VM $_)[3].NetworkName}} |`
Export-csv -Path "$($FilesAndLogDir)\$vMotion_Template_Name" -NoTypeInformation -UseCulture -ErrorAction Stop
Catch
{
""
Write-Warning ""
Write-Host "Ran into an issue: $($PSItem.ToString())" -ForegroundColor Red
}
Not sure I see the question.
Help you with what?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
I need to reference the following table
Reference Table
Source_cluuster_Name | Source_VLAN | Destination_cluuster_Name | Destination_VLAN |
cluuster005_BAK_Test | VLAN-752-BB-VMN-Test | abc01-w03-clu02 | abc01-w03-clu02--pg-vlan-752 |
cluuster005_BAK_Test | VLAN-753-BB-VMN-Test | abc01-w03-clu02 | abc01-w03-clu02--pg-vlan-753 |
cluuster049_cluU_P2_WNN | P2-VLAN-258-WNN | abc01-w04-clu01 | abc01-w04-clu01--pg-vlan-258
|
Hi LucD
The code below only works to reference two columns but i need to reference four columns
ry {
$tabvlan =$null
$tabvlan = @{}
Import-Csv -Path "$workingdir\vMotion_VLAN_Reference_Table\vLan_Reference.csv" -Delimiter ";" -PipelineVariable row |
ForEach-Object -Process {
if(-not $tabvlan.($row.SrcDvPG)) {$tabvlan.Add($row.SrcDvPG,$row.DstDvPG)}
}
}
Catch
{
Write-Warning ""
Write-Host "Error Ran into issues: $($PSItem.ToString()) " -ForegroundColor Red
""
Write-Host "Error !!! Check above error for details" -ForegroundColor DarkYellow
}
I got that, but what do you need to do?
Just add this to the same hash table?
And how are you going to use that hash table?
What are you looking up (of those 4 columns)?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
I am doing VM migrations across Clusters so I have the source cluster and Source portgroup, which i need to match with Destination cluster and destination portgroup
Once its matched then i used the following script to create a Template file and I use that template file for migrations
Get-cluster $selectedCLuster.name -ErrorAction Stop |Get-VMHost $TemplateDetails.vmHost -ErrorAction Stop |get-vm -ErrorAction Stop|`
#Get-cluster $selectedCLuster.name |Get-VMHost -Name $TemplateDetails.vmHost |get-vm |`
Select-Object @{N= 'Comment' ; E={ '#'}},
@{N= 'VMName' ; E={$_.name }},
@{N= 'NW_Adapter1' ; E={(Get-NetworkAdapter -VM $_)[0].Name }},
@{N= 'Src_NW1' ; E={(get-networkadapter -VM $_)[0].NetworkName}},
@{N= 'SDI_NW1' ; E={ $tabvlan[(Get-NetworkAdapter -VM $_)[0].NetworkName]}},
@{N= 'NW_Adapter2' ; E={(Get-NetworkAdapter -VM $_)[1].Name }},
@{N= 'Src_NW2' ; E={(get-networkadapter -VM $_)[1].NetworkName}},
@{N= 'SDI_NW2' ; E={ $tabvlan[(Get-NetworkAdapter -VM $_)[1].NetworkName]}},
@{N= 'NW_Adapter3' ; E={(Get-NetworkAdapter -VM $_)[2].Name }},
@{N= 'Src_NW3' ; E={(get-networkadapter -VM $_)[2].NetworkName}},
@{N= 'SDI_NW3' ; E= { $tabvlan[(Get-NetworkAdapter -VM $_)[2].NetworkName]}},
@{N= 'NW_Adapter4' ; E={(Get-NetworkAdapter -VM $_)[3].Name }},
@{N= 'Src_NW4' ; E={(get-networkadapter -VM $_)[3].NetworkName}} |`
Export-csv -Path "$($FilesAndLogDir)\$vMotion_Template_Name" -NoTypeInformation -UseCulture -ErrorAction Stop
Many thanks
RXJ
Ok, if I understand it correctly you also need to find the destination cluster based on the current cluster (same concept as for the portgroup).
Since a hash table contains a Key and a Value, it is impossible to look up something based on 2 different types of keys.
In your case I would just create a 2nd hash table with the source and destination cluster information from the CSV.
Then you can look up the destination cluster in the same way as you now do for the portgroup.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
No I need to match the entries of Source PortGroup and Destination Cluster to get the correct Destination Portgroup
Thats is Source_Portgroup , Destination_Cluster ==> Destination_PortGroup
So what i need to know is how can use two keys and find the value
$tabvlan =$null
$tabvlan = @{}
Import-Csv -Path "$workingdir\vMotion_VLAN_Reference_Table\vLan_Reference.csv" -Delimiter ";" -PipelineVariable row |
ForEach-Object -Process {
if(-not $tabvlan.($row.Source_Portgroup)) {$tabvlan.Add($row.Source_Portgroup,$row.Source_Cluster , $row.Destination_Portgroup)}
Hope i have made it clear
Many thanks
RXJ
Then you will have to append the Source Portgroup and Destination Cluster as a unique key.
But how do you know the Destination Cluster?
In your code, for a VM, you can find the Source Portgroup and the Source Cluster.
Which logic do you use to find the Destination Cluster?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
The destination Cluster and Destination VLAN are mapped from the CSV file
So basically I need to use the CSV file and determine the Destination VLAN ( to determine the destination VLAN i am using the Source_Portgroup and the destination Cluster )
This worked perfectly when i had SOurce_Portgroup and Destination_Portgroup
Now i need to take Destination Cluster into consideration and thats where I have no idea how to put this across
Many thanks
RXJ
It is still not clear to me from where you get the Destination Cluster.
Is that based on the Source Portgroup?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference