StorageUtility.psm1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 |
############################################################################## # #.SYNOPSIS # Get the Vms Disk foot print # #.DESCRIPTION # Disk foot print is calculated below file which makes an VM # Config files (.vmx, .vmxf, .vmsd, .nvram) # Log files (.log) # Disk files (.vmdk) # Snapshots (delta.vmdk, .vmsn) # Swapfile (.vswp) # # Get-View -VIObject centOs-1 # TypeName: VMware.Vim.VirtualMachineFileInfo # FtMetadataDirectory Property string FtMetadataDirectory {get;set;} # LogDirectory Property string LogDirectory {get;set;} # SnapshotDirectory Property string SnapshotDirectory {get;set;} # SuspendDirectory Property string SuspendDirectory {get;set;} # VmPathName Property string VmPathName {get;set;} # #.PARAMETER vm # VM Object returned by Get-VM cmdlet # #.EXAMPLE # $vmSize = Get-VmDisksFootPrint($vm) # ############################################################################## Function Get-VmDisksFootPrint($vm) { #Initialize variables $VmDirs = @() $VmSize = 0 $vmDsIdMap = @{} $searchSpec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec $searchSpec.details = New-Object VMware.Vim.FileQueryFlags $searchSpec.details.fileSize = $TRUE Get-View -VIObject $vm | % { #Populate the array with the vm's directories $VmDirs += $_.Config.Files.VmPathName.split("/")[0] $VmDirs += $_.Config.Files.SnapshotDirectory.split("/")[0] $VmDirs += $_.Config.Files.SuspendDirectory.split("/")[0] $VmDirs += $_.Config.Files.LogDirectory.split("/")[0] foreach ($dsMoref in $_.Datastore){ $vmDsIdMap[(Get-Datastore -Id $dsMoref).Name] = $dsMoRef } #Add directories of the vm's virtual disk files foreach ($disk in $_.Layout.Disk) { foreach ($diskfile in $disk.diskfile) { $VmDirs += $diskfile.split("/")[0] } } #Only take unique array items $VmDirs = $VmDirs | Sort-Object | Get-Unique foreach ($dir in $VmDirs) { $datastoreObj = $vmDsIdMap[ ($dir.split("[")[1]).split("]")[0] ] $datastoreBrowser = Get-View (( Get-Datastore -Id $datastoreObj | get-view).Browser) $taskMoRef = $datastoreBrowser.SearchDatastoreSubFolders_Task($dir,$searchSpec) $task = Get-View $taskMoRef while($task.Info.State -eq "running" -or $task.Info.State -eq "queued") {$task = Get-View $taskMoRef } foreach ($result in $task.Info.Result){ foreach ($file in $result.File){ $VmSize += $file.FileSize } } } } return $VmSize } ############################################################################## # #.SYNOPSIS # Get the ESX version of the Host # #.DESCRIPTION # Return the ESX product version of the HostObjects supplied in parameter # #.PARAMETER EsxHosts # Host Objects # #.EXAMPLE # $HostObjects = Get-View -ViewType HostSystem # $Hash = Get-HostVersion -EsxHosts $HostObjects # ############################################################################## Function Get-HostVersion { param([Object]$EsxHosts= "") $EsxHostVersion = @{} Foreach ($esx in $HostObjects) { $version = $esx.Config.Product.version $EsxHostVersion[$esx] = $version } return $EsxHostVersion } ################################################################################################################## # #.SYNOPSIS # Perform preflight check before proceeding with migration # #.DESCRIPTION # Top level function calling respective preflight checks before proceeding # with migration # #.PARAMETER Function # Function to call # #.PARAMETER TargetObjects # Target Object is being verified # #.PARAMETER ExpectedValue # Attribute to verify # #.EXAMPLE # PreFlightCheck -Function "CheckHostVersion" -TargetObjects $HostObjects -ExpectedValue $TargettedHostVersion # ################################################################################################################## Function PreFlightCheck { param( [parameter(Mandatory=$true)][string]$Function, [object]$TargetObjects, [object]$ExpectedValue ) if(Get-Command $Function -ea SilentlyContinue) { #write-host $Function $TargetObjects $ExpectedValue & $Function $TargetObjects $ExpectedValue } else { # ignore } } ############################################################################## #.SYNOPSIS # PreFLight check for ESX version # #.DESCRIPTION # Function check the host version # #.PARAMETER HostObjects # Target Object is being verified # #.PARAMETER Version # Expected Version # #.EXAMPLE # $status = CheckHostVersion -HostObjects $hostObject -Version $version ############################################################################## Function CheckHostVersion { param( [parameter(Mandatory=$true)][object]$HostObjects, [String]$Version ) $status = $true $targetVersion = New-Object System.Version($version) $Hash = Get-HostVersion -EsxHosts $HostObjects foreach ($host in $HostObjects) { $hostName = $host.Name $hostVersion = New-Object System.Version($host.Config.Product.version) if($hostVersion -ge $targetVersion) { $status = $status -And $true Format-output -Text "VM host $hostName is of version $hostVersion" -Level "SUCCESS" -Phase "Pre-Check" } else { $status = $status -And $false Format-output -Text "VM host $hostName is of version $hostVersion" -Level "ERROR" -Phase "Pre-Check" } } return $status } ############################################################################## # #.SYNOPSIS # Format the log messages # #.DESCRIPTION # Format the log message printed on the screen # Also redirect the message to a log file # #.PARAMETER # Text - log message to be printed # Level - SUCCESS,INFO,ERROR # Phase - Different phase of commandlet, Preperation,Migration,Roll back # # #.EXAMPLE # Format-output -Text $MsgText -Level "INFO" -Phase "Migration Pre-Check phase" # ############################################################################## Function Format-output { param ( [Parameter(Mandatory=$true)][string]$Text, [Parameter(Mandatory=$true)][string]$Level, [Parameter(Mandatory=$false)][string]$Phase ) BEGIN { filter timestamp {"$(Get-Date -Format s) `[$Phase`] $Text" } } PROCESS { $Text | timestamp | Out-File -FilePath $global:LogFile -Append -Force if($Level -eq "SUCCESS" ) { $Text | timestamp | write-host -foregroundcolor "green" } elseif ( $Level -eq "INFO") { $Text | timestamp | write-host -foregroundcolor "yellow" } else { $Text | timestamp | write-host -foregroundcolor "red" } } } <# .SYNOPSIS Wrapper Funtion to Call Storage Vmotion .DESCRIPTION You may send a list of vm names .PARAMETER VM Pass vmnames .PARAMETER Destination PASS Destination datastore name .PARAMETER Destination PASS ParallelTasks to perform .INPUTS .OUTPUTS .EXAMPLE Storage-Vmotion -VM $vmlist -Destination 'Datastore_1' -ParallelTasks 2 #> Function Concurrent-SvMotion { [CmdletBinding()] param ( [Parameter(Mandatory = $true)][VMware.VimAutomation.ViCore.Util10.VersionedObjectImpl]$session, [Parameter(Mandatory = $true)][string[]]$VM, [Parameter(Mandatory = $true)][string]$SourceId, [Parameter(Mandatory = $true)][string]$DestinationId, [Parameter(Mandatory = $true)][int]$ParallelTasks ) BEGIN { $TargetDatastoreId = $DestinationId $Date = get-date $VmsToMigrate = $VM $Failures = 0; $LoopCtrl = 1 $VmInput = $VM $GB = 1024 * 1024 * 1024 $BufferSize = 5 $RelocateTaskList = @() } PROCESS { while ($LoopCtrl -gt 0) { $shiftedVm = shift -array ([ref]$vmInput) -numberOfElements $ParallelTasks $vmToMigrate = $shiftedVm $LoopCtrl = $vmInput.Count #Check the datastore contain sufficient space foreach ($TargetVm in $vmToMigrate) { $vm = Get-VM $TargetVm $vmSize += Get-VmDisksFootPrint $vm } $vmSize = [math]::Round(($vmSize / $GB) + $BufferSize) $tagetDatastoreObj = Get-Datastore -Id $TargetDatastoreId if($tagetDatastoreObj.FreeSpaceGB -gt $vmSize) { $MsgText = "$TargetDatastore Contain FreeSpace of $($tagetDatastoreObj.FreeSpaceGB) GB to accomodate $vmToMigrate of size $vmSize GB" Format-output -Text $MsgText -Level "INFO" -Phase "Migration Pre-Check phase" $RelocateTaskList += Storage-Vmotion -session $session -Source $SourceId -VM $vmToMigrate -Destination $DestinationId # Iterate through has list of TaskMap and check for task failures foreach ($Task in $RelocateTaskList ) { if ( $Task["State"] -ne "Success" ) { $Failure += 1 return $RelocateTaskList } else { $Success += 1 } } } else { #If insufficient datastore space just mark the migration task as failure $MsgText = "$TargetDatastore have insufficient space. FreeSpace of $($tagetDatastoreObj.FreeSpaceGB) GB to accomdate $vmToMigrate of size $vmSize GB" Format-output -Text $MsgText -Level "INFO" -Phase "Migration Pre-Check phase" $TaskMap = @{} $TaskMap["Name"] = $TargetVm $TaskMap["State"] = "Error" $TaskMap["Cause"] = "INSUFFICIENT_DATASTORE_SPACE" $RelocTaskList += $TaskMap return $RelocateTaskList } } return $RelocateTaskList } } Function MoveTheVM { [CmdletBinding()] param ( [Parameter(Mandatory=$true)][VMware.VimAutomation.ViCore.Util10.VersionedObjectImpl]$session, [Parameter(Mandatory=$true)][String]$VM, [Parameter(Mandatory=$true)][string]$SourceId, [Parameter(Mandatory=$true)][string]$DestinationId ) BEGIN { $vm = $VM $datastore = (Get-Datastore -id $SourceId) $tempdatastore = (Get-Datastore -id $DestinationId) } PROCESS { try { $vmName=Get-VM -Name $vm $vmId = $vmName.id $MsgText ="VM = $vm, Datastore = $datastore and Target datastore = $tempdatastore and id is $vmId" Format-output -Text $MsgText -Level "INFO" -Phase "VM migration" $hds = Get-HardDisk -VM $vm $spec = New-Object VMware.Vim.VirtualMachineRelocateSpec $vmView=get-view -id $vmId if($vmView.Summary.Config.VmPathName.Contains($datastore)) { $spec.datastore = ($tempdatastore).Extensiondata.MoRef } $hds | %{ if ($_.Filename.Contains($datastore)) { $disk = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator $disk.diskId = $_.ExtensionData.Key $disk.datastore = ($tempdatastore).Extensiondata.MoRef $spec.disk += $disk } else { $extendedDs = $_.ExtensionData.Backing.Datastore $disk = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator $disk.diskId = $_.ExtensionData.Key $disk.datastore = $extendedDs $spec.disk += $disk } } $task = $vmName.Extensiondata.RelocateVM_Task($spec, "defaultPriority") $task1 = Get-Task -server $session | where { $_.id -eq $task } return $task1 } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "Error" -Phase "Moving Virtual Machines" Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option. If problem persists, move all the VMs from $Source to $Destination manually and then try again." -Level "Error" -Phase "Moving Virtual Machines" Return } } } ######################################################################################################## # #.SYNOPSIS # Perform Concurrent Storage VMotion # #.DESCRIPTION # Perform concurrent Migration based on no of Async task to run # Continous DS space validation before migration # #.PARAMETER # VM - List of VM names to Migrate # Destination - Destination Datastore Names # Return the TaskMap about VC migration task # # #.EXAMPLE # $RelocTaskList = Concurrent-SvMotion -VM $vmList -Destination $TemporaryDatastore -ParallelTasks 2 # ######################################################################################################## function Storage-Vmotion { [CmdletBinding()] param ( [Parameter(Mandatory=$true)][VMware.VimAutomation.ViCore.Util10.VersionedObjectImpl]$session, [Parameter(Mandatory=$true)][string[]]$VM, [Parameter(Mandatory=$true)][string]$SourceId, [Parameter(Mandatory=$true)][string]$DestinationId ) BEGIN { $TargetDatastoreId = $DestinationId $VmsToMigrate = $VM $RelocateTaskStatus = @() $Failures = 0 $Success = 0 $TaskTab = @{} $GB = 1024 * 1024 * 1024 } PROCESS { foreach ($TargetVm in $VmsToMigrate) { $date = get-date Format-output -Text "$TargetVm : Migration is in progress From:$Source To:$TargetDatastoreId" -Level "INFO" -Phase "Migration" $task = MoveTheVM -VM $TargetVm -session $session -SourceId $SourceId -DestinationId $TargetDatastoreId $TaskTab[$task.id] = $TargetVm } # Get the status of running tasks $RunningTasks = $TaskTab.Count while($RunningTasks -gt 0) { Get-Task | % { if ($TaskTab.ContainsKey($_.Id) -and $_.State -eq "Success") { $TaskMap = @{} $Success += 1 $TaskMap["Name"] = $TaskTab[$_.Id] $TaskMap["TaskId"] = $_.Id $TaskMap["StartTime"] = $_.StartTime $TaskMap["EndTime"] = $_.FinishTime $TaskMap["State"] = $_.State $TaskMap["Cause"] = "" $TaskTab.Remove($_.Id) $RunningTasks-- $RelocateTaskStatus += $TaskMap } elseif ($TaskTab.ContainsKey($_.Id) -and $_.State -eq "Error") { $TaskMap = @{} $Failures += 1 $TaskMap["Name"] = $TaskTab[$_.Id] $TaskMap["TaskId"] = $_.Id $TaskMap["StartTime"] = $_.StartTime $TaskMap["EndTime"] = $_.FinishTime $TaskMap["State"] = $_.State $TaskMap["Cause"] = "" $TaskTab.Remove($_.Id) $RunningTasks-- $RelocateTaskStatus += $TaskMap } } Start-Sleep -Seconds 15 } } END { Foreach ($Tasks in $RelocateTaskStatus) { if ($Tasks["State"] -eq "Success") { $MsgText = "Migration of $($Tasks["Name"]) is successful Start Time : $($Tasks["StartTime"]) End Time : $($Tasks["EndTime"])" Format-output -Text $MsgText -Level "SUCCESS" -Phase "Migration" } else { $MsgText = "Migration of $($Tasks["Name"]) is failure Start Time : $($Tasks["StartTime"]) End Time : $($Tasks["EndTime"])" Format-output -Text $MsgText -Level "FAILURE" -Phase "Migration" } } return $RelocateTaskStatus } } ############################################################################## # #.SYNOPSIS # Function to shift an array # #.DESCRIPTION # Perform shift action similar to Perl shift # #.PARAMETER # array - Array to shift # numberOfElements - No of elements to shift # On success Orginal array is resized # # #.EXAMPLE # # $shiftedVm = shift -array ([ref]$array) -numberOfElements 2 # ############################################################################## Function shift { param ( [Parameter(Mandatory=$true)][ref]$array, [Parameter(Mandatory=$true)][int]$numberOfElements ) BEGIN { $shiftedValue = @() $temp = @() $temp = $array.Value } PROCESS { if ($temp.Count -ge $numberOfElements) { $Iterate = $numberOfElements } else { $Iterate = $temp.Count } for ($i = $Iterate; $i -gt 0; $i -= 1) { $firstElement,$temp = $temp; $shiftedValue += $firstElement } } END { $array.value = $temp return $shiftedValue } } ############################################################################### # #.SYNOPSIS # Get the Items in a Datastore # #.DESCRIPTION # Get the list of Items in a Datastore # #.PARAMETER # Datastore - UUID/ID of the Datastore # #.EXAMPLE # $list = Get-DataStoreItems -Datastore "local-0" # ############################################################################## Function Get-DataStoreItems { param( [Parameter(Mandatory=$true)][string]$DatastoreId, [Parameter()][Switch]$Recurse, [Parameter()][string]$fileType ) $childItems = @() $datastoreObj = Get-Datastore -Id $DatastoreId if ($Recurse) { $childItems = Get-ChildItem -Recurse $datastoreObj.DatastoreBrowserPath | Where-Object {$_.name.EndsWith($fileType)} } else { $childItems = Get-ChildItem $datastoreObj.DatastoreBrowserPath | Where-Object {$_.name -notmatch "^[.]"} } return $childItems } ################################################################################################### # #.SYNOPSIS # Copy files from Source to Desintation # #.DESCRIPTION # Copy Orphaned files, not registered in VC # #.PARAMETER # SourceDatastore - Source # DestinationDatastore - Destination # #.EXAMPLE # $Return Status = Copy-DatastoreItems -SourceDatastore "local-0" -DestinationDatastore "local-1" # ################################################################################################### Function Copy-DatastoreItems { param( [Parameter(Mandatory=$true)][string]$SourceDatastoreId, [Parameter(Mandatory=$true)][string]$DestinationDatastoreId ) $copyOrphanPhase = "Copying Orphaned data" $SrcChildItems = @() $DstChildItems = @() $sourceDsObj = Get-Datastore -Id $SourceDatastoreId $targetDsObj = Get-Datastore -Id $DestinationDatastoreId #Map Drives try { $sourceDrive = new-psdrive -Location $sourceDsObj -Name sourcePsDrive -PSProvider VimDatastore -Root "/" $targetDrive = new-psdrive -Location $targetDsObj -Name targetPsDrive -PSProvider VimDatastore -Root "/" $SrcChildItems = Get-DataStoreItems -DatastoreId $SourceDatastoreId $DstChildItems = Get-DataStoreItems -DatastoreId $DestinationDatastoreId Format-output -Text "Copying Orphaned Items: $SrcChildItems" -Level "INFO" -Phase $copyOrphanPhase $Fileinfo = Copy-DatastoreItem -Recurse -Item sourcePsDrive:/* targetPsDrive:/ -Force } catch [Exception] { Remove-PSDrive -Name sourcePsDrive Remove-PSDrive -Name targetPsDrive $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "ERROR" -Phase $copyOrphanPhase Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option. If problem persists, move all the orphaned data from $SourceDatastore to $DestinationDatastore manually and then try again." -Level "ERROR" -Phase $copyOrphanPhase Return $false } Remove-PSDrive -Name sourcePsDrive Remove-PSDrive -Name targetPsDrive Return $true } #################################################################################### # #.SYNOPSIS # Return Success or Failure list of Tasks # #.DESCRIPTION # This Function checks through the list of Task and return a list of success or # Failure tasks based on the input # #.PARAMETER # RelocateTasksList = List containing the Relocate Task Map # #.EXAMPLE # $SuccessTaskList=Get-RelocTask -RelocateTasksList $migrateTaskList -State "SUCCESS" # #################################################################################### Function Get-RelocTask { param ( [Parameter(Mandatory=$true)][hashtable[]]$TasksList, [Parameter(Mandatory=$true)][string]$State ) BEGIN { $SuccessList = @() $FailureList = @() } PROCESS { # Iterate through has list of TaskMap hash and check for task failures foreach ($Task in $TasksList ) { $NumberOfMigration += 1 if ($Task["State"] -ne "Success") { $FailureList += $Task } else { $SuccessList += $Task } } } END { if ($State -eq "SUCCESS") { return $SuccessList } else { return $FailureList } } } #################################################################################### #.SYNOPSIS # Creats Zip file with the log folder # #.PARAMETER # $logdir = Log directory to zip/archive # # # #################################################################################### Function Zip-Logs { param([Parameter(Mandatory=$true)][string] $logdir) $sourceDir = Join-Path -Path $pwd -ChildPath $logdir $LogTime = Get-Date -Format "MM-dd-yyyy_hh-mm-ss" $destination = "$sourceDir" + "_" + "$LogTime.zip" If (Test-path $destination) { Remove-item $destination } Add-Type -assembly "system.io.compression.filesystem" [io.compression.zipfile]::CreateFromDirectory($sourceDir, $destination) Format-output -Text "Zip file is available at: $destination" -Level "INFO" -Phase "Log Zip" } #################################################################################### # #.SYNOPSIS # Unmount the datastore # #.DESCRIPTION # Unmount the datastore from all connected hosts # #.PARAMETER # Datastore = Datastore to unmount # #.EXAMPLE # # Unmount-Datastore -Datastore "local-0" # #################################################################################### Function Unmount-Datastore { [CmdletBinding()] Param ([Parameter(ValueFromPipeline=$true)][string]$DatastoreId) BEGIN { $dsObject = Get-Datastore -Id $DatastoreId } Process { Foreach ($eachDsObj in $dsObject) { if ($eachDsObj.ExtensionData.Host) { $attachedHosts = $eachDsObj.ExtensionData.Host Foreach ($VMHost in $attachedHosts) { $hostview = Get-View $VMHost.Key $mounted = $VMHost.MountInfo.Mounted #If the device is mounted then unmount it if ($mounted -eq $true) { $StorageSys = Get-View $HostView.ConfigManager.StorageSystem Format-output -Text "Unmounting VMFS Datastore $($eachDsObj.Name) from host $($hostview.Name)..." -Level "INFO" -Phase "Unmount Datastore" $StorageSys.UnmountVmfsVolume($eachDsObj.ExtensionData.Info.vmfs.uuid); } else { Format-output -Text "VMFS Datastore $($eachDsObj.Name) is already unmounted on host $($hostview.Name)..." -Level "INFO" -Phase "Unmount Datastore" } } } } } } #################################################################################### # #.SYNOPSIS # Remove a datastore # #.DESCRIPTION # Remove a datastore # #.PARAMETER # Datastore = Datastore to delete # #.EXAMPLE # # Delete-Datastore -Datastore "local-0" # #################################################################################### Function Delete-Datastore { [CmdletBinding()] Param ( [Parameter(ValueFromPipeline=$true)] [string]$DatastoreId ) BEGIN { $dsObjectList = Get-Datastore -Id $DatastoreId } Process { Foreach ($eachDsObj in $dsObjectList) { if ($eachDsObj.ExtensionData.Host) { $attachedHosts = $ds.ExtensionData.Host $deleted = $false Foreach ($VMHost in $attachedHosts) { $hostview = Get-View $VMHost.Key if($deleted -eq $false) { Format-output -Text "Removing Datastore $($eachDsObj.Name) on host $($hostview.Name)..." -Level "INFO" -Phase "Delete Datastore" Remove-Datastore -Datastore (Get-Datastore -Id $DatastoreId) -VMHost $hostview.Name -Confirm:$false $deleted = $true } } } } } } #################################################################################### # #.SYNOPSIS # Create a Vmfs6 datastore # #.DESCRIPTION # Create a New Vmfs6 volume on the give Lun a datastore # #.PARAMETER # LunCanonical = Canonical name of lun # hostConnected = Hostobjects # #.EXAMPLE # # $LunCanonical = Get-ScsiLun -Datastore $Datastore | select -Property CanonicalName # $hostConnected = Get-VMHost -Datastore $Datastore # Create-Datastore -LunCanonical $LunCanonical -hostConnected $hostConnected # # #################################################################################### Function Create-Datastore { [CmdletBinding()] Param ( [Parameter(ValueFromPipeline=$true)] $LunCanonical, [Parameter(ValueFromPipeline=$true)] $hostConnected ) Process { $device = $LunCanonical $isCreated = $false $found = $True $DatastoreId = 0 #check if the Datastore is still mounted or not in a busy vCenter $cliXmlPath = Join-Path -Path $variableFolder -ChildPath ("Vmfs6Datastore" + ".xml") if (Test-Path $cliXmlPath) { $newVmfs6Datastore = Import-Clixml $cliXmlPath $DatastoreId = Get-Datastore -Id $newVmfs6Datastore.Id $fileSystemVersion = $DatastoreId.FileSystemVersion.split('.')[0] } $fileSystemVersion = $Datastore.FileSystemVersion.split('.')[0] while ($found -and ($fileSystemVersion -eq 5)) { $srcDs = @() $srcDs += Get-Datastore if (!$srcDs.contains($Datastore)) { $found = $False } } $hostScsiDisk = @() foreach ($mgdHost in $hostConnected) { $path = $null if ($isCreated -eq $false) { if ($device -is [System.Array]) { $path = $device[0] } else { $path = $device } if ($fileSystemVersion -lt 6) { New-Datastore -VMHost $mgdHost.Name -Name $Datastore.Name -Path $path -Vmfs -FileSystemVersion $TargetVmfsVersion | Out-Null Format-output -Text "Create new datastore is done" -Level "INFO" -Phase "Datastore Create" #$newVmfs6Datastore | Export-Clixml $cliXmlPath # query the newly created datastore from the mgdHost $newVmfs6Datastore = Get-Datastore -VMHost $mgdHost.Name|where{ $_.name -eq $Datastore.Name } $DatastoreId = $newVmfs6Datastore.Id $newVmfs6Datastore | Export-Clixml $cliXmlPath } # if we have more than one unique $device per datastore, we need to expand the current DS. if ($device.Count -gt 1) { $newDatastoreObj = Get-Datastore -Id $DatastoreId -ErrorAction SilentlyContinue $BaseExtent = $newDatastoreObj.ExtensionData.Info.Vmfs.Extent | Select -ExpandProperty DiskName $hostSys = Get-View -Id ($newDatastoreObj.ExtensionData.Host | Get-Random | Select -ExpandProperty Key) $DataStoreSys = Get-View -Id $hostSys.ConfigManager.DatastoreSystem $hostScsiDisk = $DataStoreSys.QueryAvailableDisksForVmfs($newDatastoreObj.ExtensionData.MoRef) $existingLuns = Get-ScsiLun -Datastore $newDatastoreObj |select -ExpandProperty CanonicalName|select -Unique $newDevList = Compare-Object $device $existingLuns -PassThru foreach ($eachDevice in $newDevList) { # expand the datastore. $canName = Get-ScsiLun -CanonicalName $eachDevice -VmHost $mgdHost $lun = $hostScsiDisk | where{ $BaseExtent -notcontains $_.CanonicalName -and $_.CanonicalName -eq $CanName } $vmfsExtendOpts = $DataStoreSys.QueryVmfsDatastoreExtendOptions($newDatastoreObj.ExtensionData.MoRef, $lun.DevicePath, $null) $spec = $vmfsExtendOpts.Spec $DataStoreSys.ExtendVmfsDatastore($newDatastoreObj.ExtensionData.MoRef, $spec) Format-output -Text "Extending of datastore is done" -Level "INFO" -Phase "Extend Datastore" } } $isCreated = $true } #refresh storage on this host and see if the datastore created can be fetched from $mdgHost. $mgdHostDatastores = Get-Datastore -VMHost $mgdHost.Name if($mgdHostDatastores -contains $DatastoreId ){ Format-output -Text "The datastore $Datastore found on host: $mgdHost " -Level "INFO" -Phase "VMFS6 Verify" } } } } #.ExternalHelp StorageUtility.psm1-help.xml Function Update-VmfsDatastore { [CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='High')] param ( [Parameter(Mandatory=$true)][VMware.VimAutomation.ViCore.Types.V1.VIServer]$Server, [Parameter(Mandatory=$true, ValueFromPipeline=$true)][VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.Datastore]$Datastore, [Parameter(Mandatory=$true)][VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.Datastore]$TemporaryDatastore, [Parameter()][Int32]$TargetVmfsVersion, [Switch]$Rollback, [Switch]$Resume, [Switch]$Force ) $variableFolder = "log_folder_$($Server.Name)_$($Datastore.Name)" if(!(Test-Path $variableFolder)) { New-Item -ItemType directory -Path $variableFolder | Out-Null } #check point saved for each stage $checkFile = "check$($Server.Name)$($Datastore.Name)" $LogTime = Get-Date -Format "MM-dd-yyyy_hh-mm-ss" $workingDirectory = (Get-Item -Path $variableFolder -Verbose).FullName $logFileName = "Datastore_Upgrade_" + $LogTime + ".log" $global:LogFile = Join-Path $workingDirectory $logFileName Format-output -Text "Log folder path: $workingDirectory" -Level "INFO" -Phase "Preparation" Format-output -Text "Log file path: $global:LogFile" -Level "INFO" -Phase "Preparation" Format-output -Text "Checkpoint file path: $checkFile" -Level "INFO" -Phase "Preparation" $caption = "WARNING !!" $warning = "Update VMFS datastore. This operation will delete the datastore to update and will re-create the VMFS 6 datastore using the same LUN. Do yo want to continue?" $description = "This operation will delete the datastore to update and will re-create the VMFS 6 datastore using the same LUN." Format-output -Text "The datastore $Datastore will deleted and Recreated with VMFS-6." -Level "ERROR" -Phase "Preparation" if ($PSCmdlet.ShouldProcess($description, $warning, $caption) -eq $false) { Return } # Check if HBR or SRM is enabled $warningCaption = "WARNING !!" $warningQuery = "The update to VMFS-6 of VMFS-5 datastore should not be done if HBR or SRM is enabled. Do you still want to continue?" Format-output -Text "The datastore $Datastore Should not be part of HBR[Target/Source] / SRM config." -Level "ERROR" -Phase "Preparation" if (($Force -Or $PSCmdlet.ShouldContinue($warningQuery, $warningCaption)) -eq $false) { Return } #Workflow begins here # Check that target VMFS version is 6. only 6 is supported at present if ($TargetVmfsVersion -eq 0 -or $TargetVmfsVersion -ne 6) { Format-output -Text "Update to target VMFS version $TargetVmfsVersion is not supported. Only VMFS 6 is supported as target VMFS version" -Level "ERROR" -Phase "Preparation" Return } #Check PrimaryDatastore is present in the Datastore list from VC $PrimaryDsStaus = Get-Datastore |where { $_ -eq $Datastore} $DatastoreName = $null if ($PrimaryDsStaus -ne $null) { $PrimaryDatastore = Get-Datastore -Id $Datastore.Id if ($PrimaryDatastore -eq $null) { Format-output -Text "The datastore $Datastore does not exist or has been removed." -Level "ERROR" -Phase "Preparation" Return } $Datastore | Export-Clixml (Join-Path $variableFolder 'PrimaryDs.xml') } # Verify thet the specified server is vCenter server if (-not $server.ExtensionData.Content.About.Name.Contains("vCenter")) { Format-output -Text "The specified server is not a vCenter server." -Level "ERROR" -Phase "Preparation" Return } # Verify the vCenter server is of $targetServerVersion or higher $targetServerVersion = New-Object System.Version("6.5.0") $vcVersion = New-Object System.Version($Server.Version) if ($vcVersion -lt $targetServerVersion) { Format-output -Text "The vCenter server is not upgraded to $targetServerVersion." -Level "ERROR" -Phase "Preflight Check" Return } # Verify that $PrimaryDatastore and $TemporaryDatastore are in specified vCenter server if ($PrimaryDsStaus -ne $null) { $ds = Get-Datastore -Id $PrimaryDatastore.Id -Server $Server if ($ds -eq $null -Or $ds.Uid -ne $PrimaryDatastore.Uid) { Format-output -Text "The datastore $PrimaryDatastore is not present in specified vCenter $Server." -Level "ERROR" -Phase "Preflight Check" Return } } $tempDs = Get-Datastore -Id $TemporaryDatastore.Id -Server $Server if ($tempDs -eq $null -Or $tempDs.Uid -ne $TemporaryDatastore.Uid) { Format-output -Text "The temporary datastore $TemporaryDatastore is not present in specified vCenter $Server." -Level "ERROR" -Phase "Preflight Check" Return } $precheck = $null if ( $Resume ) { $precheckXml = Join-Path $variableFolder 'precheck.xml' if ( Test-Path $precheckXml){ $precheck = Import-Clixml $precheckXml } } if ( $precheck -ne 'Done' ) { #Verify if first class disks are present in the primary datastore $vdisk = Get-VDisk -Datastore $PrimaryDatastore if ($vdisk -ne $null) { $msgText = "FCD disks can't be moved. Please migrate them then start the commandlet again." Format-output -Text "$msg1" -Level "ERROR" -Phase "Preflight Check" Return } #Verify if the Host connected to Primary datastore is part of HA $cluster = Get-VMHost -Datastore $PrimaryDatastore | Get-Cluster if($cluster) { if($cluster.HAEnabled){ $msg1 = "The host connected to datastore $PrimaryDatastore is part of HA cluster" Format-output -Text "$msg1" -Level "INFO" -Phase "Preflight Check" } } # Verify that VADP is disable. If enabled quit Format-output -Text "checking if VADP is enabled on any of the VMs" -Level "INFO" -Phase "Preflight Check" if ($PrimaryDsStaus -ne $null) { $vmList = Get-VM -Datastore $PrimaryDatastore Format-output -Text "Checking for VADP enabled VM(s)" -Level "INFO" -Phase "Preflight Check" foreach ($vm in $vmList) { $disabledMethods = $vm.ExtensionData.DisabledMethod if ($disabledMethods -contains 'RelocateVM_Task') { Format-output -Text "Cannot move virtual machine $vm because migration is disabled on it." -Level "ERROR" -Phase "Preflight Check" Return } } # Verify that SMPFT is not turned ON Format-output -Text "checking if SMPFT is enabled on any of the VMs" -Level "INFO" -Phase "Preflight Check" foreach ($vm in $vmList) { $vmRuntime = $vm.ExtensionData.Runtime if ($vmRuntime -ne $null -and $vmRuntime.FaultToleranceState -ne 'notConfigured') { Format-output -Text "Cannot move VM $vm because FT is configured for this VM." -Level "ERROR" -Phase "Preflight Check" Return } } $precheck = 'Done' $precheck | Export-CliXml (Join-Path $variableFolder 'precheck.xml') } #If PrimaryDs is part of DsCluster the TempDs should be part of same DsCluster if( !$Resume ) { $primeDsCluster = Get-DatastoreCluster -Datastore $PrimaryDatastore $tempDsCluster = Get-DatastoreCluster -Datastore $TemporaryDatastore } if (($primeDsCluster -ne $tempDsCluster) -and !$Resume) { Format-output -Text "Both Primary/Source Datastore and Temparory Datastore should be part of same sDrs-Cluster : $primeDsCluster" -Level "ERROR" -Phase "Preflight Check" Return } # Verify MSCS, Oracle cluster is not enabled Format-output -Text "checking if MSCS/Oracle[RAC] Cluster is configured on any of the VMs" -Level "INFO" -Phase "Preflight Check" if ($vmList -ne $null){ $hdList = Get-HardDisk -VM $vmList foreach ($hd in $hdList) { if ($hd.ExtensionData.Backing.Sharing -eq 'sharingMultiWriter') { $vm = $hd.Parent $msg1= "The disk:$hd is in Sharing mode -Multi-writer flag is on. The virtual machine:$vm may be part of a cluster" $msg2= "If you want to proceed please disable the cluster settings on VM and -Resume again." Format-output -Text "$msg1, $msg2" -Level "ERROR" -Phase "Preflight Check" Return } else { $scsiController = Get-ScsiController -HardDisk $hd if (($scsiController.UnitNumber -ge 1) -and ($scsiController.BusSharingMode -ne 'NoSharing')) { $msg1= "The scsi controller:$scsiController attached to the $vm is in sharing mode and hence the VM cannot be migrated. The VM may be part of a cluster" $msg2= "If you want to proceed please disable the cluster settings on VM and -Resume again." Format-output -Text "$msg1,$msg2" -Level "ERROR" -Phase "Preflight Check" Return } } } } } $ErrorActionPreference = "stop" $checkCompleted = $null $ImportPrimeDs = Import-Clixml (Join-Path $variableFolder 'PrimaryDs.xml') $DatastoreName = Get-Datastore -Id $ImportPrimeDs.Id $RollBackOption = $Rollback if($RollBackOption -eq $true -and $Resume -eq $true) { write-host "Both Resume and Staging-rollback cannot be true at the same time. Returning.." Return } if ($Resume -eq $true -or $RollBackOption -eq $true) { if (Test-Path $checkFile) { $checkCompleted = get-content $checkFile $checkCompleted = $checkCompleted -as [int] if ($checkCompleted -eq $null -and $Resume -eq $True) { $datastoreFsVersion = (Get-Datastore -Id $DatastoreName.id).FileSystemVersion.split('.')[0] if($datastoreFsVersion -eq 6) { # In case post vmfs update, if the checkpoint get corrupted then cmdlet can't proceed futher. Format-output -Text "Datastore is of VMFS-6 type and " -Level "ERROR" -Phase "Resume-Post Update" Format-output -Text "check-point file is corrupted so cannot proceed further. Manually move back the contents from Temporary Datastore " -Level "ERROR" -Phase "Resume-Post Update" Return } Format-output -Text "check-point file is corrupted/not found, proceeds from beginning" -Level "INFO" -Phase "Preparation" } } elseif ($RollBackOption -eq $false) { $datastoreFsVersion = (Get-Datastore -Id $DatastoreName.id).FileSystemVersion.split('.')[0] if ($datastoreFsVersion -eq 6 -and $Resume -eq $true) { # In case post vmfs update, if the checkpoint file removed then cmdlet can't proceed futher. # If checkpoint file is missing post vmfs update cmdlet don't know the progress, so throw error Format-output -Text "Datastore is of VMFS-6 type and " -Level "ERROR" -Phase "Resume-Post Update" Format-output -Text "check-point file is not available so cannot proceed further. Manually move back the contents from Temporary Datastore " -Level "ERROR" -Phase "Resume-Post Update" Return } #pre vmfs6 update proceed the resume from beginning $checkCompleted = 0 Format-output -Text "Writing checkCompleted : $checkCompleted" -Level "INFO" -Phase "Preparation" $checkCompleted | out-file $checkFile } } else { $checkCompleted = 0 $checkCompleted | out-file $checkFile } if ($RollBackOption -eq $true) { if($checkCompleted -eq $null){ Format-output -Text "check-point file is corrupted/not found cannot roll back. Manually move back the contents from Temporary Datastore " -Level "ERROR" -Phase "Roll Back" Return } elseif ($checkCompleted -lt 5) { $msgText = "No action performed previously to Roll back, Rollback is not needed" Format-output -Text $msgText -Level "INFO" -Phase "Roll-back" Return } $checkCompleted = $checkCompleted + 1 $dsCheck = Get-Datastore -Id $DatastoreName.Id if ($dsCheck.Type.Equals('VMFS')) { if (($dsCheck.FileSystemVersion).split('.')[0] -eq 6) { $msgText1 = "Datastore is upgraded to VMFS6.Upgrade is in post-upgrade stage,can not rollback. Returning" $msgText2 = "At this stage only -Resume is allowed" Format-output -Text "$msgText1, $msgText2" -Level "Error" -Phase "Pre-Roll Back Check" Return } } else { $msgText = "Datastore to upgrade is not of VMFS type. Returning." Format-output -Text $msgText -Level "INFO" -Phase "Preflight Check" Return } if ($checkCompleted -ge 9) { $msgText = "Moving VMs back to original datastore, if present." Format-output -Text $msgText -Level "INFO" -Phase "VM Migration" $vmList = @() $vms = Get-Datastore -Id $TemporaryDatastore.Id | Get-VM try { if ($vms.Count -gt 0) { $RelocTaskList = Concurrent-SvMotion -session $Server -SourceId $TemporaryDatastore.Id -VM $vms -DestinationId $DatastoreName.Id -ParallelTasks 2 foreach ($eachTask in $RelocTaskList) { if ($eachTask["State"] -ne "Success") { Format-output -Text "VM failed to Migrate try running the commandlet again with -Resume option." -Level "Error" -Phase "VM Migration" Return } } } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "ERROR" -Phase "Moving Vms during Rollback." Format-output -Text "Unable to proceed, try running the commandlet again. If problem persists, move all the VMs from $TemporaryDataStore to $DatastoreName manually and then try again." -Level "ERROR" -Phase "Moving VMs during rollback." Return } } if ($checkCompleted -ge 11) { $msgText = "Moving orphaned data back to original datastore, if present" Format-output -Text $msgText -Level "INFO" -Phase "Roll-back Orphan data" try { $dsItems = Get-DataStoreItems -DatastoreId $TemporaryDatastore.id if (($dsItems -ne $null) -and ($dsItems.Count) -gt 0 ) { Format-output -Text "Moving Orphaned items to $DatastoreName" -Level "INFO" -Phase "Copying Orphaned Items" Format-output -Text "all the contents already available in $DatastoreName; so skip copy from $TemporaryDatastore" -Level "INFO" -Phase "Copying Orphaned Items" } #Register template VM[s] back in respective hosts. $SrcTemplateMapXml = Join-Path $variableFolder 'SrcTemplateMap.xml' if (Test-Path SrcTemplateMapFilepath) { $SrcTemplateMap = Import-Clixml $SrcTemplateMapXml foreach ($templatePath in $SrcTemplateMap.Keys) { try { $register = New-Template �VMHost $SrcTemplateMap[$templatePath] -TemplateFilePath $templatePath $esxHost= $SrcTemplateMap[$templatePath] Format-output -Text "Template VM registered in host $esxHost " -Level "INFO" -Phase "Template Register" } catch { $errName = $_.Exception.GetType().FullName if ($errName -match "AlreadyExists") { Format-output -Text "$templatePath :Template already registered" -Level "INFO" -Phase "Template Register" } } } } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "ERROR" -Phase "Moving orphaned data" Format-output -Text "Unable to proceed, try running the commandlet again. If problem persists, move all the orphaned data from $TemporaryDataStore to $DatastoreName manually and then try again." -Level "ERROR" -Phase "Moving orphaned data." Return } } if ($checkCompleted -ge 8) { $msgText = "Changing back datastore cluster properties to previous State." Format-output -Text $msgText -Level "INFO" -Phase "SDRS Cluster" $sdrsClusterXml = Join-Path $variableFolder 'sdrsCluster.xml' if (Test-Path $sdrsClusterXml) { $dsCluster = Import-CliXml $sdrsClusterXml if ($dsCluster.Name -ne $null) { $datastorecluster = Get-DatastoreCluster -Name $dsCluster.Name } } $oldAutomationLevelXml = Join-Path $variableFolder 'oldAutomationLevel.xml' if (Test-Path $oldAutomationLevelXml) { $oldAutomationLevel = Import-CliXml $oldAutomationLevelXml } $ioloadbalancedXml = Join-Path $variableFolder 'ioloadbalanced.xml' if (Test-Path $ioloadbalancedXml) { $ioloadbalanced = Import-CliXml $ioloadbalancedXml } if ($oldAutomationLevel) { Set-DatastoreCluster -DatastoreCluster $datastorecluster -SdrsAutomationLevel $oldAutomationLevel | Out-Null } if ($ioloadbalanced) { Set-DatastoreCluster -DatastoreCluster $datastorecluster -IOLoadBalanceEnabled $ioloadbalanced | Out-Null } } if ($checkCompleted -ge 7) { $msgText = "Changing datastore properties to previous State" Format-output -Text $msgText -Level "INFO" -Phase "StorageIOControl" $ds1iocontrolXml = Join-Path $variableFolder 'ds1iocontrol.xml' if (Test-Path $ds1iocontrolXml) { $ds1iocontrol = Import-CliXml $ds1iocontrolXml } $ds2iocontrolXml = Join-Path $variableFolder 'ds2iocontrol.xml' if (Test-Path $ds2iocontrolXml) { $ds2iocontrol = Import-CliXml $ds2iocontrolXml } if ($ds1iocontrol) { (Get-Datastore -Id $DatastoreName.Id) | set-datastore -storageIOControlEnabled $ds1iocontrol | Out-Null } if ($ds2iocontrol) { (Get-Datastore -Id $TemporaryDatastore.Id) | set-datastore -storageIOControlEnable $ds2iocontrol | Out-Null } } if ($checkCompleted -ge 6) { $msgText = "Changing cluster properties to previous State" Format-output -Text $msgText -Level "INFO" -Phase "Cluster properties" $drsMapXml = Join-Path $variableFolder 'drsMap.xml' if (Test-Path $drsMapXml) { $drsMap = Import-CliXml $drsMapXml } $clustersXml = Join-Path $variableFolder 'clusters.xml' if (Test-Path $clustersXml) { $tempClus = Import-CliXml $Set-DatastoreClusterXml if ($tempClus.Name -ne $null) { $clusters = Get-Cluster -Id $tempClus.Id } } if ($clusters -and $drsMap) { foreach ($clus in $clusters) { Set-Cluster -Cluster $clus -DrsAutomationLevel $drsMap[$clus.Id] -Confirm:$false | Out-Null } } } Format-output -Text "Rollback completed successfully" -Level "INFO" -Phase "Rollback successful" Zip-Logs -logdir $variableFolder Remove-Item $variableFolder -recurse Remove-Item $checkFile $errorActionPreference = 'continue' Return } #check 1 $tempDsItems = Get-DataStoreItems -DatastoreId $TemporaryDatastore.Id try { if ($checkCompleted -lt 1) { if ($tempDsItems -ne $null -and !$RollBackOption -and !$Resume) { Format-output -Text "$TemporaryDatastore is not Empty:$tempDsItems this operation could cause damage to files in $TemporaryDatastore. Returning" -Level "Error" -Phase "Querying Temporary datastore" Return } $checkCompleted = 1 $checkCompleted | out-file $checkFile } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "Error" -Phase "Querying Temporary datastore" Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option." -Level "Error" -Phase "Querying Temporary datastore" Return } # check 2 # Check if hosts connected to DS are upgraded try { if ($checkCompleted -lt 2) { $hostConnectedToDs = Get-VMHost -Datastore $Datastore $hostObjects = Get-View -VIObject $hostConnectedToDs $status = CheckHostVersion -HostObjects $hostObjects -Version $targetServerVersion if ($status -eq $false) { Format-output -Text "Hosts are not upgraded to $targetServerVersion. Returning " -Level "INFO" -Phase "Preflight Check" Return } # All hosts connected to DS should be also connected to temp DS $hostConnectedToTempDs = Get-VMHost -Datastore $TemporaryDatastore Format-output -Text "checking if the Target Datastore is accessbile to all the Hosts, as of Source" -Level "INFO" -Phase "Preflight Check" if (Compare-Object $hostConnectedToDs $hostConnectedToTempDs -PassThru) { $msg1= "Temporary datastore $TemporaryDatstore is not accessible from one or more host(s)" $msg2= "Ensure the Hosts connected to Source and Temporary Datastores are same." Format-output -Text "$msg1,$msg2" -Level "ERROR" -Phase "Preflight Check" Return } $checkCompleted = 2 $checkCompleted | out-file $checkFile } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "Error" -Phase "Querying Hosts" $msg1= "Unable to proceed, try running the commandlet again with -Resume option" $msg2= "Or Source datastore might be re-created with VMFS-6 filesystem" Format-output -Text "$msg1, $msg2" -Level "Error" -Phase "Querying Hosts" Return } # Check if the Temporary DS size is >= Size of DS requiring Vmfs6 upgrade $tmpDs = $TemporaryDatastore $tmpDsSize = [math]::Round($tmpDs.CapacityMB) # Check 3 try { if ($checkCompleted -lt 3) { if ($tmpDs.Type.Equals('VMFS')) { Format-output -Text "checking if Temporary Datastore is of VMFS-5 type" -Level "INFO" -Phase "Preflight Check" if ($tmpDs.FileSystemVersion -lt 6 -and $tmpDs.FileSystemVersion -gt 4.999) { $msgText = "$TemporaryDatastore is of VMFS 5 type" Format-output -Text $msgText -Level "INFO" -Phase "Preflight Check" } else { $msgText = "$TemporaryDatastore is not of VMFS 5 type, Returning." Format-output -Text $msgText -Level "INFO" -Phase "Preflight Check" Return } } else { $msgText = "$TemporaryDatastore is not of VMFS 5 type, Returning.." Format-output -Text $msgText -Level "INFO" -Phase "Preflight Check" Return } $checkCompleted = 3 $checkCompleted | out-file $checkFile } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "Error" -Phase "Querying Temporary datastore" Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option." -Level "Error" -Phase "Querying Temporary datastore" Return } # Check 4 try { if ($checkCompleted -lt 4){ $datastoreObj1 = Get-Datastore -Id $DatastoreName.Id $dsSize = [math]::Round($datastoreObj1.CapacityMB) Format-output -Text "checking Datastores capacity" -Level "INFO" -Phase "Preflight Check" if ($tmpDsSize -ge $dsSize) { $msgText = "$TemporaryDatastore having Capacity : $tmpDsSize MB Greater or Equal than $DatastoreName capacity : $dsSize MB" Format-output -Text $msgText -Level "INFO" -Phase "Preflight Check" } else { $msgText = "$TemporaryDatastore having Capacity : $tmpDsSize MB lesser than $DatastoreName capacity : $dsSize MB. Returning.." Format-output -Text $msgText -Level "INFO" -Phase "Preflight Check" Return } $checkCompleted = 4 $checkCompleted | out-file $checkFile } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "Error" -Phase "Querying Temporary datastore" Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option." -Level "Error" -Phase "Querying Temporary datastore" Return } $RelocTaskList = @() $RelocTaskList1 = @() $esxMap = @{} $esxUser = @{} $esxPass = @{} $esxLoc = @{} $countesx=0 #check 5 try { if ($checkCompleted -lt 5) { $dsCheck = Get-Datastore -Id $DatastoreName.Id if ($dsCheck.Type.Equals('VMFS')) { if ($dsCheck.FileSystemVersion -lt 6 -and $dsCheck.FileSystemVersion -gt 4.999) { $msgText = "$DatastoreName to upgrade is of VMFS 5 type" Format-output -Text $msgText -Level "INFO" -Phase "Preflight Check" } else { $msgText = "$DatastoreName to upgrade is not of VMFS 5 type, Returning." Format-output -Text $msgText -Level "INFO" -Phase "Preflight Check" Return } } else { $msgText = "$DatastoreName to upgrade is not of VMFS 5 type, Returning.." Format-output -Text $msgText -Level "INFO" -Phase "Preflight Check" Return } $checkCompleted = 5 $checkCompleted | out-file $checkFile } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "Error" -Phase "Querying datastore version" Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option." -Level "Error" -Phase "Querying datastore version" Return } # Setting DRS automation level to manual of cluster. $drsAutoLevel = $null try { # $dsCluster = Get-Datastore -IdCluster -datastore $DatastoreName $drsMap = @{} $clusters = @() # check 6 if ($checkCompleted -lt 6) { #$clusters=get-cluster $clusters = Get-Datastore -Id $DatastoreName.Id |Get-VMHost|Get-Cluster $datastoreCluster = Get-DatastoreCluster -datastore $DatastoreName $msgText = "Changing DrsAutomationLevel of clusters to manual. Will be reverted to original once operation is completed." foreach ($clus in $clusters) { $drsMap[$clus.Id]=$clus.DrsAutomationLevel } if ($drsMap -ne $null) { $drsMap | Export-CliXml (Join-Path $variableFolder 'drsMap.xml') } if ($datastoreCluster-ne $null) { $datastoreCluster | Export-CliXml (Join-Path $variableFolder 'sdrsCluster.xml') } if ($clusters -ne $null) { $clusters | Export-CliXml (Join-Path $variableFolder 'clusters.xml') } foreach ($clus in $clusters) { if ($clus.DrsEnabled) { Format-output -Text $msgText -Level "INFO" -Phase "DRS Cluster Settings" Set-Cluster -Cluster $clus -DrsAutomationLevel Manual -confirm:$false | Out-Null } } $checkCompleted = 6 $checkCompleted | out-file $checkFile } else { $drsMapXml = Join-Path $variableFolder 'drsMap.xml' if (Test-Path $drsMapXml) { $drsMap = Import-CliXml $drsMapXml } else { Format-output -Text "Unable to find the configuration files no changes done to DRS cluster." -Level "INFO" -Phase "Querying DRS" } $sdrsClusterXml = Join-Path $variableFolder 'sdrsCluster.xml' if (Test-Path $sdrsClusterXml) { $datastoreCluster = Import-CliXml $sdrsClusterXml } else { Format-output -Text "Unable to find the configuration files no changes will be done SDRS cluster." -Level "INFO" -Phase "Querying SDRS" } $clustersXml = Join-Path $variableFolder 'clusters.xml' if (Test-Path $clustersXml) { $tempClus = Import-CliXml $clustersXml if ($tempClus.Name -ne $null) { $clusters = get-cluster -Id $tempClus.Id } } else { Format-output -Text "Unable to find the DRS and SDRS configuration files, No action will be take on these clusters." -Level "INFO" -Phase "Querying DRS and SDRS config" } } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "Error" -Phase "Capturing settings." Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option." -Level "Error" -Phase "Capturing settings." } #check 7 : getting and setting storageIOControlEnabled $ds1iocontrol = $false $ds2iocontrol = $false try { if ($checkCompleted -lt 7) { $msgText = "Changing storageIOControlEnabled to false. It will be reverted to original once operation is complete." $ds1iocontrol=(Get-Datastore -Id $DatastoreName.Id).StorageIOControlEnabled $ds2iocontrol=(Get-Datastore -Id $TemporaryDatastore.Id).StorageIOControlEnabled $ds1iocontrol | Export-CliXml (Join-Path $variableFolder 'ds1iocontrol.xml') $ds2iocontrol | Export-CliXml (Join-Path $variableFolder 'ds2iocontrol.xml') if ($ds1iocontrol) { Format-output -Text $msgText -Level "INFO" -Phase "StorageIOControl" (Get-Datastore -Id $DatastoreName.Id) | set-datastore -storageIOControlEnabled $false | Out-Null } if ($ds2iocontrol) { Format-output -Text $msgText -Level "INFO" -Phase "StorageIOControl" (Get-Datastore -Id $TemporaryDatastore.Id) | set-datastore -storageIOControlEnabled $false | Out-Null } $checkCompleted = 7 $checkCompleted | out-file $checkFile } else { $ds1iocontrolXml = Join-Path $variableFolder 'ds1iocontrol.xml' if (Test-Path $ds1iocontrolXml) { $ds1iocontrol = Import-CliXml $ds1iocontrolXml } $ds2iocontrolXml = Join-Path $variableFolder 'ds2iocontrol.xml' if (Test-Path $ds2iocontrolXml) { $ds2iocontrol = Import-CliXml $ds2iocontrolXml } } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "Error" -Phase "StorageIOControl." Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option." -Level "Error" -Phase "StorageIOControl" Return } $tmpDs = Get-Datastore -Id $TemporaryDatastore.Id #check 8 : getting and setting stuffs related to datastore cluster $datastorecluster = Get-Datastorecluster -Datastore $tmpDs $oldAutomationLevel = 0 $ioloadbalanced = 0 try { if ($checkCompleted -lt 8) { if ($datastorecluster) { $msgText = "Save properties of datastore cluster. It will be reverted to original once operation is complete." Format-output -Text $msgText -Level "INFO" -Phase "DRS Cluster" $oldAutomationLevel = $datastorecluster.SdrsAutomationLevel $ioloadbalanced = $datastorecluster.IOLoadBalanceEnabled $oldAutomationLevel | Export-CliXml (Join-Path $variableFolder 'oldAutomationLevel.xml') $ioloadbalanced | Export-CliXml (Join-Path $variableFolder 'ioloadbalanced.xml') Set-DatastoreCluster -DatastoreCluster $datastorecluster -SdrsAutomationLevel Manual -IOLoadBalanceEnabled $false | Out-Null } $checkCompleted = 8 $checkCompleted | out-file $checkFile } else { $sdrsClusterXml = Join-Path $variableFolder 'sdrsCluster.xml' if (Test-Path $sdrsClusterXml) { $dsClusterExists = Import-CliXml $sdrsClusterXml } if ($dsClusterExists) { $oldAutomationLevelXml = Join-Path $variableFolder 'oldAutomationLevel.xml' if (Test-Path $oldAutomationLevelXml) { $oldAutomationLevel = Import-CliXml $oldAutomationLevelXml } $ioloadbalancedXml = Join-Path $variableFolder 'ioloadbalanced.xml' if (Test-Path $ioloadbalancedXml) { $ioloadbalanced = Import-CliXml $ioloadbalancedXml } } } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "Error" -Phase "Moving datastore to same cluster" Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option. If problem persists, move both the datastores to same cluster manually and then try again." -Level "Error" -Phase "Moving datastore to same cluster" Return } # Getting list of VMs present on datastore to migrate. $vmList = @() #check 9 : Move VMs across datastores try { if ($checkCompleted -lt 9) { # Getting list of VMs present on datastore to migrate. $vms = Get-Datastore -Id $DatastoreName.Id | Get-VM if ($vms.Count -gt 0) { Format-output -Text "Moving list of VMs to temporary datastore." -Level "INFO" -Phase "Preparation" Format-output -Text "$vms" -Level "INFO" -Phase "Preparation" $RelocTaskList = Concurrent-SvMotion -session $Server -SourceId $Datastore.Id -VM $vms -DestinationId $TemporaryDatastore.Id -ParallelTasks 2 foreach ($eachTask in $RelocTaskList) { if ($eachTask["State"] -ne "Success") { Format-output -Text "VM failed to Migrate try running the commandlet again with -Resume option." -Level "Error" -Phase "Preperation" Return } } # if there are any active VMs left , throw error $vms = Get-Datastore -Id $DatastoreName.Id | Get-VM if ($vms -ne $null) { $vswapItems = Get-DataStoreItems -DatastoreId $DatastoreName.Id -Recurse -fileType $vswap if ($vswapItems) { $msgText1 = "There are still active .vswp :$vswapItems files in $DatastoreName, which can't be migrated " $msgText2 = "Please move these files to other datastore then try again with -Resume option " Format-output -Text "$msgText1, $msgText2" -Level "ERROR" -Phase "Migraton" Return } Return } } else { Format-output -Text "No VirtualMachine is running from $DatastoreName" -Level "INFO" -Phase "Preperation" } $checkCompleted = 9 $checkCompleted | out-file $checkFile } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "Error" -Phase "Moving Virtual Machines" Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option. If problem persists, move all the VMs from $DatastoreName to $TemporaryDatastore manually and then try again." -Level "Error" -Phase "Moving Virtual Machines" Return } $tagList = $null # check 10 : Datastore Tag if ($checkCompleted -lt 10) { # Save Tags attached to the Source Datastore $msgText = "Getting list of tags assigned to datastore. These tags will be applied to final VMFS 6 datastore." try { $tagList = Get-TagAssignment -Entity $DatastoreName | Select -ExpandProperty Tag if ($tagList) { Format-output -Text $msgText -Level "INFO" -Phase "Datastore Tagging" $tagList | Export-CliXml (Join-Path $variableFolder 'TagList.xml') } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "Error" -Phase "Datastore Tagging" Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option." -Level "Error" -Phase "Datastore Tagging" Return } $checkCompleted = 10 $checkCompleted | out-file $checkFile } # check 11 : move orphaned data to temporary datastore $SrcTemplateMap = @{} if ($checkCompleted -lt 11) { try{ $vswap = ".vswp" $snapShotDelta = "-delta.vmdk" $vswapItems = Get-DataStoreItems -DatastoreId $DatastoreName.Id -Recurse -fileType $vswap $snapShotDeltaItems = Get-DataStoreItems -DatastoreId $DatastoreName.Id -Recurse -fileType $snapShotDelta if ($vswapItems -or $snapShotDeltaItems ) { $msgText1 = "SnapShot delta disks:$snapShotDeltaItems (or) .vswp :$vswapItems files can't be moved " $msgText2 = "Please move these files to other datastore then try again with -Resume option " Format-output -Text "$msgText1, $msgText2" -Level "ERROR" -Phase "Copying Orphaned Items" Format-output -Text "SnapShot delta disks:$snapShotDeltaItems (or) .vswp :$vswapItems" -Level "ERROR" -Phase "Copying Orphaned data" Return } $templates = Get-Template -Datastore $DatastoreName #Cache template VM DS PathName and respective Host $SrcTemplateMapXml = Join-Path $variableFolder 'SrcTemplateMap.xml' if ($Resume -and (Test-Path $SrcTemplateMapXml)) { $SrcTemplateMap = Import-Clixml $SrcTemplateMapXml } foreach ( $eachtemplate in $templates) { $hostId=$eachTemplate.HostId $hostRef = Get-VMHost -Id $hostId $templateVmPath = $eachTemplate.ExtensionData.Config.Files.VmPathName $SrcTemplateMap[$templateVmPath] = $hostRef Remove-Template $eachtemplate Format-output -Text "Template $eachtemplate unregistered from host $hostRef" -Level "INFO" -Phase "Copying Orphaned data" $SrcTemplateMap | Export-CliXml (Join-Path $variableFolder 'SrcTemplateMap.xml') } } catch [Exception] { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "ERROR" -Phase "Copying orphaned data" Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option. If problem persists, move all the orphaned data from $DatastoreName to $TemporaryDatastore manually and then try again." -Level "ERROR" -Phase "Copying orphaned data." Return } $dsItems = Get-DataStoreItems -DatastoreId $DatastoreName.Id if (($dsItems -ne $null) -and ($dsItems.Count -gt 0)) { # Copy all the orphaned items Format-output -Text "copying Orphaned items to $TemporaryDatastore" -Level "INFO" -Phase "Copying Orphaned data" $result = Copy-DatastoreItems -SourceDatastoreId $DatastoreName.Id -DestinationDatastoreId $TemporaryDatastore.Id if (!$result) { Format-output -Text "Try again with -Resume option" -Level "ERROR" -Phase "Copying orphaned data" Return } } $checkCompleted = 11 $checkCompleted | out-file $checkFile } $hostConnected = @() $LunCanonical = @() #check 12 : Unmount datastore if ($checkCompleted -lt 12) { $msgText = "Unmounting datastore from all Hosts" Format-output -Text $msgText -Level "INFO" -Phase "Unmount Datastore" try { $hostConnected = Get-VMHost -Datastore $DatastoreName $LunCanonical = $DatastoreName.ExtensionData.Info.vmfs.extent|select -ExpandProperty DiskName #ExportCLI $hostConnected | Export-CliXml (Join-Path $variableFolder 'srcHosts.xml') $LunCanonical | Export-CliXml (Join-Path $variableFolder 'srcLunCanonical.xml') # Unmount the Source datastore from all the host Format-output -Text "Unmounting datastore $DSName..." -Level "INFO" -Phase "Unmount Datastore" Unmount-Datastore $DatastoreName.Id } catch [Exception] { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "ERROR" -Phase "Unmount Datastore" Format-output -Text "Caught the exception while unmounting the datastore. Try again with -Resume option." -Level "ERROR" -Phase "Unmount Datastore" Return } $checkCompleted = 12 $checkCompleted | out-file $checkFile } #check 13 : delete datastore #Get the Lun if ($checkCompleted -lt 13) { $msgText = "Deleting and recreating VMFS-6 Filesystem." Format-output -Text $msgText -Level "INFO" -Phase "Delete Datastore" try { #Delete the Source datastore from all the host Format-output -Text "Deleting datastore $DSName from hosts..." -Level "INFO" -Phase "Delete Datastore" Delete-Datastore $DatastoreName.Id } catch [Exception] { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "ERROR" -Phase "Delete Datastore" Format-output -Text "Caught the exception while deleting the datastore. Try again with -Resume option." -Level "ERROR" -Phase "Delete Datastore" Return } $checkCompleted = 13 $checkCompleted | out-file $checkFile } #check 14 : Create datastore and create new one with VMFS 6 #Get the Lun if ($checkCompleted -lt 14) { $msgText = " Creating VMFS-6 Filesystem" Format-output -Text $msgText -Level "INFO" -Phase "Create VMFS-6" try { if ($Resume) { #Read $host $luncan $hostConnected = Import-CliXml (Join-Path $variableFolder 'srcHosts.xml') $LunCanonical = Import-CliXml (Join-Path $variableFolder 'srcLunCanonical.xml') } Format-output -Text "Creating Datastore..." -Level "INFO" -Phase "Datastore Create" Create-Datastore -LunCanonical $LunCanonical -hostConnected $hostConnected } catch [Exception] { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "ERROR" -Phase "Datastore Create" Format-output -Text "Caught the exception creating new datastore. Try again with -Resume option." -Level "ERROR" -Phase "Datastore Create" Return } $checkCompleted = 14 $checkCompleted | out-file $checkFile } $DatastoreName = Import-CliXml (Join-Path $variableFolder 'Vmfs6Datastore.xml') #check 15 : move the created datastore to cluster #Move Ds to its respective cluster try { $msgText = "Moving newly created datastore to its original datastore cluster." if ($checkCompleted -lt 15) { $sdrsClusterXml = Join-Path $variableFolder 'sdrsCluster.xml' if ($Resume -and (Test-Path $sdrsClusterXml)) { $datastorecluster = Import-CliXml $sdrsClusterXml } if ($datastorecluster) { Format-output -Text $msgText -Level "INFO" -Phase "SDRS Cluster" $datastoreObj = Get-Datastore -Id $DatastoreName.Id $datastorecluster = Get-DatastoreCluster -Id $datastorecluster.Id Move-Datastore $datastoreObj -Destination $datastorecluster | Out-Null } $checkCompleted = 15 $checkCompleted | out-file $checkFile } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "ERROR" -Phase "Moving datastore" Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option. If problem persists, move the newly created datastore to the same cluster as $TemporaryDatastore" -Level "Error" -Phase "Moving datastore." Return } Format-output -Text "Entering restoration phase.." -Level "INFO" -Phase "Restoring VMs" # Getting list of VMs present on temporary datastore. $dsArray = @() $vms = Get-Datastore -Id $TemporaryDatastore.Id | Get-VM # check 16 : move the vms back to original datastore. try { $msgText = "Moving VMs back to original datastore, if present" $msgText = "Moving VMs back to original datastore, if present" if ($checkCompleted -lt 16) { Format-output -Text $msgText -Level "INFO" -Phase "Migration" if ($vms.Count -gt 0) { $RelocTaskList = Concurrent-SvMotion -session $Server -SourceId $TemporaryDatastore.Id -VM $vms -DestinationId $DatastoreName.Id -ParallelTasks 2 foreach ($eachTask in $RelocTaskList) { if ($eachTask["State"] -ne "Success") { Format-output -Text "VM failed to Migrate try running the commandlet again with -Resume option." -Level "Error" -Phase "Migration" Return } } } # if there are any active VMs left , throw error $vms = Get-Datastore -Id $TemporaryDatastore.Id | Get-VM if($vms -ne $null){ Format-output -Text "VM(s)-$vms still left in Datastore $TemporaryDatastore,Try w/ Resume again" -Level "Error" -Phase "Migraton" Return } $checkCompleted = 16 $checkCompleted | out-file $checkFile } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "ERROR" -Phase "Moving Virtual Machines" Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option. If problem persists, move all the VMs from $TemporaryDataStore to $DatastoreName manually and then try again." -Level "Error" -Phase "Moving Virtual Machines" Return } # Attaching tags back to original datastore if ($checkCompleted -lt 17) { # Attach Tags to the datastore $TagListXml = Join-Path $variableFolder 'TagList.xml' if ($Resume -and (Test-Path $TagListXml)) { $tagList = Import-CliXml $TagListXml } $msgText = "Attaching Tags back to original datastore." try { foreach ($tag in $tagList) { $tagObj = $null $tagObj = Get-Tag -Name $tag.Name -Category $tag.Category.Name $msgText = "Adding back the Tags to Datastore :$DatastoreName.Name" Format-output -Text $msgText -Level "INFO" -Phase "Datastore Tags" $newTag = New-TagAssignment -Tag $tagObj -Entity $DatastoreName } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "Error" -Phase "Datastore Tag" Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option." -Level "Error" -Phase "Datastore Tag" Return } $checkCompleted = 17 $checkCompleted | out-file $checkFile } # check 17 : move the orphaned data back to original datastore. try { $msgText = "Moving orphaned data back to original datastore, if present." $dsItems = Get-DataStoreItems -DatastoreId $TemporaryDatastore.Id if ($checkCompleted -lt 18) { Format-output -Text $msgText -Level "INFO" -Phase "Restoring Orphan data" if (($dsItems -ne $null) -and ($dsItems.Count) -gt 0) { Format-output -Text "Copying Orphaned items to $DatastoreName" -Level "INFO" -Phase "Copying Orphaned Items" $result = Copy-DatastoreItems -SourceDatastoreId $TemporaryDatastore.Id -DestinationDatastoreId $DatastoreName.Id if (!$result) { Format-output -Text "Try again with -Resume option" -Level "ERROR" -Phase "Copying orphaned data" Return } $tempds = Get-Datastore -Id $TemporaryDatastore.Id New-PSDrive -Location $tempds -Name tempds -PSProvider VimDatastore -Root "/" | Out-Null # Remove contents from temporary Datastore Remove-Item tempds:/* -Recurse } # Register templateVM(s) back in the respective hosts $SrcTemplateMapXml = Join-Path $variableFolder 'SrcTemplateMap.xml' if ($Resume -and (Test-Path $SrcTemplateMapXml)) { $SrcTemplateMap = Import-Clixml $SrcTemplateMapXml } foreach ($templatePath in $SrcTemplateMap.Keys) { try { $register = New-Template �VMHost (Get-VMHost -Name $SrcTemplateMap[$templatePath]) -TemplateFilePath $templatePath $esxHost= $SrcTemplateMap[$templatePath] Format-output -Text "Template VM registered in host $esxHost " -Level "INFO" -Phase "Template Register" } catch { $errName = $_.Exception.GetType().FullName if ( $errName -match "AlreadyExists") { Format-output -Text "$templatePath :Template already registered" -Level "INFO" -Phase "Template Register" } else { throw $_.Exception } } } $checkCompleted = 18 $checkCompleted | out-file $checkFile } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "ERROR" -Phase "Moving orphaned data" Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option. If problem persists, move all the orphaned data from $TemporaryDataStore to $DatastoreName manually and then try again." -Level "ERROR" -Phase "Moving orphaned data." Return } # check 18 : Update SRDS properties of cluster.-SDRS try { if ($checkCompleted -lt 19) { $sdrsClusterXml = Join-Path $variableFolder 'sdrsCluster.xml' if ($Resume -and (Test-Path $sdrsClusterXml)) { $datastorecluster = Import-CliXml $sdrsClusterXml } if ($datastorecluster) { $msgText = "Setting datastore-cluster properties to previous State." Format-output -Text "$msgText : $oldAutomationLevel" -Level "INFO" -Phase "SDRS Cluster" if ($Resume) { $oldAutomationLevel = Import-CliXml (Join-Path $variableFolder 'oldAutomationLevel.xml') $ioloadbalanced = Import-CliXml (Join-Path $variableFolder 'ioloadbalanced.xml') } $datastorecluster = Get-DatastoreCluster -Id $datastorecluster.Id Set-DatastoreCluster -DatastoreCluster $datastorecluster -SdrsAutomationLevel $oldAutomationLevel -IOLoadBalanceEnabled $ioloadbalanced | Out-Null } $checkCompleted = 19 $checkCompleted | out-file $checkFile } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "ERROR" -Phase "Reverting to original datastore settings" Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option." -Level "ERROR" -Phase "Reverting to original datastore settings." Return } try { # check 20 : set datastore storageIOControlEnabled to previous value. if ($checkCompleted -lt 20) { $msgText = "Setting datastore properties to previous State." $ds1iocontrolXml = Join-Path $variableFolder 'ds1iocontrol.xml' if ($Resume -and (Test-Path $ds1iocontrolXml)) { $ds1iocontrol = Import-CliXml $ds1iocontrolXml } $ds2iocontrolXml = Join-Path $variableFolder 'ds2iocontrol.xml' if ($Resume -and (Test-Path $ds2iocontrolXml)) { $ds2iocontrol = Import-CliXml $ds2iocontrolXml } Format-output -Text $msgText -Level "INFO" -Phase "Datastore Settings" (Get-Datastore -Id $DatastoreName.Id) | set-datastore -storageIOControlEnabled $ds1iocontrol | Out-Null (Get-Datastore -Id $TemporaryDatastore.Id) | set-datastore -storageIOControlEnable $ds2iocontrol | Out-Null $checkCompleted = 20 $checkCompleted | out-file $checkFile } # check 21 : set cluster DrsAutomationLevel to previous value. -DRS if ($checkCompleted -lt 21) { $msgText = "Setting cluster properties to previous State." Format-output -Text $msgText -Level "INFO" -Phase "DRS Cluster" foreach ($clus in $clusters) { if ($clus.DrsEnabled) { $drsMapXml = Join-Path $variableFolder 'drsMap.xml' if ($Resume -and (Test-Path $drsMapXml)) { $drsMap = Import-Clixml $drsMapXml } Set-Cluster -Cluster $clus -DrsAutomationLevel $drsMap[$clus.Id] -Confirm:$false | Out-Null } } $checkCompleted = 21 $checkCompleted | out-file $checkFile } } catch { $errName = $_.Exception.GetType().FullName $errMsg = $_.Exception.Message Format-output -Text "$errName, $errMsg" -Level "ERROR" -Phase "Reverting to original datastore and datastore cluster settings" Format-output -Text "Unable to proceed, try running the commandlet again with -Resume option." -Level "ERROR" -Phase "Reverting to original datastore and datastore-cluster settings." Return } Format-output -Text "Datastore upgraded successfully" -Level "INFO" -Phase "Upgrade successful" Format-output -Text "Zip the log directory " -Level "INFO" -Phase "Upgrade successful" Zip-Logs -logdir $variableFolder Remove-Item $variableFolder -Recurse Remove-Item $checkFile $errorActionPreference = 'continue' } # SIG # Begin signature block # MIIhmgYJKoZIhvcNAQcCoIIhizCCIYcCAQExDzANBglghkgBZQMEAgEFADB5Bgor # BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG # KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCDMaSkaPmTZxUkk # a0tk1fQG1z4kRCD9WEhPcxiseqVfE6CCD8swggTMMIIDtKADAgECAhBdqtQcwalQ # C13tonk09GI7MA0GCSqGSIb3DQEBCwUAMH8xCzAJBgNVBAYTAlVTMR0wGwYDVQQK # ExRTeW1hbn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