Skip to content

Instantly share code, notes, and snippets.

@Diagg
Diagg / Create-NatSwitch.ps1
Created November 29, 2017 00:31
Create a single nat switch for Windows 10 Hyper-V
$NatNicIP = '192.168.10.1'
$NatNicSubnet = '192.168.10.0'
$NatNicPrefixLenght = '24'
$NatName = 'Nat-Network'
New-VMSwitch -Name $NatName -SwitchType Internal
# Get the MAC Address of the VM Adapter bound to the virtual switch
$MacAddress = (Get-VMNetworkAdapter -ManagementOS -SwitchName Nat-Network).MacAddress
@Diagg
Diagg / TestReboot.wsf
Last active July 17, 2019 18:48
This script for MDT/SCCM demonstrate how to reboot to the same Task Séquence step wether you are on WinPE or Windows.
<job id="BIOSCheck">
<script language="VBScript" src="ZTIUtility.vbs"/>
<script language="VBScript">
Option Explicit
RunNewInstance
Class TestReboot
Function Main
@Diagg
Diagg / WebService.Ps1
Last active June 11, 2024 06:03
Simple PowerShell Web Service/Rest API
function New-ScriptBlockCallback
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
param(
[parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[scriptblock]$Callback
)
# Is this type already defined?
@Diagg
Diagg / GUI.ps1
Last active April 17, 2019 13:26
This example demonstrate how to build a 2 cents GUI by tricking cmdlet Show-Command
Function Install-WEBService
{
[CmdletBinding()]
Param
(
[Parameter(Position=0, Mandatory=$true, ParameterSetName='1-Settings')]
[String]$User,
[Parameter(Position=1,Mandatory=$true,ParameterSetName='1-Settings')]
[String]$Password,
@Diagg
Diagg / GUI-V2.ps1
Last active April 15, 2019 14:44
This is another example on using Show-command to create simple user interface
Function Install-WEBService
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,position=0)]
[String]${_0_User},
[Parameter(Mandatory=$true,position=1)]
[String]${_1_Password},
#########################
#
# Set-DefaultAppAsociation
#
# Version 3.0 By Diagg/OSD-Couture.com
# XML node creation part by Helmut Wagensonner (https://blogs.msdn.microsoft.com/hewagen/making-file-type-associations-enterprise-ready/)
# Release Date 01/10/2019
# Latest relase: 06/01/2020
#
# Purpose: Create file association on the fly during MDT/SCCM deployment
@Diagg
Diagg / RunASTrustedInstaller.ps1
Last active February 20, 2025 09:20
Run task as Trusted installer using Scheduled Task under system account
# Run task as Trusted Installer From system context (Yeah, Intune, SCCM)
# Should also work under Admin context (if not, remove all references to $P).
# Credit due to : https://www.tiraniddo.dev/2019/09/the-art-of-becoming-trustedinstaller.html
$a = New-ScheduledTaskAction -Execute notepad.exe
$P = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrateurs"
#$P = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrators" #Warning: the admin Group name is localised
Register-ScheduledTask -TaskName 'TestTask' -Action $a -Principal $P
@Diagg
Diagg / RunScriptBlockAsTrustedInstaller.ps1
Last active July 11, 2024 23:17
Run Powershell Script block as Trusted installer using Scheduled Task under Admin account
# Run Powershell scriptblock as Trusted Installer From Admin context (Yeah, MDT) using Scheduled Task.
# Credit due to : https://www.tiraniddo.dev/2019/09/the-art-of-becoming-trustedinstaller.html
$ScriptBlock = {
$Script:TsEnv = New-Object PSObject
$Script:TsEnv|Add-Member -MemberType NoteProperty -Name 'SystemHostName' -Value ([System.Environment]::MachineName)
$Script:TsEnv|Add-Member -MemberType NoteProperty -Name 'SystemIPAddress' -Value (Get-NetIPAddress -AddressFamily IPv4 -PrefixOrigin Dhcp -AddressState Preferred).IPAddress
$Script:TsEnv|Add-Member -MemberType NoteProperty -Name 'SystemOSversion' -Value ([System.Environment]::OSVersion.VersionString)
@Diagg
Diagg / UnPDFEdge.Ps1
Last active May 3, 2021 08:13
Various untested trick to prevent edge from hijacking the PDF viewer
# Stops edge from taking over as the default .PDF viewer
Write-Output "Stopping Edge from taking over as the default .PDF viewer"
# Identify the edge application class
$Packages = "HKCU:SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages"
$edge = Get-ChildItem $Packages -Recurse -include "MicrosoftEdge"
# Specify the paths to the file and URL associations
$FileAssocKey = Join-Path $edge.PSPath Capabilities\FileAssociations
@Diagg
Diagg / GetCurrentUser.ps1
Last active September 25, 2023 17:52
Get Current user from system/admin context. Works with Workgroup/AD user, Windows Sandbox user and Azure AD user. Works also with an x86 Powershell client on an X64 Windows 10
# By Diagg/OSDC
# https://www.osd-couture.com/
# Twitter: @Diagg
#V 2.0 - Logic refactored, Added support for X86 powershell on X64 windows
#V 1.0 - Initial release
# Get Workgroup/AD User
$CurrentLoggedOnUser = (Get-CimInstance –ClassName Win32_ComputerSystem | Select-Object -expand UserName)
If ([String]::IsNullOrWhiteSpace($CurrentLoggedOnUser))