Skip to content

Commit

Permalink
fix the windows hyperv smb synced folder creation/destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
rgl committed Oct 3, 2022
1 parent c1fa7e4 commit 9154771
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
29 changes: 14 additions & 15 deletions plugins/hosts/windows/scripts/set_share.ps1
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

# The names of the user are language dependent!
$objSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-1-0")
$objUser = $objSID.Translate([System.Security.Principal.NTAccount])

$grant = "$objUser,Full"

for ($i=0; $i -le $args.length; $i = $i + 3) {
for ($i = 0; ($i+2) -lt $args.length; $i = $i + 3) {
$path = $args[$i]
$share_name = $args[$i+1]
$share_id = $args[$i+2]


if ($path -eq $null) {
Write-Warning "empty path argument encountered - complete"
exit 0
if (!$path) {
Write-Error "error - no share path provided"
exit 1
}

if ($share_name -eq $null) {
if (!$share_name) {
Write-Output "share path: ${path}"
Write-Error "error - no share name provided"
exit 1
}

if ($share_id -eq $null) {
if (!$share_id) {
Write-Output "share path: ${path}"
Write-Error "error - no share ID provided"
exit 1
}

$result = net share $share_id=$path /unlimited /GRANT:$grant /REMARK:"${share_name}"
if ($LastExitCode -ne 0) {
$host.ui.WriteLine("share path: ${path}")
$host.ui.WriteErrorLine("error ${result}")
exit 1
}
New-SmbShare `
-Name $share_id `
-Path $path `
-FullAccess $objUser `
-Description $share_name
}
exit 0
12 changes: 6 additions & 6 deletions plugins/hosts/windows/scripts/unset_share.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

ForEach ($share_name in $args) {
$result = net share $share_name /DELETE /YES
if ($LastExitCode -ne 0) {
Write-Output "share name: ${share_name}"
Write-Error "error - ${result}"
exit 1
}
Remove-SmbShare `
-Name $share_name `
-Force
}
Write-Output "share removal completed"
exit 0

0 comments on commit 9154771

Please sign in to comment.