Skip to content

Instantly share code, notes, and snippets.

View schittli's full-sized avatar

Tom-- schittli

  • Biel / Bienne, Switzerland
  • 18:22 (UTC +02:00)
View GitHub Profile
@Jaykul
Jaykul / RemoveOldFiles.ps1
Last active April 8, 2018 01:35 — forked from anonymous/gist:93c9fa41bef0253096bc08bf9518e301
Gists can have multiple files, and if you set the extension, they get syntax highlighting
Import-Module "D:\Coding\PowerShell\Modules\remove-OldFiles.psm1"
remove-OldFiles -Path 'D:\Coding' -ExcludeFolders "Bootstrap Learning","PowerShell","Waaah!"
#the folder Waaah! dont exists in the Folder mentioned above. so in the PSM there is a write-Host line to display this error. but i dont see it when i call the function from the ps1 script.
param(
$Source = "c:\users\USER1\desktop\test\folder1",
$Destination = "c:\users\USER1\desktop\test\folder2"
)
$Sources = Get-ChildItem $Source -recurse -depth 4 | Where-Object {$_.name -like "*``, *`` *``(*2016)"} | Select-Object -ExpandProperty FullName
Push-Location $Source
foreach($SourcePath in $Sources) {
$DestPath = Join-Path $Destination (Resolve-Path $SourcePath -Relative)
@Jaykul
Jaykul / Write-ModuleSpecRepro.ps1
Created November 3, 2016 22:17
ModuleSpec dependency failure
#.Synopsis
# Generate a bunch of test modules to demonstrate ModuleSpec "cyclic dependency" bug
#.Example
# Write-ModuleSpecRepro
#
# Uses the default values to create a series of modules which will fail to import
#.Example
# Write-ModuleSpecRepro -Depth 6 -ModuleSpec First2
#
# Creates a series of modules where only two modules have specified the versions of their dependencies,
@Jaykul
Jaykul / VSCode.psm1
Created November 1, 2016 01:10
Update-VSCode
function Get-VSCodeProduct {
#.Synopsis
# Get the current VSCode Product Info
Get-Item "${Env:ProgramFiles(x86)}\Microsoft VS Code*\Resources\app\product.json" | Get-Content | ConvertFrom-Json
}
function Get-WebFile {
#.Synopsis
@Jaykul
Jaykul / Initialize-SelfSignedRemoting.ps1
Last active March 13, 2018 00:22
Enabling background jobs on Azure AD
function Enable-LocalRemoting {
<#
.Synopsis
Generate and configure a local self-signed SSL certificate and configure PowerShell remoting
#>
param(
# If set, recreates existing certificates, listeners and firewall rules
[switch]$Force
)
end {
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class NativeConsoleMethods
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr GetStdHandle(int handleId);
function Invoke-Parallel {
<#
.SYNOPSIS
Function to control parallel processing using runspaces
.DESCRIPTION
Function to control parallel processing using runspaces
Note that each runspace will not have access to variables and commands loaded in your session or in other runspaces by default.
This behaviour can be changed with parameters.
@jdhitsolutions
jdhitsolutions / ToDo.ps1
Last active September 18, 2024 20:28
A PowerShell function that you can use to insert ToDo messages into your scripts and functions.
<#
based on a comment from Matt Penny
function todo {
param ([string]$TodoText)
write-host -foregroundcolor DarkYellow ” [o] Todo: $TodoText”
}
Get more from Matt at https://mattypenny.net/
@Jaykul
Jaykul / Test-Elevation.ps1
Last active March 13, 2018 00:20
What's the simplest way to test if we're currently running "As Administrator"?
#.Synopsis
# Returns TRUE if the current PowerShell is running elevated, FALSE otherwise.
[CmdletBinding()]param()
$IsElevated = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
if($IsElevated -ne ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole("Administrators")) {
Write-Warning "String Method does not work"
}
if($IsElevated -ne [Bool]([Security.Principal.WindowsIdentity]::GetCurrent().Groups -eq "S-1-5-32-544")) {
@Jaykul
Jaykul / ConEmu.xml
Last active June 23, 2023 20:11
Blog: ConEmu Install
<?xml version="1.0" encoding="utf-8"?>
<key name="Software">
<key name="ConEmu">
<key name=".Vanilla" modified="2016-09-13 00:43:10" build="160904">
<value name="StartType" type="hex" data="02"/>
<value name="CmdLine" type="string" data=""/>
<value name="StartTasksFile" type="string" data=""/>
<value name="StartTasksName" type="string" data="{Shells::PowerShell}"/>
<value name="StartFarFolders" type="hex" data="00"/>
<value name="StartFarEditors" type="hex" data="00"/>