<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:clearspace="http://www.jivesoftware.com/xmlns/clearspace/rss" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>VMware Communities: Message List - How to find Local Datastores with Powershell?</title>
    <link>http://communities.vmware.com/community/vmtn/vsphere/automationtools/windows_toolkit?view=discussions</link>
    <description>Most recent forum messages</description>
    <language>en</language>
    <pubDate>Sun, 04 Jan 2009 10:48:56 GMT</pubDate>
    <generator>Clearspace 1.10.12 (http://jivesoftware.com/products/clearspace/)</generator>
    <dc:date>2009-01-04T10:48:56Z</dc:date>
    <dc:language>en</dc:language>
    <item>
      <title>Re: How to find Local Datastores with Powershell?</title>
      <link>http://communities.vmware.com/message/1135575?tstart=0#1135575</link>
      <description>SCampbell, First of all thanks for the script, it was a great help.&lt;br /&gt;
But I found an issue within the local datastore function if there are multiple local devices, because comparing the content of an array with the&lt;br /&gt;
content of another array with -contains isn´t working in that way.&lt;br /&gt;
&lt;br /&gt;
Furthermore if there are dozens or hundreds of datastores and hosts, I think it´s a good idea to filter datastores first occuring on more than one host.&lt;br /&gt;
&lt;br /&gt;
Therefore I created the following function:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="jive-pre"&gt;&lt;code class="jive-code jive-plain"&gt;function IsLocalStorage($ds)
{
$hstorage = Get-VMHost -Datastore $ds
$result = $false
	if (!$hstorage.length)
	{
	$LocalDevices=(Get-VMHostStorage -VMHost $hstorage | Get-View).StorageDeviceInfo.HostBusAdapter | `
      Where-Object { `
        ($_.Key -like &amp;quot;key-vim.host.ParallelSCSIHBA-*&amp;quot;) -or `
        ($_.Key -like &amp;quot;key-vim.host.BlockHBA-*&amp;quot;) `
        } | %{ [string]($_.Device) }
		
		foreach ($ld in $LocalDevices)
		{
		
		$localstorage = $ds | Where-Object { 
			(($_ | Get-View).Info.vmfs.extent | %{ ([string]$_.DiskName).split(&amp;quot;:&amp;quot;,2)[0]} ) `
			-contains $ld
			}
		}
	 if ($localstorage) {$result = $true}
	}
	
	return $result
}

&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Call that function with the datastore object, true means it is local storage, false it isn´t.&lt;br /&gt;
&lt;br /&gt;
Comments and improvements are very welcome&lt;br /&gt;
&lt;br /&gt;
Dennis&lt;br /&gt;
&lt;br /&gt;
VI PowerScripter &lt;a class="jive-link-external" href="http://www.powerscripter.net"&gt;http://www.powerscripter.net&lt;/a&gt;&lt;br /&gt;
Every Click can be a customized function within VI client</description>
      <pubDate>Sun, 04 Jan 2009 10:48:56 GMT</pubDate>
      <author>doomdevice</author>
      <guid>http://communities.vmware.com/message/1135575?tstart=0#1135575</guid>
      <dc:date>2009-01-04T10:48:56Z</dc:date>
      <clearspace:dateToText>10 months, 3 weeks ago</clearspace:dateToText>
    </item>
    <item>
      <title>Re: How to find Local Datastores with Powershell?</title>
      <link>http://communities.vmware.com/message/1070091?tstart=0#1070091</link>
      <description>These functions provide assistance dealing with Datastores. I have included the code in this post and in an attached file.&lt;br /&gt;
&lt;br /&gt;
Comments and improvements are welcomed.&lt;br /&gt;
&lt;br /&gt;
All functions, with some usage information and a sample, is in the attachment&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Get-DatastoreHost -Datastore $DS -IsConnected $True&lt;/b&gt; returns a list of VIM VMHost objects that have access to the store. Use IsConnected if you only want ones that are properly alive. &lt;br /&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;br /&gt;
&lt;pre class="jive-pre"&gt;&lt;code class="jive-code jive-java"&gt;function Get-DatastoreHost &lt;font color="navy"&gt;{&lt;/font&gt;
Param(
[http:&lt;font color="darkgreen"&gt;//VMware.VimAutomation.Client20.DatastoreImpl|http://VMware.VimAutomation.Client20.DatastoreImpl] $Datastore,&lt;/font&gt;
[&amp;lt;b&amp;gt;boolean&amp;lt;/b&amp;gt;] $IsConnected=$True
)
($Datastore | Get-View).Host | ForEach-Object &lt;font color="navy"&gt;{&lt;/font&gt; get-view -id $_.Key &lt;font color="navy"&gt;}&lt;/font&gt; | `
Where-Object &lt;font color="navy"&gt;{&lt;/font&gt; (-not $IsConnected) -or ($_.Runtime.ConnectionState -eq &lt;font color="red"&gt;&amp;quot;connected&amp;quot;&lt;/font&gt;) &lt;font color="navy"&gt;}&lt;/font&gt;
&lt;font color="navy"&gt;}&lt;/font&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;p /&gt;
&lt;br /&gt;
&lt;b&gt;Get-LocalDatastore -VMHost $Host&lt;/b&gt; returns a list of VIToolkit Datastore objects which are hosted on devices of type ParallelSCSIHBA or BlockHBA. I think these are only owned by a local ESX server. I wanted this code to reliably rename local datastores so they aren't accidentally selected when operations teams provisions VMs &lt;br /&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;br /&gt;
&lt;pre class="jive-pre"&gt;&lt;code class="jive-code jive-java"&gt;function Get-LocalDatastore &lt;font color="navy"&gt;{&lt;/font&gt;
  Param(
    [http:&lt;font color="darkgreen"&gt;//VMware.VimAutomation.Client20.VMHostImpl|http://VMware.VimAutomation.Client20.VMHostImpl] $VMHost    &lt;/font&gt;
    )
    $LocalDevices=(Get-VMHostStorage -VMHost $VMHost | Get-View).StorageDeviceInfo.HostBusAdapter | `
      Where-Object &lt;font color="navy"&gt;{&lt;/font&gt; `
        ($_.Key -like &lt;font color="red"&gt;&amp;quot;key-vim.host.ParallelSCSIHBA-*&amp;quot;&lt;/font&gt;) -or `
        ($_.Key -like &lt;font color="red"&gt;&amp;quot;key-vim.host.BlockHBA-*&amp;quot;&lt;/font&gt;) `
        &lt;font color="navy"&gt;}&lt;/font&gt; | %&lt;font color="navy"&gt;{&lt;/font&gt; [string]($_.Device) &lt;font color="navy"&gt;}&lt;/font&gt;
    Get-Datastore -VMHost $VMHost | Where-Object &lt;font color="navy"&gt;{&lt;/font&gt; 
      (($_ | Get-View).Info.vmfs.extent | %&lt;font color="navy"&gt;{&lt;/font&gt; ([string]$_.DiskName).split(&lt;font color="red"&gt;&amp;quot;:&amp;quot;&lt;/font&gt;,2)[0]&lt;font color="navy"&gt;}&lt;/font&gt; ) `
      -contains $LocalDevices
      &lt;font color="navy"&gt;}&lt;/font&gt;
  &lt;font color="navy"&gt;}&lt;/font&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;p /&gt;
&lt;b&gt;Get-DatastoreDatacenter -Datastore $DS&lt;/b&gt; There are some (e.g., vifs.pl) processes that insist on a Datacenter in some cases. This returns the datacenter VIToolkit object a given Datastore is in. This could also be easily adapted to hosts. &lt;br /&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;br /&gt;
&lt;pre class="jive-pre"&gt;&lt;code class="jive-code jive-java"&gt;function Get-DatastoreDatacenter &lt;font color="navy"&gt;{&lt;/font&gt;
  Param(
    $Datastore
  )
  Get-Datacenter | Where-Object &lt;font color="navy"&gt;{&lt;/font&gt;
    (($_ | Get-View).Datastore | %&lt;font color="navy"&gt;{&lt;/font&gt; (Get-View -Id $_).Summary.Url&lt;font color="navy"&gt;}&lt;/font&gt;) `
      -contains (($Datastore | Get-View).Summary.Url)
    &lt;font color="navy"&gt;}&lt;/font&gt;
  &lt;font color="navy"&gt;}&lt;/font&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Edited on Oct 10 to replace completely wrong Get-DatastoreDatacenter</description>
      <pubDate>Wed, 08 Oct 2008 19:54:11 GMT</pubDate>
      <author>SCampbell</author>
      <guid>http://communities.vmware.com/message/1070091?tstart=0#1070091</guid>
      <dc:date>2008-10-08T19:54:11Z</dc:date>
      <clearspace:dateToText>1 year, 1 month ago</clearspace:dateToText>
      <clearspace:replyCount>1</clearspace:replyCount>
    </item>
    <item>
      <title>Re: How to find Local Datastores with Powershell?</title>
      <link>http://communities.vmware.com/message/1069724?tstart=0#1069724</link>
      <description>&lt;p /&gt;
You can try using Get-VMHostStorage view&lt;br /&gt;
&lt;p /&gt;
&lt;pre class="jive-pre"&gt;&lt;code class="jive-code jive-java"&gt;
&amp;nbsp;
$hsv = Get-VMHostStorage -VMHost (Get-VMHost) | Get-View
&amp;nbsp;
&amp;nbsp;
&lt;/code&gt;&lt;/pre&gt; &lt;br /&gt;
&lt;p /&gt;
I believe that you can found all needed information in $hsv.StorageDeviceInfo.ScsiTopology.Adapter&lt;br /&gt;
&lt;p /&gt;
Look for FibreChannelHba, ParallelScsiHba, BlockHba etc.&lt;br /&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;br /&gt;</description>
      <pubDate>Wed, 08 Oct 2008 14:41:33 GMT</pubDate>
      <author>gstaykov</author>
      <guid>http://communities.vmware.com/message/1069724?tstart=0#1069724</guid>
      <dc:date>2008-10-08T14:41:33Z</dc:date>
      <clearspace:dateToText>1 year, 1 month ago</clearspace:dateToText>
      <clearspace:replyCount>2</clearspace:replyCount>
    </item>
    <item>
      <title>Re: How to find Local Datastores with Powershell?</title>
      <link>http://communities.vmware.com/message/1069010?tstart=0#1069010</link>
      <description>Hi Doug,&lt;br /&gt;
&lt;br /&gt;
Thanks for this.&lt;br /&gt;
&lt;br /&gt;
I have been digging in the API extensively trying to extend lbert's excellent ESXi provisioning script to add licensing, SSL certificate publication, support for ESX as well as ESXi, etc.&lt;br /&gt;
&lt;br /&gt;
One thing I want to do is either rename or remove local datastores so they don't accidentally get used during VM provisioning.&lt;br /&gt;
&lt;br /&gt;
Right now, I'm just looking for datastores that end with :storage1 but that's not terribly reliable.  &lt;br /&gt;
&lt;br /&gt;
I could wait until I get this added to VC and then enumerate like you suggest which might be interesting.&lt;br /&gt;
&lt;br /&gt;
I will have a look at the multipleHostAccess thingie.  That might also just do the trick.&lt;br /&gt;
&lt;br /&gt;
I'll will post the finished script...  someday.... when its done....  &lt;br /&gt;
&lt;br /&gt;
Thanks....</description>
      <pubDate>Tue, 07 Oct 2008 19:07:25 GMT</pubDate>
      <author>SCampbell</author>
      <guid>http://communities.vmware.com/message/1069010?tstart=0#1069010</guid>
      <dc:date>2008-10-07T19:07:25Z</dc:date>
      <clearspace:dateToText>1 year, 1 month ago</clearspace:dateToText>
    </item>
    <item>
      <title>Re: How to find Local Datastores with Powershell?</title>
      <link>http://communities.vmware.com/message/1068992?tstart=0#1068992</link>
      <description>I guess you could walk through your VMhosts and build a list of datastores visible to each host, then weed out the multiple-access ones.  &lt;br /&gt;
&lt;br /&gt;
The remaining ones would be local or presented to a single host.  Or, you could rely on naming conventions to tell you what is local and what is not.&lt;br /&gt;
&lt;br /&gt;
If you're up for digging into the API a little, there is a boolean called "multipleHostAccess" under the "summary" of the Datastore object.</description>
      <pubDate>Tue, 07 Oct 2008 18:48:44 GMT</pubDate>
      <author>DougBaer</author>
      <guid>http://communities.vmware.com/message/1068992?tstart=0#1068992</guid>
      <dc:date>2008-10-07T18:48:44Z</dc:date>
      <clearspace:dateToText>1 year, 1 month ago</clearspace:dateToText>
      <clearspace:replyCount>1</clearspace:replyCount>
    </item>
    <item>
      <title>Re: How to find Local Datastores with Powershell?</title>
      <link>http://communities.vmware.com/message/1067372?tstart=0#1067372</link>
      <description>You might be able to look at the paths associated with the datastores to check their SAN identifiers, which would indicate network storage. I'm not sure that local datastores even have paths.</description>
      <pubDate>Mon, 06 Oct 2008 03:05:07 GMT</pubDate>
      <author>c_shanklin</author>
      <guid>http://communities.vmware.com/message/1067372?tstart=0#1067372</guid>
      <dc:date>2008-10-06T03:05:07Z</dc:date>
      <clearspace:dateToText>1 year, 1 month ago</clearspace:dateToText>
      <clearspace:replyCount>2</clearspace:replyCount>
    </item>
    <item>
      <title>How to find Local Datastores with Powershell?</title>
      <link>http://communities.vmware.com/message/1067280?tstart=0#1067280</link>
      <description>You can easily create a local datastore with the New-Datastore -Local option.&lt;br /&gt;
&lt;br /&gt;
I am now trying find local datastores.  &lt;br /&gt;
&lt;br /&gt;
So far I am at this to return an array of extents for my VMFS partitions&lt;br /&gt;
&lt;pre class="jive-pre"&gt;&lt;code class="jive-code jive-plain"&gt;$DS=Get-DataStore | Where-Object { $Extents=($_ | Get-View).Info.VMFS.Extents; ...
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
I was going to try to map this to list of LUNs and look at the associated driver.  All our shared LUNs will have QLogic or iSCSI S/W drivers&lt;br /&gt;
&lt;pre class="jive-pre"&gt;&lt;code class="jive-code jive-plain"&gt;$LUNs= (Get-VMHost | Get-View).Config.StorageDevice.SCSILun 
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Has anyone found the easy way to Get-Datastore -Local?&lt;br /&gt;
&lt;br /&gt;
Thanks....</description>
      <pubDate>Sun, 05 Oct 2008 20:53:57 GMT</pubDate>
      <author>SCampbell</author>
      <guid>http://communities.vmware.com/message/1067280?tstart=0#1067280</guid>
      <dc:date>2008-10-05T20:53:57Z</dc:date>
      <clearspace:dateToText>1 year, 1 month ago</clearspace:dateToText>
      <clearspace:replyCount>6</clearspace:replyCount>
    </item>
  </channel>
</rss>

