PowerShell Direct (Guest Scripting)

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 VM
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 VM
Copy-Item -FromSession $Session -Path <SourcePath> -Destination <DestinationPath>
# Close the PSSession
Remove-PSSession -Session $Session

windows/hyper-v/powershell-direct.1776175071.txt.gz · Last modified: 2026/04/14 13:57