Lessons on the looping and global variables in functions

I'm trying to gather a complete inventory of virtual machines and hosts in my environment.  For VMS, I am train to collect the information below but problem a loop in the case of hard drives and network cards.  For example, on hard drives, I get the following result:

VMNIC1: Network card 1
NICMAC1: 00:50:56:87:01:e6
NICNetwork1: dvPortGroup6666

NICState1: Logged, GuestControl, StartConnected
HDName1: hard drive 2
StorageFormat1: thin
HDCapacityGB1: 100
Datastore1: [RXCXN00020] host108a/host108a_1.vmdk

As you can see, only the last instance of the disc is saved in my outings.  In other words, HDNamex is never incremented but the value (here "drive 2") always represents the last disk that is, this virtual machine has two disks.  I have a few virtual methods with five disks and, in this case, there HDName 1 to a value of hard drive 5.  How properly I loop through each instance of my hard drives?

A key part of my information on Virtual Machines is the Cluster they are on.  This value, however, is only available by attribute parent of the host object.  Therefore, I created a hash table to try to do that research, but it seems that the hash table is lost outside the function Get-HostInfo.  Note the Get-VMInfo function tries to access the values in this Hashtable with the following result:

Cannot perform indexing in a null table.
D:\scripts\VMInventory.ps1:36 tank: 82
+ $VMStuff | Add-Member-type noteproperty-name HostCluster-value $HostHashTa
wheat [< < < < $VMStuff.Host]
+ CategoryInfo: InvalidOperation: (host012.domain.com:VMHostIm
[of] pl), RuntimeException
+ FullyQualifiedErrorId: NullArray

Looks like I need to be "global" and not just its function, this hash table.  Any help of any of these two issues would be greatly appreciated.  Here is my code:

Function Get-HostInfo {}
Begin {}
{In process
$HostStuff = new-object psobject
$HostHashTable = @ {}

$HostStuff | Add-Member-type noteproperty-name HostName-value $_
$HostStuff | Add-Member-type noteproperty - name PowerState-value of $_. PowerState
$HostStuff | Add-Member-type noteproperty-name CPUQty-value of $_. NumCpu
$HostStuff | Add-Member-type noteproperty-name of generation - value $_. Build
$HostStuff | Version-value add-Member-type noteproperty-name $_. Version
$HostStuff | Add-Member-type noteproperty-name manufacturer-value of $_. Manufacturer
$HostStuff | Add-Member-type noteproperty-name MemoryTotalGB-value of $_. MemoryTotalGB
$HostStuff | Add-Member-type noteproperty-model name - value of $_. Model
$HostStuff | Add-Member-type noteproperty-name NetworkInfo-value of $_.NetworkInfo
$HostStuff | Add-Member-type noteproperty-name of Cluster - value of $_. Parent
$HostStuff | Add-Member-type noteproperty-storage of value-name $_. StorageInfo

$HostHashTable [$HostStuff.HostName] = $HostStuff.Parent

write-output $HostStuff
}
{End}
}

Function Get-VMInfo {}
Begin {}
{In process
$VMStuff = new-object psobject
$VMHashTable = @ {}

$VMStuff | Add-Member-type noteproperty - name VMName-value $_
$VMStuff | Add-Member-type noteproperty-name Mnmemonic-value of $_. Folder
$VMStuff | Add-Member-type noteproperty-name of the host - value $_. Host
#Link the virtual machine to its location of cluster
$VMStuff | Add-Member-type noteproperty-name HostCluster-$HostHashTable [$VMStuff.Host value]
$VMStuff | Add-Member-type noteproperty - name PowerState-value of $_. PowerState
$VMStuff | Add-Member-type noteproperty-name ProvisionedSpaceGB-value of $_. ProvisionedSpaceGB
$VMStuff | Add-Member-type noteproperty-name UsedSpace-value of $_. UsedSpaceGB
$VMStuff | Version-value add-Member-type noteproperty-name $_. Version
#Get information about the adapter on each instance
$AdapterInfo = get-NetworkAdapter $_
{foreach ($Adapter to $AdapterInfo)
$j = 1
$VMStuff | Add-Member-type noteproperty-name VMNIC$ j-$Adapter.Name value
$VMStuff | Add-Member-type noteproperty-name NICMAC$ j-$Adapter.MACAddress value
$VMStuff | Add-Member-type noteproperty-name NICNetwork$ j-$Adapter.NetworkName value
$VMStuff | Add-Member-type noteproperty-name NICState$ j-$Adapter.ConnectionState value
$j ++
} adapter #end foreach loop
Information disk hard #Get for each instance
$HardDisks = hard disk get $_
{foreach ($HD in $Harddisks)
$i = 1
$VMStuff | Add-Member-type noteproperty-name HDName$ I have $HD value. Name - force
$VMStuff | Add-Member-type noteproperty-name StorageFormat$ I have $HD value. StorageFormat-force
$VMStuff | Add-Member-type noteproperty-name HDCapacityGB$ I have $HD value. CapacityGB-force
$VMStuff | Add-Member-type noteproperty-name data store $ I have $HD value. Filename-force
$i ++
} foreach #end HD loop
#Select the windows machines for obtaining information from WMI
If ($_ - like "w *") {}
$OSinfo = get-WmiObject-class Win32_OperatingSystem - computer $_
$VMStuff | Add-Member-type noteproperty-name OSSerialNumber-$OSinfo.SerialNumber value
$VMStuff | Add-Member-type noteproperty - name OSVersion-value $OSinfo.Version
$VMStuff | Add-Member-type noteproperty-name OSVServicePack-$OSinfo.ServicePackMajorVersion value
$VMStuff | Add-Member-type noteproperty-name OSCaption-$OSinfo.Caption value
$VMStuff | Add-Member-type noteproperty-name OSInstallDate-$OSinfo.InstallDate value
$VMStuff.OSInstallDate = ([WMI] "). ConvertToDateTime (($OSInfo). InstallDate). ToString ("yyyy-MM-DD hh: mm :") ")
$VMStuff | Add-Member-type noteproperty-name OSLastBoot-$OSinfo.LastBootupTime value
$VMStuff.OSLastBoot = ([WMI] "). ConvertToDateTime (($OSInfo). LastBootUpTime). ToString ("yyyy-MM-DD hh: mm :") ")
$ComputerInfo = get-WmiObject-class Win32_ComputerSystem - computer $_
$VMStuff | Add-Member-type noteproperty-name OSSystemType-$ComputerInfo.SystemType value
IP #Get each adapter information
$OSNICArray = @)
$OSNICrecord = get-wmiobject Win32_NetworkAdapterConfiguration - filter IPEnabled = TRUE - computer $_. Select legend, IPAddress,: IPSubnet, DefaultIPGateway, DNSDomainSUffixSearchOrder and DNSServerSearchOrder
$OSNICArray += $OSNICrecord
{foreach ($LAN to $OSNICArray)
$VMStuff | Add-Member-type noteproperty-name OSAdapterName-value $LAN. Legend
$VMStuff | Add-Member-type noteproperty-name OSIPAddress-value $LAN. IPAddress
$VMStuff | Add-Member-type noteproperty-name OSIPSubnet-value $LAN. : IPSubnet
$VMStuff | Add-Member-type noteproperty-name OSGateway-value $LAN. DefaultIPGateway
$VMStuff | Add-Member-type noteproperty-name OSDNSSearchOrder-value $LAN. DNSServerSearchOrder
$VMStuff | Add-Member-type noteproperty-name OSDNSSuffix-$LAN.dnsdomainsuffixsearchorder value
} foreach LAN #end loop
} #end if

$VMHashTable [$VMStuff.VMName] = $VMStuff.Host

write-output $VMStuff
}
{End}

}
#Specify location to search
$Location = 'My Place'
SE connect-VIServer 'VIServer1 '.

#Gather the host information
$HostatSite = get-vmhost-location $Location
$HostatSite | Get-Hostinfo
#$HostatSite | Get-Hostinfo | export-csv "d:\scripts\server-report\'$Location'-HostReport.csv".

#Gather VM information
$VMatSite = get-vm-location $Location
#$VMatSite | Get-VMInfo | export csv d:\scripts\server-report\$Location-VMReport.csv - NoTypeInformation
#$VMatSite | Get-VMInfo | ConvertTo-Html | Set-Content d:\scripts\server-report\$Location-VMReport.htm
$VMatSite | Get-VMInfo

The problem is that the Export-CSV cmdlet examines the properties of the first record it only reads and displays the properties for all the records. You can leave the script write a dummy record as the first album with all the columns that are possible. That will solve this problem.

Tags: VMware

Similar Questions

  • Get local and global variables using API

    Hi, I do in LV a Publisher for TS. The user should be able to change the value of global variables and the inhabitants of file. Using the TS API, it is possible to get all files of Globals and locals without knowing the name of these variables have ts? I mean, if I knew the name I could use the value of property Get with the search string. But if the I do not know the name of the variable, can I get the list (and their values) of the variable?

    Thank you very much.

    Try the following link

    http://forums.NI.com/NI/board/message?board.ID=330&message.ID=3390&query.ID=6624776#M3390

    In summary:

    Use the GetNumSubProperties method to get the total number of inhabitants / FileGlobals.

    Use GetNthSubProperty to get sub properties using the index starting with 0 to GetNumSubProperties-1

    Use the Name property to get the name of the subproperty.

    Concerning

    Ray Farmer

  • APEX 4.2 translate data 'function and Global Variable declaration '.

    Hello everyone,

    I use APEX 4.2.1.00.08 and I wonder if there is a way to translate "Function and Global Variable declaration" textarea. Any other script text box is available for translation, but not this one.
    I know what the code is loaded on the header, but may contain important alert messages of global functions.

    Thanks in advance.

    Hi Grandmaster,

    "Function and global variables declaration" contains the JavaScript code, that is why it is not wise to include in the standard translation process.

    In my opinion, you have several options to access your translated messages:

    -) Use Application-> Substitutions or
    -) Store your message in the form of component shared-> SMS and and assign it to an application with the APEX_LANG element. Api MESSAGE (http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35127/apex_lang.htm#CHDBCEAB)

    In 'Function and Global Variable declaration' use substitution syntax to replace the value. For example:

    var myDeleteMessage = "&G_MY_DELETE_MESSAGE.";
    ...
    alert(myDeleteMessage);
    

    where G_MY_DELETE_MESSAGE would be a part of the application or the request for Substitution.

    Concerning
    Patrick
    -----------
    Member of the APEX development team
    My Blog: http://www.inside-oracle-apex.com
    APEX Plug-Ins: http://apex.oracle.com/plugins
    Twitter: http://www.twitter.com/patrickwolf

  • DLL and global variables

    OK, here's a strange problem.  I am very new to create the dll, so I don't know that I have just an installation problem.

    But I'm trying to pass a global variable of a host program to its attached DLL.  I got this job when I was the CVI 2014. I recently upgraded to 2015 and then started getting "undefined symbols" errors.  With some struggle I managed to compile again, but broke the variable connection in the process.

    I have compiled my DLL in debug mode so that I walk in from the test project.  Right now, my global variable exists in the test project, as well as in the DLL.

    Can I export the variable and the use of DLLIMPORT/DLLEXPORT?  Confused and curiously not to find anyone quite like this on the forums.

    EDIT: this post stack overflow described pretty well from my experience.  I am linking statically.

    Well, what do you know?  I found my problem.  This draft article and example WERE vital to the solution.  This article called, "using the Export method qualifier"was also useful.  I'll cut to the Chase...

    If you use a qualifier of export on the definition and the import on the declaration, LabWindows/CVI identifier export symbol.

    This is the right key.

    So in my example, it should look like this:

    DLL fichier.c

    int DLLEXPORT varName = 0;

    Header.h DLL

    int DLLIMPORT varName;

    Project that uses DLL.c

    #include "header.h DLL.

    varName! = 1 ;  a method to change this variable for local use

    Pretty easy, huh?  But wow, it took some time to find.

  • understand the concept of global variables

    Hi guys,.

    I just have a small question...

    I discovered that my main program uses global variables 855.

    It was not built by me.

    I hope that if you guys done with this before?

    What do you think this is a good approach for me.

    Find ways to get rid of all the global variables using cluster?

    or leave it like that because his work and don't borther with her.

    or is there another solution?

    Thanks in advance

    If I were you I just whine a little and then conform to the architecture, that I inherited.

  • The values of global variables change spontaneously

    I am currently doing a quiz/board game. There is a 'Question to card' button that goes to a random image in a specified movie. All images in this film has a question with answers that make players advence on the Board of Directors. The problem is, I have to make sure that once a question appeared and has received a reply, it cannot pop up again. I thought to declare a global variable for each question ("_global.q1" in question 1 and so on) in the framework one of the movie root with a value of '0 '. The answers to each question, to move the pieces on the Board, becomes the '1' variable value (on (release) {_global.q1 = "1"}). And directly under each question of the film container question, I made an invisible film with the script below, thinking the first time governing load the variable must be set to 0, then the question will load normally. and later, since the answer is set to 1, the script below in the next section. Thus, no question is repeated.

    onClipEvent (enterFrame) {}
    If (_global.q1 = '1') {this._parent.nextFrame ()};
    }

    However, on the film tests, I push the button with the gotoAndPlay (random ()) and all my values of variables defined by one, taking me all the way to the last image in the question that contains the movie.

    > If (_global.q1 = "1")

    Must be:

    If (_global.q1 is "1")

    A = single assignment, a double == is a test for equality.

    --
    Dave-
    www.offroadfire.com
    Developer leader
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.Adobe.com/communities/experts/

  • complete the loop and get data

    I need to acquire the acquisition values of data every x seconds. Waiting in the loop of data acquisition is defined so that the next N samples are acquired after x seconds. Pressing stop the loop of consumer DAQ stops after the sec x which is connected to the wait function.

    1. how to stop the inner loop immediately when you press a stop?

    I also write acquired samples after doing some calculations on the samples.

    1. plan of sample of the queue to file consumer loop. Is there any other recommendations such as drop loop is not without samples? How many data can an expectation of the queue?

    Thank you.

    sonotk,

    You've missed the point. Rather than having a 5000 milliseconds of wait, use an expectation of 100 ms and count the number of times that you have been waiting for 100 ms.  When the count reaches 50, sample and start the count again.

    The counter is just in the shift register containing an integer. Inside the while loop you have a box structure. Test the shift count register to see if it is 50. If set to True, use the real case of the structure of the case. Inside, it's all in your loop except waiting and the logic of the judgment. In the case of false, you add 1 to the shift register and wait 100 ms.

    Looking at your picture code once again, it seems that the shift with TempData and VoltData regsiters are not necessary because you never use the data previous iteration on the left side.

    Ranjeet,

    Make a simple VI with two loops and some expectations.  Run with execution highlighting market to see what is happening.  It is a good learning tool.

    Lynn

  • While the loop and the passage of a string to a Subvi problem

    Hello world

    My problem is this: I have a MainVI and a Subvi, the MainVI is running a while loop in which the Subvi is called and goes to 2 parameters, 1 bool and 1 chain. the problem is, inside the Subvi the chain should be placed in a text box so that the user can see before pressing ok.

    Background of the present: normally "Get_DMC.vi" opens with just the text box and a button cancel, means to scan 10 characters of big entry. It still works fine. If the user selects the DMC model in the MainVI, it should only copy the dummy DMC of the MainVI (the above string) to the show, and Subvi in the text box as well as allow another button 'OK' for the opportunity to control themselves (Advanced) users.

    The Subvi is reloaded on every call because he'd be stuck in the while loop, I had not done that. Not quite sure why, if someone has an answer to that aswell please tell me.

    Many thanks in advance,

    Kind regards

    Pedro

    It might be that the writing of the DMC to "Value DMC" model that happens before the "reset DMC by default".  Try the error off DMC Reint default wiring to the value DMC error to force the order of execution

    Ken

  • Date show invites by using the calendar and presentation Variables

    Hi all

    That's what it takes...

    I need to create a two prompts (from_date and to_date) on a date column so that I can filter the data by using a condition. This is how I do

    I created two guests (edited the formula) and passing values to two variables var_from and var_to presentation. In the report, I limit the query on assistance between motor coaches for both the presentation variable. Everything works fine but the problem is I need display var_from and var_to in my report also.

    I'm referencing variables like ' @{var_from}' and ' @{var_to}' but I get two columns as white. I don't really know why I get empty values for these two columns only when I am able to filter my report with success on the basis of the date values in the guests...

    Just to metion... in my database, I have values in m/d/yyyy format only. So I am able to use the calendar successfully

    Any help on this would be much appreciated...


    Thank you
    -Ronny

    Ronny,
    Drafts of answers do you see? ID wait, but on the dashboard when you set filters, you should see values that crosses?
    You can extend the syntax of the variable closely and provide a default value, so when you work in the answers you can see what it looks like,

    something like @{var_from} {January 1, 2010 ""}

    Also you can reference variables in the title, the subtitle or the narrative views if you want.

  • By the way and form Variables collection

    Let's say it's for my form code:

    < html >
    < head >
    < script type = "text/javascript" >
    function formSubmit()
    {
    document.getElementById("myForm").submit)
    }
    < /script >
    < / head >

    < body >
    < p > enter text in the fields of text below and press the "Send" button to submit the form. < /p >

    < form id = "myForm" action = "js_form_action.asp" method = "get" > "
    First name: < input type = "text" name = "FirstName" size = "20" > < br / >
    LastName: < input type = "text" name = "lastname" size = "20" > < br / >
    < br / >
    < input type = "button" onclick = "formSubmit ()" value = "Submit" > "
    < / make >
    < / body >

    < / html >

    Now, let's say I want to take the first name and the last name of variables and their gathering in another form (i.e.) passing variables from one form to the other. How can I do this?

    I thought about it using coldfusion. on the following form I just use FORM. #fieldname #. Thank you.

  • How can I fix the speakers on my Asus laptop? I played with the settings and accidentally deleted some functions.

    original title: speakers on windows 7

    How to fix speakers on my Asus laptop. I played with the settings and accidentally deleted some features and I can't restore it to its original.

    Can you help me with this problem?

    Thank you in advance.

    The best

    YinNooy

    Use system restore to go back to an earlier date at the beginning of the problem.  To run system restore, click Start-> programs-> Accessories-> System Tools-> system restore.  Click on the box that says show more restore points.

    I hope this helps.  Good luck.

  • insert into the table using the loop and permanently display

    Hello

    I am trying to insert some values of loop loop run into two tables and trying to draw using Graph XY. I need values Joanie be inserted one by one in each iteration. But at the end of the iteration in the table, I get only last value... can someone help me?

    Hello Manu,

    use a shift register to store each table. BuildArray allows to add/Add (not Insert!) of new values in the table.

    Then you need not use an ExpressVI to create the chart, a knot simple bundle (as indicated in the context-sensitive help) is enough to create a field in a XY Chart...

    Example with a table:

    Keep in mind:

    It's not (memory/CPU time) effective to use for time of data acquisition time (giving rise to large Bay). Use different approaches then...

  • Cursor implicit FOR THE LOOP and WHERE CURRENT OF

    Is it possible to add some updates and WHERE CURRENT OF for an implicit cusror of LOOPS?  There seems to be no way to reference the cursor as you can with an explicit cursor.

    BEGIN

    FOR point IN)

    SELECT last_name, job_id

    Employees

    WHERE job_id LIKE '% % CLERK '.

    AND manager_id > 120

    ORDER BY name

    )

    LOOP

    ...

    ...

    ...

    END LOOP;

    END;

    /

    Thank you

    It must be an explicit cursor.

  • for the loop and array

                     

    Can someone explain to me how becomes the array1 (1 X 2) added added table 2 (4 X 2); I didn't understand how indexing works here.

    Thank you

    Hi Vincent,.

    in the exit tunnel every 1 d table 1 × 2 will go to a 2D table ROW. As see you: the last values in table 1 are the last line of the table 2D...

    This is how works the autoindexing: scalars form a 1 d vectors table 1 d become lines of a 2D array, 2D table becomes a 3D table pages and so on... And vice versa for a tunnel of entry!

  • Tables: using the loop and delivery

    I'm not very good with tables. Here is my broken code:

    //Create array with 4 movieclips
    var invArray:Array = new Array("i_greenLine", "i_orangeDot", "i_yellowBlock", "i_brownThing");
    //repeat this code for every item (+1)
    for (i=0; i<invArray.length; i++) {
         trace(invArray[i]);
         //Outputs:
         //i_greenLine
         //i_orangeDot
         //i_yellowBlock
         //i_brownThing
         invArray[i].onPress = function() {
              trace("hit");
         };//the movieclips are not clickable.
    }
    

    Is there a way to get the clips on the stage to be clickable via a table? There are many, many clips.

    Help?

    Thank you?

    If you use strings of the instance for the table names, then you will need to use the support rating to target instances with them...

    var invArray:Array = new Array("i_greenLine", "i_orangeDot", "i_yellowBlock", "i_brownThing");
    for (i=0; i}
    
    

    An alternative would be to use only the instance names and no channels to them...

    var invArray:Array = new Array(i_greenLine, i_orangeDot, i_yellowBlock, i_brownThing);
    for (i=0; i}
    
    

    If you plan to have a large number of them, so a better approach would be to name them all with digital ending (mc0, mc1, mc2, mc3, etc..)  You can then use the notation of support without the need for table...

    for (i=0; i}
    
    

Maybe you are looking for

  • Pavilion HPE h8 - 1360t: the graphics card upgrades

    My current system has used an AMD Radeon HD graphics card 7570.  I am interested in upgrading this map and looking for a recommendation for a mid range to high level card that corresponds to this case / motherboard. My system uses UEFI and I already

  • accident LV2013?

  • modification of Favorites

    How can I change my favorites?

  • VDI with ISE access control

    Hi guys,. Can ISE access control for VDI users with thinclients like PC? Now, we want to implement authentication 802. 1 x for the VDI users, but I don't know if this can be done by ISE. We just need to configure access switch ports to open 802. 1 x

  • Hide advanced action does not work after that triggered the effect

    I have a pretty simple step action that does the following:Hide bannerApply motion effect to 3 SmartShape from right to leftCache: SmartShape3SmartShape 3 is essentially half a rectangle rounded, which acts as a banner with text. At the beginning of