VMware Cloud Community
jv101
Contributor
Contributor

log storage vmotion end times

I have a script to stg vmotion 8 servers at a time, and its working fine thanks to some of you guys who provided sample scripts.

My current issue is that I want the script to capture the start and end time of each servers svmotion.

Currently my script only seems to capture the start time and end time of the execution of the script but not actually the start and end of the actual  svmotion tasks.

If anyone could help in proving some enhancement to the script to help achieve my requirements, it would be appreciated.

*******************

$logfile = "D:\xxxx\Scripts\svmotion-test15012024\svmotion_log.txt"
$maxParallel = 7
$filepath = "D:\xxxx\Scripts\svmotion-test15012024\svmotion-servers.csv"
$csvobj = import-csv $filepath

foreach ($row in $csvobj) {

# Log Start
$time = Get-Date -Format "dd/MM/yy_HH:mm: "
$value = "$time Storage vMotion $($csvobj.VMName) to $($csvobj.TargetDS) STARTED....."
$value | Add-Content $logfile

$vmobj = get-vm $row.VMName
$ds = get-datastore $row.TargetDS
$vmobj | move-vm -datastore $ds -confirm:$false -runasync

do

{

sleep 5

}

while((Get-Task -Status Running | where{$_.Name -eq 'RelocateVM_Task'}).Count -gt $maxParallel)

#Log Completed
$time = Get-Date -Format "dd/MM/yy_HH:mm: "
$value = "$time Storage vMotion $($csvobj.VMName) to $($csvobj.TargetDS) COMPLETED!!!!!"
$value | Add-Content $logfile

}

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

Reply
0 Kudos