-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathCreateSymbolicLink.ps1
More file actions
45 lines (37 loc) · 1.29 KB
/
Copy pathCreateSymbolicLink.ps1
File metadata and controls
45 lines (37 loc) · 1.29 KB
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
function CreateSymbolicLink
{
<#
.SYNOPSIS
Creates a symbolic link in the filesystem.
.DESCRIPTION
Creates a symbolic link in the filesystem. Requires Vista or higher. Requires administrator access.
.NOTES
(func kernel32 CreateSymbolicLink ([bool]) @(
[String], #_Out_ LPCTSTR lpSymlinkPath,
[String], #_In_ LPCTSTR lpTargetPath,
[UInt32] #_In_ DWORD SYMBOLIC_LINK_FLAG
) -EntryPoint CreateSymbolicLink -SetLastError)
)
Author: Matt Green (@mgreen27)
License: BSD 3-Clause
Required Dependencies: PSReflect, SYMBOLIC_LINK_FLAG (enums)
Optional Dependencies: None
#>
param
(
[Parameter(Mandatory = $true)]
[String]
$lpSymlinkPath,
[Parameter(Mandatory = $true)]
[String]
$lpTargetPath,
[Parameter(Mandatory = $true)]
[UInt32]
$dwFlags
)
$SUCCESS = $kernel32::CreateSymbolicLink($lpSymlinkPath, $lpTargetPath, $dwFlags); $LastError = [Runtime.InteropServices.Marshal]::GetLastWin32Error()
if(-not $SUCCESS)
{
throw "[CreateSymbolicLink] Error: $(([ComponentModel.Win32Exception] $LastError).Message)"
}
}