Skip to content

Instantly share code, notes, and snippets.

@jonathanelbailey
jonathanelbailey / GetUsersNotLoggedIn.ps1
Last active October 6, 2015 17:15
A small script that allows an administrator to get a list of all users who have not logged in to a terminal server.
# you must be logged in to the terminal server in question.
$session = New-PSSession -ComputerName $ComputerName # this must be the name of the DC whose session you must import.
Invoke-Command -ScriptBlock {Import-Module ActiveDirectory} -Session $session
Import-PSSession -Module activedirectory -Session $session
$ou = Get-ADOrganizationalUnit -Filter * -Properties * | where-object name -match "$OUName"
$users = Get-ADUser -Filter * -Properties * | Where-Object distinguishedname -Match $ou.distinguishedname
@jonathanelbailey
jonathanelbailey / SamplePushConfig.ps1
Created September 30, 2015 21:58
A PowerShell Desired State Configuration Script that configures a server with the DNS and DHCP roles, and configures said roles for a web farm.
<#
Sample DSC Configuration for a DNS/DHCP Server
DNS is configured to house addresses for a server pool and a sql server
DHCP is configured for reservations to the server pool
Script was tested in a DSC push configuration.
Tested using Server 2012 R2 DC Core running PowerShell v4.
Server is not joined to a domain.
Test Server has two virtual network interfaces with one configured as "TestInt".
Before testing, please run the following on the test server:
winrm qc
@jonathanelbailey
jonathanelbailey / push-desktoppackages.ps1
Last active October 6, 2015 00:10
A script that demonstrates the ease by which a windows machine can be provisioned using Chocolatey and PsRemoting.
$scriptblock = {choco.exe install adobereader -y
choco.exe install openoffice -y}
$servers = Get-ADComputer -Filter * -Properties * | Where-Object name -match $SomeName
foreach ($s in $servers){
$session = new-pssession $s
Invoke-Command -ScriptBlock $scriptblock -Session $session
}
@jonathanelbailey
jonathanelbailey / Mount-Lvm.sh
Last active October 14, 2015 14:29
A script that creates an LVM and mounts it.
PhysVol = "$1"
VolSize = "$2"
MountDir = "$3"
pvcreate $PhysVol
pvdisplay $PhysVol
vgcreate volgrp1 $PhysVol
lvcreate -L $VolSize -n LogVol1
@jonathanelbailey
jonathanelbailey / WikiScrape.py
Created October 6, 2015 00:49
A Python script that uses MWClient to work with the MediaWiki API.
## This script was tested using Python 2.7.9
## The MWClient library was used to access the api. It can be found at:
## https://github.com/mwclient/mwclient
import mwclient
site = mwclient.Site(('https', 'en.wikipedia.org'))
site.login('$user', '$pass') # credentials are sanitized from the script.
listpage = site.Pages['User:$user/World_of_Warcraft'] # page is sanitized.
text = listpage.text()
for page in site.Categories['World_of_Warcraft']:
@jonathanelbailey
jonathanelbailey / Install-Sql2012.ps1
Last active September 29, 2022 17:34
A function that installs sql 2012 silently.
$SqlInstance = 'MsSqlServer'
$QuietSimple = $true
$x86 = $false
$InstanceName = 'SqlExpress'
$Pass = 'P@$$w0rd'
$chocopath = 'c:\programdata\chocolatey'
$Source = @"
;SQL Server 2012 Configuration File
; SQL-2012-Base.ini
@jonathanelbailey
jonathanelbailey / Set-UefiActivation.ps1
Last active October 10, 2020 02:44
A Function that utilizes oa3tool.exe to activate Windows 8/8.1 32/64-bit.
Function Set-UEFIActivation{
<#
.NAME
Set-UEFIActivation
.AUTHOR
Jonathan Bailey
.SYNOPSIS
Pulls the Product key hex value from the motherboard, converts it to ASCII, and pipes it to slmgr.vbs for activation.
.SYNTAX
Set-UEFIActivation [-OA3ToolPath] <string>
@jonathanelbailey
jonathanelbailey / Export-VMArchives.ps1
Last active October 7, 2015 16:06
A few functions that allow you to manage export of VMs for archiving.
Function Remove-Checkpointsforexport{
Param( [ValidateSet('All','RDP','SQL','DC')]
$VMScope )
BEGIN{}
PROCESS{
switch ($VMScope){
ALL { $VMs = Get-VM }
RDP { $VMs = Get-VM | Where-Object name -Match 'RDP' }
SQL { $VMs = Get-VM | Where-Object name -Match 'SQL' }
DC { $VMs = Get-VM | Where-Object name -Match 'DC' }
@jonathanelbailey
jonathanelbailey / New-RdpVm.ps1
Created October 7, 2015 21:23
A set of functions that create a Virtual Machine and its VHD.
New-RdpVmConfig{
Param( $Name,
$SwitchName,
$VhdPath,
$Path )
BEGIN{}
PROCESS{
New-VM -Name $Name -MemoryStartupBytes 2048 -BootDevice VHD -SwitchName $SwitchName -VHDPath $VhdPath -Path $Path -Generation 1
Set-VM -Name $Name -ProcessorCount 4 -DynamicMemory $true -MemoryMinimumBytes 2048
Enable-VMIntegrationService -VMName $Name
@jonathanelbailey
jonathanelbailey / Set-LegacyConsoleSettings.ps1
Created October 7, 2015 21:54
A function that allows the configuration of Windows 10 32-bit OS for 16-bit application support
Function Set-SSSLegacyConsoleSettings{
BEGIN{
$checkwin10 = Gcim win32_operatingsystem
}
PROCESS{
if ($checkwin10.Name -notmatch 'Windows 10'){
Write-Host 'No update needed. Operating system must be Windows 10.' -ForegroundColor Green
}
else{
if ((Get-WindowsOptionalFeature -Online -featurename ntvdm).state -ne 'enabled'){