Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Test chocolatey package install on a vm. Resets the vm to last clean state and runs the package pointing to a local path that has the .nupkg file
#uses a Hyper-v vm whose name is the same as its computername
#Assumes chocolatey is installed and powershell remoting is configured
#on vm and client as well as cssp auth
#configure remoting and cssp on vm using
# Enable-PSRemoting -Force
# Enable-WSManCredSSP –Role Server
#Enable on client with
# Enable-PSRemoting -Force
# Enable-WSManCredSSP –Role client –DelegateComputer $VmName
#On clienr edit group policy in gpedit.msc Computer Configuration –> Administrative Templates –> System –> Credential Delegation
#select "Allow Delegating Fresh Credentials with NTLM-only Server Authentication"
#Enable the setting, click "Show..." and enter vm computrname as "wsman/<computername>
function Test-VM {
$vm = Get-VM $VmName
Restore-VMSnapshot $vm -Name $vm.ParentSnapshotName -Confirm:$false
Start-VM $VmName
$creds = Get-Credential -Message "$vmName credentials" -UserName "$env:UserDomain\$env:username"
$expandedPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($sourcePath)
$remoteDir = $expandedPath.replace(':','$')
Write-Host "Waiting for $vmName to start..."
do {Start-Sleep -milliseconds 100}
until ((Get-VMIntegrationService $vm | ?{$ -eq "Heartbeat"}).PrimaryStatusDescription -eq "OK")
Write-Host "Using source path $source"
Invoke-Command -ComputerName $vmName -Credential $creds -Authentication Credssp -ScriptBlock {cinst $args[0] -source $args[1]} -Argumentlist $package,$source
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.