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?
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
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
What is this dollar sign ($) doing before Remove-VM ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
I would just use get-vm and then pipe it to remove-vm
-DeletePermanently
Hmm..my post was cut off Get-VM "CLONE-FRIDAY-LSAS*" | remove-VM -DeletePermanently -Confirm:False
Change that line to
Remove-VM -VM CLONE-FRIDAY-TRD1* -DeletePermanently -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference