<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hypervisor.fr &#187; vmsize</title>
	<atom:link href="http://www.hypervisor.fr/?feed=rss2&#038;tag=vmsize" rel="self" type="application/rss+xml" />
	<link>http://www.hypervisor.fr</link>
	<description>French Bare-Metal weblog</description>
	<lastBuildDate>Wed, 26 Jun 2024 22:42:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Quelle taille (totale) fait ma VM ? &#8211; MAJ</title>
		<link>http://www.hypervisor.fr/?p=1034</link>
		<comments>http://www.hypervisor.fr/?p=1034#comments</comments>
		<pubDate>Tue, 18 Aug 2009 17:45:58 +0000</pubDate>
		<dc:creator>NiTRo</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[snapshot]]></category>
		<category><![CDATA[vmsize]]></category>

		<guid isPermaLink="false">http://www.hypervizor.fr/?p=1034</guid>
		<description><![CDATA[MAJ 19/05/2011 : Mise à jour du script pour supporter vCenter 4.1 U1
MAJ 29/03/2011 : Mise à jour du script pour supporter vCenter 4.1
En cherchant un moyen élégant de remonter dans rapport la taille occupée par les différents snapshots d&#8217;une VM, nous sommes tombés sur un script powershell récemment posté par Arnim van Lieshout : [...]]]></description>
			<content:encoded><![CDATA[<p><em><span style="color: #ff0000;">MAJ 19/05/2011</span> : Mise à jour du script pour supporter vCenter 4.1 U1</em></p>
<p><em><span style="color: #ff0000;">MAJ 29/03/2011</span> : Mise à jour du script pour supporter vCenter 4.1</em></p>
<p>En cherchant un moyen élégant de remonter dans rapport la taille occupée par les différents snapshots d&#8217;une VM, nous sommes tombés sur un script powershell récemment posté par <a href="http://www.van-lieshout.com">Arnim van Lieshout</a> : <a href="http://www.van-lieshout.com/2009/07/how-big-is-my-vm/">How big is my VM?</a></p>
<p>Malheureusement, son script n&#8217;est pas compatible avec vCenter 4.0, à cause d&#8217;un petit bug d&#8217;API repéré par plusieurs membres de la <a href="http://communities.vmware.com/message/1330657">communauté VMware lors de l&#8217;adaptation d&#8217;un script peremetant de lister les vmdk orphelins.</a></p>
<p><a href="http://www.hypervizor.fr/wp-content/uploads/2009/08/vmsize_bug.jpg" title="vmsize_bug" rel="lightbox[1034]"><img class="aligncenter size-medium wp-image-1039" title="vmsize_bug" src="http://www.hypervizor.fr/wp-content/uploads/2009/08/vmsize_bug-300x102.jpg" alt="" width="300" height="102" /></a></p>
<p>C&#8217;est grâce à <a href="http://communities.vmware.com/message/1330657#1330657">Yasen Kalchev</a> que nous avons pu modifier ce script et le rendre opérationnel pour vCenter 4.0 :</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$vm</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">function</span> Get<span style="color: pink;">-</span>VmSize<span style="color: #000000;">&#40;</span><span style="color: #800080;">$vm</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #008000;">#Initialize variables</span>
    <span style="color: #800080;">$VmDirs</span> <span style="color: pink;">=@</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #800080;">$VmSize</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>
&nbsp;
		<span style="color: #800080;">$fileQueryFlags</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.FileQueryFlags
		<span style="color: #800080;">$fileQueryFlags</span>.FileSize <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>
		<span style="color: #008000;">#$fileQueryFlags.FileType = $true</span>
		<span style="color: #008000;">#$fileQueryFlags.Modification = $true</span>
		<span style="color: #800080;">$searchSpec</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.HostDatastoreBrowserSearchSpec
		<span style="color: #800080;">$searchSpec</span>.details <span style="color: pink;">=</span> <span style="color: #800080;">$fileQueryFlags</span>
&nbsp;
    Get<span style="color: pink;">-</span>View <span style="color: pink;">-</span>ViewType VirtualMachine <span style="color: pink;">-</span><span style="color: #0000FF;">Filter</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span><span style="color: #800000;">&quot;Name&quot;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;^$vm$&quot;</span> <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #008000;">#Create an array with the vm's directories</span>
        <span style="color: #800080;">$VmDirs</span> <span style="color: pink;">+=</span> <span style="color: #000080;">$_</span>.Config.Files.VmPathName.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;/&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>
        <span style="color: #800080;">$VmDirs</span> <span style="color: pink;">+=</span> <span style="color: #000080;">$_</span>.Config.Files.SnapshotDirectory.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;/&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>
        <span style="color: #800080;">$VmDirs</span> <span style="color: pink;">+=</span> <span style="color: #000080;">$_</span>.Config.Files.SuspendDirectory.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;/&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>
        <span style="color: #800080;">$VmDirs</span> <span style="color: pink;">+=</span> <span style="color: #000080;">$_</span>.Config.Files.LogDirectory.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;/&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>
        <span style="color: #008000;">#Add directories of the vm's virtual disk files</span>
        <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$disk</span> <span style="color: #0000FF;">in</span> <span style="color: #000080;">$_</span>.Layout.Disk<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$diskfile</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$disk</span>.diskfile<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
                <span style="color: #800080;">$VmDirs</span> <span style="color: pink;">+=</span> <span style="color: #800080;">$diskfile</span>.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;/&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #008000;">#Only take unique array items</span>
        <span style="color: #800080;">$VmDirs</span> <span style="color: pink;">=</span> <span style="color: #800080;">$VmDirs</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Sort</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Get-Unique</span>
&nbsp;
        <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$dir</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$VmDirs</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
            <span style="color: #800080;">$ds</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>Datastore <span style="color: #000000;">&#40;</span><span style="color: #800080;">$dir</span>.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;[&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;]&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>
            <span style="color: #800080;">$dsb</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>View <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$ds</span> <span style="color: pink;">|</span> get<span style="color: pink;">-</span>view<span style="color: #000000;">&#41;</span>.Browser<span style="color: #000000;">&#41;</span>
			<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$global</span>:DefaultVIServer<span style="color: #000000;">&#41;</span>.Version <span style="color: #FF0000;">-cge</span> <span style="color: #800000;">&quot;4.1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$searchSpec</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>VMware.Vim.VIConvert<span style="color: #000000;">&#93;</span>::ToVim41<span style="color: #000000;">&#40;</span><span style="color: #800080;">$searchSpec</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span>
			<span style="color: #0000FF;">elseif</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$global</span>:DefaultVIServer<span style="color: #000000;">&#41;</span>.Version <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;4.0.0&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$searchSpec</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>VMware.Vim.VIConvert<span style="color: #000000;">&#93;</span>::ToVim4<span style="color: #000000;">&#40;</span><span style="color: #800080;">$searchSpec</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #800080;">$searchSpec</span>.details.fileOwnerSpecified <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>
&nbsp;
			<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$global</span>:DefaultVIServer<span style="color: #000000;">&#41;</span>.Version <span style="color: #FF0000;">-cge</span> <span style="color: #800000;">&quot;4.1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$dsBrowserMoRef</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>VMware.Vim.VIConvert<span style="color: #000000;">&#93;</span>::ToVim41<span style="color: #000000;">&#40;</span><span style="color: #800080;">$dsb</span>.MoRef<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span>
            <span style="color: #0000FF;">elseif</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$global</span>:DefaultVIServer<span style="color: #000000;">&#41;</span>.Version <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;4.0.0&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$dsBrowserMoRef</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>VMware.Vim.VIConvert<span style="color: #000000;">&#93;</span>::ToVim4<span style="color: #000000;">&#40;</span><span style="color: #800080;">$dsb</span>.MoRef<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #800080;">$taskMoRef</span>  <span style="color: pink;">=</span> <span style="color: #800080;">$dsb</span>.Client.VimService.SearchDatastoreSubFolders_Task<span style="color: #000000;">&#40;</span><span style="color: #800080;">$dsBrowserMoRef</span><span style="color: pink;">,</span> <span style="color: #800080;">$dir</span><span style="color: pink;">,</span> <span style="color: #800080;">$searchSpec</span><span style="color: #000000;">&#41;</span>
            <span style="color: #800080;">$task</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>VMware.Vim.VIConvert<span style="color: #000000;">&#93;</span>::ToVim<span style="color: #000000;">&#40;</span><span style="color: #800080;">$dsb</span>.WaitForTask<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>VMware.Vim.VIConvert<span style="color: #000000;">&#93;</span>::ToVim<span style="color: #000000;">&#40;</span><span style="color: #800080;">$taskMoRef</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> 
&nbsp;
            <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$result</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$task</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
                <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$file</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$result</span>.File<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
                    <span style="color: #800080;">$VmSize</span> <span style="color: pink;">+=</span> <span style="color: #800080;">$file</span>.FileSize
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0000FF;">return</span> <span style="color: #800080;">$VmSize</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #800080;">$size</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>VmSize<span style="color: #000000;">&#40;</span><span style="color: #800080;">$vm</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$size</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>math<span style="color: #000000;">&#93;</span>::round<span style="color: #000000;">&#40;</span><span style="color: #800080;">$size</span><span style="color: pink;">/</span>1GB<span style="color: pink;">,</span><span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span>
<span style="color: #008080; font-weight: bold;">WRITE</span> <span style="color: #800000;">&quot;$size Gb&quot;</span></pre></div></div>

<p><strong><span style="color: #ff0000;">/!\ les fichiers de swap (.vswp) ne sont comptabilisés que s&#8217;ils sont dans le répertoire de la VM /!\</span></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hypervisor.fr/?feed=rss2&amp;p=1034</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
