title: powershell vmware powerCLI automatic script
body: <p>I am making a script to run in powershell (powerCLI) for vmware. I try to do a automatic report exported to a csv file but i dont know how to resolve couple of problems.</p>
  
  <p>All parameters which i dont know how to export them.</p>
  
  <ol>
  <li><p>"virtual machine working location"
  I can export disks where is a mashine, but i don't know how to export all path with folders.</p></li>
  <li><p>domain / workgroup</p></li>
  <li><p>Name of computer
  When i try to export a name i get name with domain "name.domainname.com" (that is strange because my VM are not in domain, there are in workgroup)
  <strong>name</strong> i mean a name inside of OS not in esxi, because esxi name of vm i get from this</p></li>
  </ol>
  
  <blockquote>
    <p>$name = (get-vm name_maschine|select-object name).name</p>
  </blockquote>
  
  <p>or simple when in loop parameter is a name of mashine, i only export a parameter</p>
  
  <p><strong>less important parameters</strong></p>
  
  <p>4 . The name of vcenter in which host is working</p>
  
  <ol>
  <li>The name of datacenter in which host is working</li>
  </ol>
  
  <p><strong>Code:</strong></p>
  
  <pre class="lang-powershell prettyprint-override"><code>connect-viserver -server IP-ADDRES -user root -password PASSWORD 
  Get-View -ViewType VirtualMachine | %{ 
      New-Object PSObject -Property @{ 
      # mashine name 
      'Mashine name' = $_.Name 
      #date when edited 
      'Date' = Get-Date 
      # resource pull 
      'pull' = (Get-VM $_.Name | Get-ResourcePool | select-object name).name 
      #disk where is mashine 
      'Datastore' = [system.String]::Join(",",($_.Storage.PerDatastoreUsage | %{Get-View $_.Datastore} | %{$_.Name}))
      }
  }
  </code></pre>