Automation

 View Only
  • 1.  problems formatting output

    Posted Mar 31, 2008 07:59 AM

    Hi,

    for my daily report I want to execute the following script

    $server = Get-VIServer -Server

    echo "VMs with CDROMs connected:"

    echo "============================"

    Get-VM | where { $_ | get-cddrive | where { $_.ConnectionState.Connected -eq "true" } } | select Name,powerState

    echo ""

    echo "VMs with existing snapshots:"

    echo "============================"

    Get-VM | Get-Snapshot | select { $_.vm.name },{ $_.vm.powerState },name,created

    echo ""

    echo "VMs with existing snapshots older than 3 Months:"

    echo "============================"

    Get-VM | Get-Snapshot | where {$_.created -lt ((get-Date).addMonths(-3))} | select { $_.vm.name },{ $_.vm.powerState },name,created

    When I execute each block separately it works fine but running it in conjunction the last two blocks (existing snaps and snaps older than three months) will output only the name of the snap.

    Any idea where this may result from?



  • 2.  RE: problems formatting output
    Best Answer

    Posted Mar 31, 2008 08:09 AM

    See this thread for the explanantion: http://communities.vmware.com/thread/135569?tstart=0

    And this should work:

    $server = Get-VIServer -Server <server></server>

    echo "VMs with CDROMs connected:"

    echo "============================"

    Get-VM | where { $_ | get-cddrive | where { $_.ConnectionState.Connected -eq "true" } } | select Name,powerState | Out-Default

    echo ""

    echo "VMs with existing snapshots:"

    echo "============================"

    Get-VM | Get-Snapshot | select { $_.vm.name },{ $_.vm.powerState },name,created | Out-Default

    echo ""

    echo "VMs with existing snapshots older than 3 Months:"

    echo "============================"

    Get-VM | Get-Snapshot | where {$_.created -lt ((get-Date).addMonths(-3))} | select { $_.vm.name },{ $_.vm.powerState },name,created | Out-Default



  • 3.  RE: problems formatting output

    Posted Mar 31, 2008 08:12 AM

    works perfectly.

    thnx!