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

Tags: VMware

Similar Questions

  • Export the results of a query to a CSV file

    Hello

    My requirement is that I need to export the results of a query to a CSV file. Can someone please suggest a way to also include the names of columns in the CSV file?

    Thanks in advance.

    Annie

    Following code comes from asktom. I changed to include the column header. This will get your CSV file desired for a given query.

    create or replace function  dump_csv( p_query     in varchar2,
                                          p_separator in varchar2
                                                        default ',',
                                          p_dir       in varchar2 ,
                                          p_filename  in varchar2 )
    return number
    AUTHID CURRENT_USER
    is
        l_output        utl_file.file_type;
        l_theCursor     integer default dbms_sql.open_cursor;
        l_columnValue   varchar2(2000);
        l_status        integer;
        l_colCnt        number default 0;
        l_separator     varchar2(10) default '';
        l_cnt           number default 0;
    
         l_colDesc          dbms_sql.DESC_TAB;
    begin
        l_output := utl_file.fopen( p_dir, p_filename, 'w' );
    
        dbms_sql.parse(  l_theCursor,  p_query, dbms_sql.native );
    
        for i in 1 .. 255 loop
            begin
                dbms_sql.define_column( l_theCursor, i,
                                        l_columnValue, 2000 );
                l_colCnt := i;
            exception
                when others then
                    if ( sqlcode = -1007 ) then exit;
                    else
                        raise;
                    end if;
            end;
        end loop;
    
        dbms_sql.define_column( l_theCursor, 1, l_columnValue, 2000 );
    
        l_status := dbms_sql.execute(l_theCursor);
    
         dbms_sql.describe_columns(l_theCursor,l_colCnt, l_colDesc);
    
         l_separator := '';
    
         for lColCnt in 1..l_colCnt
         loop
                utl_file.put( l_output, l_separator ||  '"' || Upper(l_colDesc(lColCnt).col_name) || '"');
                   l_separator := p_separator;
         end loop;
    
         utl_file.new_line( l_output );
    
        loop
            exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 );
            l_separator := '';
            for i in 1 .. l_colCnt loop
                dbms_sql.column_value( l_theCursor, i,
                                       l_columnValue );
                utl_file.put( l_output, l_separator ||  '"' ||
                                        l_columnValue || '"');
                l_separator := p_separator;
            end loop;
            utl_file.new_line( l_output );
            l_cnt := l_cnt+1;
        end loop;
        dbms_sql.close_cursor(l_theCursor);
    
        utl_file.fclose( l_output );
        return l_cnt;
    end dump_csv;
    

    The original link is below.

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:95212348059

    Thank you
    Knani.

  • Hello, need help for Adobe Reader DC playing animation files that are specified in the pdf output by script Latex Beamer. My Adobe Reader DC refuse to open any format that I gave him.  Thank you very much

    Hello, need help for Adobe Reader DC playing animation files that are specified in the pdf output by script Latex Beamer. My Adobe Reader DC refuse to open any format that I gave him.  Thank you very much

    Hey ihorl18351266,

    Please note that you can open PDF files using only the CD player. Any other format will not be supported by the software.

    Kind regards

    Ana Maria

  • Creation of the two controlfiles in an auxiliary init.ora file

    How the two controlfiles can be created in an auxiliary init.ora file?

    (1) immediate stop

    (2) manually copy original controlfile and paste in any other destination

    (3) changing init.ora

    control_file = ,

    (4) starting with the init.ora.

  • Export several pieces of information into a single CSV file

    Hi guys,.

    I try to export the information to a .csv file.  At the end of the day, I want the following information in the CSV file with the following headers:

    Name, NumCpu MemoryMB, Description, NetworkName


    I can get all the information for the first four topics (name, Description, NumCpu, MemoryMB) with the following command:

    Get - VM MYVM | Select Name, NumCpu, MemoryMB Description | Export-Csv-path "c:\outp\VMs.csv" - NoTypeInformation

    For the VLAN (aka NetworkName) I run the following command:

    Get - VM MYVM | Get-NetworkAdapter | Select NetworkName | Export-Csv "c:\output\VMs.csv" - NoTypeInformation

    The command to run successfully, however the second command is to crush the first information.  I tried - add the switch which gives an error, which suggests that I use - force, I also tried, that is the best that I could realize all the information exported, but with the unwanted spaces.  Is there an easy way to combine these two orders and export them to the CSV on the same line?

    Thank you.

    Use a calculated property.

    Try like this

    Get - VM |

    Select the name, NumCpu MemoryMB, Description,@{N='NetworkName'; {E = {Get-NetworkAdapter - VM $_______ | select - ExpandProperty NetworkName}} |

    Export-Csv-path "c:\outp\VMs.csv" - NoTypeInformation

  • Set the priority to restart HA of a csv file

    Hello

    I have a problem HA restart the priority of a CSV on the VMs.

    My share of script is like this:

    If ($Export)

    {

    # Export to CSV

    $mycluster = get-Cluster-name $Cluster

    $mycluster. ExtensionData.Configuration.DasVmConfig |

    Select @{N = "VM"; E = {Get-view $_.} Key - the name of the property. {{Select - ExpandProperty name}}.

    @{N = "RestartPriority"; E={$_. RestartPriority}} |

    {Csv Export $Path\HARestartPrio.csv - NoTypeInformation - UseCulture}

    If ($Set)

    {

    # Put csv

    $Import = import-Csv $Path\HARestartPrio.csv

    foreach ($line in $Import)

    {set-VM - vm $line. "" VM "-HARestartPriority $line. {{"" RestartPriority "-confirm: $false}}

    When I put the priority, the CLI will give an error:

    The parameter HARestartPriority can not check. The Argument is Null or is empty

    What is the problem in my script? You have any ideas?

    It is not the Export-Csv is the problem in my humble opinion, you must also specify the Import-Csv cmdlet UseCulture switch.

  • VM list name and the cluster that it flows in a CSV file

    Hello

    I want to have a created CSV file that will conaitn 2 fields: vm_name, vm_custer

    Which means, I want to list the name of the virtual machine and the cluster is running in a CSV file.

    Here is the code I wrote:

    #! / usr/bin/perl - w
    use strict;
    Use Data::Dumper;
    use VMware::VIRuntime;
    My % opts = (data center = > {})
    Type = > "s =",
    help = > 'enter the name of the data center. "
    required = > 1,
    });
    OPTS::add_options (%OPTS);
    OPTS::parse();
    OPTS::Validate();
    Util::connect;
    "open (my $FH, ' > ', 'final.csv') or die" cannot opne final.csv: $! » ;
    print $FH 'VM_Cluster, VM_Name, \n ";
    my $dc = Opts::get_option ("data center");
    My $dc_view = Vim::find_entity_view (view_type = > 'Data center',)
    filter = > {name = > $dc});
    My $clu_views = Vim::find_entity_views (view_type = > "ComputeResource")
    begin_entity = > $dc_view);
    my $cluster foreach (@$clu_views)
    {
    My $clu_name = $cluster-> name;
    my $hosts = $cluster-> host;
    foreach (@$hosts)
    {
    My $host_hash_ref = Vim::get_view (mo_ref = > $_);
    My $vm_view = $host_hash_ref-> virtual machine;
    foreach (@$vm_view)
    {
    My $vm_hash_ref = Vim::get_view (mo_ref = > $_);
    My $vm_name = $vm_hash_ref-> name;
    $FH print $clu_name. ", ".  $vm_name. », «. "\n" unless $clu_name = ~ m/0bld0 /; "
    }
    }
    }
    Close ($FH);
    Util::disconnect;

    Now, I get the CSV file created as I wanted to, but the question is, there are 3500 + VMs in vCenter and this script side took 50 minutes to complete. It is therefore a huge performance impact. Also, I don't like the concept of 3 layers netsted foreach loops.

    Therefore, there is an effective way to get this information?

    Thank you.

    Your welcome.  It could be made faster, but the complexity of the additional code is probably not worth if the runtime you have now is enough.  No doubt, you can add additional data to your report without too slow.

    You can also find the script works faster or slower depending on what is happening in your virtual center system.

    Thanks for the update on the success!

  • Cannot export the report via MaxL script

    Hello

    IM only running the following MaxL script, but I cannot get it to generate the report file.
    "
    database export 'realtest'.' LoadTest'
    using fichier_de_rapport 'Exp09.rep '.
    of data_file '\\nkm18e83\\logs2\\Realbud\\reperr.txt ';
    "
    Does anyone have an idea? Its the same syntax that I use when I write an error report...

    Any help would be appreciated.

    In fact, it will run without specifying the player to exit from. (at least in a batch script it does)

    I'm guessing that it generates for the drive on which you run for?

  • Export the default output directory

    When I export media the default directory is a directory, I have visited during my first installation of Premiere Pro. The FAQ on that dated back to 2009 by saying that it was a known issue (useless). I tried to adjust the preference of the SOUL, but not not do that either. Looks like the default directory is coming from first, but there is no preference for that.

    Try to set in the settings dialog box, before clicking on the button of the queue.

  • How can I produce two outputs of the same project

    Dear Sir.

    My goal is to produce the two outputs of the same main project, Webhelp and HTML help, each of them will be used differently in my compnay.

    Producing two outputs is fine, but the problem was that external links are done differently for HTML help and Webhelp and as I Knew about you that can be solved by using conditional tags.

    Actually I am new to conditional tags and I don't know how to use them. Could you please help me to do this or recommend a link on how to use condtional tags to produce different outputs.

    Thank you very much

    Hi there ahlam323

    See if the link below helps everything. Some goober wrote something on it.

    Click here to read the goober guide

    See you soon... Rick

  • Merger of the two devices

    Is it possible to merge all data on two Palms (TX and LifeDrive) in one simple step, while a Palm acts as one backup/copy on the other? If so, how?

    There is really no one simple step to transfer the data from one device to another. Since you have 2 different models of Palm devices, you will need to have 2 different user names in Palm desktop, one for each device. Download the current data in one of your user names. Export data from Palm desktop. Select the other user name of Palm desktop and import the data into this user name. Synchronize with your handheld.

    You will need to use this procedure each time you want to update or the other username with the data from the other device.

    You cannot synchronize the same username in Palm desktop because the devices are dissimilar models. With 2 different models, the preferences and settings of a device are not compatible with each other. If synchronize you with the same user name, it will cause problems.

    The best way to protect your data is to export the data in each category of Palm Desktop in a separate folder on your PC.

    Create a new folder on your PC somewhere that suits. Name it something like Palm Desktop data. Click on the link below and follow the instructions on this page for the export procedure.

    http://www.Palm.com/cgi-bin/cso_kbURL.cgi?id=28734

    Make sure you only select everything for the beach in the export window.

    With the data stored in the created folder, make a copy of this file and save it on a USB key, cd - rw or external hard drive.

    Whenever you change in Palm Desktop, export the data that has been changed in this file and save again to external media.

    With this process you can always import the data in Palm Desktop, whenever you have a problem with the data in Palm Desktop, or if your computer/hard drive/device crash.

    For reference purposes, click the following link to the support page for your TX device on the kb.palm.com Web page.
    http://KB.Palm.com/wps/portal/KB/na/tungsten/TX/unlocked/home/page_en.html

    There are links on the page the user Troubleshooting Guide, how to, downloads, etc.

    For reference purposes, click the following link to the support page for your Lifedrive device on the kb.palm.com Web page.
    http://KB.Palm.com/wps/portal/KB/na/LifeDrive/LifeDrive/unlocked/home/page_en.html

    There are links on the page the user Troubleshooting Guide, how to, downloads, etc.

  • How to export data from a string to a CSV file

    Hello

    I have a string in a script object Livecycle Designer with a couple of lines with different inputs divided by a semicolon:

    COLUMN1;COLUMN2;COLUMN3
    Entry1;Entry2;Entry3
    Entry4;Entry5;Entry6
    

    The goal now is to export this channel of Livecycle Designer in a CSV file, by clicking a button. Is there a suggested solution?

    Thank you very much.

    Hello

    You can try to create a dataObject object and then export, you can get some warning messages popup but try this;

    var csvData. = "COLUMN1; COLUMN2; COLUMN3\r\n ';

    csvData += 'Entry1; Entry2; Entry3\r\n ';

    csvData += "Entry4; Entry5; Entry6\r\n ';

    var PDF = event.target;

    pdf.createDataObject ("Data.csv", csvData);

    pdf.exportDataObject ({cName: "Data.csv"});

    If you replace the last line with

    pdf.exportDataObject ({cName: "Data.csv", nLaunch: 2});

    It will be opened in a .csv is approved (Excel on my system)

    Concerning

    Bruce

  • I'm looking for a Script that can list all virtual machines with type of NIC E1000 via the output of the CSV file.

    Hi gurrus and LucD

    I'm looking for a Script that can list all virtual machines with type of NIC E1000 via the output of the CSV file.

    The script should search for information in a multiple Vcenter servers and multiple clusters and list all the VMs name, status (two powers on or off) with type card NETWORK Type E1000 only no other.

    Concerning

    Nauman

    Try like this

    $report = @)

    {foreach ($cluster Get-cluster)

    foreach ($rp in Get-ResourcePool-location $cluster) {}

    foreach ($vm in (Get-VM-location the $rp |)) Where {Get-NetworkAdapter - VM $_______ | where {$_.}} Type - eq "e1000"}})) {}

    $report += $vm. Select @{N = "VM"; E={$_. Name}},

    @{N = 'vCenter'; E={$_. Uid.Split('@') [1]. "Split(':') [0]}},"

    @{N = "Cluster"; E = {$cluster. Name}},

    @{N = "ResourcePool"; E = {$rp. Name}}

    }

    }

    }

    $report | Export Csv C:\temp\report.csv - NoTypeInformation - UseCulture

  • Need a little help. Script to export the single document for different types of files.

    Hey guys, I'm new to scripting. have looked everywhere but cannot find an answer to this, I'm sure it's pretty simple


    At work we export logos all the time in a few different formats for the clients.
    I looked in the script as a way to automate the process.

    So far, I thought a little script to export my Illustrator formats document... now I need to be able to export this document even outside as a res low and high PNG, low and high res JPEG, EPS, PDF and TIFF etc.
    I have scripts to do all these separately but just need to know how to put it all in a single script I can do all at once

    Here is an example of my two different scripts to export PNG. I just need to know how string together so I can add all of the formats without breaking it.

    function savePNG() {}
    var destFolder = Folder.selectDialog ("select the folder to export the PNG files to :');")
    If {(destFolder)
    If (app.documents.length > 0) {}
    var Nomdoc = app.activeDocument.name.match(/^.*[^.ai]/i);
    var destFile = new file (destFolder + ' /' + Nomdoc + "-HR.png");
    if(destFile == null) {return ;}
    var doc = app.activeDocument;
    var artRect = doc.artboards [0] .artboardRect;
    var exportOptions = new ImageCaptureOptions;
    exportOptions.resolution = 300;
    exportOptions.antiAliasing = true;
    exportOptions.transparency = true;
    doc.imageCapture (destFile, artRect, exportOptions);
    }
    }
    }
    savePNG();

    and here is the version low resolution

    function savePNG() {}
    var destFolder = Folder.selectDialog ("select the folder to export the PNG files to :');")
    If {(destFolder)
    If (app.documents.length > 0) {}
    var Nomdoc = app.activeDocument.name.match(/^.*[^.ai]/i);
    var destFile = new file (destFolder + ' /' + Nomdoc + "-LR.png");
    if(destFile == null) {return ;}
    var doc = app.activeDocument;
    var artRect = doc.artboards [0] .artboardRect;
    var exportOptions = new ImageCaptureOptions;
    exportOptions.resolution = 72;
    exportOptions.antiAliasing = true;
    exportOptions.transparency = true;
    doc.imageCapture (destFile, artRect, exportOptions);
    }
    }
    }
    savePNG();

    Thanks for any advice you can give!
    Eli

    Oh, you want to perform two functions, one after another at the same time? then just name with different names and perform one function after another, if all files will be saved in the same folder, the argument selectDialog move method on each of your functions to don't do only once.

    function savePNG_HR(){
        var destFolder = Folder.selectDialog('Select the folder to export the PNG files to:');
        if (destFolder) {
            if(app.documents.length > 0){
                var docName = app.activeDocument.name.match(/^.*[^.ai]/i);
                var destFile = new File(destFolder + '/' + docName + " - HR.png");
                if(destFile == null){return;}
                var doc = app.activeDocument;
                var artRect = doc.artboards[0].artboardRect;
                var exportOptions = new ImageCaptureOptions;
                exportOptions.resolution = 300;
                exportOptions.antiAliasing = true;
                exportOptions.transparency = true;
                doc.imageCapture(destFile, artRect, exportOptions);
            }
        }
    }
    
    function savePNG_LR(){
        var destFolder = Folder.selectDialog('Select the folder to export the PNG files to:');
        if (destFolder) {
            if(app.documents.length > 0){
                var docName = app.activeDocument.name.match(/^.*[^.ai]/i);
                var destFile = new File(destFolder + '/' + docName + " - LR.png");
                if(destFile == null){return;}
                var doc = app.activeDocument;
                var artRect = doc.artboards[0].artboardRect;
                var exportOptions = new ImageCaptureOptions;
                exportOptions.resolution = 72;
                exportOptions.antiAliasing = true;
                exportOptions.transparency = true;
                doc.imageCapture(destFile, artRect, exportOptions);
            }
        }
    }
    savePNG_HR();
    savePNG_LR();
    
  • Script to export the virtual disk information in a specific format

    Hi all

    First too all the Scripting Guys who I borrowed the code here, thank you!

    Now, I was able to get all the information I want vcenter but I have problems with two of the scripts I wrote.  It is with regard to obtaining information on the virtual disks associated with all virtual machines in the environment.

    I was able to export the data, but I get a line by VM that does not work for the way in which we want to use the data.

    What I am looking for is a csv export with one line per virtual machine that looks like:

    VM number 1, hard disk number 1 name number 1 datastore, path of vmdk number 1 hd, hd number 1 capactity, number 1 hd, hard drive controller number 2 name,... up to 7

    name of number 2 VM...

    Thank you!

    Alec

    OK, I see what happened.

    The 2nd block is to create empty properties in the object.

    The value should be $null like this

    $report = @()foreach($vm in Get-VM){  $row = New-Object PSObject -Property @{Name = $vm.Name}  $i = 1  Get-HardDisk -VM $vm | %{    $row | Add-Member -Name "Disk #$($i) Name" -Value $_.Name -MemberType NoteProperty    $row | Add-Member -Name "Disk #$($i)" -Value $_.FileName.Split("/")[1] -MemberType NoteProperty    $row | Add-Member -Name "Disk$($i)path" -Value $_.FileName -MemberType NoteProperty    $row | Add-Member -Name "Disk$($i)Capacity(MB)" -Value ($_.CapacityGB*1024) -MemberType NoteProperty    $row | Add-Member -Name "Disk$($i)Controller" -Value ($_ | Get-ScsiController).Name -MemberType NoteProperty    $row | Add-Member -Name "Disk$($i)Datastore" -Value $_.FileName.Split(']')[0].TrimStart('[') -MemberType NoteProperty    $i++  }  while($i -le 8){    $row | Add-Member -Name "Disk #$($i) Name" -Value $null -MemberType NoteProperty    $row | Add-Member -Name "Disk #$($i)" -Value $null -MemberType NoteProperty    $row | Add-Member -Name "Disk$($i)path" -Value $null -MemberType NoteProperty    $row | Add-Member -Name "Disk$($i)Capacity(MB)" -Value $null -MemberType NoteProperty    $row | Add-Member -Name "Disk$($i)Controller" -Value $null -MemberType NoteProperty    $row | Add-Member -Name "Disk$($i)Datastore" -Value $null -MemberType NoteProperty    $i++  }  $report += $row}
    
    $report  | Export-Csv -path virtual_disks2.csv -notype
    

Maybe you are looking for