VMware Cloud Community
Pinball
Enthusiast
Enthusiast

Finding who created a vm

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

Reply
0 Kudos
1 Reply
kunaludapi
Expert
Expert

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

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
Reply
0 Kudos