-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code-Snippets.ps1
61 lines (53 loc) · 1.96 KB
/
Code-Snippets.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
# Credit to https://github.com/MatsHellman
#
#
############################################
# Check Outlook Running and close if needed
############################################
function CheckOutlookRunning {
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName PresentationFramework
$OutlookRunningMessage = "Your Outlook is open and it needs to be closed before we continue. Please save" +
" all your on-going work. By selecting YES, your Outlook will be automatically closed." +
" Select NO if you would like to continue later."
# get Outlook process
$outlook = Get-Process Outlook -ErrorAction SilentlyContinue
if ($outlook) {
$msgCloseOutlook = [System.Windows.Messagebox]::Show(
$OutlookRunningMessage,
'Outlook needs to be closed',
'YesNo',
'Error'
)
switch ($msgCloseOutlook) {
Yes {
$Answer = $True
# Try gracefully first
$outlook.CloseMainWindow()
# Kill after fifteen seconds
Start-Sleep 15
if (!$outlook.HasExited) {
$outlook | Stop-Process -Force
}
}
Default {
$Answer = $False
}
}
}
Return $Answer
}
#############################################
# Get the users to find a folder SelectTarget
#############################################
function SelectTarget {
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")|Out-Null
$foldername = New-Object System.Windows.Forms.FolderBrowserDialog
$foldername.Description = "Please select a folder. Ex. C:\Temp, all files will be moved here."
$foldername.rootfolder = "MyComputer"
if($foldername.ShowDialog() -eq "OK")
{
$folder += $foldername.SelectedPath
}
return $folder
}