-
Use
Add-Type
with-MemberDefinition
-
Making
Windows API calls
- Get Signature (
pinvoke.net
recommended) - Make the
method declarations public
- Use the modified signature in
Add-Type -MemberDefinition
- Get Signature (
-
New-SymLink.ps1
$ApiCode = @"
[DllImport("kernel32.dll")]
public static extern bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, int dwFlags);
"@
$SymLink = Add-Type -MemberDefinition $ApiCode -Name Symlink -Namespace CreatSymLink -PassThru
$SymLink::CreateSymbolicLink('C:\test\link', 'C:\Users\', 1)
PS C:\Users\Administrator\Desktop> .\New-SymLink.ps1
True
PS C:\Users\Administrator\Desktop>