Skip to content

Instantly share code, notes, and snippets.

View janegilring's full-sized avatar

Jan Egil Ring janegilring

View GitHub Profile
@janegilring
janegilring / 2013SGEvent3BeginnerSample.ps1
Created May 16, 2013 20:34
Entry from the 2013 Scripting Games Beginner Event 3, reviewed at blog.powershell.no
Get-CimInstance -ClassName Win32_LogicalDisk -ComputerName localhost -Filter 'DriveType = 3' -Property DeviceID,Size,FreeSpace |
Select-Object -Property @{Name="Drive";Expression={$_.DeviceID}},
@{Name="Size(GB)";Expression={"{0:N2}" -f ($_.Size/1GB)}},
@{Name="FreeSpace(MB)";Expression={"{0:N2}" -f ($_.FreeSpace/1MB)}} |
ConvertTo-Html -Property Drive,'Size(GB)','FreeSpace(MB)' `
-Head "<title>Disk Free Space Report</title><h2>Local Fixed Disk Report</h2>" `
-PostContent "<hr>",(Get-Date) |
@janegilring
janegilring / 2013SGEvent3AdvancedSample.ps1
Created May 16, 2013 21:20
Entry from the 2013 Scripting Games Advanced Event 3, reviewed at blog.powershell.no
function Ping-SYHost ([string] $hostName) {
<#
    .SYNOPSIS
        Tests server availability by using PING command.
         
    .DESCRIPTION
        This script will ping a host and return TRUE/FALSE.  Use this function to determine if the host is reachable.
               
    .EXAMPLE
        Ping-SYHost -hostName "CHAGRES01"
@janegilring
janegilring / 2013SGEvent4BeginnerSample.ps1
Created May 22, 2013 09:24
Entry from the 2013 Scripting Games Beginner Event 4, reviewed at blog.powershell.no
<#
.SYNOPSIS
This will export info on 20 randomly selected AD users to an html
file located on the desktop of the user running it.
It will provide the username, department, title, last logon time,
last password change and account enabled / lockout status sorted by user.
***Notes***
It will import the AD module in order to use Get-ADUser.
@janegilring
janegilring / 2013SGEvent4AdvancedSample.ps1
Created May 22, 2013 10:36
Entry from the 2013 Scripting Games Advanced Event 4, reviewed at blog.powershell.no
#Requires -Version 3.0 -Module ActiveDirectory
<#
.SYNOPSIS
Create a report of randomly selected Active Directory users to be provided to auditors.
.DESCRIPTION
Randomly sample all Active Directory user accounts and create an html report of the
following properties: SamAccountName, Department, Title, LastLogonDate, PasswordLastSet, Enabled, LockedOut
@janegilring
janegilring / 2013SGEvent5BeginnerSample.ps1
Created May 28, 2013 18:08
Entry from the 2013 Scripting Games Beginner Event 5, reviewed at blog.powershell.no
<#
.SYNOPSIS
Gets the Unique IP Information from a directory of *.log files.
.DESCRIPTION
This script was written for the Event 5 Beginners Track in the 2013 Scripting Games.
It will look through IIS logs in a directory and all sub directories and pull out a
list of unique ip's.
.PARAMETER PathToLogs
Path to the Log files (Example C:\Temp\LogFiles\)
.EXAMPLE
@janegilring
janegilring / 2013SGEvent5AdvancedSample.ps1
Created May 28, 2013 18:45
Entry from the 2013 Scripting Games Advanced Event 5, reviewed at blog.powershell.no
<#
.Synopsis
   Gets client IP collection from IIS logs
.DESCRIPTION
   Extracts the Client IP addresses from IIS logs, and returns the unique addresses
   found.  Optionally, it will include counts of how many times each address appeared
   in the logs, by enabling the -Count switch. If -Count is enabled you can return either
   a collection of PS objects having ClientIP and Count properties, or a hash table of the
   ip addresses and counts by using the -AsHash switch.
.PARAMETER Path
@janegilring
janegilring / 2013SGEvent6BeginnerSample.ps1
Created June 8, 2013 19:57
Entry from the 2013 Scripting Games Beginner Event 6, reviewed at blog.powershell.no
# Requires -Version 3.0
 
<#
.SYNOPSIS
    This script is used to perform basic configuration tasks on one or many Server 2012 core installations.
.DESCRIPTION
    New-CoreVMConfig is a script that will import a list of MAC addresses located at C:\Mac.txt by default and then query the DHCP server using the DhcpServer module
    introduced in PowerShell 3.0 and Server 2012 to determine its associated dynamically assigned IP address.  When these results have been gathered we will process
    each IP address one at a time, joining the machine to the domain.  During the join operation we will also be renaming the machine to SERVER(count) as well as
    restarting the machine after the join is completed.  This operation will force the join and will not propmt the user for confirmation as defined by the event 6
@janegilring
janegilring / 2013SGEvent6AdvancedSample.ps1
Created June 8, 2013 20:41
Entry from the 2013 Scripting Games Advanced Event 6, reviewed at blog.powershell.no
function  Join-Computer {
 
    <#
        .SYNOPSIS
            Adds server core machines to the domain from MAC address.
 
        .DESCRIPTION
            Takes a list of mac address and queries DHCP server for IP address.
            Machines are then renamed and joined to the domain.
 
@janegilring
janegilring / CM12Client-functions.ps1
Created June 16, 2013 11:30
Sample PowerShell functions for working with the ROOT\ccm\ClientSDK WMI namespace. For more info, see the related article on blog.powershell.no.
function Get-CMMissingUpdate {
param (
$computer = "localhost"
)
Get-WmiObject -Query "SELECT * FROM CCM_SoftwareUpdate" -Namespace "ROOT\ccm\ClientSDK" -ComputerName $computer
}
@janegilring
janegilring / Get-CommandGridView
Created August 2, 2013 13:13
Get-CommandGridView is a PowerShell function for exploring modules and snapins. You can read more by searching for Get-CommandGridView at blog.powershell.no
#requires -version 3
Function Get-CommandGridView {
[cmdletbinding()]
Param([string]$Module,
[ValidateRange(1,20)]
[int]$MaxHelpWindowCount = 5
)