-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMount.psm1
49 lines (43 loc) · 1.29 KB
/
Mount.psm1
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
38
39
40
41
42
43
44
45
46
47
48
49
Function New-Mount {
[CmdletBinding()]
Param (
[Parameter(Mandatory)]
[String] $drive,
[Parameter(Mandatory)]
[String] $path
)
Process {
Invoke-DefineDosDevice 0 $drive $path
}
}
Function Remove-Mount {
[CmdletBinding()]
Param (
[Parameter(Mandatory)]
[String] $drive,
[Parameter(Mandatory)]
[String] $path
)
Process {
Invoke-DefineDosDevice 6 $drive $path
}
}
Function Invoke-DefineDosDevice {
[CmdletBinding()]
Param (
[Parameter(Mandatory)]
[uint32] $flags,
[Parameter(Mandatory)]
[String] $drive,
[Parameter(Mandatory)]
[String] $path
)
Process {
$DefineDosDevice = '[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)] public static extern bool DefineDosDevice(int dwFlags, string lpDeviceName, string lpTargetPath);'
$Kernel32 = Add-Type -MemberDefinition $DefineDosDevice -Name 'Kernel32' -Namespace 'Win32' -PassThru
$success = $Kernel32::DefineDosDevice($flags, $drive, $path)
if ( -not $success ) {
throw [ComponentModel.Win32Exception][Runtime.InteropServices.Marshal]::GetLastWin32Error()
}
}
}