Output on screen and EXPORT. CSV

Hi all

Were the creation of scripts for some general tasks and I got a little confused on what is happening.  I have two scripts that are output on the screen even with EXPORT. CSV commond to end.  I get the output sent to the CSV fine and there is no obvious errors.

Any whay Idears, that this could happen?  I can post my script if that helps.

Thank you

Phil

This is the line with only $objHba in it.

It will display the content of this variable to the screen.

# $vmlist = Get-VM
$table = @()

foreach ($vmhost in (Get-view -ViewType Hostsystem )) {
     foreach ($hba in ($vmhost.config.storagedevice.hostbusadapter | where {$_.PortWorldWideName})) {
          $objHba = "" | Select-Object Hostname,Device,Model,Driver,Pci,Wwpn
          $objHba.HostName = $vmhost.Name
          $objHba.Device = $hba.Device
          $objHba.Model = $hba.Model
          $objHba.Driver = $hba.Driver
          $objHba.Pci = $hba.Pci
          $objHba.Wwpn = "{0:x}" -f $hba.PortWorldWideName
#           $objHba
          $table += $objHba
     }
}

$table | Export-Csv $outputDir\data\$date.$viserver.$filename.csv -NoTypeInformation

BTW what is the first (of line) doing here? It has nothing to do with the rest of the script.

Copy & paste mistake I guess?

____________

Blog: LucD notes

Twitter: lucd22

Tags: VMware

Similar Questions

  • The screen can be cropped in and exported a report width / height custom?

    I think I need a Prime Minister to do something that it simply was not designed to do. Do I have to do is take five or six other screen and audio capture of the same event (a 3D virtual reality teaching session), each representing another person of this event view, assemble in a split screen, synchronize audio Delete, the capture of 'main' designated the other audio tracks and add a title CG labelling each one. The effect is like watching a screen showing six images from security cameras. I know it is possible to do these things first.

    However, I then have to do is to cut back on all extra space on the left and right of this image of the split screen and export the file as a .mov format of image produced by cropping so that videos are as broad as possible and are not deformed resize in order to fit standard proportions. Depending on the size of the screencaps, the .mov that results can have almost a 1:1 ratio. What is essential for this is that the video be as big as possible and the 'black' to be space as small as possible, so that the person who comes in later to analyze these composite videos see just as clearly as possible. I also need to refocus on the fly; because these images are not always captured in the same size, it is impossible to screening a size for the video.

    We used a tool of screenshot to do what works, but a pain; clips can be moved and resized by mouse-dragged, and the software to import and export from its own format owner, which is very slow. However, piece of video editing software 'true' I looked only ever seems to export in formats TV or film. QuickTime Pro looked a bit like the best bet, but it doesn't seem to be able to manage several audio tracks (which are necessary, since I have to synchronize tracks by ear most of the time).

    Is what I'm describing - exporting files .mov while preserving the custom extensions created by cropping when editing - something the Prime Minister can do? If so, it would be something easy enough for beginners to do?

    Stephen_Spider wrote:

    You also say that you don't want no carpet at the top or bottom of the final product. Once again to help monitor HD A as a model, looking something like a pixel of W 214 X 1920Pixel H.

    What is the size of your target display? And do you intend to have all the clips of six aligned horizontally?

    **************************************

    Edit, OK, you gave more information, while I was typing

    Heck, Jive forum also is miserable for not showing the changes.

    If this is the process, which will not work. We will just continue to use our current software. Thank you.

  • How to extract data from an arbitrary xml file and export it to a CSV friendly?

    Hallo,
    I am facing big problems in the use of XML files. I have a
    application that generates XML files with clusters containing arrays
    and scalars as in the example pasted below. My task is to
    Read it and export the data into a CSV document readable by a human.
    Since I do not know the actual content of the cluster, I need some sort
    Smart VI through the XML looking for berries
    and other data structures for export properly in the CSV file
    format (columns with headers).
    Thank you



    3


    6


    0



    1



    2



    3



    4



    5




    3.14159265358979



    Ciao

    Rather than to get the

    node, you can just go directly to the node since ' one that really interests you. Basically what it means to determine the elements of table how much you have, and it depends on if you have 1 or 2 knots . The rest is just of the child nodes and the next siblings. See attachment as a starting point. The attached XML file is a table 2D (change the .xml extension).

    Notes on the example:

    • I did not close properly references, so it's something you need to do.
    • It is limited to tables 1 d or 2D.
    • I suggest using a control path of the file to specify the input XML file and path of the file/folder control to specify the location of the output file.

  • Need help with an Export-CSV and ForEach loop

    Hi guys, I'm total NOOB in CLI so please forgive the stupid question.

    I need your expert advice for the very large environment and will award points.

    I have a working script that alerts to our logout ESXi hosts, maintenance and NotResponidng mode

    His job well, but need to send a mail to all three of our VCenters

    Current script only works for a VC at a time. How do I ForEach and always the hose of the same body CSV and HTML

    It would be nice to have an HTML and CSV output that looks like this (assuming that there are currently disconnected etc.)

    I have a set of credentials, that work on all 3 of my VC

    VC1

    Host1 disconnected

    Host2 NotResponding

    VC2

    Host3 disconnected

    Host4 NotResponding

    VC3

    No disconnected/maintemance/notresponding hosts for VC3

    Here is my current code, etc. of the hidden passwords >

    # Clear old sessions
    Disconnect VIServer VC01-confirm: $false

    # VC01 VC check for disconnection and Maintenance mode and does not
    SE connect-VIServer-Server VC01 - FakeUSer username-password FakePassword

    $Report = get-VMhost-State disconnected, maintenance, NotResponding | SELECT name, connectionstate

    # scan info to be html and give him a date stamp

    $ReportHtml = $report | ConvertTo-Html | Out-string

    # Write CSV file and give it a character of data

    $filePath = "C:\PS\Output".
    $filename = "VC01disconnectedHosts".
    $CurrentDate = get-Date
    $CurrentDate = $CurrentDate.ToString ('MM-dd-yyyy_hh-mm-ss')

    $Report | Export-Csv "C:\PS\Output\VC_$Currentdate.csv".

    # Send the info by Mail

    Send-MailMessage-to [email protected] - subject VMwareMorningcheckVC01$ CurrentDate '
    SmtpServer - mail.sanlam.co.za - from [email protected] '
    -BodyAsHtml-body $reportHtml - accessories 'C:\PS\Output\VC_$CurrentDate.csv '.

    Thank you in advance for help.

    You could use a ForEach loop through all vCenters and combine the results in a $1 report.

    Something like that

    $vCenters = "VC01","VC02","VC03"
    
    # Clear old sessionsDisconnect-VIServer $vCenters -Confirm:$false
    
    $report = @()# Check VC VC01 for Disconnects and Maintenance mode and Not Respondingforeach($vc in $vCenters){  Connect-VIServer -Server $vc -User FakeUSer -Password FakePassword
    
      $Report += (Get-VMhost -State Disconnected,Maintenance,NotResponding | Select @{N="VC";E={$vc}},name ,connectionstate)  Disconnect-VIServer $vc -Confirm:$false}
    
    # parse info to be html ,and give it date stamp
    
    $ReportHtml = ($report | ConvertTo-Html | out-String)
    
    # Write out CSV file and give it a Data Stamp
    
    $CurrentDate = Get-Date -Format 'MM-dd-yyyy_hh-mm-ss'$filename = "C:\PS\Output\DisconnectedHosts-$($CurrentDate).csv"
    
    $Report | Export-Csv -Path $filename -NoTypeInformation -UseCulture
    
    # Send info with Mail
    
    Send-MailMessage -To [email protected] -Subject VMwareMorningcheck$CurrentDate `-SmtpServer mail.sanlam.co.za -From [email protected] `-BodyAsHtml -Body $reportHtml -Attachments "C:\PS\Output\DisconnectedHosts-$($CurrentDate).csv"
    

    I added the property vCenter for each line in the report

  • Find records VM size and export to csv format

    Hello

    I need this script to export to csv format, but I have problems to make it work.

    Notice-EEG - ViewType VirtualMachine-property name, Config.Hardware.Device, LayoutEx | %{

    $viewVM = $_; $viewVM.Config.Hardware.Device |? {$_-is [VMware.Vim.VirtualDisk]} | %{

    # for each device VirtualDisk, get some info

    $oThisVirtualDisk = $_

    # get the disk element LayoutEx, which corresponds to the VirtualDisk

    $oLayoutExDisk = $viewVM.LayoutEx.Disk |? {$_. {Key - eq $oThisVirtualDisk.Key}

    # get the FileKeys that correspond to the LayoutEx-> sort items of this VirtualDisk

    $arrLayoutExDiskFileKeys = $oLayoutExDisk.Chain |? {$_-is [VMware.Vim.VirtualMachineFileLayoutExDiskUnit]}

    New-Object PSObject-property @ {} TypeName

    # Add the VM name

    VMName = $viewVM.Name

    # disc label, such as "disk 1".

    DiskLabel = $_. DeviceInfo.Label

    # the path to the data store for the file VirtualDisk

    DatastorePath = $_. Backing.FileName

    # the size provisioned to the VirtualDisk

    ProvisionedSizeGB = [Math]: tour ($_.) CapacityInKB / 1 MB, 1).

    # Get the file LayoutEx elements that correspond to the FileKeys for this LayoutEx disk and the size for items that are "diskExtents" (retrieved in the form of bytes, so convert to GB)

    SizeOnDatastoreGB = [Math]: round (($arrLayoutExDiskFileKeys | % {$_.)) FileKey} | % {$intFileKey = $_; $viewVM.LayoutEx.File |?} {($_. Eq - $intFileKey - button) and ($_.) Type - eq "diskExtent")}} | Measure - Object - size of the sum). Summary / 1 GB, 1).

    } # end new object

    } # end foreach-object

    } # end external foreach-object

    Capture all the output in a variable and send this variable in a CSV file.

    Something like that

    $result = Get-View -ViewType VirtualMachine -Property Name, Config.Hardware.Device, LayoutEx | %{
        $viewVM = $_; $viewVM.Config.Hardware.Device | ?{$_ -is [VMware.Vim.VirtualDisk]} | %{
            ## for each VirtualDisk device, get some info         $oThisVirtualDisk = $_        ## get the LayoutEx Disk item that corresponds to this VirtualDisk         $oLayoutExDisk = $viewVM.LayoutEx.Disk | ?{$_.Key -eq $oThisVirtualDisk.Key}
            ## get the FileKeys that correspond to the LayoutEx -> File items for this VirtualDisk         $arrLayoutExDiskFileKeys = $oLayoutExDisk.Chain | ?{$_ -is [VMware.Vim.VirtualMachineFileLayoutExDiskUnit]}
            New-Object -TypeName PSObject -Property @{
                ## add the VM name            VMName = $viewVM.Name
                ## the disk label, like "Hard disk 1"            DiskLabel = $_.DeviceInfo.Label
                ## the datastore path for the VirtualDisk file            DatastorePath = $_.Backing.FileName
                ## the provisioned size of the VirtualDisk            ProvisionedSizeGB = [Math]::Round($_.CapacityInKB / 1MB, 1)
                ## get the LayoutEx File items that correspond to the FileKeys for this LayoutEx Disk, and get the size for the items that are "diskExtents" (retrieved as bytes, so converting to GB)            SizeOnDatastoreGB = [Math]::Round(($arrLayoutExDiskFileKeys | %{$_.FileKey} | %{$intFileKey = $_; $viewVM.LayoutEx.File | ?{($_.Key -eq $intFileKey) -and ($_.Type -eq "diskExtent")}} | Measure-Object -Sum Size).Sum / 1GB, 1)
            } ## end new-object    } ## end foreach-object } ## end outer foreach-object
    
    $result | Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture
    
  • script to get the csv vm disk usage and export to csv format

    Hi all

    I am trying to create a script to get the use of disk for vm - space - free space and total disk space.

    I used this script that allows me to get the required result.

    but I need to edit the script for each cluster, VM he should get computers virtual cluster and check the vm disuage. and export of csv file

    $vms = import-CSV "C:\Cluster.csv".

    $outputfile = "c:\Diskusage.csv".

    SE connect-viserver VC-vcadmin username-password

    {foreach ($vm to $vms)

    Get - VM $vm.name | Where {$_.} PowerState - eq "Receptor"} | Get-VMGuest | Select the ExpandProperty - VMName disks | Select VMName, path, @{Name = "DiskCapacityGB"; Expression = {[math]: Round ((($_.))} {{((Ability) / 1 GB), 2)}}, @{Name = "DiskUsedMB"; Expression = {[math]: Round ((($_.))} Capacity - $_. {{((FreeSpace) / 1 MB), 2)}}, @{Name = "DiskFreeMB"; Expression = {[math]: Round ((($_.))} {{((FreeSpace) / 1 MB), 2)}} | Export-Csv - NoTypeInformation $outputfile}

    Viserver disconnect

    Joint the output file

    Veuileez help me in creating the script

    You can try like this?

    Connect-viserver VC -user vcadmin -password
    foreach($cluster in Get-CLuster){
        $outputfile = "c:\" + $cluster.Name + "-Diskusage.csv"    Get-VM -Location $cluster |
        Where { $_.PowerState -eq "PoweredOn" } |
        Get-VMGuest |
        Select VMName -ExpandProperty Disks |
        Select VMName, Path,
            @{Name="DiskCapacityGB";Expression={[math]::Round((($_.Capacity)/1GB),2)}},
            @{Name="DiskUsedMB";Expression={[math]::Round((($_.Capacity - $_.FreeSpace)/1MB),2)}},
            @{Name="DiskFreeMB";Expression={[math]::Round((($_.FreeSpace)/1MB),2)}} |
        Export-Csv -NoTypeInformation $outputfile}
    
    Disconnect-viserver
    

    The script creates a CSV file for each cluster.

  • Images high resolution that I matter IIN indesign appear in a definition very mlauvaise to the screen and once exported to pdf, they are still quite far from the original. Perhaps to remedy these problems.

    Images high resolution that I import in indesign appear in a very bad definition on-screen and when exported to pdf, they are still quite far from the original. Perhaps to address these problems?

    The bad export quality could be linked to the pre-selection of PFD you have chosen. Some of the presets are designed to re - sample images to make a smaller final PDF

  • Last night my 5 Lightroom suddenly seems to update. A shooting blue veined lgo ratings appeared on my screen and many of my settings have been changed. My problem now is that when I export an image on my drive C:, the exported image n

    Last night my 5 Lightroom suddenly seems to update. A shooting blue veined lgo ratings appeared on my screen and many of my settings have been changed. My problem now is that when I export an image on my C: drive, the exported image is no longer automatically appears in my Picasa files as it has for years. How can I fix this please?

    Hello

    Greetings!

    In the export dialog box change the export after option.

    Concerning

    Jitendra

  • Welcome and export as screen screen does not show entirely

    I don't think I've seen that never happen in any of my prior Adobe apps, but when I just upgraded to Photoshop CC 2015, the Welcome screen is not fully displayed on my Macbook Pro 13 "when executing a second Cinema Display.  Same thing happens when I tried in the file - export.  The pop up appears incomplete, there is no way I see to move where I can view the whole component.  A way to fix this?  Here is a screenshot of my Macbook Pro.

    Screen Shot 2015-06-26 at 6.32.27 PM.png

    OK, here's a suggestion. Organize the largest display to the right of the smaller screen and move the menu bar to the larger screen, just like mine.

    Note that my laptop wallpaper is on low level of the larger screen.

    Another note must close Photoshop before you connect or disconnect your monitor.

    I think that your problems will go away with this arrangement.

    What it does is make the large display of the main screen when connected. To get to Photoshop to use up the full display area, click the Green Resize button and it will fill the screen.

    If you open the export dialog box, it should be where mine is in my example.

  • Get-Annotation and export to CSV

    I am trying to export of Annotation custom fields in a CSV with foreach and difficulty to operate there where I want.

    1. is it possiible export with foreach or do I have to use foreach-object?

    $vms = get-vm pt*
    foreach ($vm in $vms){
        $vm = Get-View $vm.ID
        $nm = $vm.name
        $hn = $vm.guest.hostname
        $ip = $vm.guest.ipaddress
        $contact = get-vm $vms | Get-Annotation -CustomAttribute "System Contact"|select Value
        $vm | select `
        @{Name = "Name"; E={$nm}},`
        @{Name = "Contact"; E={$contact}},`
        @{Name = "Hostname"; E={$hn}},`
        @{Name = "IP"; E={$ip}}
    }format-table -AutoSize -Wrap

    2. How can I get rid of the "{@{value ="in the exit?}} "

    Name                          Contact                       Hostname                      IP
    ----                          -------                       --------                      --
    PT1                      {@{Value=abcd.Serverteam...     pt1.abcd.com              10.0.1.5
    PT2                      {@{Value=abcd.Serverteam...     pt2.abcd.com              10.0.1.33

    The better, more PowerShell, way to do this would be to use the pipeline.

    Something like that

    Get-VM tp* | Select Name,  @{N="Hostname";E={$_.Guest.Hostname}},  @{N="IP address";E={$_.Guest.IpAddress}},  @{N="Contact";E={
        Get-Annotation -Entity $_ -CustomAttribute "System Contact" |
        Select -ExpandProperty Value}} | Export-Csv c:\report.csv -NoTypeInformation -UseCulture
    
  • Strange output from Get - VM... A cruise ship Export-CSV

    If I type this in PowerCLI I get expected results

    Get-Datacenter -name "name of my datacenter" | Get-VM | Where { ($_ | Get-CDDrive).ISOPath } | FT -auto Name, @{Label="OS"; Expression = { $_.Guest.OSFullName }}, @{Label="ISO file"; Expression = { ($_ | Get-CDDrive).ISOPath }}

    But if I try to export to a CSV file

    Get-Datacenter -name "name of my datacenter" | Get-VM | Where { ($_ | Get-CDDrive).ISOPath } | FT -auto Name, @{Label="OS"; Expression = { $_.Guest.OSFullName }}, @{Label="ISO file"; Expression = { ($_ | Get-CDDrive).ISOPath }} | Export-CSV virtual_machines_mounted_ISO.csv

    I get output like this:

    #TYPE Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
    "ClassId2e4f51ef21dd47e99d3c952918aff9cd","pageHeaderEntry","pageFooterEntry","autosizeInfo","shapeInfo","groupingEntry"
    "033ecb2bc07a4d43b5ef94ed5a35d280",,,"Microsoft.PowerShell.Commands.Internal.Format.AutosizeInfo","Microsoft.PowerShell.Commands.Internal.Format.TableHeaderInfo",
    "9e210fe47d09416682b841769c78b8a3",,,,,
    "27c87ef9bbda4f709f6b4002fa4af63c",,,,,
    "27c87ef9bbda4f709f6b4002fa4af63c",,,,,
    "27c87ef9bbda4f709f6b4002fa4af63c",,,,,
    "27c87ef9bbda4f709f6b4002fa4af63c",,,,,
    "27c87ef9bbda4f709f6b4002fa4af63c",,,,,
    "27c87ef9bbda4f709f6b4002fa4af63c",,,,,
    "27c87ef9bbda4f709f6b4002fa4af63c",,,,,
    "27c87ef9bbda4f709f6b4002fa4af63c",,,,,
    

    What Miss me?

    Try to replace the 'FT-auto' by 'Select-Object.

  • Hot to export the two outputs a script to a csv file

    Hi all

    I have a simple sctipt which is the instant list of two DC in my environment. Currently each line generates a separate CSV file with data.

    Is it possible to create a single file with the output of these two lines data?

    Get-data center-name DC1. Get - vm | Get-snapshot | Select-Object name, Description, PowerState, VM, created, @{Name = 'Host'; Expression = {(Get-VM $_.)} {{VM). $host.name}} | Export ' E:\artur\reports\DC1_snapshot.csv

    Get-data center-name DC2. Get - vm | Get-snapshot | Select-Object name, Description, PowerState, VM, created, @{Name = 'Host'; Expression = {(Get-VM $_.)} {{VM). $host.name}} | Export 'E:\artur\reports\DC2_snapshot.csv '.

    both files will be sent by mail

    Copy & paste the problem.

    The Export-Csv should be of course outside the loop

    get-datacenter -name "blackburn","coventry" | %{
         $dcName = $_.Name
         $_ | get-vm | get-snapshot | `
              Select-Object @{Name="DC"; Expression={$dcName}},VM, Name, Description, PowerState, Created,
                   @{Name="Host"; Expression = {(Get-VM $_.VM).Host.Name}} | `
    } | Export-Csv 'C:\DC_snapshot.csv'
    

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • Export-csv column order

    Is there a way to control or to format the output to a CSV of powercli?  It seems that columns are always just in random order and I would be able to dictate that.

    The problem is not with the Export-Csv cmdlet, but with the way in which the properties are stored in an object by PowerShell.

    In PowerShell v2, you can explicitly specify the order before the Export-CSV

    $array | Select prop1, prop1, prop2 | Export Csv C:\file.csv - NoTypeInformation - UseCulture

    In PowerShell v3, you now have the casting [ordered].

    See Export-Xlsx, the suite and the data ordered, who throw also works with Export-Csv

  • Include the attribute custom report (Export-Csv)

    I am writing a script to report on disk / the use of the capacity for each virtual machine in the environment.

    I try to include a column in the generated report (CSV), which includes the CustomField/CustomAttributes for each virtual computer as well as the news of disk capacity.  The report runs fine, but after you export the report to CSV (Export-Csv using) the newly created column just to the custom attribute field displays the following parameters for each line/entry:

    VMware.VimAutomation.ViCore.Impl.V1.Util.ReadOnlyDictionary'2 (System.String, System.String)

    When I use out-file it works, but formatting is very obscured...

    Here's the function/script that I use, I 'bolded in Red' the part of the script which I believe is the origin of the problem:

    Function Get-VMGuestDiskUsage {}
    (param
    [parameter (valuefrompipeline = $true required = $true, HelpMessage = "enter an entity vm")]
    ([VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl] $VM)
    {in process
    $ErrorActionPreference = "SilentlyContinue".
    foreach ($disk in $VM. Guest.Disks) {}
    $objDisk = new-Object System.Object
    $objDisk | Add-Member - MemberType NoteProperty-VM name-value $VM. Name
    $objDisk | Add-Member - MemberType NoteProperty-name of Volume-value $disk. Path
    $objDisk | Add-Member - MemberType NoteProperty-CapacityMB name-value ([math]: round ($disk.) Capacity / 1 MB))
    $objDisk | Add-Member - MemberType NoteProperty-FreeSpaceMB name-value ([math]: round ($disk.) FreeSpace / 1 MB))
    $objDisk | Add-Member - MemberType NoteProperty - percent use of name-value ('{0:p2}' f (($disk.))) Capacity - $disk. FreeSpace) / $disk. Capacity))
    $objDisk | Add-Member - MemberType NoteProperty-name CustomFields-value ($VM. CustomFields)
    $objDisk
    }
    }
    }

    Get - VM * | Get-VMGuestDiskUsage | Export-Csv - NoTypeInformation c:\scripts\output\test.csv

    Any help is greatly appreciated!  Also please let me know if I did a poor job explaining the scenario and what I'm after here.

    Hello, jSun311-

    Because the property "CustomFields" itself is an object, and you try to get out of the strings to the CSV format, you must manage the object.  You can replace the line in question by something like:

    $objDisk | Add-Member -MemberType NoteProperty -Name CustomFields -Value (($VM.CustomFields | %{"$($_.Key) = $($_.Value)"}) -join ",")
    

    Which would result in the output for the column that might look like:

    dTestAttrib0 = someValue,dTestAttrib1 = AnotherValue
    

    In other words, there is a list separated by characters of the key/value pairs in the CustomFields property for the virtual machine.

    In addition, if you are interested, you might be able to clean up your code a bit by using the '-property ' New-Object parameter.  As:

    ...foreach ($disk in $VM.Guest.disks) {    New-Object PSObject -Property @{        VM = $VM.Name        Volume = $disk.Path        CapacityMB = [math]::Round($disk.Capacity / 1MB)        FreeSpaceMB = [math]::Round($disk.FreeSpace/1MB)        "Usage%" = "{0:p2}" -f (($disk.Capacity - $disk.FreeSpace) / $disk.Capacity)        CustomFields = ($VM.CustomFields | %{"$($_.Key) = $($_.Value)"}) -join ","    } ## end new-object} ## end foreach...
    

    In this way, you shouldn't bother with calls Add-Member and repetitive cases here.  Enjoy.

  • result of foreach not getting attached to the export-csv

    Hello people,

    I am trying to learn powercli. I use under commads to get information for VMs. looks like the results not add in the csv file. CSV file shows the result of the latest VM in import-csv file.

    Q1 - can you please help identify what is bad in the commands below?

    Q2 - How can I use a single export-csv command to get an output of lines both (get - vm and get-cluster)?

    $vmname = import-csv "C:\vmname.csv".
    {foreach ($_.name in $vmname)}
    Get - vm $_.name | Select 'Name', 'Host ' | export-csv - UseCulture - NoTypeInformation C:\vmname-host-info.csv
    Get-cluster - vm $_.name | Select 'name ' | export-csv - UseCulture - NoTypeInformation C:\vmcluster-info.csv}

    Thank you!

    You're crushed the CSV file with each iteration of the loop.

    Why do you want to produce 2 CSV files? Is it not easier to keep all the info in 1 file?

    Her you could do something like that

    $vmname = import-csv "C:\vmname.csv".
    & {{foreach ($_.name in $vmname)}}
    Get - vm $_.name | Select 'Name","Host",@{N="Cluster '; E = {Get-Cluster - VM $_______ |} Select name - ExpandProperty}}

    }} | Export-csv - UseCulture - NoTypeInformation C:\vm-info.csv

    But the best is to use the track more PowerShell

    $vmname = import-csv "C:\vmname.csv".

    Get-VM-name $vmname |

    Select Name,Host,@{N="Cluster; E = {Get-Cluster - VM $_______ |} Select name - ExpandProperty}} |

    Export-csv - UseCulture - NoTypeInformation C:\vm-info.csv

Maybe you are looking for