Microsoft Virtualization Discussions
Microsoft Virtualization Discussions
I have to preface this by saying I'm new to powershell.
Criteria:
I want to create a DR Recovery script that will flexclone snapmirrored volumes in our DR Controller based on the VolumeMirrorAttributes.
Script:
$dr_vs0 = "net01"
$dr_vs1 = "net02"
$cluster = "net"
Connect-NcController $cluster -Vserver $dr_vs0
###################################
###################################
$dr_Attributes = Get-NcVol -VserverContext $dr_vs0 -Template
$dr_Query = Get-NcVol -Template
Initialize-NcObjectProperty -object $dr_Query -name VolumeMirrorAttributes
$dr_Query.VolumeMirrorAttributes.IsDataProtectionMirror = "True"
$dr_sm_volumes = Get-NcVol -Attributes $dr_Attributes -Query $dr_Query
$dr_clonevol = $dr_sm_volumes | Select-Object Name | ForEach-Object {$_.Name}
ForEach ($dr_i in $dr_clonevol) {
New-NcVolClone -CloneVolume $dr_vol"" -VserverContext $dr_vs0 -ParentVolume $dr_vol -SpaceReserve none
}
How would I pass the variable "$dr_clonevol" in to the ForEach loop and use it to name the cloned volume in the -CloneVolume parameter?
I keep getting "New-NcVolClone : Cannot bind argument to parameter 'ParentVolume' because it is null."
echo $dr_clonevol
vs1_data_xpd_2hr_01_mirror
vs1_data_xpd_2hr_04_mirror
vs1_data_xpd_2hr_05_mirror
vs1_vs1_data_xpd_2hr_02_mirror
vs1_vs1_data_xpd_2hr_03_mirror
Thanks in advance!!!
Solved! See The Solution
Hi,
I don't see the variable dr_vol being defined anywhere (assuming you've posted the entire script). That is the reason you're getting the "Can not bind" error - $dr_vol is in fact null.
As far as getting the cloneVol names in the for-each loop, I would suggest
$dr_sm_volumes = Get-NcVol -Attributes $dr_Attributes -Query $dr_Query ForEach ($dr_clonevol in $dr_sm_volumes) { New-NcVolClone -CloneVolume $dr_clonevol.Name -VserverContext $dr_vs0 -ParentVolume $dr_vol -SpaceReserve none }
But from your problem description, I think you want the output of Get-NcVol to be the parent volumes and create a clone as parent_vol_name_clone or something similar? In that case, I would suggest
$dr_sm_volumes = Get-NcVol -Attributes $dr_Attributes -Query $dr_Query ForEach ($dr_vol in $dr_sm_volumes) { $dr_clonevol_name = $dr_vol.Name + "_clone"; New-NcVolClone -CloneVolume $dr_clonevol_name -VserverContext $dr_vs0 -ParentVolume $dr_vol.Name -SpaceReserve none }
Hope this helps,
Aparajita
Hi,
I don't see the variable dr_vol being defined anywhere (assuming you've posted the entire script). That is the reason you're getting the "Can not bind" error - $dr_vol is in fact null.
As far as getting the cloneVol names in the for-each loop, I would suggest
$dr_sm_volumes = Get-NcVol -Attributes $dr_Attributes -Query $dr_Query ForEach ($dr_clonevol in $dr_sm_volumes) { New-NcVolClone -CloneVolume $dr_clonevol.Name -VserverContext $dr_vs0 -ParentVolume $dr_vol -SpaceReserve none }
But from your problem description, I think you want the output of Get-NcVol to be the parent volumes and create a clone as parent_vol_name_clone or something similar? In that case, I would suggest
$dr_sm_volumes = Get-NcVol -Attributes $dr_Attributes -Query $dr_Query ForEach ($dr_vol in $dr_sm_volumes) { $dr_clonevol_name = $dr_vol.Name + "_clone"; New-NcVolClone -CloneVolume $dr_clonevol_name -VserverContext $dr_vs0 -ParentVolume $dr_vol.Name -SpaceReserve none }
Hope this helps,
Aparajita
@Aparajita wrote:Hi,
I don't see the variable dr_vol being defined anywhere (assuming you've posted the entire script). That is the reason you're getting the "Can not bind" error - $dr_vol is in fact null.
As far as getting the cloneVol names in the for-each loop, I would suggest
$dr_sm_volumes = Get-NcVol -Attributes $dr_Attributes -Query $dr_Query ForEach ($dr_clonevol in $dr_sm_volumes) { New-NcVolClone -CloneVolume $dr_clonevol.Name -VserverContext $dr_vs0 -ParentVolume $dr_vol -SpaceReserve none }But from your problem description, I think you want the output of Get-NcVol to be the parent volumes and create a clone as parent_vol_name_clone or something similar? In that case, I would suggest
$dr_sm_volumes = Get-NcVol -Attributes $dr_Attributes -Query $dr_Query ForEach ($dr_vol in $dr_sm_volumes) { $dr_clonevol_name = $dr_vol.Name + "_clone"; New-NcVolClone -CloneVolume $dr_clonevol_name -VserverContext $dr_vs0 -ParentVolume $dr_vol.Name -SpaceReserve none }
Hope this helps,
Aparajita
I didn't include the intire script, only the final "at wits end" attempt but you obviously got the gist of what I was attempting to do. I ran with your recommendation and got the following error:
New-NcVolClone : Clone of a DP volume vs1_data_xpd_2hr_01_mirror cannot be created without snapshot. Please provide snapshot
I made the following modification:
ForEach ($dr_vol in $dr_sm_volumes) { $getsnap = Get-NcSnapshot -Volume $dr_vol.Name | sort Created -Descending $getsnap_snap0 = $getsnap[0] $dr_clonevol_name = $dr_vol.Name + "_DR_Test"; New-NcVolClone -CloneVolume $dr_clonevol_name -VserverContext $dr_vs0 -ParentVolume $dr_vol.Name -SpaceReserve none -ParentSnapshot $getsnap_snap0 }
This worked perfectly... the takeaway being the .Name after the variable. I don't understand why it's required - is this something you learn as you go?
Thanks!