Skip to content

Instantly share code, notes, and snippets.

Avatar

Clem Messerli clemmesserli

View GitHub Profile
View SetFileTimeStamp.ps1
<#
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 / Test-NameServer.ps1
Created May 1, 2020
Sample on how you might verify DNS name resolution
View Test-NameServer.ps1
cls
Clear-DnsClientCache
$NameServers = @(
"8.8.8.8",
"8.8.4.4",
"208.67.222.222",
"1.1.1.1"
)
View gist:8aaa40cc59578282c8ff39d9c99cc5a7
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
Ways to get latest version of PowerShell
View GetPowerShell
#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-WinCred.ps1
Last active Jun 18, 2020
Snippet to show how to retrieve user credential, including passwords, from WinCred Manager
View Get-WinCred.ps1
function InitializeWindowsCredential
{
Write-Verbose ("Loading PasswordVault Class.")
[void][Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime]
}
function ConvertTo-PasswordCredential
{
<#
.Synopsis
@clemmesserli
clemmesserli / Get-ChromeCred.ps1
Created Jun 18, 2020
Get any credentials saved within chrome browser
View Get-ChromeCred.ps1
## 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 / Get-PasswordVault.ps1
Last active Jun 18, 2020
Returns all credentials found for logged on user of windows credential manager
View Get-PasswordVault.ps1
<#
.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]
View MyRemoteSession.psm1
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 Jan 8, 2021
This script can be used to forcibly remove the v3/v4 versions that typically ship with Windows and update to latest from PSGallery
View Invoke-Update-Pester.ps1
#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
View Invoke-Update-Module.ps1
<#
.SYNOPSIS
Module clean-up script during updates
.DESCRIPTION
Module clean-up script during updates.
This script will presently remove all pre-existing versions from all 'Modules' paths within $env:PSModulePath.
This script will then install the desired new version within a single PSModulePath based upon the version of PowerShell running the script.
.EXAMPLE