Skip to content

Commit 05391cd

Browse files
2 parents af7f636 + 064a44e commit 05391cd

File tree

4 files changed

+239
-18
lines changed

4 files changed

+239
-18
lines changed

Convert-ADSPowerShellForMarkdown.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ function Convert-ADSPowerShellForMarkdown {
1717
Will not output to screen but instead will set the clipboard
1818
1919
.EXAMPLE
20-
Convert-ADSPowerShellForMarkdown if+%28-not+%28%24IsLinux+-or+%24IsMacOS%29+%29+%7B%0D%0A++++if+%28-not%28Test-Path+C%3A%5C%5CMSSQL%5C%5CBACKUP%29%29+%7B%0D%0A++++++++Write-Output+%22I%27m+going+to+create+C%3A%5C%5CMSSQL%5C%5CBACKUPS+so+that+the+docker-compose+will+work%22%0D%0A++++++++New-Item+C%3A%5CMSSQL1%5CBACKUP1+-ItemType+Directory%0D%0A++++%7D%0D%0A++++else+%7B%0D%0A++++++++Write-Output+%22C%3A%5C%5CMSSQL%5C%5CBACKUPS+already+exists%22%0D%0A++++%7D%0D%0A%7D%0D%0Aelse+%7B%0D%0A++++Write-Warning+%22Sorry+This+code+won%27t+run+on+Linux+-+You+will+have+to+do+it+manually+and+edit+the+docker+compose+file%22%0D%0A%7D -ToClipBoard
20+
Convert-ADSPowerShellForMarkdown -inputstring "Set-Location C:\temp" -LinkText "CLick this link to set the location" -ToClipboard
2121
22-
Converts the encoded URL so that it works with MarkDown and sets it to the clipboard
22+
Converts the PowerShell code Set-Location C:\temp so that it works with MarkDown, creates a link and sets it to the clipboard
2323
2424
.NOTES
2525
June 2019 - Rob Sewell @SQLDbaWithBeard
@@ -35,17 +35,18 @@ function Convert-ADSPowerShellForMarkdown {
3535
clear
3636
[Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null
3737
$encodedstring = [System.Web.HttpUtility]::UrlEncode($inputstring)
38-
$linkage = $encodedstring.Replace('+', ' ').Replace('%3a', ':').Replace('%5c', '%5c%5c').Replace('%22', '\u0022').Replace('%27', '\u0027').Replace('%0D%0A', '').Replace('%3b%0a','\u003B ').Replace('%0a','\u000A')
38+
$linkage = $encodedstring.Replace('+', ' ').Replace('%3a', ':').Replace('%5c', '%5c%5c').Replace('%22', '\u0022').Replace('%27', '\u0027').Replace('%0D%0A', '').Replace('%3b%0a','\u003B ').Replace('%0a','\u000A').Replace('%0d','')
3939

4040
$outputstring = @"
41-
<a href="command:workbench.action.terminal.sendSequence?%7B%22text%22%3A%22 $linkage \u000D %22%7D">$linktext</a>
41+
<a href="command:workbench.action.terminal.sendSequence?%7B%22text%22%3A%22 $linkage \u000D \u000D %22%7D">$linktext</a>
4242
"@
4343
if ($ToClipBoard) {
44-
if (-not ($IsLinux -or $IsMacOS) ) {
44+
if ($IsCore) {
45+
4546
$outputstring | Set-Clipboard
4647
}
4748
else {
48-
Write-Warning "Set-Clipboard - Doesnt work on Linux - Outputting to screen"
49+
Write-Warning "Set-Clipboard - Doesnt work on Core - Outputting to screen"
4950
$outputstring
5051
}
5152
}

Get-PwnedPassword.ps1

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<#
22
.SYNOPSIS
3-
Connects to the API at https://haveibeenpwned.com/ to see if a Password or Password hash has been found in a breach
3+
Connects to the API at https://api.pwnedpasswords.com/ to see if a Password or Password hash has been found in a breach
44
55
.DESCRIPTION
6-
Connects to the API at https://haveibeenpwned.com/ to see if a Password or Password hash has been found in a breach
6+
Connects to the API at https://api.pwnedpasswords.com/ to see if a Password or Password hash has been found in a breach
77
88
Troy Hunt @troyhunt has created an API which allows you to query if a Password has been found in a breach.
99
This is a simple function enabling you to query it
1010
11-
IT IS NOT RECOMMENDED TO USE ACTIVE PASSWORDS WITH THIS SERVICE
11+
ONLY THE FIRST FIVE (5) CHARACTERS OF THE PASSWORD HASH ARE EVER SENT
1212
1313
.PARAMETER Password
1414
The password to check as a secure string. If not supplied will be prompted
@@ -20,30 +20,28 @@ A SHA1 hash of the password to be checked
2020
$Password = Read-Host -AsSecureString
2121
Get-PwnedPassword -Password Password
2222
23-
Connects to the API at https://haveibeenpwned.com/ and checks if a password has been found
23+
Connects to the API at https://api.pwnedpasswords.com/ and checks if a password has been found
2424
in a breach.
2525
2626
2727
.EXAMPLE
2828
Get-PwnedPassword -Hash 8be3c943b1609fffbfc51aad666d0a04adf83c9d
2929
30-
Connects to the API at https://haveibeenpwned.com/ and checks if the SHA1 hash of 'Password' has been found
30+
Connects to the API at https://api.pwnedpasswords.com/ and checks if the SHA1 hash of 'Password' has been found
3131
in a breach.
3232
3333
Don't run this. It has!!
3434
3535
.EXAMPLE
3636
Get-PwnedPassword
3737
38-
Prompts for a Password and connects to the API at https://haveibeenpwned.com/ and checks if it has been found
38+
Prompts for a Password and connects to the API at https://api.pwnedpasswords.com/ and checks if it has been found
3939
in a breach.
4040
4141
.NOTES
4242
AUTHOR : Rob Sewell @sqldbawithbeard https://sqldbawithabeard.com
4343
DATE : 4th August 2017
4444
45-
IT IS NOT RECOMMENDED TO USE ACTIVE PASSWORDS WITH THIS SERVICE
46-
4745
With many many thanks to Troy Hunt for creating this service
4846
You can find Troy on Twitter @TroyHunt
4947
You can read his blog at https://troyhunt.com
@@ -78,11 +76,21 @@ function Get-PwnedPassword {
7876
switch ($PSCmdlet.ParameterSetName) {
7977
'Password' {
8078
$Pass = (New-Object PSCredential "user", $Password).GetNetworkCredential().Password
81-
$URL = 'https://haveibeenpwned.com/api/v2/pwnedpassword/' + $Pass
79+
$StringBuilder = New-Object System.Text.StringBuilder
80+
[System.Security.Cryptography.HashAlgorithm]::Create("SHA1").ComputeHash([System.Text.Encoding]::UTF8.GetBytes($Pass))|% {
81+
[Void]$StringBuilder.Append($_.ToString("x2"))
82+
}
83+
$sha1 = $StringBuilder.ToString()
84+
$sha1Prefix = $sha1.Substring(0, 5)
85+
$sha1Suffix = $sha1.Substring(5)
86+
87+
$URL = 'https://api.pwnedpasswords.com/range/' + $sha1Prefix
8288
break
8389
}
8490
'Hash' {
85-
$URL = 'https://haveibeenpwned.com/api/v2/pwnedpassword/' + $Hash
91+
$sha1Prefix = $Hash.Substring(0, 5)
92+
$sha1Suffix = $Hash.Substring(5)
93+
$URL = 'https://api.pwnedpasswords.com/range/' + $sha1Prefix
8694
break
8795
}
8896
default {
@@ -109,7 +117,13 @@ function Get-PwnedPassword {
109117
break
110118
}
111119
if ($Response.StatusCode -eq '200') {
112-
Write-Warning -Message "Oh No! - Password has been pwned - Change it NOW! `nYou should sign up for free at https://haveibeenpwned.com/ to be notified when your account is in a breach"
120+
if ($Response.Content.Contains($sha1Suffix.ToUpper())) {
121+
# Password has been pwned
122+
Write-Warning -Message "Oh No! - Password has been pwned - Change it NOW! `nYou should sign up for free at https://haveibeenpwned.com/ to be notified when your account is in a breach"
123+
}
124+
else {
125+
Write-Output "Hurrah! - No Password found - Congratulations this password has not been pwned. `nYou should still sign up for free at https://haveibeenpwned.com/ to be notified when your account is in a breach"
126+
}
113127
}
114128
}
115129
end {
@@ -123,7 +137,7 @@ function Get-PwnedPassword {
123137
124138
.AUTHOR Rob Sewell @sqldbawithbeard https://sqldbawithabeard.com
125139
126-
.DESCRIPTION Connects to the API at https://haveibeenpwned.com/ to see if a Password or Password hash has been found in a breach. Troy Hunt @troyhunt has created an API which allows you to query if a Password has been found in a breach. This is a simple function enabling you to query it
140+
.DESCRIPTION Connects to the API at https://api.pwnedpasswords.com/ to see if a Password or Password hash has been found in a breach. Troy Hunt @troyhunt has created an API which allows you to query if a Password has been found in a breach. This is a simple function enabling you to query it
127141
128142
.COMPANYNAME Sewells Consulting
129143

New-DummyFile.ps1

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<#
2+
.SYNOPSIS
3+
Creates a dummy empty file of a specified size
4+
5+
.DESCRIPTION
6+
This will create one or a number of empty files of a specified size
7+
Useful for creating demos or dummy files to delete as an emergency when
8+
drives are full
9+
10+
.PARAMETER FilePath
11+
The Directory for the files
12+
13+
.PARAMETER Name
14+
The Name of the file, will have underscore integer added if more than one file requested - If you include an extension it will retained otherwise it will have a .dmp extension
15+
16+
.PARAMETER Size
17+
The Size of the File(s) to be created in Mb unless the Gb switch is used
18+
19+
.PARAMETER Number
20+
The number of files to create defaults to 1
21+
22+
.PARAMETER Gb
23+
Switch to change Size to Gb instead of Mb
24+
25+
.PARAMETER Force
26+
OverWrite Existing Files
27+
28+
.EXAMPLE
29+
New-DummyFile -FilePath C:\temp -Name Jeremy -Size 10
30+
31+
Will create 1 file of size 10Mb called jeremy.dmp at C:\temp
32+
33+
.EXAMPLE
34+
New-DummyFile -FilePath C:\temp -Name Jeremy.txt -Size 10 -Number 10
35+
36+
Will create 10 files of size 10Mb called jeremy_N.txt where N is 1-10 at C:\temp
37+
38+
.EXAMPLE
39+
New-DummyFile -FilePath C:\temp -Name Jeremy -Size 10 -Gb
40+
41+
Will create 1 file of size 10Gb called jeremy.dmp at C:\temp
42+
43+
.EXAMPLE
44+
New-DummyFile -FilePath C:\temp -Name Jeremy.txt -Size 10 -Number 10 -Gb
45+
46+
Will create 10 files of size 10Gb called jeremy_N.txt where N is 1-10 at C:\temp
47+
48+
.EXAMPLE
49+
New-DummyFile -FilePath C:\temp -Name Jeremy -Size 10 -Force
50+
51+
Will create 1 file of size 10Mb called jeremy.dmp at C:\temp and overwrite the exisitng file if it exists
52+
53+
.NOTES
54+
SQLDBAWithABeard @SqlDbaWithABeard
55+
#>
56+
57+
function New-DummyFile {
58+
[CmdletBinding(SupportsShouldProcess)]
59+
Param (
60+
[Parameter(Mandatory = $true)]
61+
[string]$FilePath,
62+
[string]$Name = 'DummyFile',
63+
[Parameter(Mandatory = $true)]
64+
[int]$Size,
65+
[int]$Number = 1,
66+
[Switch]$Gb ,
67+
[switch]$Force
68+
)
69+
Begin {
70+
if ($Gb) {
71+
$SizeMsg = "$Size Gb"
72+
}
73+
else {
74+
$SizeMsg = "$Size Mb"
75+
}
76+
Write-Verbose "Creating $Number files of $SizeMsg named $Name at $FilePath "
77+
$fileSize = $Size * 1024 * 1024
78+
if ($Gb) {
79+
$fileSize = $fileSize * 1024
80+
}
81+
}
82+
Process {
83+
for ($i = 1; $i -le $Number; $i++) {
84+
$BaseName, $extension = $Name.Split('.')
85+
if ($null -eq $extension) { $extension = 'dmp' }
86+
if($i -ne 1){
87+
$FileName = "$FilePath\$($BaseName)_$i.$Extension"
88+
} else{
89+
$FileName = "$FilePath\$($BaseName).$Extension"
90+
}
91+
92+
if (-not $Force) {
93+
if (Test-Path $FileName) {
94+
Write-Warning "Nope I am not creating the file as -Force was not specified and $FileName already exists"
95+
Continue
96+
}
97+
}
98+
if ($PSCmdlet.ShouldProcess("$FilePath", "Creating $FileName ($i/$Number) $FilePath\$FileName")) {
99+
$file = [System.IO.File]::Create($FileName)
100+
$file.SetLength($fileSize)
101+
$file.Close()
102+
}
103+
}
104+
}
105+
End {
106+
Write-Verbose "Done!"
107+
}
108+
}

New-IsoFile.ps1

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
function New-IsoFile
2+
{
3+
<#
4+
.Synopsis
5+
Creates a new .iso file
6+
.Description
7+
The New-IsoFile cmdlet creates a new .iso file containing content from chosen folders
8+
.Example
9+
New-IsoFile "c:\tools","c:Downloads\utils"
10+
This command creates a .iso file in $env:temp folder (default location) that contains c:\tools and c:\downloads\utils folders. The folders themselves are included at the root of the .iso image.
11+
.Example
12+
New-IsoFile -FromClipboard -Verbose
13+
Before running this command, select and copy (Ctrl-C) files/folders in Explorer first.
14+
.Example
15+
dir c:\WinPE | New-IsoFile -Path c:\temp\WinPE.iso -BootFile "${env:ProgramFiles(x86)}\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\amd64\Oscdimg\efisys.bin" -Media DVDPLUSR -Title "WinPE"
16+
This command creates a bootable .iso file containing the content from c:\WinPE folder, but the folder itself isn't included. Boot file etfsboot.com can be found in Windows ADK. Refer to IMAPI_MEDIA_PHYSICAL_TYPE enumeration for possible media types: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366217(v=vs.85).aspx
17+
.Notes
18+
NAME: New-IsoFile
19+
AUTHOR: Chris Wu
20+
LASTEDIT: 03/23/2016 14:46:50
21+
#>
22+
23+
[CmdletBinding(DefaultParameterSetName='Source')]Param(
24+
[parameter(Position=1,Mandatory=$true,ValueFromPipeline=$true, ParameterSetName='Source')]$Source,
25+
[parameter(Position=2)][string]$Path = "$env:temp\$((Get-Date).ToString('yyyyMMdd-HHmmss.ffff')).iso",
26+
[ValidateScript({Test-Path -LiteralPath $_ -PathType Leaf})][string]$BootFile = $null,
27+
[ValidateSet('CDR','CDRW','DVDRAM','DVDPLUSR','DVDPLUSRW','DVDPLUSR_DUALLAYER','DVDDASHR','DVDDASHRW','DVDDASHR_DUALLAYER','DISK','DVDPLUSRW_DUALLAYER','BDR','BDRE')][string] $Media = 'DVDPLUSRW_DUALLAYER',
28+
[string]$Title = (Get-Date).ToString("yyyyMMdd-HHmmss.ffff"),
29+
[switch]$Force,
30+
[parameter(ParameterSetName='Clipboard')][switch]$FromClipboard
31+
)
32+
33+
Begin {
34+
($cp = new-object System.CodeDom.Compiler.CompilerParameters).CompilerOptions = '/unsafe'
35+
if (!('ISOFile' -as [type])) {
36+
Add-Type -CompilerParameters $cp -TypeDefinition @'
37+
public class ISOFile
38+
{
39+
public unsafe static void Create(string Path, object Stream, int BlockSize, int TotalBlocks)
40+
{
41+
int bytes = 0;
42+
byte[] buf = new byte[BlockSize];
43+
var ptr = (System.IntPtr)(&bytes);
44+
var o = System.IO.File.OpenWrite(Path);
45+
var i = Stream as System.Runtime.InteropServices.ComTypes.IStream;
46+
47+
if (o != null) {
48+
while (TotalBlocks-- > 0) {
49+
i.Read(buf, BlockSize, ptr); o.Write(buf, 0, bytes);
50+
}
51+
o.Flush(); o.Close();
52+
}
53+
}
54+
}
55+
'@
56+
}
57+
58+
if ($BootFile) {
59+
if('BDR','BDRE' -contains $Media) { Write-Warning "Bootable image doesn't seem to work with media type $Media" }
60+
($Stream = New-Object -ComObject ADODB.Stream -Property @{Type=1}).Open() # adFileTypeBinary
61+
$Stream.LoadFromFile((Get-Item -LiteralPath $BootFile).Fullname)
62+
($Boot = New-Object -ComObject IMAPI2FS.BootOptions).AssignBootImage($Stream)
63+
}
64+
65+
$MediaType = @('UNKNOWN','CDROM','CDR','CDRW','DVDROM','DVDRAM','DVDPLUSR','DVDPLUSRW','DVDPLUSR_DUALLAYER','DVDDASHR','DVDDASHRW','DVDDASHR_DUALLAYER','DISK','DVDPLUSRW_DUALLAYER','HDDVDROM','HDDVDR','HDDVDRAM','BDROM','BDR','BDRE')
66+
67+
Write-Verbose -Message "Selected media type is $Media with value $($MediaType.IndexOf($Media))"
68+
($Image = New-Object -com IMAPI2FS.MsftFileSystemImage -Property @{VolumeName=$Title}).ChooseImageDefaultsForMediaType($MediaType.IndexOf($Media))
69+
70+
if (!($Target = New-Item -Path $Path -ItemType File -Force:$Force -ErrorAction SilentlyContinue)) { Write-Error -Message "Cannot create file $Path. Use -Force parameter to overwrite if the target file already exists."; break }
71+
}
72+
73+
Process {
74+
if($FromClipboard) {
75+
if($PSVersionTable.PSVersion.Major -lt 5) { Write-Error -Message 'The -FromClipboard parameter is only supported on PowerShell v5 or higher'; break }
76+
$Source = Get-Clipboard -Format FileDropList
77+
}
78+
79+
foreach($item in $Source) {
80+
if($item -isnot [System.IO.FileInfo] -and $item -isnot [System.IO.DirectoryInfo]) {
81+
$item = Get-Item -LiteralPath $item
82+
}
83+
84+
if($item) {
85+
Write-Verbose -Message "Adding item to the target image: $($item.FullName)"
86+
try { $Image.Root.AddTree($item.FullName, $true) } catch { Write-Error -Message ($_.Exception.Message.Trim() + ' Try a different media type.') }
87+
}
88+
}
89+
}
90+
91+
End {
92+
if ($Boot) { $Image.BootImageOptions=$Boot }
93+
$Result = $Image.CreateResultImage()
94+
[ISOFile]::Create($Target.FullName,$Result.ImageStream,$Result.BlockSize,$Result.TotalBlocks)
95+
Write-Verbose -Message "Target image ($($Target.FullName)) has been created"
96+
$Target
97+
}
98+
}

0 commit comments

Comments
 (0)