-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctions.ps1
91 lines (79 loc) · 1.91 KB
/
Functions.ps1
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function mkcd
{
if($args.Count -eq 1)
{
mkdir $args[0] | set-location
}
}
function Get-Base64($textIn)
{
$b = [System.Text.Encoding]::UTF8.GetBytes($textIn)
return [System.Convert]::ToBase64String( $b )
}
function Read-Base64($textBase64)
{
$b = [System.Convert]::FromBase64String($textBase64)
return [System.text.Encoding]::UTF8.GetString($b)
}
function guid
{
return [Guid]::NewGuid().ToString()
}
function newguid
{
guid | Set-Clipboard
}
function get-vimShortPath([string] $path)
{
$loc = $path.Replace($env:HOME, '~')
$loc = $loc.Replace($env:WINDIR, '[Windows]')
#remove prefix for UNC paths
$loc = $loc -replace '^[^:]+::', ''
if ( $loc.Length -lt 64 )
{
return $loc
}
return ($loc -replace '\\(\.?)([^\\])[^\\]*(?=\\)', '\$1$2')
}
function Get-IsAdminUser()
{
$id = [Security.Principal.WindowsIdentity]::GetCurrent()
$wp = new-object Security.Principal.WindowsPrincipal($id)
return $wp.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Get-CommandLocation
{
Param(
[string]$command = $(Throw New-Object System.ArgumentException "A command must be specified", "command")
)
$oldPreference = $ErrorActionPreference
$ErrorActionPreference = 'stop'
Try
{
$cmd = Get-Command $command
if ( $cmd.CommandType -eq "Function" )
{
Write-Host $cmd.ScriptBlock
}
elseif ( $cmd.CommandType -eq "Alias" )
{
Write-Host $cmd.ResolvedCommand
}
elseif ( $cmd.CommandType -eq "Application" )
{
Write-Host $cmd.Path
}
}
Catch [System.Management.Automation.CommandNotFoundException]
{
Write-Host "Command '$command' not found."
}
Catch
{
Write-Host "Unknown Error"
}
Finally
{
$ErrorActionPreferece = $oldPreference
}
}