Automation

 View Only
  • 1.  Finding who created a vm

    Posted Apr 01, 2014 09:49 AM

    Hi there

    I'm using the below to find the creator for a single vm but running into a syntax issue. Can you please assist me in resolving the issue.

    Get-VM -Name DCPLMS01 | Get-VIEvent -Types Info |`

    Where {`

         $_.GetType().Name -eq "VmBeingDeployedEvent"`

    -or $_.GetType().Name -eq "VmCreatedEvent"`

    -or $_.GetType().Name -eq "VmRegisteredEvent"} |`

    Select UserName, CreatedTime, FullFormattedMessage | FT -AutoSize



    Error:

    PowerCLI C:\Users\Johan45\Documents\PS> .\GetVm.ps1

    At C:\Users\Johan45\Documents\PS\GetVm.ps1:3 char:27

    +      $_.GetType().Name -eq "VmBeingDeployedEvent"`

    +                           ~

    You must provide a value expression following the '-eq' operator.

    At C:\Users\Johan45\Documents\PS\GetVm.ps1:3 char:28

    +      $_.GetType().Name -eq "VmBeingDeployedEvent"`

    +                            ~

    Unexpected token '&' in expression or statement.

    At C:\Users\Johan45\Documents\PS\GetVm.ps1:3 char:54

    +      $_.GetType().Name -eq "VmBeingDeployedEvent"`

    +                                                      ~

    The ampersand (&) character is not allowed. The & operator is reserved for

    future use; wrap an ampersand in double quotation marks ("&") to pass it as

    part of a string.

    At C:\Users\Johan45\Documents\PS\GetVm.ps1:4 char:28

    +  -or $_.GetType().Name -eq "VmCreatedEvent"`

    +                            ~

    The ampersand (&) character is not allowed. The & operator is reserved for

    future use; wrap an ampersand in double quotation marks ("&") to pass it as

    part of a string.

    At C:\Users\Johan45\Documents\PS\GetVm.ps1:4 char:48

    +  -or $_.GetType().Name -eq "VmCreatedEvent"`

    +                                                ~

    The ampersand (&) character is not allowed. The & operator is reserved for

    future use; wrap an ampersand in double quotation marks ("&") to pass it as

    part of a string.

    At C:\Users\Johan45\Documents\PS\GetVm.ps1:5 char:28

    +  -or $_.GetType().Name -eq "VmRegisteredEvent"} |`

    +                            ~

    The ampersand (&) character is not allowed. The & operator is reserved for

    future use; wrap an ampersand in double quotation marks ("&") to pass it as

    part of a string.

    At C:\Users\Johan45\Documents\PS\GetVm.ps1:5 char:51

    +  -or $_.GetType().Name -eq "VmRegisteredEvent"} |`

    +                                                   ~

    The ampersand (&) character is not allowed. The & operator is reserved for

    future use; wrap an ampersand in double quotation marks ("&") to pass it as

    part of a string.

        + CategoryInfo          : ParserError: (:) [], ParseException

        + FullyQualifiedErrorId : ExpectedValueExpression

    Thanks

    Johan



  • 2.  RE: Finding who created a vm

    Posted Apr 01, 2014 10:35 AM

    Use something like below.

    Get-VM -Name DCPLMS01 | Get-VIEvent -Types Info |

              Where {$_.GetType().Name -eq "VmBeingDeployedEvent" -or`

                       $_.GetType().Name -eq "VmCreatedEvent" -or`

                       $_.GetType().Name -eq "VmRegisteredEvent"} |

                                   Select UserName, CreatedTime, FullFormattedMessage | FT -AutoSize