Skip to content

Instantly share code, notes, and snippets.

View thomasrayner's full-sized avatar
😸
Write code, pet cats.

Thomas Rayner thomasrayner

😸
Write code, pet cats.
View GitHub Profile
$Computers = @('comp1','comp2'); Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computers | Format-Table PSComputerName,ServicePackMajorVersion,Version,@{N='BIOSSerial';E={$(Get-WMIObject -Class Win32_BIOS -ComputerName $_.PSComputerName).SerialNumber}}
@thomasrayner
thomasrayner / 2015-August Scripting Puzzle.ps1
Created August 4, 2015 15:22
2015-August Scripting Puzzle
#One-liner
Invoke-WebRequest http://www.telize.com/geoip | ConvertFrom-Json | Format-Table Longitude,Latitude,Continent_Code,Timezone -AutoSize
#Function
function Get-GeoIP
{
param
(
[array]$Attributes = '*',
[IPAddress]$IP
$filefrom = 'c:\temp\something.txt'
$fileto = 'c:\temp\1\something.txt'
if (-not (test-path $fileto))
{
$opts = @{'path' = $filefrom; 'destination' = $fileto; 'confirm' = $false}
copy-item @opts
}
else
{
$opts = @{'path' = $filefrom; 'destination' = $fileto; 'confirm' = $true}
$dir = 'c:\temp'
$who = 'domain\user'
$acl = Get-Acl $dir
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($who,"Modify, DeleteSubdirectoriesAndFiles","ContainerInherit, ObjectInherit","None","Allow")
$acl.AddAccessRule($rule)
Set-Acl $dir $acl
function something {
[CmdletBinding()]
param(
)
write-verbose 'something verbose'
}
#outputs nothing
something
$UTCTime = $(whatever-code-got-you-utc-time)
$strCurrentTimeZone = (Get-WmiObject win32_timezone).StandardName
$TZ = [System.TimeZoneInfo]::FindSystemTimeZoneById($strCurrentTimeZone)
$LocalTime = [System.TimeZoneInfo]::ConvertTimeFromUtc($UTCTime, $TZ)
$groups = import-csv "$(get-temp)\groups.csv"
foreach ($gr in $($groups.group))
{
Get-ADGroupMember $gr | % { Get-ADUser $_.SamAccountName -properties Enabled }
}
(get-command gimme-exchange).definition
$arrExchangeServersURI = @("http://redacted/Powershell","http://redacted2/Powershell")
$success = $false
ForEach ($connectionURI in $arrExchangeServersURI)
{
Try
{
If($success -ne $true)
{
function Get-SearchResults {
[CmdletBinding()]
param(
[Parameter(Mandatory,Position=0)]
[string]$SearchTerms
)
$searchURL = "http://www.bing.com/search?q=$([System.Web.HttpUtility]::UrlEncode($searchTerms))"
$searchResults = Invoke-WebRequest $searchURL
$searchResults.links | ? { $_.href -match 'http' } | select innertext,href -first 10
#don't store names and members in variables like this
#don't name variables like this
#handle hashtable "already contains key" errors better than this
#don't do this
$list1 = 'list1 name'
$list1mem = @('list 1 members')
 
$list2 = 'list2 name'
$list2mem = @('list 2 members')