Assign tags to a csv file

I am able to get the custom attributes for the vSphere Windows client and create tags to them.  What I want to do now is create and assign tags with a csv file, or at least affect the file tags, even if I have to create them separately.  I looked at this post Using tags vSphere PowerCLI | VMware PowerCLI Blog - VMware Blogs, but I'm not exactly what I wanted.  I think I can be overwhelming things.  Here's what I tested.

I have a CSV with two values "VM" and "Info".  The VM column is of course the name of the virtual machine, the column of information is the name of the tag, so I have a variable called $csv

I can try $csv.vm Get - VM and 3 VMS I in the variable coming up.  I also have tags with Get - Tag $csv.info, and the 3 tags arrive.  What I want to do, is to use the file for the virtual machines and then assign the tag for virtual machines with the same variable $csv.

I tried a lot of different things, here are a few:

($csv.vm) | foreach - pv vm-process {(Get-VM-Name $_.)} (ToString())} |

for each process {$vm New-TagAssignment-entity - Tag ($csv.info |)}

foreach {$_.} (ToString()}) -WhatIf}

$csv.info | t pv foreach {Get-Tag-name $t} | foreach {New-TagAssignment-Tag $t - entity (Get-VM-name $csv.vm [0,1])-WhatIf}

Get - vm $csv.vm | foreach {New-TagAssignment-entity $_ - Tag ($csv.info | foreach {Get-Tag-Name $_})}

I had a few attempts, but I fell the ISE and for some reason, it didn't start with the unsaved tabs (PowerGUI), he usually does, because I crushed before and she always came back with the script tabs.  Well.

I will continue to go to him, but I hope that someone can help you.  I think I'm very close.

I think that I have... I will run again, but data from all matches.

$csv | {foreach}

$vm = $_.vm

$tag = $_.info

Tag new - category Info-name $tag

New-TagAssignment-Tag $tag - entity $vm

}

Thanks for all the help over the years.

Tags: VMware

Similar Questions

  • Import CSV file and the conversion of an array

    Hi all

    I'm working on a site that is to import a CSV (comma separated values) published via actionscript 3.0 URLloader().  Now I just try to get actionscript to successfully enter the data imported from the CSV file as a table, then the CSV file has 1 single cell that contains "athleticMaroon, charcoal, colonialBlue, kellyGreen, fullColor".

    Here is the code I use:

    create table

    var shirtLiveIntense_btn_Colors:Array = new Array();

    run the import from CSV data

    URLLoaderCSV();

    shirtLiveIntense_btn.addEventListener (MouseEvent.CLICK, selectingLogo);

    function selectingLogo(e:MouseEvent):void {}

    trace ("current logo');

    var colorButtons:Array = this [e.currentTarget.name + "_Colors"];

    for (var i: uint = 0; i < colorButtons.length; i ++) {}

    .Ivar colorButtons [i] = i;

    colorButtons [i] .addEventListener (MouseEvent.CLICK, shirtColorOption);

    }

    }

    CSV data import function

    function URLLoaderCSV() {}

    var loader: URLLoader = new URLLoader();

    configureListeners (loader);

    var request: URLRequest = new URLRequest ("https://docs.google.com/spreadsheet/pub?hl=en_US & hl = en_US & key = 0AlJnOKOffTSxdFk0RVlEUTVHeF9 DMHZfZ0JzSkJjZFE & single = true & gid = 1 & output = csv");

    try {}

    Loader.Load (request);

    } catch (error: Error) {}

    trace ("unable to load requested document.");

    }

    }

    function configureListeners(dispatcher:IEventDispatcher):void {}

    dispatcher.addEventListener (Event.COMPLETE, completeHandler);

    dispatcher.addEventListener (Event.OPEN, openHandler);

    dispatcher.addEventListener (ProgressEvent.PROGRESS, progressHandler);

    dispatcher.addEventListener (SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

    dispatcher.addEventListener (HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);

    dispatcher.addEventListener (IOErrorEvent.IO_ERROR, ioErrorHandler);

    }

    function completeHandler(event:Event):void {}

    var loader: URLLoader = URLLoader (event.target);

    trace ("completeHandler:" + loader.data);

    shirtLiveIntense_btn_Colors.push (loader.data);

    }

    function openHandler(event:Event):void {}

    trace ("openHandler:" + event);

    }

    function progressHandler(event:ProgressEvent):void {}

    trace ("progressHandler loaded:" + event.bytesLoaded + "total:" + event.bytesTotal);

    }

    function securityErrorHandler(event:SecurityErrorEvent):void {}

    trace ("securityErrorHandler:" + event);

    }

    function httpStatusHandler(event:HTTPStatusEvent):void {}

    trace ("httpStatusHandler:" + event);

    }

    function ioErrorHandler(event:IOErrorEvent):void {}

    trace ("ioErrorHandler:" + event);

    }

    Here is the result:

    openHandler: [event type = "open" bubbles = false cancelable = false eventPhase = 2]

    progressHandler loaded: 57 total: 0

    httpStatusHandler: [HTTPStatusEvent type = "httpStatus" bubbles = false cancelable = false eventPhase = 2 status = 200]

    completeHandler: athleticMaroon, colonialBlue, kellyGreen, charcoal, fullColor

    chosen logo

    ReferenceError: Error #1056: cannot create ivar String property.

    at main_fla::MainTimeline/selectingLogo()

    Review of results of release, I see it's clearly to load the data from the CSV file correctly, but what I think it does is important data as a single string, aka 'athleticMaroon, charcoal, colonialBlue, kellyGreen, fullColor' and push for shirtLiveIntense_btn_Colors:Array = new Array().  But, as I see the error selectingLogo(e:MouseEvent) service cannot treat the table because it contains a string of.

    If I switch to shirtLiveIntense_btn_Colors.push (loader.data); with shirtLiveIntense_btn_Colors.push (charcoal, colonialBlue, kellyGreen, athleticMaroon, fullColor); everything works like a charm, but I need the table to assign dynamic in the CSV file data

    Can anyone help to get imported CSV data to strings pushed a table accessible?

    Thank you!


    It is an error caused by:

    var colorButtons:Array = this [e.currentTarget.name + "_Colors"];

    for (var i: uint = 0; i

    .Ivar colorButtons [i] = i;

    colorButtons [i] .addEventListener (MouseEvent.CLICK, shirtColorOption);

    }

    your table is an array of strings.  If you try to force these strings into objects on the timeline that contains your code, use array notation:

    var colorButtons:Array = this [e.currentTarget.name + "_Colors"];

    for (var i: uint = 0; i

    This .ivar [colorButtons [i]] = i;

    This [colorButtons [i]] .addEventListener (MouseEvent.CLICK, shirtColorOption);

    }

  • Tags and Notes in a single CSV file export

    I'm trying to export tags and notes in to a CSV simple change of batch and importation in vCenter.  I have a script to export tags and I can export notes, but I want to make in a single operation and to a simple CSV file.  Here's the current code, I use and please forgive me for not crediting the original creator, I built this script I don't remember!  I have a Notes column in the CSV file resulting, but he is empty...  Thanks in advance.

    Don

    Current script:

    If (-not of $DefaultVIServer.IsConnected) {}

    SE connect-VIServer "vcenter.server" - Credential (Get-Credential $_.) User name)

    }

    $tagCat = @)

    $tagTab = @ {}

    foreach ($tag in (Get-TagAssignment)) {}

    $tagCat += $tag. Tag.Category.Name

    $key = $tag. @entity.name

    {if ($tagTab.ContainsKey ($Key))}

    "$val = $tagTab.Item ($key)"

    }

    else {}

    $val = @ {}

    }

    $val. Add ($tag. Tag.Category.Name, $tag. Tag.Name)

    $tagTab [$key] = $val

    }

    $tagCat = $tagCat | Sort-Object-Unique

    $tags = foreach ($row in ($tagTab.GetEnumerator () |)) Sort - Object - property key)) {}

    $VMName = $row. Key

    $VMNotes = get - VM $VMName | Select-Object - ExpandProperty Notes

    $obj = new-Object-property PSObject @ {}

    Name = $row. Key

    }

    $tagCat | %{

    $obj | Add-Member-Name $_-value $row. Value [$_]-MemberType NoteProperty

    }

    $VMNotes | %{

    $obj | Add-Member-name 'Notes' - value $row. $VMNotes - MemberType NoteProperty

    }

    $obj

    }

    $tags | Export Csv tags.csv - NoTypeInformation - UseCulture

    Try like this

    If (-not of $DefaultVIServer.IsConnected) {}

    SE connect-VIServer "vcenter.server" - Credential (Get-Credential $_.) User name)

    }

    $tagCat = @)

    $tagTab = @ {}

    foreach ($tag in (Get-TagAssignment)) {}

    $tagCat += $tag. Tag.Category.Name

    $key = $tag. @entity.name

    {if ($tagTab.ContainsKey ($Key))}

    $val = $tagTab.Item ($key)

    }

    else {}

    $val = @ {}

    }

    $val. Add ($tag. Tag.Category.Name, $tag. Tag.Name)

    $tagTab [$key] = $val

    }

    $tagCat = $tagCat | Sort-Object-Unique

    $tags = foreach ($row in ($tagTab.GetEnumerator () |)) Sort - Object - property key)) {}

    $VMName = $row. Key

    $VMNotes = get - VM $VMName | Select-Object - ExpandProperty Notes

    $obj = new-Object-property PSObject @ {}

    Name = $row. Key

    }

    $tagCat | %{

    $obj | Add-Member-Name $_-value $row. Value [$_]-MemberType NoteProperty

    }

    $obj | Add-Member-name 'Notes' - $VMNotes - MemberType NoteProperty value

    $obj

    }

    $tags | Export Csv tags.csv - NoTypeInformation - UseCulture

  • ADF: How to manage the value zero when downloading the csv file

    Dear all,

    I'm new in the ADF and use 12.2.1. I am downloading of data in the database using af table: inputfile and CSVParser class. Data download correctly in the database where all columns are met, but whenever the csv file has value null (empty) in his column, then CSVParser class does not recognize it and get the next value of columns and assign the previous column. I also tried another one that uses a different class to download date but not get success.

    For Ex:

    ID name Dept

    1 abc Dept1

    2 cde Dept2

    3 Dept3

    In example above two first line are perfectly inserted in the table while the third line Id goes to ID column, due to the value of the column name is null class CSVParser does not recognize it and put Dept3 in the name column.

    Please help how to handle this.

    Thanks in advance.

    Kind regards

    Hello

    Try with this

    UploadedFile file = (UploadedFile)valueChangeEvent.getNewValue();
    InputStream is = null;
    BufferedReader br = null;
    try {
        is = file.getInputStream();
        br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        String line = "";
        while ((line = br.readLine()) != null) {
             String[] csvCols = line.split(",");
             // do somethinig smart with csvCols
        }
    }finally{
        if (br != null) try{br.close();}catch(Exception ex){br = null;}
        if (is != null) try {is.close();} catch(Exception exxx){is = null;}
    }
    
  • Helps to replace a string in a txt file with a string from a csv file

    Hi all

    I worked on the script following since a few days now, determined to exhaust my own knowledge before asking for help... Unfortunately, it didn't take very long to exhaust my knowledge :-(

    Basically, I need to replace a value in a single file (raw.txt) with the value of another file (userids.csv) when a variable is. Then I released the results of a third file.

    To do this, I divided the "raw" file into variables using the ',' as the separator, the problem is that some variables are intentionally empty, where the fi $variable = "statements.

    It is currently what I want to do but only when the userids.csv file contains a single line. It is obviously because of the foreach ($user in import)... What I need to figure out is how to loop through the file raw.txt, text replacement when a variable in the user ID file is the text in raw.txt... I hope that makes sense?

    The user ID file is in the following format - user, service, Dept that can contain dozens of lines

    I would appreciate any pointers :-)

    See you soon

    # Treatment
    $importraw = get-content i:\raw.txt
    $import = import-csv i:\userids.csv-en-tete UserAccount, functional, Dept

    {foreach ($user in $import)
    $useraccount = $user. UserAccount
    $userfunction = $user. Functional
    $userdept = $user. Dept
    {foreach ($line in $importraw)
    $first, $second, $third, $fourth, $fifth, $sixth, $seventh, $eighth, $ninth = $line - split(",")
    $linesproc = $linesproc + 1
    If ($sixth - eq ") {}
    $temp6 = "6TEMP".
    Write-Host "field Null detected - assigning temporary value:"$temp6 ".
    $sixth = $temp6 # the assignment of a temporary value so that - statement to replace later works
    }
    If ($seventh - eq ") {}
    $temp7 = "7TEMP".
    Write-Host "field Null detected - assigning temporary value:"$temp7 ".
    $seventh = $temp7 # the assignment of a temporary value so that - statement to replace later works
    }
    If ($fifth - eq $user.) UserAccount) {}
    $line - $seventh, replace $user. Dept | Add content i:\Output.txt
    }
    else {}
    $line - $seventh, replace "/ / customer. Add content i:\Output.txt
    }
    }

    }

    Try the attached version.

    The problem, in my opinion, was in nested ForEach loops.

    Instead I've implemented with a lookup table

  • Script export to a .csv file

    Hi guys,.

    I have this script to get some info for my ESX hosts, it works fine but I need to get the report to a .csv file, will be possible to do?


    foreach ($esxImpl in (Get-VMHost)) {}
    $esx = $esxImpl | Get-View
    $netSys = get-view $esx.ConfigManager.NetworkSystem
    {foreach ($pnic to $esx.Config.Network.Pnic)}
    $vSw = $esxImpl | Get-VirtualSwitch | where {$_.} {NIC-contains $pNic.Device}
    $pg = $esxImpl | Get-VirtualPortGroup | where {$_.} {VirtualSwitchName - eq $vSw.Name}
    $order = ($esx.Config.Network.Vswitch |) where {$_.} ({Name - eq $vSw.Name}). Spec.Policy.NicTeaming.NicOrder
    $cdpInfo = $netSys.QueryNetworkHint($pnic.) Device)
    $pnic | Select @{N = "ESXname"; {E = {$esxImpl.Name}}.
    @{N = "Teddy"; E = {$pnic. Device}},
    @{N = ' model'; E = {($esx.)} Hardware.PciDevice | where {$_.} ID - eq $pnic. PCI}). DeviceName}},
    @{N = "vSwitch"; {E = {$vSw.Name}}.
    @{N = "Exchange"; E = {$pg | % {$_. Name}}},
    @{N = 'Speed'; E = {$pnic. LinkSpeed.SpeedMb}},
    @{N = 'Status'; E = {if($pnic.) (LinkSpeed-ne $null) {'up'} else {'down'}}},
    @{N = "PCI slot"; E = {$pnic. PCI}},
    @{N = ' Active/stand-by/no assigned'; E = {if($order.) ActiveNic-contains $pnic. Device) {'active'} elseif($order.) StandByNic-contains $pnic. {{Device) {"standby"} else {"unused"}}},
    @{N = "IP range"; E = {[string]: join ("/", @($cdpInfo [0].))} Subnet | {{((% {$_.: IpSubnet + "(" + $type + "") ""}))}}.
    @{N = 'Physical switch'; E = {& {if($cdpInfo[0].connectedSwitchPort) {. connectedSwitchPort.devId $cdpInfo [0]} else {"CDP not configured"}}},
    @{N = "PortID"; E = {& {if($cdpInfo[0].connectedSwitchPort) {. connectedSwitchPort.portId $cdpInfo [0]} else {"CDP not configured"}}}
    }
    }

    Thanks in advance.

    Oops, I had a name of my test environment.

    Should be ok now.

  • Configure vswitches from a .csv file - problem

    I have a script that works very well for the installation of my virtual past by using the updatevirtualswitch method. (Thanks to LucD, see here: ) http://communities.VMware.com/message/1556669#1556669 )

    I now want to go further and to feed my script with variables from a .csv file.

    It works fine for all, with the exception of the definition of vmnic. Description of the problem:

    Excerpt from my .csv file:

    lannics; dmznic1; dmznic2; dmznic3; storagenics; vmotionnics;

    @("vmnic0"); @("vmnic1", "vmnic2");

    Then import the settings from the csv file, example:

    $lannics = $parameterfile.dmznic1

    Now, if I check what's in $dmznic1, I have the good: @("vmnic1", "vmnic2")

    But it seems to be a string, not a true table. Therefore, I can not pass it to my updatevirtualswitch function:

    function standardvswitch {}

    Param ($esx, $vs, [string []] $dmznic1)

    ....

    $ns. UpdateVirtualSwitch ($vs, $vsSpec)

    }

    So the question is: how could I get my .csv file information, so that it can be used for a definition of vmnic compatible with the UpdateVirtualSwitch method?

    Thanks for your help or ideas!

    I've done a few tests more and saw that my previous solution does not work. "But one that follows). I'll try to explain how it works. In the .csv file, a semicolon is used as a field separator. This means that you can use a comma in a field to separate the members of the group. The Import-CSV cmdlet reads the .csv file and - separator "," parameter instructs the cmdlet that a semicolon is the field delimiter. The output of the Import-CSV cmdlet is piped in a ForEach-Object cmdlet. In the scriptblock ForEach-Object according to the value of the dmznic1 property string is shared by the comma, so each string before, between and after the comma will become a member of separate table. This table is assigned to the dmznic1 property. Loop loop through all the members of the Group and displays them on separate lines. So you can see that it is really a picture.

    Import-CSV -Path LanNics.CSV -Delimiter ";" | `
    ForEach-Object {
      $_.dmznic1 = ($_.dmznic1).split(",")
      for ($i=0;$i -lt $_.dmznic1.length; $i++) {
        Write-Output $_.dmznic1[$i]
      }
    }
    

    See the attached screenshot for output.

    I think that this solution is more beautiful that create a different column for each vmnic because in my solution you don't have to know in advance how many cards you have.

    Post edited by: RvdNieuwendijk

  • Use OdiOutFile to create the csv file

    Hello
    I am trying to write a csv file by using the file ODIOutFile.The is created with success, but all EI tags column coming in one line.
    I need to write different columns given different columns in csv. Kindly guide me which character I include as up to meet my requirement.

    Thank you
    Ritika

    Ritika, as mentioned in the email, this error occurs because you did not mention something in the command on the source, in the jython code, we allocate the technology and the schema required so that we must manually provide all the required parameters and ODI can pick up from the root.

    Also once you mentioned are, of course, call you this code after you odisqlunload else you don't have the header, since odisqlunload erases the file and write. Hope that this help please let me know if you have still problems with the program and also showed me a sample of the program odisqunload and header as well as the results, only a few responses back.

    Thank you
    Dev

  • Error FLOW_EXCEL_OUTPUT_R in the downloaded csv file

    Hello
    I'm trying to use the features of the FLOW_EXCEL_OUTPUT_R as follows:

    href = "f? "p = & APP_ID.:14: & SESSION.: FLOW_EXCEL_OUTPUT_R & P_REGION_ID._en.

    When the calculation for P_REGION_ID is:
    Region_id SELECT FROM apex_application_page_regions
    WHERE application_id =: app_id
    AND page_id =: app_page_id
    AND region_name = 'CSV export.

    In the CSV file downloaded, I get the following:
    -the first line: + <. div id = "report_33994800669487811_catch" > +.
    -the last 2 rows: + <. pre > error report: +.
    ORA-06502: PL/SQL: digital or value error: character of number conversion error < | /pre >
    (|| -sign is if I show the tags in the post)
    The rest of the data is downloaded ok.
    But still how can I get rid of these errors?
    Thank you
    Adela

    Hello

    The area has active partial page refresh?

    If so remove it and this can help.

    See you soon

    Ben

    Published by: Munky on December 9, 2009 10:08

  • CSV file will not work in Excel after update of the Sierra

    Excel is not able to properly open CSV files more. I have two MacMinis to work with the same version of Excel/Office, but one with macOS Sierra displays all the data in the first column.

    Must be a problem that macOS as Sierra mess up to the deliminter. Very annoying.

    Barebones Textwrangler can force CSVs to use a standard delimiter that Office can understand.  Try to open your CSV with that and save it as MS-DOS text file.

  • Export the library of books as a .csv file?

    I'm trying to compare my Calibre library with my library of books in iTunes 11.4. Caliber exports data .csv file, but I don't see how the same (or even a file of Excel data or numbers) to the ca. 950 books in my library of books to iTunes. I managed to 'print' a PDF (28 pages) of it, however.

    Is it possible to get a data file of the compatible spreadsheet of my books on iTunes?

    I never did anything with iBooks, but with iTunes you can actually highlight a series of lines, copy, and paste.

  • Numbers does not correctly Import CSV files

    Using numbers v 3.6.2 under OS X El Capitan v 10.11.6 CSV files are not imported correctly. A file with 8 columns appears in number with the first two columns containing data of 7 columns and the second containing the remaining column data. This does not happen with numbers v 2.1 I have on another Mac OS x 10.6.8

    Well, I know one answer would be to always download on the Mac of the latter, but I'm trying to stop using it, once all the data I need is available on the other, later, Mac.

    If Apple could provide a program that does work properly, why on Earth can't a version later do the same thing, it is a fundamental requirement and I don't want to play anywhere to try to sort out just that it works as it should.

    might be useful to provide an example of the file, or, perhaps to share data... Nobody here can change the numbers, we are all of the users like you.  The only options that we are thus solutions using what is already there, or work around issues by other means.

    You can still provide feedback to post using the menu item "numbers > provide Feedback numbers.

  • Extension of merger and mailing 4.1.0 says «no recipients specified...» "has {{Email}} in the line using a CSV file

    Attempt to send email from MASS of Thunderbird. I have the address of a CSV file in a column named Email. I {{Email}} in the TO: field of the email - and go through file-Mail Merge and have the CSV file in the dialog box. When I click on OK - I get the message 'no recipients were determined... ". »

    Wile, we do not support the add-on here.
    As a convenience.
    Most of the problems of this nature with the add-on will focus on how the email header is defined in the CSV file. Make sure it is defined as the domain name, you think it is and that it is surrounded by double quotes. Also make sure that none of your "data" contains quotes like send the CSV into a spin, introducing this amount on a Cape randomly in the middle of data.

    Failure to comply with this e-mail from the author of the add-on. His email address is on the page of download add-on.

  • I need to export the address book in unicode csv files. When?

    My address book contains Chinese and Korean names. Their special characters get lost when I export the address book to a CSV files to import them from Open Office.

    It is true that Chinese and Korean characters are not maintained when you use the export into csv format, but I tried an example with the option provided by MoreFunctionsForAddressBook and it seems to work fine.

    Select an address book in the address book, then make a right click, MFFAB/Export/as csv (.csv).

  • Download must be a csv file, but download a text document

    http://www.arttimesjournal.com/data/events-August-2015.csv
    is the address that needs access to a csv file. Instead, I get a word document

    Opening of the site Web with Firefox looks like a text document. However, if you right click on [Save Page as...], events-August - 2015.csv (all files (*. *) and open it with a program such as Excel, it will appear correctly)

Maybe you are looking for