-
Notifications
You must be signed in to change notification settings - Fork 0
/
Library.ps1
97 lines (80 loc) · 2.48 KB
/
Library.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
92
93
94
95
96
97
Function Create-Menu (){
Param(
[Parameter(Mandatory=$True)][String]$MenuTitle,
[Parameter(Mandatory=$True)][array]$MenuOptions
)
$MaxValue = $MenuOptions.count-1
$Selection = 0
$EnterPressed = $False
Clear-Host
While($EnterPressed -eq $False){
Write-Host "$MenuTitle"
For ($i=0; $i -le $MaxValue; $i++){
If ($i -eq $Selection){
Write-Host -BackgroundColor Cyan -ForegroundColor Black "[ $($MenuOptions[$i]) ]"
} Else {
Write-Host " $($MenuOptions[$i]) "
}
}
$KeyInput = $host.ui.rawui.readkey("NoEcho,IncludeKeyDown").virtualkeycode
Switch($KeyInput){
13{
$EnterPressed = $True
Return $Selection
Clear-Host
break
}
38{
If ($Selection -eq 0){
$Selection = $MaxValue
} Else {
$Selection -= 1
}
Clear-Host
break
}
40{
If ($Selection -eq $MaxValue){
$Selection = 0
} Else {
$Selection +=1
}
Clear-Host
break
}
Default{
Clear-Host
}
}
}
}
function Remove-EmptyFolders([string]$folder){
Get-ChildItem $folder -Recurse | Where-Object{$_.PSIsContainer -and !(Get-ChildItem $_.Fullname -Recurse | Where-Object{!$_.PSIsContainer})} | remove-item -Force -Recurse -EA SilentlyContinue
}
function Check-FolderFile{
param(
[Parameter(Mandatory=$false)]
[string]$FileName,
[Parameter(Mandatory=$false)]
[string]$FilePath,
[Parameter(Mandatory=$false)]
[string]$FileDescription
)
If (!$FileDescription){ $FileDescription=$FileName }
If (!$FilePath){ $FilePath=$PSScriptRoot }
Write-Host -NoNewline "Check $($FileDescription): "
If (Test-Path $FilePath\$FileName) {
Write-Host -ForegroundColor Green "PASSED "
}else{
Write-Host -ForegroundColor Red "FAILED "
If (!$FileName) {
Write-Host -ForegroundColor DarkBlue -NoNewline "$($FilePath) does not exist. "
$confirmation = Read-Host "Should the directory be created for you? [YES/no]"
if ($confirmation -eq 'YES') {
New-Item -Path $FilePath -ItemType Directory
} else {
exit
}
}
}
}