PowerCLI

 View Only
Expand all | Collapse all

(Audit virtual Machine)

  • 1.  (Audit virtual Machine)

    Posted Oct 27, 2012 06:36 AM

    Dear Friends,
    I need help too, i am not a scripting man, but i need your help.
    I have a task to get all the summary details of each virtual machine in either vApps or in a resource pool.
    1.Guest OS:
    2. VM Version:
    3.CPU
    4.Memory
    5.Memory Overhead
    6. VMware Tools:
    7.IP Addresses:
    8.DNS Name
    9.Host



  • 2.  RE: (Audit virtual Machine)

    Posted Oct 27, 2012 08:54 AM

    Try something like this

    $rpName = "MyRespoolName"

    Get-ResourcePool -Name $rpName | Get-VM |
    Select
    Name,
    @{N="Guest OS";E={$_.Guest.OSFullName}},
    @{N="HW Version";E={$_.Version}},
    @{N="CPU";E={$_.NumCPU}},
    @{N="Memory";E={$_.MemoryMB}},
    @{N="Memory Overhead";E={"???"}},
    @{N="VMware Tools";E={$_.ToolsVersionSTatus}},
    @{N="IP ADdresses";E={[string]::Join(',',($_.Guest.IPAdress))}},
    @{N="DNS Name";E={$_.Guest.Hostname}},
    @{N="Host";E={$_.HostName}}

    You can do the same for a vApp.

    Not sure what you want to see under "Memory Overhead". Is that a statistical value over a specific preriod of time ?



  • 3.  RE: (Audit virtual Machine)

    Posted Oct 27, 2012 06:57 PM

    Thank you for your knowlegde share:

    so here is my script:

    $rpName = "ApplicationServerPool" Get-ResourcePool -Name $rpName | Get-VM | Select Name, @{N="Guest OS";E={$_.Guest.OSFullName}},@{N="HW Version";E={$_.Version}},@{N="CPU";E={$_.NumCPU}},@{N="Memory";E={$_.MemoryMB}},@{N="Memory Overhead";E={"???"}},@{N="VMware Tools";E={$_.ToolsVersionSTatus}},@{N="IP ADdresses";E={[string]::Join(',',($_.Guest.IPAdress)}},@{N="DNS Name";E={$_.Guest.Hostname}},@{N="Host";E={$_.HostName}}

    .................................................................................................................................................................................................................................

    Error result :

    Unexpected token 'Get-ResourcePool' in expression or statement.
    At line:1 char:51
    + $rpName = "ApplicationServerPool" Get-ResourcePool <<<<  -Name $rpName | Get-
    VM | Select Name, @{N="Guest OS";E={$_.Guest.OSFullName}},@{N="HW Version";E={$
    _.Version}},@{N="CPU";E={$_.NumCPU}},@{N="Memory";E={$_.MemoryMB}},@{N="Memory
    Overhead";E={"???"}},@{N="VMware Tools";E={$_.ToolsVersionSTatus}},@{N="IP ADdr
    esses";E={[string]::Join(',',($_.Guest.IPAdress)}},@{N="DNS Name";E={$_.Guest.H
    ostname}},@{N="Host";E={$_.HostName}}
        + CategoryInfo          : ParserError: (Get-ResourcePool:String) [], Paren
       tContainsErrorRecordException
        + FullyQualifiedErrorId : UnexpectedToken



  • 4.  RE: (Audit virtual Machine)

    Posted Oct 28, 2012 07:13 AM

    It looks as if something went wrong with your copy/paste of the code.

    Some older browsers, mostly IE, seem to have problems with the forum SW.

    I attached the script as a file, try that.



  • 5.  RE: (Audit virtual Machine)

    Posted Oct 29, 2012 05:23 AM

    Thank you some much for your help.

    Still can get it to work. please can give it a go in your lab and kindly provide a set of instruction please.

    I really appricate this kind help of yours.



  • 6.  RE: (Audit virtual Machine)

    Posted Oct 29, 2012 05:29 AM

    look up rvtools.

    its a nice program that will also get you the info you want.

    if you are having script problems thats a quick way to get the info you need.

    then you can trobleshoot why you cant run the commands later



  • 7.  RE: (Audit virtual Machine)

    Posted Oct 29, 2012 06:00 AM

    RVtools is indeed a great tool.

    Just wondering how you use it to troubleshoot your scripts ?



  • 8.  RE: (Audit virtual Machine)

    Posted Oct 29, 2012 06:14 AM

    ah I dont use it to troubleshoot my scripts themselves but use it more as a base to refine what Im looking for

    then work off the data

    i like to work off excel. so I export the data to csv fles

    help visually see/sort then end result of basic stuff like vm disk usage, etc.

    then you can use the csv files to add commands in to the cells.



  • 9.  RE: (Audit virtual Machine)

    Posted Oct 29, 2012 06:18 AM

    I am still trying, still not working. i will download the RVtool now, 



  • 10.  RE: (Audit virtual Machine)

    Posted Oct 29, 2012 06:33 AM

    Are you still getting the same error message ?



  • 11.  RE: (Audit virtual Machine)

    Posted Oct 29, 2012 06:44 AM

    so far i have got to this stage after connect the powercli to the host.

    then paste your script but error again so far i have got here.

    get-resourcepool -name domaincontrollers | get-vm | select name,

    With below result:

    Name                 PowerState Num CPUs MemoryGB
    ----                 ---------- -------- --------
    xyz        PoweredOn  1        2.000
    abc        PoweredOn  1        6.000

    now got challenge with:

    @{N="Guest OS";E={$_.Guest.OSFullName}},
    @{N="HW Version";E={$_.Version}},
    @{N="CPU";E={$_.NumCPU}},
    @{N="Memory";E={$_.MemoryMB}},
    @{N="Memory Overhead";E={"???"}},
    @{N="VMware Tools";E={$_.ToolsVersionSTatus}},
    @{N="IP ADdresses";E={[string]::Join(',',($_.Guest.IPAdress))}},
    @{N="DNS Name";E={$_.Guest.Hostname}},
    @{N="Host";E={$_.HostName}}



  • 12.  RE: (Audit virtual Machine)
    Best Answer

    Posted Oct 29, 2012 06:48 AM

    Can you try the following:

    • save the file I attached as .ps1 file, say audit.ps1
    • update the file so the resourcepool name is the one you want to audit
    • start the PowerCLI prompt
    • connect to the vCenter
    • go to the folder where you stored the .ps1 file (use the cd command)
    • run the script by typing ./audit.ps1 at the PowerCLI prompt


  • 13.  RE: (Audit virtual Machine)

    Posted Oct 29, 2012 07:02 AM

    so i did as you have instructed, but i didnt connect to vcenter but to the host, will that make a difference.

    event with .\aduit-vm.ps-1 or ./aduit-vm.ps1 it just goes to the cursor. or would it have saved it somewhere?

    PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\scripts>
    audit-vm.ps1
    The term 'audit-vm.ps1' is not recognized as the name of a cmdlet, function, sc
    ript file, or operable program. Check the spelling of the name, or if a path wa
    s included, verify that the path is correct and try again.
    At line:1 char:13
    + audit-vm.ps1 <<<<
        + CategoryInfo          : ObjectNotFound: (audit-vm.ps1:String) [], Comman
       dNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException


    Suggestion [3,General]: The command audit-vm.ps1 was not found, but does exist i
    n the current location. Windows PowerShell doesn't load commands from the curren
    t location by default. If you trust this command, instead type ".\audit-vm.ps1".
    See "get-help about_Command_Precedence" for more details.
    PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\scripts>
    ".\audit-vm.ps1"
    .\audit-vm.ps1
    PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\scripts>



  • 14.  RE: (Audit virtual Machine)

    Posted Oct 29, 2012 07:15 AM

    That has successfully worked when i connected to the vcenter.

    But so far missing some information like IPaddress, memory overhead, virtual tool.

    If i have a parent resource pool and how will i tell the script to pull from the child please?

    Inaddition to the above how will i pull the result to a single file?

    Thanks for you great help



  • 15.  RE: (Audit virtual Machine)

    Posted Oct 29, 2012 07:21 AM

    The Get-ResourcePool cmdlet is by default recursive.

    So if you pass the name of the parent resourcepool, it will return all resourcepools from the parent node and downwards in the tree.

    And consequently the Get-VM cmdlet will return the VMs from all these resourcepools.



  • 16.  RE: (Audit virtual Machine)

    Posted Oct 29, 2012 07:30 AM

    But so far missing some information like IPaddress, memory overhead, virtual tool.

    Inaddition to the above how will i pull the result to a single file?



  • 17.  RE: (Audit virtual Machine)

    Posted Oct 29, 2012 07:41 AM

    A lot of the info is only available when you have the VMware tools running inside the VMs.

    Concerning the memory overhead, it's not clear to me what you want to see here (see my first reply).

    To get the reszults to a file, you can "pipe" the objects to another cmdlet like for example the Export-Csv cmdlet.

    $rpName = "resourcepoolname" 
    
    Get-ResourcePool
    -Name $rpName | Get-VM | Select Name,
    @
    {N="Guest OS";E={$_.Guest.OSFullName}},
    @
    {N="HW Version";E={$_.Version}},
    @
    {N="CPU";E={$_.NumCPU}},
    @{N="Memory";E={$_.MemoryMB}},
    @
    {N="Memory Overhead";E={"???"}},
    @
    {N="VMware Tools";E={$_.ToolsVersionSTatus}},
    @
    {N="IP ADdresses";E={[string]::Join(',',($_.Guest.IPAdress))}},
    @{N="DNS Name";E={$_.Guest.Hostname}},
    @
    {N="Host";E={$_.HostName}} |
    Export-Csv
    "C:\report.csv" -NoTypeInformation -UseCulture


  • 18.  RE: (Audit virtual Machine)

    Posted Jan 02, 2014 07:15 PM

    Any way to add parent ESX host and port group information?



  • 19.  RE: (Audit virtual Machine)

    Posted Jan 03, 2014 01:32 PM


  • 20.  RE: (Audit virtual Machine)

    Posted Oct 29, 2012 05:58 AM

    You're right, there was a parenthesis missing.

    I updated the code above, and I attached the corrected script.

    Sorry about that