Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

combine commands or output

$
0
0

I am pulling info with powercli but my question is powershell centralized.   Below is a snipit of the code.  I set the $vm, $Partitions  and $disk variable and collect what I want.  My issue is I have to run loops for $vm, $disk and down further the extensiondata.guest.disk which is the partitions of a host vm.  This is probably more info than needed but I wanted to lay it out.  What I want to know is how can I run these 3 various loops or combine them and output the results to one line for each computer name and export to csv eventuyally.  I want to get vm info, hardisk info and the partition info of the harddisk all from powercli.  I am fairly new to powershell and am sure this can be done.  The script is a mess I have been trying various things to get the output to work so it is ugly currently.  So in summary I want to get the info from the 3 for loops and add results to one line for each  computer name imported from my csv. 

 

 

Import-CSV $importCSV | Foreach-Object{

    $strComputer = $_.computer

     

      $VM = get-vm $strComputer | Select name,VmHost,ProvisionedSpaceGB,UsedSpaceGB,DatastoreIdList,guest,disk,extensionData

      $Disk = Get-HardDisk $strComputer | Select filename,storageFormat,persistence,disktype,Capacitykb,name

     
 


foreach($object in $VM){
           

             $Name=$object.name

            $vmhost = $object.vmhost

            $datastoreidList = $object.datastoreidList

            $provisionedspacegb = $object.provisionedspacegb

            $usedspacegb = $object.usedspacegb

           

             $output = "$name `t $vmhost `t $datastoreidlist `t $provisionedspacegb `t $usedspacegb `t" | Out-File $logfile -Append

 

$count=0

           

             foreach($objDisk in $disk){

           

              $vmdk = $objDisk.filename

              $DiskFormat = $objDisk.storageFormat

              $DiskPersistence = $objDisk.persistence

              $DiskType = $objDisk.disktype

              $Capacity = $objDisk.capacitykb

              $diskName = $objDisk.name

             


        $Partitions = $VM.extensionData.guest.disk | select DiskPath,FreeSpace,Capacity

     

        $diskcount = 0                                        

                                                  

                  foreach($partition in $Partitions){

      $partitionDiskPath = $partition.DiskPath

      $PartitionCapacity = [math]::Round($partition.Capacity/ 1GB)

      $PartitionFreeSpace = [math]::Round($partition.FreeSpace / 1GB)

      $PartitionPercentFree = [math]::Round(((100* ($partition.FreeSpace))/ ($partition.Capacity)),0)


Viewing all articles
Browse latest Browse all 6937

Trending Articles