{"record":{"id":"21ccdfff370b42b6","repo":"hashicorp/vagrant","slug":"vagrant-requires-administrator-access-for-pruning","errorCode":null,"errorMessage":"Vagrant requires administrator access for pruning SMB shares and\nmay request access to complete removal of stale shares.","messagePattern":"Vagrant requires administrator access for pruning SMB shares and\nmay request access to complete removal of stale shares\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"plugins/hosts/windows/cap/smb.rb","lineNumber":57,"sourceCode":"        def self.smb_cleanup(env, machine, opts)\n          script_path = File.expand_path(\"../../scripts/unset_share.ps1\", __FILE__)\n\n          m_id = machine_id(machine)\n          prune_shares = existing_shares.map do |share_name, share_info|\n            if share_info[\"Description\"].to_s.start_with?(\"vgt-#{m_id}-\")\n              @@logger.info(\"removing smb share name=#{share_name} id=#{m_id}\")\n              share_name\n            else\n              @@logger.info(\"skipping smb share removal, not owned name=#{share_name}\")\n              @@logger.debug(\"smb share ID not present name=#{share_name} id=#{m_id} description=#{share_info[\"Description\"]}\")\n              nil\n            end\n          end.compact\n\n          @@logger.debug(\"shares to be removed: #{prune_shares}\")\n\n          if prune_shares.size > 0\n            machine.env.ui.warn(\"\\n\" + I18n.t(\"vagrant_sf_smb.uac.prune_warning\") + \"\\n\")\n            sleep UAC_PROMPT_WAIT\n            @@logger.info(\"remove shares: #{prune_shares}\")\n            result = Vagrant::Util::PowerShell.execute(script_path, *prune_shares, sudo: true)\n            if result.exit_code != 0\n              failed_name = result.stdout.to_s.sub(\"share name: \", \"\")\n              raise SyncedFolderSMB::Errors::PruneShareFailed,\n                name: failed_name,\n                stderr: result.stderr,\n                stdout: result.stdout\n            end\n          end\n        end\n\n        def self.smb_prepare(env, machine, folders, opts)\n          script_path = File.expand_path(\"../../scripts/set_share.ps1\", __FILE__)\n\n          shares = []\n          current_shares = existing_shares","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/plugins/hosts/windows/cap/smb.rb#L39-L75","documentation":"On Windows hosts, Vagrant prunes stale SMB shares (shares whose Vagrant-managed ID no longer belongs to an active machine) by running an elevated PowerShell script. Before executing it, Vagrant prints this UAC warning, sleeps UAC_PROMPT_WAIT seconds, and then invokes the script with sudo: true, which may raise a consent dialog; a non-zero exit raises SyncedFolderSMB::Errors::PruneShareFailed.","triggerScenarios":"Teardown or setup on a Windows host where prune_shares is non-empty — previously created Vagrant SMB shares whose machines no longer exist, e.g. after deleting .vagrant state or removing machines by hand.","commonSituations":"Leftover shares from manually deleted machines; running Vagrant from a non-elevated terminal so a UAC dialog interrupts the flow; CI agents without interactive elevation.","solutions":["Run Vagrant from an elevated (Administrator) terminal so the elevated PowerShell call needs no interactive consent","Remove stale shares yourself in an elevated shell: `Remove-SmbShare -Name <share>` or via fsmgmt.msc","Use `vagrant destroy` to tear down machines so share pruning has little to do"],"exampleFix":"# before\nvagrant up   # from a normal terminal, UAC dialog may appear mid-run\n# after\n# open an elevated PowerShell, then:\nvagrant up","handlingStrategy":"validation","validationCode":"# PowerShell preflight: is this shell elevated?\n([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run Vagrant from an Administrator terminal whenever SMB folders are involved","Tear down machines with `vagrant destroy` instead of deleting state by hand","Periodically audit stale shares with Get-SmbShare and remove them yourself"],"tags":["vagrant","smb","windows-host","uac","prune"],"backgroundTag":"privilege-elevation-required","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}