Skip to content

Instantly share code, notes, and snippets.

View JohnRoos's full-sized avatar

John Roos JohnRoos

View GitHub Profile
@JohnRoos
JohnRoos / ScriptingGames2015-July.ps1
Last active August 29, 2015 14:24
PowerShell Scripting Games 2015 - July
#Am I the only one using CIM?
gcim Win32_OperatingSystem -cn Win81|ft PSC*,*aj*,V*,@{n='BIOSSerial';e={(gcim win32_Bios -cn $_.csname).SerialNumber}}
@JohnRoos
JohnRoos / Scripts.ps1
Last active August 29, 2015 14:24
Scripts
### Which AD groups do I manage?
get-adgroup -LD "(ManagedBy=$((Get-ADUser -id $env:username).distinguishedname))" | select name
### Edit the ISE profile
if (Test-Path -Path $profile){
psedit $profile
}else{
New-Item -Path $profile -ItemType file -Force -Value
psedit $profile
}
@JohnRoos
JohnRoos / ShowAllGists.html
Last active August 29, 2015 14:24
Show all gists
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<div id="placeholder"></div>
<script>
var username = 'johnbravo'
$.getJSON('https://api.github.com/users/' + username + '/gists', function (data) {
for (var i in data) {
var oldDocumentWrite = document.write
@JohnRoos
JohnRoos / SimpleSelectFromDB.ps1
Created July 14, 2015 09:22
Simple select from database using PowerShell
# Variables for server, database and query
$server = 'localhost\sqlexpress'
$database = 'test'
$query = 'select top 10 * from fjutt'
# Set up the objects needed
$connection = New-Object -TypeName System.Data.SqlClient.SqlConnection
$adapter = New-Object -TypeName System.Data.SqlClient.SqlDataAdapter $command
$dataset = New-Object -TypeName System.Data.DataSet
@JohnRoos
JohnRoos / XpressionClass.ps1
Last active August 29, 2015 14:24
Xpression class
class Xpression
{
[string]$Name
[scriptblock]$Expression
[hashtable] getExpression() {
return @{ Name = $this.Name; Expression = $this.Expression }
}
}
class XpressionArray
@JohnRoos
JohnRoos / Get-ParamAlias.ps1
Created August 3, 2015 15:59
Get parameter alias
# Enter the cmdlet you want to see parameter variables for:
$cmdlet = 'Get-Process'
$out = @{}
foreach ( $param in (get-command $cmdlet).Parameters.Keys ){
$aliases = ''
foreach ( $a in $cmd.Parameters.$param.Aliases ){
$aliases += "$a "
}
@JohnRoos
JohnRoos / Play-JingleBells.ps1
Created December 23, 2015 13:51
Play-JingleBells.ps1
function Play-JingleBells {
[System.Console]::Beep(659, 300);
[System.Console]::Beep(659, 300);
[System.Console]::Beep(659, 300);
[System.Threading.Thread]::Sleep(300);
[System.Console]::Beep(659, 300);
[System.Console]::Beep(659, 300);
[System.Console]::Beep(659, 300);
[System.Threading.Thread]::Sleep(300);
[System.Console]::Beep(659, 300);
@JohnRoos
JohnRoos / ConvertSecureToString.ps1
Created May 29, 2017 18:15
Convert secure string to plain text
function ConvertSecureToString
{
[CmdletBinding()]
[OutputType([String])]
param (
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
Position=0)]
[ValidateNotNull()]
[SecureString]
function Get-FileEncoding {
[CmdletBinding()]
param (
[ValidateScript({Test-Path -Path $_})]
[string]$Path
)
$fullpath = (Resolve-Path -Path $Path).Path
$file = [System.IO.FileStream]::new($fullpath,[System.IO.FileMode]::Open)
#region LabModule.psd1
@{
RootModule = 'LabModule.psm1'
ModuleVersion = '1.0'
GUID = 'd00578f5-fb6b-4c47-83fb-ed1c8d9a1ec2'
FunctionsToExport = 'Get-PublicStuff'
}
#endregion