Skip to content

Instantly share code, notes, and snippets.

@nikyodo85
nikyodo85 / DiskPartPowerShell.psm1
Last active October 31, 2018 22:10
Created this to extract information from diskpart. As of this writing, it supports the following disk part commands: "list disk", "list partition", "list volume", "shrink querymax", "detail disk"
function Parse-SizeUnit {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)][string]$SizeUnit
)
$SizeUnit = $SizeUnit.Trim()
$Size = 0;
$Unit = 'B';
@nikyodo85
nikyodo85 / SizeUnit.psm1
Last active October 31, 2018 16:41
Just a quick module with a function to parse size unit. For example: Parse-SizeUnit "1GB" or "1 GB" will return 1073741824. Improve support up to YottaByte.
function Parse-SizeUnit {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)][string]$SizeUnit
)
$SizeUnit = $SizeUnit.Trim()
$Size = 0;
$Unit = 'B';
@nikyodo85
nikyodo85 / ConvertTo-Object.psm1
Created October 24, 2018 22:17
Was looking for a way to easily convert output of df command in Linux to PowerShell object and ended up writing a simple one my own. This will take string array and by default, attempt to create properties from the first entry/ element. Non-alphanumeric character of property name will be replaced with empty string and property name will be prefi…
function ConvertTo-Object {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, Position=0)][string[]] $StringArray,
[int] $PropertiesRowIndex = 0,
[string] $Separator = '\s+'
)
$Properties = $StringArray[$PropertiesRowIndex] -split $Separator
@nikyodo85
nikyodo85 / DiskDrivesToEbsVolumesMapping.json
Created October 16, 2018 17:40
AWS SSM Document to map disk drives attached to EC2 to EBS Volumes. This is a slightly customized version of code in https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-windows-volumes.html and only for windows as of this version. This document will output the result as json.
{
"schemaVersion": "2.2",
"description": "Map Disk Drives to EBS Volumes",
"mainSteps": [
{
"name": "DisksToVolumesMappingWindows",
"action": "aws:runPowerShellScript",
"precondition": {
"StringEquals": [
"platformType",
@nikyodo85
nikyodo85 / querystring.js
Created October 16, 2018 17:30
Function to extract query string from address bar and return them as Javascript array. Usage: var qs = getQueryString(); var value = qs["key"];
function getQueryString() {
var qsDict = {};
var qs = location.search.substr(1).split("&");
function decode(s) { return decodeURIComponent(s.replace(/\+/g, " ")); };
for (var i = 0; i < qs.length; i += 1) {
var qKV = qs[i].split('=');
if (qKV.length > 1) {
qsDict[decode(qKV[0])] = decode(qKV[1]);
@nikyodo85
nikyodo85 / EFSqlBulkCopy.vb
Created September 28, 2018 18:27
Allow inserting Entity Framework entities to the database using SqlBulkCopy
Imports System.ComponentModel.DataAnnotations.Schema
Imports System.Data.Common
Imports System.Data.Entity.Core.Metadata
Imports System.Reflection
Imports System.Data.Entity
Public Class EFSqlBulkCopy(Of T As Class)
Public Property DestinationTableName As String
@nikyodo85
nikyodo85 / IEnumerableExtensions.vb
Last active October 2, 2018 17:45
VB.NET extension method to sort IEnumerable of entities from Entity Framework by specifying either property name or column name (through column attribute). It is updated to support multiple columns and remove case sensitivity. For example: list.SortBy("propertyName, columeAttributeName DESC")
Imports System.ComponentModel.DataAnnotations.Schema
Imports System.Reflection
Imports System.Runtime.CompilerServices
Public Module IEnumerableExtensions
<Extension>
Public Function SortBy(Of T)(list As IEnumerable(Of T), sortByParams As String) As IEnumerable(Of T)
If String.IsNullOrWhiteSpace(sortByParams) Then
Return list
End If