PowerShell describes the bulk export templates for SCVMM and the import

Source: Internet
Author: User

SCVMM templates are also used by Windows Azure Pack, which can be a cumbersome task if you have a lot of nodes at hand that need to be imported and exported, which is a lot of work to manually change.

For example, the following diagram, a VHDX file contains at least the name, family, version, operating system, and the name of the original path, and if it is used for Windows Azure Pack, it may also contain a tag. These properties all require one by one inputs, and one or two may be willing to modify them manually, but much more? Not only is it easy to make mistakes, but the speed of making money is also greatly reduced. The solution to this problem is also done using PowerShell, with a few methods, and still a few of the methods that the blog mentioned earlier, the integration.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/70/87/wKiom1W5lkjDWom8AAJLsS41InE445.jpg "title=" 2015-7-30 11-03-43.jpg "alt=" Wkiom1w5lkjdwom8aajlss41ine445.jpg "/>

First I need to get the name of the original VHDX file, which is contained in the "path" attribute, similar to the following form

\\vm121.contoso.com\MSSCVMMLibrary\M-CentOS64.vhdx

I just need the M-CENTOS64.VHDX part, for the first time, I used a very silly method, here is the pseudo-code

$GHD = get-scvirtualharddisk# This is a less efficient method $2b = $GHD. Name$2b$zz = (Get-scvirtualharddisk-name $2b). SharePath $zz = $zz-replace "\", "" "#必须填写vhdx文件所在的库服务器名和库共享名 $zz = $zz-replace" vm121.contoso.com "," "$zz = $zz-replace "Msscvmmlibrary", "Add-member-inputobject $tagx-membertype noteproperty-name" vhdxname2 "-value $zz-force #写入变量到vhdx Name2 this attribute}

So why is the above method more silly? Because it just uses -replace to do the replacement method, this time need to replace three times, the first replacement \, the second replacement of the library name, the third replacement of the library share name, the last thing left is the file name. And this substitution is not universal, you need to manually write the variables in.


So I used split method, efficiency and versatility improved

$2b = $tagx. Name$zz = (Get-scvirtualharddisk-name $2b). SharePath $zz = $zz. Split ("\") [-1]

This means to use \ partition to take the last set of data.

Okay, let's take a look at the complete code for fetching data.

$GHD = Get-scvirtualharddiskforeach ($tagx in $GHD) {[string] $tagxx = $tagx. Tagadd-member-inputobject $tagx-membertype Noteproperty-name "tagx2"-value $tagxx-force$2b = $tagx. Name$zz = (Get-scvirtualharddisk-name $2b). SharePath $zz = $zz. Split ("\") [ -1]add-member-inputobject $tagx-membertype noteproperty-name "vhdxname2"-value $zz-force} $GHD |select Nam E,familyname, OperatingSystem, release,tagx2,vhdxname2,virtualizationplatform| Export-csv c:/grlistold.csv-force-encoding UTF8


After fetching, we need to import on the new server, copy the above c:/grlistold.csv, then we will use another set of code, note that in the Windows Azure Pack environment, tag may be multiple arrays, Here my method can only input an array, so if necessary, for the array aspect, you also need to add a bit.

Import-csv-path C:/grlistold.csv | foreach {$vhdxname = $_. Name$vhdxname2 = $_.vhdxname2 $OperatingSystem = $_. Operatingsystem$familyname = $_. Familyname$release = $_. Release$tags = $_.tagx2$virtualizationplatform = $_. Virtualizationplatform$myvhd = Get-scvirtualharddisk-name $vhdxnameSet-scvirtualharddisk–virtualharddisk $myVHD – OperatingSystem $OperatingSystem –familyname $familyName –release $release –tag $tags-name $vhdxname 2-VIRTUALIZATIONPL Atform $VirtualizationPlatform}get-scvirtualharddisk |select name,familyname, OperatingSystem, Release,tag, Virtualizationplatform|ft


This article is from the "Nine uncle-Microsoft Private Cloud" blog, please make sure to keep this source http://jiushu.blog.51cto.com/972756/1680016

PowerShell describes the bulk export templates for SCVMM and imports

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.