This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Install-WindowsUpdates($computerName) { | |
| $command = { | |
| if (! (Test-Path c:\updates )) { New-Item c:\updates -ItemType Directory } | |
| if (Test-Path c:\updates\installUpdates.ps1 ) { Remove-Item c:\updates\installUpdates.ps1 -Force -Confirm:$false } | |
| "Get-WUInstall -AcceptAll -AutoReboot -Verbose " | Out-File c:\updates\installUpdates.ps1 | |
| } | |
| Invoke-Command -ComputerName $computerName -ScriptBlock $command | |
| ##WSUS doesn't like remote execution... so we have to jump through several hoops to make it think it's executing locally.... | |
| if (Test-Path \\$computerName\c$\updates\prepareForReboot.ps1 ) { | |
| ## Prepare for reboot is an optional script you can install on the remote server to gracefully shutdown things before reboot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-DotNetVersion { | |
| [cmdletbinding()] | |
| Param( | |
| [Parameter(ValueFromPipeline=$True)] [object] $ComputerName | |
| ) | |
| BEGIN { | |
| } | |
| PROCESS { | |
| if (-not $ComputerName) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static byte[] GetDirectoryHash(string path) | |
| { | |
| var fileCount = 0; | |
| var fileHasher = SHA1Managed.Create(); | |
| var sumHasher = SHA1Managed.Create(); | |
| sumHasher.Initialize(); | |
| var sw = new Stopwatch(); | |
| sw.Start(); | |
| foreach (var file in Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //License: | |
| // This code was authored by Steven Swenson (github.com/ctigeek, twitter.com/ctigeek) | |
| // and is released under the MIT license. | |
| // https://opensource.org/licenses/MIT | |
| // | |
| // Use cases for this code: | |
| // You need to have an in-memory dictionary that's only added to, and is typically built when the process spins up. | |
| // You can add items to the dictionary at any time, but it's expensive (i.e. it rebuilds the entire underlying dict) but reads are extrememly fast. | |
| // You can easily augment this code to implement a remove function, but if you're doing lots of adds and removes you're probably better off using a regular ConcurrentDictionary. | |
| // It *does* allow you to modify values. This is slightly misleading since it implements IReadOnlyDictionary. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // **snip*** | |
| } else { | |
| mongo = { | |
| db: 'db', | |
| host: 'localhost', | |
| password: 'pass', | |
| port: 27017, | |
| url: '"mongodb://localhost:27017/db', | |
| username: 'admin', | |
| ssl: true // <<<--------------Add this.... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Start-Sleep($seconds) { | |
| $doneDT = (Get-Date).AddSeconds($seconds) | |
| while($doneDT -gt (Get-Date)) { | |
| $secondsLeft = $doneDT.Subtract((Get-Date)).TotalSeconds | |
| $percent = ($seconds - $secondsLeft) / $seconds * 100 | |
| Write-Progress -Activity "Sleeping" -Status "Sleeping..." -SecondsRemaining $secondsLeft -PercentComplete $percent | |
| [System.Threading.Thread]::Sleep(500) | |
| } | |
| Write-Progress -Activity "Sleeping" -Status "Sleeping..." -SecondsRemaining 0 -Completed | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Compare-XmlDocs($actual, $expected) { | |
| if ($actual.Name -ne $expected.Name) { | |
| throw "Actual name not same as expected: actual=" + $actual.Name | |
| } | |
| ##attributes... | |
| if ($actual.Attributes.Count -ne $expected.Attributes.Count) { | |
| throw "attribute mismatch for actual=" + $actual.Name | |
| } | |
| for ($i=0;$i -lt $expected.Attributes.Count; $i =$i+1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void SetInt64(this ISession session, string key, long lng) | |
| { | |
| var bytes = BitConverter.GetBytes(lng); | |
| session.Set(key, bytes); | |
| } | |
| public static long GetInt64(this ISession session, string key, long defaultIfNull) | |
| { | |
| var bytes = session.Get(key); | |
| if (bytes == null || bytes.Length == 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Send-SlackNotification($message) { | |
| $url = "https://slack.com/api/chat.postMessage" | |
| $headers = @{"Content-Type"="application/x-www-form-urlencoded";"User-Agent"="SlackBot"} | |
| $body = @{ token="PUT_YOUR_BOT_KEY_HERE"; channel="PUT_CHANNEL_HERE"; text=$message; as_user="true"; } | |
| ##If you are using powershell v5 you can change this to Invoke-RestMethod. | |
| ##The UsePasicParsing option is not supported in v4 for Invoke-RestMethod, and you really want that option. | |
| $result = Invoke-WebRequest -Uri $url -Body $body -Headers $headers -Method Post -ErrorAction SilentlyContinue -UseBasicParsing | |
| $result.Content | ConvertFrom-Json | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| **Encryption doesn't have to be difficult!** | |
| In this pragmatic talk we'll be discussing how to use cryptography in your application. | |
| As an example, we'll walk through how to use various cryptographic technologies to design an end-to-end encrypted chat application. | |
| What kind of encryption do you use? | |
| What are the most common and secure configurations? | |
| And most importantly how do you integrate it into your software? | |
| We'll address all these questions and walk through code samples in c#. | |
| We'll cover symmetrical (AES) and public-key cryptographic algorithms, along with multiple types of hashing, | |
| and various use-cases for each. | |
| Cryptography configuration can sometimes be tricky, but we'll look at the most secure and versatile configurations for each methodology. |