Several Variables import from CSV file

Hello PowerCLI Masters!

I've been dabbling in PowerCLI now for about 6 months, especially for larger deployments VM.  I've been tweaking my scripts to automate more over time.  I started with setting all the variables manually and just import the virtual machine to a txt file names, then created several loops in a single script that would incorporate different text files, depending on model, data store, disc sizes VLAN, etc..

I think that the next step here is to import variables by vm (essentially, a line of a CSV file).  We receive our demands for construction as a spreadsheet, so it would be relatively easy to fill in the correct fields in a spreadsheet and run a script that will import values.  I can't seem to put on the right track with the simple search, so I thought I'd post it here and see if:

1. someone already did and can provide guidance

2. can someone put me on the right track to how I would go all this

3. someone tell me that it is not possible (in the hope that it does not go down like that, but it is certainly possible)

This IS JUST a SAMPLE of the SCRIPTS - may or may not have a syntax perfect at this stage...

# SET VARIABLES #.

$vmname = get-content C:\PowerShell\serverlist_1.txt
$vmname | {foreach-object
$vmname = $_

$templatename = "TMPLT-GSI.
$folder = "GSI".
$date = get-Date - uformat "%Y %m %d '.
$expdate = "20110930".
$reqno = "00034.
$sysowner = "GSI".

$esxhost = "esxhost1.test.com".
$datastore = "DATASTORE_1".

$cpu = 1
$mem = 4096
$datadrive1 = 26214400

$datadrive2 = 52428800
$pgname = "ECOM_902".

#

# BUILD/CONFIGURE VM #.

#

New-VM - vmhost $esxhost - name $vmname - model $templatename - Datastore $datastore - thick DiskStorageFormat - location $folder

New-disk-hard - vm $vmname - CapacityKB $datadrive1
New-disk-hard - vm $vmname - CapacityKB $datadrive2
Get-VM-name $vmname | $mem set-VM - MemoryMB - NumCPU $cpu - confirm: $false
Get-networkadapter $vmname | together-networkadapter - networkname $pgname - confirm: $false
Get-VM-name $vmname | Game-CustomField-name "creation Date" - value $date - confirm: $false
Get-VM-name $vmname | Game-CustomField-name 'expiry Date' - value $expdate - confirm: $false
Get-VM-name $vmname | Game-CustomField-name "Application number" - value $reqno - confirm: $false
Get-VM-name $vmname | Game-CustomField-name "Proprietary system" - value $sysowner - confirm: $false

}

So, rather than setting these values in the script, I want to shoot them from a spreadsheet that looks like this (a partial list at condition of course):

$vmname$templatename$cpu$mem$pgname$datadrive1$datadrive2
Testdeploy001TMPLT RHEL614'ECOM_902 '.2621440052428800
Testdeploy002TMPLT-2008_ENT_6428'ECOM_902 '.26214400104857600
Testdeploy003TMPLT-2008_ENT_6428'ECOM_906 '.26214400104857600


Thanks in advance for any help provided!

-Brent

vmname TemplateName central processing unit MEM pgname datadrive1 datadrive2 folder
Testdeploy001 TMPLT RHEL6 1 4 'ECOM_902 '. 26214400 52428800 GSI
Testdeploy002 TMPLT-2008_ENT_64 2 8 'ECOM_902 '. 26214400 104857600 GSI
Testdeploy003 TMPLT-2008_ENT_64 2 8 'ECOM_906 '. 26214400 104857600 GSI

I would do something like this:

$date= Get-Date -uformat "%Y%m%d"
$expdate="20110930"
$reqno="00034"
$sysowner="GSI"
$esxhost="esxhost1.test.com"
$datastore="DATASTORE_1"

Import-CSV C:\PowerShell\serverlist.csv | Foreach {
 New-VM -vmhost $esxhost -Name $_.vmname -Template $_.templatename -Datastore $datastore -DiskStorageFormat thick -Location $_folder
 New-Harddisk -vm $_.vmname -CapacityKB $_.datadrive1
 New-Harddisk -vm $_.vmname -CapacityKB $_.datadrive2
 Set-VM -VM $_.vmname -MemoryMB $_.mem -NumCPU $_.cpu -Confirm:$false
 get-networkadapter $_.vmname | set-networkadapter -networkname $_.pgname -Confirm:$false
 Get-VM -Name $_.vmname | Set-CustomField -Name "Creation Date" -Value $date -Confirm:$false
 Get-VM -Name $_.vmname | Set-CustomField -Name "Expiration Date" -Value $expdate -Confirm:$false
 Get-VM -Name $_.vmname | Set-CustomField -Name "Request Number" -Value $reqno -Confirm:$false
 Get-VM -Name $_.vmname | Set-CustomField -Name "System Owner" -Value $sysowner -Confirm:$false
}

Tags: VMware

Similar Questions

  • Import from CSV file into oracle using pl/sql - sql loader 3.1

    Hello

    I am trying to learn how to import a CSV file in an oracle table. I tried the import utility in SQL Loader, but it generates specific lines of code to import each line. I would like a loop to go through the CSV file stored on my local disk and transferred it to my table.

    I tried the following, but not luck
    DOWNLOAD THE DATA
    INFILE 'sample_csv.csv '.
    IN THE TEST TABLE
    FIELDS TERMINATED BY ', '.
    ;

    951716 wrote:
    Hello

    I am trying to learn how to import a CSV file in an oracle table. I tried the import utility in SQL Loader, but it generates specific lines of code to import each line. I would like a loop to go through the CSV file stored on my local disk and transferred it to my table.

    line-by-line is slow by slow.
    PL/SQL will be NEVER faster than simple SQL
    INSERT INTO MYTABLE SELECT * FROM EXTERNAL_TBL;

    http://www.orafaq.com/wiki/External_table

  • Anyone has any experience of importing a csv file and store it in a database in MS SQL

    Anyone has any experience of importing a csv file and store it in a database MS SQL. Outside sql injection there is any another converns security?

    Draft of the steps.

    1. use to download the file from the client to the server see
    http://www.dennismiller.TV/index.cfm/2007/12/26/file-upload-using-ColdFusion-and-Flex

    2. use to read the contents of the file into a variable.

    3. perform a loop on the content of variables for each line, dealing with the variable as a list delimited by a newline rather then a comma

    4. use list functions on each line to get the data you need, and then to transmit these data to SQL with CFQUERY or CFPROCPARAM.

  • import a csv file into AddressBook

    I'm migrating from outlook to Thunderbird. Import all the emails and addresses does not work. So I exported by e-mail addresses from my server to a csv file. I imported the csv file into Thunderbird. I have to OK the addresses import. Is it possible to import in one click

    If you export all your contacts in a single csv file, you should be able to import the file in a single step, although you may need to edit the csv file before you do:

    https://support.Mozilla.org/en-us/questions/1012084

  • How can I synchronize contacts from csv file to samsung omnia

    do not have outlook on my computer and do not spend $100 to get it.  I want to add my 137 contact to my samsung omnia.  How?  mobile device does not allow to import a csv file, nor does my total access.  I got my info in a file and also in hotmail.  How can I get it in the phone without having to type everything in?

    http://www.Samsung.com/au/consumer/detail/support.do?group=Mobilephone&type=Mobilephone&subtype=megapixelphone&model_cd=SGH-I900XKBXSA&mode=C

    Download the manual on the link above.

    Samsung may be able to help with their product.

    See you soon. Mick Murphy - Microsoft partner

  • Import data from CSV file

    Dear friends,

    I have already created the directory DIR1.

    I get the following warning message

    1 CREATE OR REPLACE PROCEDURE P2
    2 is
    3 BEGIN
    4. create table (ext_table_csv1)
    5 I have the number,
    Varchar2 (20) n 6,.
    7 m Varchar2 (20)
    4%
    9 organization external)
    type oracle_loader 10
    By default 11 Dir1 directory
    (settings) 12 access
    13 records delimited by newline
    14 fields completed by «,»
    15 field missing values are null
    16)
    17 location ("file.csv")
    18)
    19 reject limit unlimited;
    20 * END P2;
    QL > /.

    CAUTION: Procedure created with compilation errors.

    QL > show err
    rreurs for PROCEDURE P2:

    ERROR OF INE / COL
    ------- -----------------------------------------------------------------
    / 1 PLS-00103: encountered the symbol "CREATE" when expecting one of
    What follows:
    begin case declare exit for goto if loop mod null pragma
    raise return select update while < ID >
    < between double quote delimited identifiers of > < a variable binding > < <
    Close current delete fetch locking insert open rollback
    SAVEPOINT SQLExecute set pipe fusion commit forall

    Please help me.

    NGK246 wrote:
    If at all, I want to recover data from another file CSV (say 'test20101214.txt') to the external table defined so I just need to
    change the location of the CSV pointing to the table, as shown below...
    run immediately "change the location of the table ext_test (" test ' |) " to_char(sysdate-1,'YYYYMMDD') |'. txt ")';
    And then use INSERT... SELECT to inject data into my actual table residing on my database.

    Please correct me if I'm wrong.

    Yes, that's about all.

  • import contacts from gmail from csv file

    I can't get the file import function in address book to work.

    I have my gmail and Outlook 2003 account csv files but after spending hours trying to map the fields later, I settled for a very limited subset of the coordinates: each contact display when I select 'Next', but when I click 'OK', it always adds a secondary address book, with 0 contacts.

    I waded through a lot of forum posts and tried to export a Vcard to Outlook 2003 file (it does not option); I removed most of the columns of the csv files and moved them around to avoid the horrible way as the 'Move Up' and 'Down' other shift keys, already reset fields - apparently at random; and even if I limit the importation of any name and primary e-mail address of the import program always produces an address book under zero contact.

    Is there a programme of work itself, to allow the migration of contacts from Thunderbird outdoors?

    https://support.Mozilla.org/en-us/questions/1148390

  • How to import data from CSV file in a table using oracle forms

    Hello

    I have a CSV file and I want to insert in the oracle database in a table by using a button under forms of oracle.
    the user can select the CSV file by using the open dialog box.
    can someone help me find the method to import and select the client machine file?

    THX.

    You want to import the contents of the file or the file itself? I assume that you want to import the contents of the file. For this, there are really only two options to make an Excel (.csv) file and import into shapes; WebUtil or a JavaBean. Some examples of both:
    WebUtil: How to read an Excel file in a form of Oracle
    Oracle is CJP/BEAN - project Excel

    Try them both and see which works best for you.

    Craig...

  • How to import data from CSV files to IOM?

    Hello
    We have to import some files in the csv format and are set up in a specific folder hierarchy. Please help as I am not able to go further.

    Thank you very much!

    So you mean, you want to create users in the IOM based on the data contained in these files...
    Then, you should probably create GTC file connector to consume your CSV file and create users in the IOM.

    Thank you
    Suren

  • How to import a csv file in a histogram

    Hi, I'm looking for a way to be able to import data from a csv file in LabVIEW 8.6 have it create a histogram chart. I've seen this done before, so I know it's possible, I just need to some resources are started vi get me in the right direction. I have thousands of entries, and it gets teadious importation vi macros QI. Does anyone know of a vi, or the Toolbox that will give me the building blocks to do so. Appreciate any help, thanks, AJ

    Bob, the op clearly LabVIEW 8.6.

    AlphaDog,

    You have a shortened exaple of the data file you?  There are several channels or just one?

    No matter, if you look in mathematics-> palette of probability & statistics, you will find a Histogram.vi that will take a table of data and do a histogram out of it.  To display it, use a chart and change the type of route to be a bar chart.

  • Address book import of csv file gets empty address book

    I have a .csv file from a Windows 'Contacts' window. It contains four hundred entries, each composed of a name and E-mail address. The first line of the file says .csv "name, Email '; the entries are separated by returns and the areas that fall within the comma.

    When I import to intoThunderbird, I say to import an address book from the file and to import only the Email address and display name fields. When the import is executed, it is very fast and no errors are displayed. The new address book is displayed among the Thunderbird address books, but it is empty.

    Thank you
    Joe Nelan

    To import an address book, try the following steps:

    Of the Treasury Board, click "Address book" (or 3-bar menu-> tools-> address book).

    In the list in the left pane address books, click the one you want to import (or use the "personal address book").

    On the menu bar, select Tools-> import. Opens a new window "import."

    Click on "Address books" and "Next"

    Select "Text file", click "Next".

    Near the lower-right corner replace LDIF 'separated by commas.

    Navigate to the folder where your CSV file. Left click on it once. Click on 'open '.

    For CSV, there is no standard for the number or the order of the fields. The screen you see allows you to 'match' your entry with the fields of TB.
    With respect to mapping of the fields, you have two columns: one of your CSV names and one of the CT. What you're trying to get first name, last name first name family name, etc.. If you are lucky, they will be already matched to the top. But if not, you can click on one and move it upwards or downwards in the list until it is opposite the name of the corresponding field. This will get names, email, phone, etc. in the right places. Make sure the fields are checked and the ones you don't want is unchecked.
    Once you have everything set, click OK.

    Note 1: the file name of your CSV file becomes the name of the address book (for example AddrBook.csv will produce an address book named "AddrBook").
    Note 2: when you first watch the imported address book, it can be empty. Click on another (for example, "personal address book"), and then return to that matter.

  • Import a csv file to workspace root folder using Batch script

    Hello

    I usually use LCM to export/import from one instance to another in my planning and HSS and Reporting objects.

    Here, I have a specific requirement where I want to import couple of CSV file from a path on the server specified in the root directory of the workspace that is accessible to users similar to other FR and IR reports.

    I was looking for a utility to import or batch scripts I use to import the file to specific path from the server to the folder root of the workspace. \

    any help?

    -KP

    Checkbox Oracle - Hyperion Labs...: upload files in bulk of permissions in the workspace he wrote for the pdf files, but you can change it

    Concerning

    Celvin

  • How to call and receive from csv file

    I have a file employee.csv which contains details empid empname,
    I want to fetch corresponding empid offering empname entry comes from the file employee.csv and write empid in DB

    I had created a file of reading for employee.csv but for the receive activity that a variable is created
    How to give input (empname) to the file and get the empid from this file.

    Please help me in this edition

    Hello

    You will need to filter the native XML content using the processing activity. In this use of the xslt file

    
    

    See for more information - http://www.w3schools.com/xsl/xsl_for_each.asp

    Kind regards
    Neeraj Sehgal

  • cannot paste copied from CSV files online entered into the Excel worksheet (chatted with Cedric_L on 03/05/10 at approximately 2.30 CST but I got disconnected. not got an answer...)

    Here is the transcript of a chat with Firefox community member zzxcon may 3/10

    Now you are chatting with Firefox community member Cedric_L
    Cedric_L: Hello
    Cedric_L: what happens when you try to download a .csv file?
    Seegal: Hello
    Seegal: it is not copy
    Cedric_L: how you try to copy?
    Seegal: pls bear with me, I'm a slow typist. Just copy the selected text
    Biolizard joined the conversation.
    Cedric_L: ok - you choose what text?
    Seegal: I reconcile my checkbook (worksheet in this way). I copy my bank acc online items and paste it in the worksheet
    Seegal: I use Firefox 2.0.0.19. Have no problem to do so.
    Cedric_L: what version of Mac OS X?
    Seegal: in the new version nothing happens when trying to paste - just doesn't add up
    Cedric_L: Firefox 2.0.0.x is no longer supported and has not been supported by more than a year
    Cedric_L: paste into Excel from Firefox?
    Seegal: Sorry, I'm early... 2.0.0.19
    Seegal: Yes. I opened my bank acc in Firefox
    Cedric_L: what version of Excel?
    Cedric_L: it would really help if you could tell me step by step what you do.
    Seegal: first re: your previous question: is OS 10.4.11
    Seegal: on Excell: it' ACE 2004 version - the lasat one product for Macs. The specific version is 11.3.7
    Seegal: so I opened my ACC. to bank online in Firfox (my main browser). I copy the last entry in the account and paste in my Excel spreadsheet.
    Cedric_L: so, you copy directly from the web page without having to download a CSV file?
    Seegal: what do you mean by CSV file download? I could export to the https://chat-support.mozilla.com:9091/webchat/getimage? image = sendmessage & workgroup=support%40workgroup.chat-support.mozilla.comFirefox to the CSV file, but the other way around?
    Cedric_L: you copy your bank statement directly from the web site to Excel by using the Clipboard?
    Seegal: so do not use the Clipboard. It is a mac. There is no need to do so. In the PC, it would be Yes.
    Cedric_L: I need to know the exact steps that you deliver to bring in excel
    Cedric_L: and I need to know what exactly goes wrong in the latest version of Firefox.
    Seegal: you have a mac it with Firefox and Excel? It is very easy to reproduce. Imagine you open access to online banking, select a few entries, click on 'copy', to make your already open Excel worksheet and click "Paste". That's all!
    Cedric_L: when this happens, do you have cryptic code pasted into Excel?
    Seegal: as I said before: in all newer versions starting with 3.0 when I go to Excel to 'stick' of my bank acc, nothing happens. It does not stick. No, I don't get a cryptic code pasted, just NOTHING.

    Cedric_L: what happens if you paste into MS Word instead?
    Seegal: haven't tried, most likely the formatting would be lost. Tried with an another el Exc spreadsheet-it lost all the formatting and pasted as continuous text.

    This has happened

    Each time Firefox opened

    Is copy of the cat above. THIS MAC OS X. In the older versions before 3.0 I could copy the CSV file on the site Web Ibank VAC) and paste it directly to my spreadheet Excel reconciling my account.

    There is a known issue with Mac Office versions prior to 2007 version that results in release of Clipboard does not correctly supported. Firefox 3.0, being a more recent application, using the new format for the HTML Clipboard data. Unfortunately, Office 2004 and Office X do not support this.

    If you upgrade to MS Office 2007, it should work as expected.

  • DIAdem - import programmatically .csv files with. STP file without dialog box

    Does anyone know how to import programmatically with a .csv files. STP file without opening the import box dialog box every time?

    I've been through the forum and seen for .xls files and solutions through the help file which is recommended to use the ExcelImport command, but these do not seem to work for .csv file types.  I am currently using the DataFileLoad command to import the files, which works very well to load the .csv files, but it forces me to go to the. STP file for each file.

    Does anyone know a better way to import a file .csv programmatically?

    Wow... Who had a fraction of the time that does the method of the dialog box.  I'll have to revise the data portion my DiAdem Advanced manual Plugin.

    Thank you, Brad!

    Steve

Maybe you are looking for