Skip to content

Instantly share code, notes, and snippets.

View clemmesserli's full-sized avatar

Clem Messerli clemmesserli

View GitHub Profile
<#
Description: How to edit timestamps with Windows PowerShell
Single File
Get-Item C:\temp\test.txt | select Mode, Name, CreationTime, LastAccessTime, LastWriteTime | fl
$(Get-Item C:\temp\test.txt).creationtime=$(Get-Date)
$(Get-Item C:\temp\test.txt).lastaccesstime=$(Get-Date "12/24/2011 07:15 am")
Get-Item C:\temp\test.txt | select Mode, Name, CreationTime, LastAccessTime, LastWriteTime | fl
#>
@clemmesserli
clemmesserli / Get-WinCred.ps1
Last active June 18, 2020 04:56
Snippet to show how to retrieve user credential, including passwords, from WinCred Manager
function InitializeWindowsCredential
{
Write-Verbose ("Loading PasswordVault Class.")
[void][Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime]
}
function ConvertTo-PasswordCredential
{
<#
.Synopsis
@clemmesserli
clemmesserli / Test-NameServer.ps1
Created May 1, 2020 04:23
Sample on how you might verify DNS name resolution
cls
Clear-DnsClientCache
$NameServers = @(
"8.8.8.8",
"8.8.4.4",
"208.67.222.222",
"1.1.1.1"
)
Snippets CTL+ALT+J
Auto-Format CTL+ALT+F
Command Palette CTL+SHIFT+P
Expand Aliases CTL+ALT+E
@clemmesserli
clemmesserli / GetPowerShell
Created May 1, 2020 04:25
Ways to get latest version of PowerShell
#Ref: https://www.thomasmaurer.ch/2019/07/how-to-install-and-update-powershell-7/
Windows:
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -Preview"
Linux:
wget https://aka.ms/install-powershell.sh; sudo bash install-powershell.sh -preview; rm install-powershell.sh
@clemmesserli
clemmesserli / Get-PasswordVault.ps1
Last active June 18, 2020 05:37
Returns all credentials found for logged on user of windows credential manager
<#
.Synopsis
Read Password Vault
.DESCRIPTION
Get Windows Password Vault for Logged on user
.EXAMPLE
Get-WinPassword
#>
#function Get-PasswordVault {
[void][Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime]
@clemmesserli
clemmesserli / Get-ChromeCred.ps1
Created June 18, 2020 05:26
Get any credentials saved within chrome browser
## CHROME
$Path = "$env:USERPROFILE\AppData\Local\Google\Chrome\User Data\Default\Login Data"
#If Path doesnt exist > Stop
if(![system.io.file]::Exists($Path)){Break}
Else{
Add-Type -AssemblyName System.Security
# Credit to Matt Graber for his technique on using regular expressions to search for binary data
$Stream = New-Object IO.FileStream -ArgumentList "$Path", 'Open', 'Read', 'ReadWrite'
$Encoding = [system.Text.Encoding]::GetEncoding(28591)
$StreamReader = New-Object IO.StreamReader -ArgumentList $Stream, $Encoding
@clemmesserli
clemmesserli / MyRemoteSession.psm1
Created November 19, 2020 14:57
MyRemoteSession
Function New-MyRemoteSession {
<#
.SYNOPSIS
Setup a PowerShell profile on a remote computer
.DESCRIPTION
By default this function will copy the local 'profile.ps1' file from $PSHOME to same location on the remote computer you choose
.EXAMPLE
PS C:\> New-MyRemoteSession -ComputerName "server01.local"
Copies profile.ps1 from local $PSHOME folder path to remote $PSHOME folder path and sets the profilename to 'WithProfile'
@clemmesserli
clemmesserli / Invoke-Update-Pester.ps1
Created January 8, 2021 17:39
This script can be used to forcibly remove the v3/v4 versions that typically ship with Windows and update to latest from PSGallery
#Requires -RunAsAdministrator
$modules = Get-Module -Name Pester -ListAvailable
if ($null -ne $modules) {
$pesterPaths = (get-item $modules.modulebase).parent.Fullname | Sort-Object -Unique
foreach ($pesterPath in $pesterPaths) {
takeown /F $pesterPath /A /R
@clemmesserli
clemmesserli / Get-LatestRelease
Created January 13, 2022 23:45
Snippet used to pull down the latest release of an F5 RPM package
$repo = "F5Networks/f5-appsvcs-extension"
$filenamePattern = "*.noarch.rpm"
$releasesUri = "https://api.github.com/repos/$repo/releases/latest"
$downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object name -like $filenamePattern ).browser_download_url
$filePath = Join-Path -Path $([System.IO.Path]::GetTempPath()) -ChildPath $(Split-Path -Path $downloadUri -Leaf)
Invoke-WebRequest -Uri $downloadUri -Out $filePath