VMware Cloud Community
chakoe
Enthusiast
Enthusiast
Jump to solution

How to use/start this script?

Hi,

maybe a stupid question:

I´ve got the following script from Hal Rottenberg. It´s named Detailed-VMReport.ps1 . I don´t know how to start it 🙂

Begin {
    # Collection of propertynames for custom objects
    $PropertyCol = @(
        "Name", "IP Adress", "OS", "Host", "CPU (Count)", "Memory(MB)","Hard Drive(Count)", "HD Capacity (Total KB)", "Floppy Drive (Count)", "CD Drive(Count)","NIC (Count)", "NIC1 MAC Adress", "NIC1 Net Name"
        )
}
Process {
    if ( $_ -isnot [VMWare.VimAutomation.Client20.VirtualMachineImpl] ) {continue}
    $Process = "" | Select-Object -Property  $PropertyCol
    $Process.Name = $_.Name
    $Process."IP Adress" = $_.Guest.IPAddress[0]
    $Process.OS = $_.Guest.OSFullname
    $Process.Host = $_.Host.Name
    $Process."CPU (Count)" = $_.NumCpu
    $Process."memory (MB)" = $_.MemoryMB
    $Process."Hard Drive (Count)" = $_.HardDisks.Length
    $process."HD Capacity (Total KB)" = '($_.HardDisks | Measure-Object -Sum CapacityKB ).Sum'
    $process."Floppy Drive (Count)" = $_.FloppyDrives.Length
    $process."CD Drive (Count)" = $_.CDDrives.Length
    $process."NIC (Count)" = $_.NetworkAdapters.Length
    $process."NIC1 MAC Address" = $_.NetworkAdapters[0].MacAdress
    $process."NIC1 Net Name" = $_.NetworkAdapters[0].NetworkName
    Write-Output $process
    }

Any idea?

Thx

Chakoe

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I get the same error when I mistype the name of the script file.

Can you try typing part of the name and then hitting <Tab>.

Command completion should provide you with full name, if the file is found in the folder where you are located.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

Might I suggest you read through the Beginners Guide to Managing VMware using PowerShell document.

It shows all the steps to begin using PowerCLI.

When you have the script stored in a .ps1 file, you can open the PowerCLI prompt.

Connect to the vCenter or an ESX(i) server with Connect-VIServer.

Run the script from the PowerCLI prompt by entering: .\<scriptname>.ps1


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
chakoe
Enthusiast
Enthusiast
Jump to solution

Hey,

all needed software is installed 🙂

My problem ist, that i cannot define a Name for the VM i want the details from 🙂

How do i tell the script which VM to read?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The script accepts pipeline input, so you can do

Get-VM MyVM | .\HalScript.ps1

Note that the script will produce several errors in the format you listed.

The colum headers are missing some blanks and there is a typo.

This version should work

begin {
    # Collection of propertynames for custom objects
    $PropertyCol = @(         "Name", "IP Adress", "OS", "Host", "CPU (Count)", "Memory (MB)","Hard Drive (Count)", "HD Capacity (Total KB)", "Floppy Drive (Count)", "CD Drive (Count)","NIC (Count)", "NIC1 MAC Address", "NIC1 Net Name"
        ) }
process {     if ( $_ -isnot [VMWare.VimAutomation.Client20.VirtualMachineImpl] ) {continue}     $Process = "" | Select-Object -Property  $PropertyCol
   
$Process.Name = $_.Name     $Process."IP Adress" = $_.Guest.IPAddress[0]     $Process.OS = $_.Guest.OSFullname     $Process.Host = $_.Host.Name     $Process."CPU (Count)" = $_.NumCpu     $Process."memory (MB)" = $_.MemoryMB     $Process."Hard Drive (Count)" = $_.HardDisks.Length     $process."HD Capacity (Total KB)" = '($_.HardDisks | Measure-Object -Sum CapacityKB ).Sum'    $process."Floppy Drive (Count)" = $_.FloppyDrives.Length     $process."CD Drive (Count)" = $_.CDDrives.Length     $process."NIC (Count)" = $_.NetworkAdapters.Length     $process."NIC1 MAC Address" = $_.NetworkAdapters[0].MacAdress     $process."NIC1 Net Name" = $_.NetworkAdapters[0].NetworkName     Write-Output $process
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
chakoe
Enthusiast
Enthusiast
Jump to solution

Hi Luc,

i tried this:

Get-VM vmname | .\Detailed-VMReportV2.ps1

Error:

The term '.\Detailed-VMReportV2.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You probably have to position yourself in the folder where you saved the script.

For example

cd C:\Scripts

Or you can pass the complete path

Get-VM MyVM | C:\Scripts\HalScript.ps1


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
chakoe
Enthusiast
Enthusiast
Jump to solution

Hi,

the folder was correct....same error 😞

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I get the same error when I mistype the name of the script file.

Can you try typing part of the name and then hitting <Tab>.

Command completion should provide you with full name, if the file is found in the folder where you are located.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
chakoe
Enthusiast
Enthusiast
Jump to solution

works now....don´t know why 🙂

thanks a lot!

Reply
0 Kudos