This is an old revision of the document!
PowerShell Direct (Guest Scripting)
Command Invokation
Invoke-Command -VMName <VM> -Credential (Get-Credential) -ScriptBlock {
<Any PowerShell commands to run inside the VM>
}
File Transfer to VM
# Open a PSSession to the Virtual Machine
$Session = New-PSSession -VMName <VM> -Credential (Get-Credential)
# Copy the File to the Virtual Machine
Copy-Item -ToSession $Session -Path <SourcePath> -Destination <DestinationPath>
# Close the PSSession
Remove-PSSession -Session $Session
File Transfer from VM
# Open a PSSession to the virtual machine
$Session = New-PSSession -VMName <VM> -Credential (Get-Credential)
# Copy the File from the virtual machine
Copy-Item -FromSession $Session -Path <SourcePath> -Destination <DestinationPath>
# Close the PSSession
Remove-PSSession -Session $Session