-
-
Notifications
You must be signed in to change notification settings - Fork 266
/
Open-File.psm1
68 lines (57 loc) · 2.48 KB
/
Open-File.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Import-Module -DisableNameChecking "$PSScriptRoot\Title-Templates.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\ui\Show-MessageDialog.psm1"
function Open-PowerShellFilesCollection {
[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory)]
[String] $RelativeLocation,
[Parameter(Position = 1, Mandatory)]
[String[]] $Scripts,
[String] $DoneTitle,
[String] $DoneMessage,
[Bool] $OpenFromGUI = $true,
[Switch] $NoDialog
)
Push-Location -Path $(Join-Path -Path "$PSScriptRoot\..\.." -ChildPath "$RelativeLocation")
Get-ChildItem -Recurse *.ps*1 | Unblock-File
ForEach ($FileName in $Scripts) {
$LastAccessUtc = "$((Get-Item "$FileName").LastWriteTimeUtc | Get-Date -Format "yyyy.MM.dd")"
$Private:Counter = Write-TitleCounter "$FileName | $LastAccessUtc" -Counter $Counter -MaxLength $Scripts.Length
If ($OpenFromGUI) {
Import-Module .\"$FileName" -Force
} Else {
PowerShell -NoProfile -ExecutionPolicy Bypass -File .\"$FileName"
}
}
Pop-Location
If (!($NoDialog)) {
Show-MessageDialog -Title "$DoneTitle" -Message "$DoneMessage"
}
}
function Open-RegFilesCollection {
[CmdletBinding()]
param (
[String] $RelativeLocation,
[Array] $Scripts,
[String] $DoneTitle,
[String] $DoneMessage,
[Switch] $NoDialog
)
Push-Location -Path $(Join-Path -Path "$PSScriptRoot\..\.." -ChildPath "$RelativeLocation")
ForEach ($FileName in $Scripts) {
$LastAccessUtc = "$((Get-Item "$FileName").LastWriteTimeUtc | Get-Date -Format "yyyy.MM.dd")"
$Private:Counter = Write-TitleCounter "$FileName ($LastAccessUtc)" -Counter $Counter -MaxLength $Scripts.Length
Start-Process -FilePath "regedit" -ArgumentList "/s", "$FileName" -Wait
}
Pop-Location
If (!($NoDialog)) {
Show-MessageDialog -Title "$DoneTitle" -Message "$DoneMessage"
}
}
<#
Example:
Open-PowerShellFilesCollection -RelativeLocation "src\scripts" -Scripts "script.ps1" -NoDialog
Open-PowerShellFilesCollection -RelativeLocation "src\scripts" -Scripts @("script1.ps1", "script2.ps1") -DoneTitle "Title" -DoneMessage "Message" -OpenFromGUI $false
Open-RegFilesCollection -RelativeLocation "src\scripts" -Scripts "script.reg" -NoDialog
Open-RegFilesCollection -RelativeLocation "src\scripts" -Scripts @("script1.reg", "script2.reg") -DoneTitle "Title" -DoneMessage "Message"
#>