File: set_share.ps1

package info (click to toggle)
vagrant 2.2.14%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,800 kB
  • sloc: ruby: 97,301; sh: 375; makefile: 16; lisp: 1
file content (37 lines) | stat: -rw-r--r-- 1,051 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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) {
    $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 ($share_name -eq $null) {
        Write-Output "share path: ${path}"
        Write-Error "error - no share name provided"
        exit 1
    }

    if ($share_id -eq $null) {
        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
    }
}
exit 0