I am trying to create a script which allows me to output the results of the cmdlet "get-vm | get-snapshot | format-list" to a file
I am using a piece of software which allows us to remotely execute scripts either via the Command Prompt or PowerShell
How could I create a single line command which would run the command Connect-VIServer vCenterServerName & then the get-vm | get-snapshot | format-list??
I am adding variables via our software for the username/password & vmware server IP. These variables have to be part of the command, for example:
Connect-VIServer -Server @VMwareHostIP@ -Protocol https -User @Username@ -Password @Password@
Is there a way I could call the PowerCLI from the Windows command prompt?
You can try below from command prompt
powershell "add-pssnapin vmware.vimautomation.core"; "Connect-VIServer -Server @VMwareHostIP@ -Protocol https -User @Username@ -Password @Password@"; "get-vm | get-snapshot | format-list"
separate each commad with ";" and best practice is Quote unquote each command.
You can try below from command prompt
powershell "add-pssnapin vmware.vimautomation.core"; "Connect-VIServer -Server @VMwareHostIP@ -Protocol https -User @Username@ -Password @Password@"; "get-vm | get-snapshot | format-list"
separate each commad with ";" and best practice is Quote unquote each command.
That doesnt seem to output anything 😕
If I dump that to a txt file
WARNING: There were one or more problems with the server certificate:
* The X509 chain could not be built up to the root certificate.
* The certificate's CN name does not match the passed value.
Certificate: [Subject]
OID.1.2.840.113549.1.9.2="1262530446,564d7761726520496e632e",
CN=localhost.localdomain, E=ssl-certificates@vmware.com, OU=VMware ESX Server
Default Certificate, O="VMware, Inc", L=Palo Alto, S=California, C=US
[Issuer]
O=VMware Installer
[Serial Number]
454472306979416A
[Not Before]
1/3/2010 6:54:06 AM
[Not After]
7/4/2021 7:54:06 AM
[Thumbprint]
059369C0E7AB3709CA6D3917015CBCCDA1946ACB
The server certificate is not valid.
WARNING: THE DEFAULT BEHAVIOR UPON INVALID SERVER CERTIFICATE WILL CHANGE IN A
FUTURE RELEASE. To ensure scripts are not affected by the change, use
Set-PowerCLIConfiguration to set a value for the InvalidCertificateAction
option.
Name Port User
---- ---- ----
192.168.0.10 443 root
out-lineoutput : The object of type "Microsoft.PowerShell.Commands.Internal.For
mat.FormatStartData" is not valid or not in the correct sequence. This is likel
y caused by a user-specified "format-list" command which is conflicting with th
e default formatting.
+ CategoryInfo : InvalidData: (:) [out-lineoutput], InvalidOperat
ionException
+ FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.P
owerShell.Commands.OutLineOutputCommand
Drop the Format-List at the end
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference