VMware Cloud Community
Mackman
Contributor
Contributor

Having issues with simple script to delete VM

Here is what I have:

Connect-VIServer 10.10.100.105 -User root -Password notnot

Remove-VM CLONE-FRIDAY-TRD1* -DeletePermanently -Confirm:$false

But it won't run in a script.  What am I missing?

0 Kudos
7 Replies
LucD
Leadership
Leadership

Let me see if I get the question.

You stored that script in a .ps1 file, let's say removeVM.ps1,

and when you call the script, it doesn't do anything ?

Is you executionpolicy set correctly ? Do

Get-ExecutionPolicy

What does it say ?


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

0 Kudos
Mackman
Contributor
Contributor

It says "RemoteSigned"

The error:

PS C:\Tasks> .\DeleteCLONE.ps1

At C:\Tasks\DeleteCLONE.ps1:4 char:8

+ $Remove-VM CLONE-FRIDAY-LSAS* -DeletePermanently -Confirm:$false

+        ~~~

Unexpected token '-VM' in expression or statement.

At C:\Tasks\DeleteCLONE.ps1:4 char:12

+ $Remove-VM CLONE-FRIDAY-TRD1* -DeletePermanently -Confirm:$false

+            ~~~~~~~~~~~~~~~~~~

Unexpected token 'CLONE-FRIDAY-TRD1*' in expression or statement.

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

    + FullyQualifiedErrorId : UnexpectedToken

0 Kudos
LucD
Leadership
Leadership

What is this dollar sign ($) doing before Remove-VM ?


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

0 Kudos
Mackman
Contributor
Contributor

Without the $ sign I get this:

Remove-VM : 5/28/2014 1:00:38 PM    Remove-VM        Value cannot be found for the mandatory parameter VM

At C:\Tasks\DeleteCLONE.ps1:4 char:1

+ Remove-VM CLONE-FRIDAY-LSAS* -DeletePermanently -Confirm:$false

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Remove-VM], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.RemoveVM

0 Kudos
DZ1
Hot Shot
Hot Shot



I would just use get-vm and then pipe it to remove-vm


-DeletePermanently

0 Kudos
DZ1
Hot Shot
Hot Shot



Hmm..my post was cut off  Get-VM "CLONE-FRIDAY-LSAS*" | remove-VM -DeletePermanently -Confirm:False

0 Kudos
LucD
Leadership
Leadership

Change that line to

Remove-VM -VM CLONE-FRIDAY-TRD1* -DeletePermanently -Confirm:$false


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

0 Kudos