Skip to content

Instantly share code, notes, and snippets.

View chrisbrownie's full-sized avatar
🛩️
computering

Chris Brown chrisbrownie

🛩️
computering
View GitHub Profile
@chrisbrownie
chrisbrownie / foreachas.ps1
Created August 10, 2017 05:19
Allows the pipeline'd "foreach" to be assigned a value other than $_
function foreachas {
Param(
[char]$as,
[ScriptBlock]$sb
)
PROCESS {
Set-Variable -Name $as -Value $_
Invoke-Command -ScriptBlock $sb
Param(
[String]$Path
)
$pfShortName = ($Path -replace "^\\\\[A-Za-z0-0@\-_. ]*\\All Public Folders\\","").Replace("\","_")
$FilePath = Join-Path -Path (Get-Location) -ChildPath "$pfShortName.pst"
$outlook = New-Object -ComObject Outlook.Application
$namespace = $Outlook.GetNamespace("MAPI")
@chrisbrownie
chrisbrownie / Install-WindowsDriversFromFolder.ps1
Created September 19, 2017 06:54
Installs Windows drivers from a folder
Get-ChildItem "C:\mydrivers\" -Recurse -Filter "*.inf" |
ForEach-Object { PNPUtil.exe /add-driver $_.FullName /install }
@chrisbrownie
chrisbrownie / CopyFileIntoPowerShellSession.ps1
Created October 10, 2017 22:59
Used in blog post: Copying files to a server using PowerShell Sessions
$session = New-PSSession -ComputerName MyServer
Copy-Item -Path "C:\myfile.txt" -Target "C:\SomeServerFolder" -ToSession $session
$AllUsers = Get-Mailbox -ResultSize unlimited
$AllUsers | % {
$_.UserPrincipalName
$PhotoData = $null
$PhotoData = Get-UserPhoto -Identity $_.UserPrincipalNAme -ErrorAction SilentlyContinue
if ($PhotoData) {
[io.file]::WriteAllBytes("$pwd\$($_.UserPrincipalName).jpg",$Photodata.PictureData)
}
}
@chrisbrownie
chrisbrownie / GenerateDocFxToc.ps1
Created November 5, 2017 22:05
DocFx TOC generator
$articleRoot = "articles"
$tocFileTypes = @("md")
function CreateTocForFolder {
Param(
[String]$Path
)
# First, create a toc for child folders
@chrisbrownie
chrisbrownie / GetExchangeGroupMemberships.ps1
Created November 29, 2017 00:59
Returns the membership of all Exchange Online Distribution Groups
$allDistributionGroups = Get-DistributionGroup -ResultSize unlimited
$allGroupMemberships = $allDistributionGroups | ForEach-Object {
$thisGroup = $_
Get-DistributionGroupMember -Identity $thisGroup.Identity |
Select-Object `
@{Name="GroupIdentity";Expression={$thisGroup.primarySmtpAddress}},
@{Name="MemberAddress";Expression={$_.PrimarySmtpAddress}}
}
@chrisbrownie
chrisbrownie / Get-MsolServicePlans.ps1
Last active December 7, 2017 02:28
Returns a list of each sku and the service plans associated. For creating LicenseOption objects with New-MsolLicenseOptions
foreach ($sku in (Get-MsolAccountSku) ) {
foreach ($sp in $sku.ServiceStatus) {
New-Object -TypeName PSObject -Property @{"AccountSkuId"=$sku.AccountSkuId;"ServicePlan"=$sp.ServicePlan.ServiceName}
}
}
@chrisbrownie
chrisbrownie / Connect-ExopsSession.ps1
Last active December 11, 2017 22:35
Automatically discovers newest EXOPS module in the user's profile
function UpdateImplicitRemotingHandler {
$modules = Get-Module tmp_*
foreach ($module in $modules)
{
[bool]$moduleProcessed = $false
[string] $moduleUrl = $module.Description
[int] $queryStringIndex = $moduleUrl.IndexOf("?")
$HHUrl = "http://happyhour.virginaustralia.com/sale-on"
$page = Invoke-WebRequest -Uri $HHUrl
$flightDivs = $page.ParsedHtml.body.getElementsByClassName('card-flight')
foreach ($flightDiv in $flightDivs) {
New-Object -TypeName PSObject -Property @{
"From" = $flightDiv.getElementsByTagName("h3")[0].innerText.Split("`n")[0].Trim() -replace '\ to', ''