Skip to content

Commit f216e7d

Browse files
committed
2020-11-22 update
1. Update Download-Channel9VideoFromRss: It now needs a explicit -Download switch 2. Replace "Microsoft Antimalware" folder with "Security" folder and a rewritten MpDefinitionPackage module
1 parent e00649d commit f216e7d

File tree

12 files changed

+482
-124
lines changed

12 files changed

+482
-124
lines changed

Download/Download-Channl9VideosFromRSS.ps1

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,66 @@
1-
Param (
2-
[Parameter(Mandatory=$true)]
1+
#Requires -Version 5.1
2+
using namespace System.Management.Automation
3+
4+
param (
5+
[Parameter(Mandatory)]
36
[string]
47
$RssUrl,
8+
9+
[Parameter()]
10+
[switch]
11+
$Download,
512

6-
[ValidateScript({Test-Path $_ -PathType 'Container'})]
13+
[Parameter()]
14+
[ValidateScript({Test-Path -Path $_ -PathType 'Container'})]
715
[string]
8-
$DownloadFolder = '.\'
16+
$Path = ".\"
917
)
1018

1119
# Open the specified download folder
12-
Push-Location $DownloadFolder
20+
Push-Location $Path
1321

1422
# Initialize the downloader
1523
$WebClient = New-Object System.Net.WebClient
1624

1725
# Download the RSS
18-
# If the download failed, throw the error into the user's face and stop the script.
19-
# That's not an awfully polite thing to say, but that's what "throw" implies.
26+
# If the download failed, raise a terminating error
2027
Write-Output 'Downloading RSS feed...'
2128
try {
22-
$RSSWebObject = ([xml]($WebClient).downloadstring($RssUrl))
29+
# $RSSWebObject = ([xml]($WebClient).downloadstring($RssUrl))
30+
$RSSWebObject = [xml]($WebClient.DownloadString($RssUrl))
2331
}
2432
catch {
25-
throw
26-
break
33+
$PSCmdlet.ThrowTerminatingError(
34+
[ErrorRecord]::new(
35+
$_,
36+
'CouldNotGetRssFeed',
37+
[ErrorCategory]::ResourceUnavailable,
38+
$RssUrl
39+
)
40+
)
2741
}
2842

43+
Write-Output 'Enumerating downloadable files...'
2944
$counter=0;
3045
foreach ($item in $RSSWebObject.rss.channel.item) {
3146
$counter++
3247

3348
# Channel 9 isn't perfect. Some RSS feeds are missing an enclosure or a URL.
3449
if ($null -eq $item.enclosure.url) {
35-
Write-Output $('{0:D2}: No URL found)' -f $counter)
50+
Write-Output $('{0:D2}: This item contains no download URL)' -f $counter)
3651
continue
3752
}
3853
$url = New-Object System.Uri($item.enclosure.url) -ErrorAction Stop
39-
$FileName = '{0:D2}. {1}' -f $counter,$url.Segments[-1]
40-
41-
Write-Output $FileName
42-
if (!(Test-Path $FileName)) {
43-
# $WebClient.DownloadFile($url, $FileName)
44-
Invoke-WebRequest -Uri $url -OutFile $FileName -ErrorAction Stop
54+
if ($Download) {
55+
$FileName = '{0:D2}. {1}' -f $counter,$url.Segments[-1]
56+
if (!(Test-Path $FileName)) {
57+
Write-Output "`"$FileName`": Downloading..."
58+
Invoke-WebRequest -Uri $url -OutFile $FileName
59+
} else {
60+
Write-Output "`"$FileName`": Already exists; won't download"
61+
}
62+
} else {
63+
Write-Output ('{0:D2}. {1}' -f $counter,$url)
4564
}
4665
}
4766

Microsoft Antimalware/Build Microsoft Antimalware virus definition update.ps1

Lines changed: 0 additions & 85 deletions
This file was deleted.

README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Administrative scripts
2+
23
Scripts for carrying out administrative tasks, mostly in Windows
34

45
## AppX
@@ -16,7 +17,7 @@ Deals with Microsoft Store app packages.
1617
2. `Active BITS jobs - Table.ps1`: Asks the BITS service to give a list of all of its download and upload operations whose status is "Transferring". The result would be in the table form. I recommend maximizing your PowerShell window for this.
1718
3. `All BITS jobs - Custom.ps1`: Asks the BITS service to give a list of all of its operation, then summarizes them, so that only the job state (color-coded), job ID, display name, type, priority, bytes transferred, and bytes total are shown, along with a list of all files in each job.
1819
4. `Pending BITS jobs - Detailed.ps1`: Asks the BITS service to give a list of all of its download and upload operations whose status is anything but "Transferred". The result would be in the list form.
19-
6. `Pending BITS jobs - Table.ps1`: Asks the BITS service to give a list of all of its download and upload operations whose status is anything but "Transferred". The result would be in the table form. I recommend maximizing your PowerShell window for this.
20+
5. `Pending BITS jobs - Table.ps1`: Asks the BITS service to give a list of all of its download and upload operations whose status is anything but "Transferred". The result would be in the table form. I recommend maximizing your PowerShell window for this.
2021

2122
## Download
2223

@@ -44,27 +45,31 @@ A matter of licensing: I did not write this script. The user who posted it was c
4445
2. `Repair-Windows.ps1`: Repairs the online Windows instance by running DISM and SFC. Their logs are moved to the desktop.
4546
3. `NGEN Update.bat`: Runs NGEN inside Windows PowerShell. While PowerShell 6 and 7 run on .NET Core, Windows PowerShell and some Windows-exclusive PowerShell modules (which PowerShell 7 also loads) run on .NET Framework. Run this script with admin privileges whenever you update .NET Framework, or whenever you feel Windows PowerShell or PowerShell 7 for Windows are sluggish at launch time.
4647

47-
## Microsoft Antimalware
48+
## Security
49+
50+
### MpDefinitionPackage
51+
52+
This entire folder, `MpDefinitionPackage`, is a PowerShell module that adds a cmdlet to your PowerShell: `Build-MpDefinitionPackage`. This cmdlet extracts Microsoft malware definition files from one computer and packages them up into a self-extracting archive, so that it can be installed on other computers. It requires WinRAR to work.
4853

49-
This folder contains one script and two utility files for extracting Microsoft malware definition files from one computer and package them up into a self-extracting archive, so that it can be installed on other computers.
54+
I conceived it as a script at a time when our site was suffering a network outage. Not only we couldn't update our antimalware, users were using USB flash drives (notorious for being malware carriers) to transfer files. Desperate times need desperate measures. I wrote this solution to keep our devices secure. Eventually, I turned it into a module.
5055

51-
I conceived this script at a time when our network was suffering an infrastructure breakdown. Many of the computers had lost their Internet connectivity and users were using USB flash drives (notorious for being malware carriers) to transfer files. Those that had Internet connectivity were suffering from a bandwidth problem too, so downloading the official Microsoft antimalware package every day was not feasible. Windows 8.1's Windows Defender, however, could download minimal delta packages quickly.
56+
**Warning:** I do not guarantee that this solution works. If you wish to update an entire network while preserving Internet bandwidth, the official solutions are _Windows Server Update Services_ and _System Center_.
5257

53-
In those dire situations, I wrote these scripts to keep a broken network secure and up-to-date.
58+
**Warning:** Residents of the United States of America must use this module in compliance with the Title 17 of United States Code, section 117 ("Limitations on exclusive rights: Computer programs"), article C. In other words, use this script only to keep your Microsoft antimalware product up-to-date and only when you have no other options.
5459

5560
## Shell
5661

57-
1. `PowerShell bug fix for 'Run with PowerShell' verb.reg` correctly registers Windows PowerShell with File Explorer. It is especially useful for those who have installed Visual Studio Code or have corrupted their .ps1 registration.
62+
1. `PowerShell bug fix for 'Run with PowerShell' verb.reg` correctly registers Windows PowerShell with File Explorer. It is also useful for those who have corrupted or otherwise undesirably altered their `.ps1` registration.
5863

5964
## Shutdown
6065

6166
The names of these scripts are self-explanatory.
6267

6368
1. Log off.vbs
64-
2. Power off (Alternative).vbs
65-
3. Power off.vbs
66-
4. Restart (Alternative).vbs
67-
5. Restart.vbs
69+
1. Power off.vbs
70+
1. Power off (Alternative).vbs
71+
1. Restart.vbs
72+
1. Restart (Alternative).vbs
6873

6974
### Further reading: modern ways
7075

@@ -85,11 +90,11 @@ The names of these scripts are self-explanatory.
8590

8691
## Time
8792

88-
1. `Firmware time is UTC.reg`: Causes Windows to interpret the real-time clock as UTC time. Ordinarily, Windows interprets it as the local time correponding to the time zone you've selected. This is in contrast to most Linux distros that interpret it as UTC. After applying this, restart the computer.
93+
1. `Firmware time is UTC.reg`: Configures Windows to interpret the real-time clock as UTC time. Ordinarily, Windows interprets it as the local time correponding to the time zone you've selected. Most Linux distros that interpret it as UTC, so you may need this script if you multi-boot a Linux distro along Windows. After applying this, restart the computer.
8994

9095
## Unicode test suite
9196

92-
A group of PNG images with multilingual file names. This set is intended to represent a practical real-world use of Unicode.
97+
A group of PNG images with multilingual file names. This set is intended to represent a practical real-world use of Unicode.
9398

9499
See [its documentation](Unicode%20test%20suite/README.md).
95100

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "PowerShell: Start debugging this file",
9+
"type": "PowerShell",
10+
"request": "launch",
11+
"script": "${file}",
12+
"cwd": "${file}"
13+
},
14+
{
15+
"name": "PowerShell: Start debugging the project",
16+
"type": "PowerShell",
17+
"request": "launch",
18+
"script": "${workspaceFolder}/~Meta~ Run.ps1",
19+
"cwd": "${workspaceFolder}"
20+
}
21+
]
22+
}

0 commit comments

Comments
 (0)