Skip to content

Instantly share code, notes, and snippets.

@joegasper
joegasper / Check-ExchLogStorage.ps1
Created July 19, 2016 16:59
Exchange: Collect total storage size for .log files older than 30 days in standard logging path
[ScriptBlock]$cmd = {
$SizeGb = 0; Get-ChildItem -Path 'C:\Program Files\Microsoft\Exchange Server\V15\Logging' -Recurse -Filter '*.log' | ? {$_.LastWriteTime -lt (Get-Date).AddDays(-30)} | % {$SizeGb += $_.Length/1024/1024/1024}; Write-Output $SizeGb
}
#assumes your systems are named 'myexchbox01', 'myexchbox02', etc.
1..20 | % { $exmbx = 'myexchbox' + '{0:D2}' -f $_; $ServerGB = Invoke-Command -ComputerName $exmbx -ScriptBlock $cmd; Write-Output "$exmbx = $ServerGB" }
@joegasper
joegasper / Get-AdDnsReplicationTime.ps1
Last active August 23, 2016 01:56
Time the replication of an Active Directory DNS record
#Requires -Version 4.0
#Create your record and then immediately run this script
$domainSuffix = '.my.domain.edu' #domain suffix for less typing
$client = 'dept-joe04' #client to query for on the DCs
$DNStype = 'CNAME' #type of DNS record to query
$DCs = @('dc-01','dc-02','dc-03','dc-04') #DCs to query against
$DClength = (-join $DCs).Length #for determining when all DCs have answered
$DCdone = '' #string that collects DC names as they answer
Write-Output "Checking $client at $(Get-Date)"
@joegasper
joegasper / Collect-PerfCounters.ps1
Last active August 26, 2016 04:24
Collect performance counters across a list of systems
$counters = @('\Paging File(_total)\% Usage','\Paging File(_total)\% Usage Peak','\Memory\Available MBytes','\Memory\% Committed Bytes In Use','\System\System Up Time')
$servers = @()
#assumes your systems are named 'myexchbox01', 'myexchbox02', etc. and you have 20 of them
1..20 | % { $servers += 'myexchbox' + '{0:D2}' -f $_ }
$Path = 'C:\Work\Perf\'
$filename = 'Exchange'
$delay = 1
$count = 1
$sequence = 1
$testrun = Get-Date -Format yyyy-MM-dd
@joegasper
joegasper / Sync-AzWebsite.ps1
Last active September 2, 2016 23:33
Sync an Azure Web Site using Continuous Deployment with PowerShell
Import-Module AzureRM.Websites
Login-AzureRmAccount
$MyResourceGroup = 'myresourcegroupname'
$MyResourceName = 'myresourcename'
Invoke-AzureRmResourceAction -ResourceGroupName $MyResourceGroup -ResourceType Microsoft.Web/sites -ResourceName $MyResourceName -Action sync -ApiVersion 2015-08-01 -Force -Verbose
#Wi-Fi Connection Information
$data = (netsh wlan show networks mode=Bssid |
where {$_ -like "SSID*" -or $_ -like "*Authentication*" -or $_ -like "*Encryption*" -or $_ -like "*Signal*"}).trim()
$result = for ( $i = 0; $i -lt $data.count; ) {
'' | Select @{n='Connection';e={($data[$i].split(':')[1]).trim()}},
@{n='Authentication';e={($data[$i+1].split(':')[1]).trim()}},
@{n='Encryption';e={($data[$i+2].split(':')[1]).trim()}},
@{n='Signal';e={($data[$i+3].split(':')[1]).trim()}}
$i = $i + 4
}

Keybase proof

I hereby claim:

  • I am joegasper on github.
  • I am joegasper (https://keybase.io/joegasper) on keybase.
  • I have a public key ASDCmG_QehgIwQJf6B46RTYvKYONihcYoWYJFBjgf5AZdwo

To claim this, I am signing this object:

@joegasper
joegasper / Fibonacci-Sequence
Last active February 26, 2017 20:19
Calculating Fibonacci Sequence to n values or calculating a specific nth value
#Show all values in sequence up to number $seqnum
[int]$seqnum = 10
$fibseq = @()
for($i = 0; $i -lt $seqnum; $i++) {
if ($i -eq 0 ) {
$fibseq = $fibseq + 0
}
if ($i -eq 1 ) {
$fibseq = $fibseq + $i
}
@joegasper
joegasper / Get-WordPressVersion.ps1
Created April 28, 2017 14:32
Get WordPress Version
#Simple check on a generic WordPress site
$page = Invoke-WebRequest -Uri http://mywordpress03.site
$WPver = ($page.Scripts.src).where({$_ -match 'wp-embed.min'}).Split('=')[1]
@joegasper
joegasper / Robocopy-WithPS.ps1
Created December 1, 2017 20:24
Run Robocopy with PowerShell
$site = 'mysite01'
$source = "\\my-web1\e$\websites\$site\"
$destination = "E:\websites\$site\"
#List only first
$logfile = "E:\$site-robo-test.txt"
$switches = "/E /L /R:2 /W:3 /NP /FFT /DST /LOG:$logfile /XF "".DS_Store"" ""thumbs.db"""
& robocopy.exe $source $destination $switches.Split(' ')
#Check Log File
Get-Content -Path $logfile -First 17
@joegasper
joegasper / Get-ShadowBox.ps1
Last active February 10, 2020 20:59
Remote Desktop Session Shadowing Mode in Windows 10
#Inspired by http://woshub.com/rdp-session-shadow-to-windows-10-user/
#You could feed ConvertFrom-String a template to have a perfect object from the qwinsta.exe command, but I didn't want to
#have to keep the template file around.
#This is quicker than walking someone through Quick Assist, but QA will work over the internet.
#This command will shadow a user's Windows 10 system and you will have control (after remote user's consent if you are proper - see GPO in the link).
$PC=(Read-Host -Prompt "PC Name");$ID = (qwinsta.exe /server:$PC | ConvertFrom-String | Where-Object P2 -eq console | select P4).P4;mstsc.exe /shadow:$ID /v:$PC /control