PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Invoke-V
MScript -VM mayank -ScriptText "dir" -GuestUser administrator -GuestPassword M@c
r5sofT
Invoke-VMScript : 2/17/2017 11:04:46 PM Invoke-VMScript Could not fin
d VirtualMachine with name 'mayank'.
At line:1 char:16
+ Invoke-VMScript <<<< -VM mayank -ScriptText "dir" -GuestUser administrator -
GuestPassword M@cr5sofT
+ CategoryInfo : ObjectNotFound: (mayank:String) [Invoke-VMScript
], VimException
+ FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_ObjectNo
tFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript
Invoke-VMScript : 2/17/2017 11:04:46 PM Invoke-VMScript Value cannot
be found for the mandatory parameter VM
At line:1 char:16
+ Invoke-VMScript <<<< -VM mayank -ScriptText "dir" -GuestUser administrator -
GuestPassword M@cr5sofT
+ CategoryInfo : NotSpecified: (:) [Invoke-VMScript], VimExceptio
n
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomatio
n.ViCore.Cmdlets.Commands.InvokeVmScript
You can specify the folder for which you want the dir.
Like this for example
$text = Invoke-VMScript -VM MyVM -ScriptText 'dir c:\' -ScriptType Bat |
select -ExpandProperty ScriptOutput
$text -split "`r`n" | where{$_ -match "<DIR>"}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It looks like the VM is not found.
Does the following return anything?
Get-VM -Name mayank
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
thanks VM name was wrong... now its working.
Invoke-VMScript -VM ashok-2012 -ScriptText "dir" -GuestUser administrator -GuestPassword M@cr5sofT
output is not correct.
I want to see folders on c drive then what will be the command ?
Please help
Regards,
Ashok
What is wrong with the output?
Could you show in a screenshot?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
its showing only .exe's and .dll files not showing any folders on c drive
| -a--- 8/22/2013 6:55 PM 33064 winnsi.dll
| -a--- 8/22/2013 4:33 PM 110080 WinOpcIrmProtector.dll
| -a--- 3/22/2014 12:19 AM 1487520 winresume.efi
| -a--- 3/22/2014 12:19 AM 1356360 winresume.exe
| -a--- 6/18/2013 8:39 PM 35 winrm.cmd
| -a--- 6/18/2013 8:39 PM 204105 winrm.vbs
| -a--- 8/22/2013 5:04 PM 30208 winrnr.dll
| -a--- 8/22/2013 3:04 PM 47616 winrs.exe
| -a--- 8/22/2013 3:03 PM 105984 winrscmd.dll
| -a--- 8/22/2013 3:16 PM 26624 winrshost.exe
| -a--- 8/22/2013 5:15 PM 1536 winrsmgr.dll
| -a--- 8/22/2013 3:33 PM 13824 winrssrv.dll
| -a--- 3/22/2014 12:19 AM 240128 WinSCard.dll
| -a--- 3/22/2014 12:19 AM 316416 winsku.dll
| -a--- 8/22/2013 4:23 PM 85504 winsockhc.dll
| -a--- 3/22/2014 12:19 AM 488960 winspool.drv
| -a--- 8/22/2013 5:02 PM 25088 WINSRPC.DLL
The output is there, but the history of your command window probably overflowed.
Try like this
$text = Invoke-VMScript -VM MyVM -ScriptText 'dir' -ScriptType Bat |
select -ExpandProperty ScriptOutput
$text -split "`r`n" | where{$_ -match "<DIR>"}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
HI LucD
thank you very much for guidance... but I am receiving below error. please assist me as I am new for scripts.
PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> $text =
Invoke-VMScript -VM ashok-2012 -ScriptText 'dir' -GuestUser administrator -Guest
Password M@cr5sofT -ScriptType Bat |select -ExpandProperty ScriptOutput $text -s
plit "`r`n" | where{$_ -match "<DIR>"}
Select-Object : A parameter cannot be found that matches parameter name 'split'
.
At line:1 char:173
+ $text = Invoke-VMScript -VM ashok-2012 -ScriptText 'dir' -GuestUser administr
ator -GuestPassword M@cr5sofT -ScriptType Bat |select -ExpandProperty ScriptOut
put $text -split <<<< "`r`n" | where{$_ -match "<DIR>"}
+ CategoryInfo : InvalidArgument: (:) [Select-Object], ParameterB
indingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comm
ands.SelectObjectCommand
The line with the -split operator is a separate line, it looks like you all have it on one line.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
its working from this .. but I need to see windows c drive directory status... as I have a folder Ashok Sharma in my windows machine c drive. but I am unable to see this folder
$text = Invoke-VMScript -VM ashok-2012 -ScriptText 'dir' -GuestUser administrator -GuestPassword M@cr5sofT -ScriptType Bat
select -ExpandProperty ScriptOutput
$text -split "`r`n" | where{$_ -match "<DIR>"}
I want to use windows command like dir . which is used to see all the folders.
kindly assist.
You can specify the folder for which you want the dir.
Like this for example
$text = Invoke-VMScript -VM MyVM -ScriptText 'dir c:\' -ScriptType Bat |
select -ExpandProperty ScriptOutput
$text -split "`r`n" | where{$_ -match "<DIR>"}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
how can I run the same for Linux
Try like this
$text = Invoke-VMScript -VM MyVM -ScriptText 'ls -l /' -ScriptType Bash -GuestUser <linux-user> -GuestPassword <linux-password> |
select -ExpandProperty ScriptOutput
$text -split "`n" | where{$_ -match "^d"}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference