Skip to content

Instantly share code, notes, and snippets.

@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
@joegasper
joegasper / Download-MsftEbooks.ps1
Last active October 24, 2024 09:58
Download free Microsoft eBooks in massive list provided by Microsoft
#[1] https://blogs.msdn.microsoft.com/mssmallbiz/2016/07/10/how-to-download-all-of-the-free-ebooks-and-resources-in-my-free-ebooks-giveaway/
#[2] https://blogs.msdn.microsoft.com/mssmallbiz/2017/07/11/largest-free-microsoft-ebook-giveaway-im-giving-away-millions-of-free-microsoft-ebooks-again-including-windows-10-office-365-office-2016-power-bi-azure-windows-8-1-office-2013-sharepo/
#Some links are to webpages or Sway, I'd like to save the link to these pages - still to do.
$saveTo = 'D:\MS_eBooks\' #where to place the eBooks
New-Item -Path $saveTo -ItemType Directory
$masterListLink = 'http://ligman.me/29zpthb' #[1] link to the text file of links to the eBooks.
#$masterListLink = 'http://ligman.me/2sZVmcG' #[2] link to the text file of links to the eBooks.
#Get an array of links, triming the header in the first line.
$eBookLinks = @((Invoke-WebRequest -Uri $masterListLink -MaximumRedirection 1).Content -split "`n" | % {$_.trim()} | select -Skip 1 )
foreach ($eBookLink in $eBookLinks) {
@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 / 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 / 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)"
#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 / ConvertFrom-DN
Last active June 5, 2024 02:37
Convert between DistinguishedName and CanonicalName
#Updated ConvertFrom-DN to support container objects
function ConvertFrom-DN {
[cmdletbinding()]
param(
[Parameter(Mandatory, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
[ValidateNotNullOrEmpty()]
[string[]]$DistinguishedName
)
process {