Skip to content

Commit 609bf0b

Browse files
committed
Updated icon converter and Outlook Quarantine folder scripts.
1 parent 8e3c37e commit 609bf0b

File tree

4 files changed

+95
-35
lines changed

4 files changed

+95
-35
lines changed

.vscode/launch.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "PowerShell",
6+
"request": "launch",
7+
"name": "PowerShell Launch (current file)",
8+
"script": "${file}",
9+
"args": [],
10+
"cwd": "${file}"
11+
},
12+
{
13+
"type": "PowerShell",
14+
"request": "attach",
15+
"name": "PowerShell Attach to Host Process",
16+
"processId": "${command.PickPSHostProcess}",
17+
"runspaceId": 1
18+
},
19+
{
20+
"type": "PowerShell",
21+
"request": "launch",
22+
"name": "PowerShell Interactive Session",
23+
"cwd": "${workspaceRoot}"
24+
}
25+
]
26+
}

Data/ConvertTo-Icon.ps1

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
$IconBMP = [System.Drawing.Image]::FromStream($IconStream)
2-
$IconBMP.MakeTransparent()
3-
$Hicon = $IconBMP.GetHicon()
4-
$IconBMP = [System.Drawing.Icon]::FromHandle($Hicon)
1+
[CmdletBinding()]
2+
param(
3+
[Parameter(
4+
Mandatory = $true,
5+
ValueFromPipeline = $true,
6+
ValueFromPipelineByPropertyName = $true
7+
)]
8+
[ValidateScript({
9+
if (Test-Path -Path $_ -PathType Leaf) {
10+
$true
11+
} else {
12+
throw "[$_] is not a valid file."
13+
$false
14+
}
15+
})]
16+
[string[]]$FilePath
17+
)
18+
19+
foreach ($Path in $FilePath) {
20+
Add-Type -AssemblyName System.Drawing
21+
22+
$File = Get-Item -Path $Path
23+
$Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($File.FullName)
24+
$Icon.ToBitmap().Save($File.FullName.Replace($File.Extension, '.ico'))
25+
}
+43-31
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,50 @@
1-
# Get Outlook object
2-
$Outlook = New-Object -ComObject Outlook.Application
3-
4-
# Get Inbox
5-
$Namespace = $Outlook.GetNamespace('MAPI')
6-
$Inbox = $Namespace.GetDefaultFolder(6)
7-
8-
try {
9-
# Create new Quarantine folder
10-
$Quarantine = $Inbox.Folders.Add('Quarantine')
11-
} catch {
12-
# Get existing Quarantine folder
1+
begin { Start-Transcript $env:TEMP\olQuarantineEnable.log }
2+
3+
process {
4+
# Get Outlook object
5+
Add-Type -AssemblyName Microsoft.Office.Interop.Outlook
6+
$Outlook = New-Object -ComObject Outlook.Application
7+
8+
# Get Inbox
9+
$Namespace = $Outlook.GetNamespace('MAPI')
10+
$Inbox = $Namespace.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox)
11+
12+
try {
13+
# Create new Quarantine folder
14+
$Quarantine = $Inbox.Folders.Add('Quarantine')
15+
} catch {
16+
# Get existing Quarantine folder
17+
$Quarantine = $Inbox.Folders | Where-Object -Property Name -eq 'Quarantine'
18+
}
19+
20+
# Set the web Url to the Quarantine admin site and set web view as default
21+
$Quarantine.WebViewURL = 'https://admin.protection.outlook.com/quarantine'
22+
$Quarantine.WebViewOn = $true
23+
24+
# Add Quarantine folder to favorites
25+
$OutlookModule = $Outlook.ActiveExplorer().NavigationPane.Modules.Item('Mail')
26+
$Favorites = $OutlookModule.NavigationGroups.Item('Favorites')
27+
$Favorites.NavigationFolders.Add($Quarantine)
28+
29+
# Validate settings
1330
$Quarantine = $Inbox.Folders | Where-Object -Property Name -eq 'Quarantine'
14-
}
15-
16-
# Set the web Url to the Quarantine admin site and set web view as default
17-
$Quarantine.WebViewURL = 'https://admin.protection.outlook.com/quarantine'
18-
$Quarantine.WebViewOn = $true
1931

20-
# Add Quarantine folder to favorites
21-
$OutlookModule = $Outlook.ActiveExplorer().NavigationPane.Modules.Item('Mail')
22-
$Favorites = $OutlookModule.NavigationGroups.Item('Favorites')
23-
$Favorites.NavigationFolders.Add($Quarantine)
32+
if ($Quarantine) {
33+
if ($Quarantine.WebViewURL -ne 'https://admin.protection.outlook.com/quarantine') { exit 996 }
2434

25-
# Validate settings
26-
$Quarantine = $Inbox.Folders | Where-Object -Property Name -eq 'Quarantine'
35+
if (-not $Quarantine.WebViewOn) { exit 997 }
2736

28-
if ($Quarantine) {
29-
if ($Quarantine.WebViewURL -ne 'https://admin.protection.outlook.com/quarantine') { exit 999 }
37+
if (-not $Favorites.NavigationFolders.Item($Quarantine.Name)) { exit 998 }
3038

31-
if (-not $Quarantine.WebViewOn) { exit 999 }
32-
33-
if (-not $Favorites.NavigationFolders.Item($Quarantine.Name)) { exit 999 }
39+
exit 0
40+
} else {
41+
exit 995
42+
}
43+
}
3444

35-
exit 0
36-
} else {
37-
exit 999
45+
end {
46+
# Used as detection method in SCCM
47+
New-Item -Path 'HKLM:\Software\SMS' -ItemType Key -Force |
48+
New-ItemProperty -Name olQuarantineEnabled -Value $LASTEXITCODE -PropertyType String -Force
49+
Stop-Transcript
3850
}

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# PowerShell-Scripts
22

33
Just a bunch of PowerShell scripts that help me get through the day.
4+
Please feel free to submit issues and requests, I work in PowerShell nearly every day and am always happy to script.

0 commit comments

Comments
 (0)