Skip to content

Instantly share code, notes, and snippets.

View mczerniawski's full-sized avatar

mczerniawski mczerniawski

View GitHub Profile
$XMLFile = Get-Content $TemplateUnattendFile -Raw
$XmlFileOutput = $XMLFile.Replace('unattendAdministratorHere',$LocalAdministrator).Replace('unattendPasswordHere',$LocalAdministratorPassword)
if (-not (Test-Path (Split-Path $OutputUnattendFile -Parent))) {
$null = New-Item (Split-Path $OutputUnattendFile -Parent) -ItemType Directory
}
$XmlFileOutput | Out-File $OutputUnattendFile -Force utf8
[CmdletBinding(DefaultParameterSetName='Directory')]
Param(
[Parameter(Mandatory=$false,
ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
[Parameter(ParameterSetName='Directory')]
[ValidateScript({Test-Path $_ -PathType Container })]
[System.String[]]
$Path,
[Parameter(Mandatory=$false,
begin {
Set-Variable Fonts -Value 0x14 -Option ReadOnly
$fontRegistryPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"
$shell = New-Object -ComObject Shell.Application
$folder = $shell.NameSpace($Fonts)
$objfontFolder = $folder.self.Path
#$copyOptions = 20
$copyFlag = [string]::Format("{0:x}",4+16)
$copyFlag
Add-Type -AssemblyName System.Drawing
$objFontCollection = New-Object System.Drawing.Text.PrivateFontCollection
$objFontCollection.AddFontFile($item.FullName)
$FontName = $objFontCollection.Families.Name
$folder.CopyHere($item.FullName, $copyFlag)
$regTest = Get-ItemProperty -Path $fontRegistryPath -Name "*$FontName*" -ErrorAction SilentlyContinue
if (-not ($regTest)) {
New-ItemProperty -Name $FontName -Path $fontRegistryPath -PropertyType string -Value $item.Name
}
process {
switch ($PsCmdlet.ParameterSetName) {
"Directory" {
ForEach ($fontsFolder in $Path){
$fontFiles = Get-ChildItem -Path $fontsFolder -File -Recurse -Include @("*.fon", "*.fnt", "*.ttf","*.ttc", "*.otf", "*.mmm", "*.pbf", "*.pfm")
}
}
"File" {
$fontFiles = Get-ChildItem -Path $FontFile -Include @("*.fon", "*.fnt", "*.ttf","*.ttc", "*.otf", "*.mmm", "*.pbf", "*.pfm")
}
@mczerniawski
mczerniawski / DownloadLaps.ps1
Last active September 6, 2017 22:04
Download LAPS
$URLs = @('https://download.microsoft.com/download/C/7/A/C7AAD914-A8A6-4904-88A1-29E657445D03/LAPS.x64.msi','https://download.microsoft.com/download/C/7/A/C7AAD914-A8A6-4904-88A1-29E657445D03/LAPS.x86.msi')
$Date = Get-Date -Format yyyyMMdd_hhmm
$TempFolder = "d:\Temp_$Date"
New-Item -Path $TempFolder -ItemType Directory -Force
$URLs | foreach-object {
$fileName = Split-Path $_ -Leaf
$DestinationPath = Join-Path $TempFolder -ChildPath $fileName
Invoke-WebRequest -Uri $_ -OutFile $DestinationPath
}
@mczerniawski
mczerniawski / LAPS_ExtendADscheme.ps1
Created September 6, 2017 22:26
Extend Active Directory scheme
Import-Module AdmPwd.PS
Update-AdmPwdADSchema
@mczerniawski
mczerniawski / LAPS_GetPassword.ps1
Created September 11, 2017 14:41
LAPS Get-Password
PS> Get-AdmPwdPassword -ComputerName SomeComputer
ComputerName DistinguishedName Password ExpirationTimestamp
------------ ----------------- -------- -------------------
SomeComputer CN=SomeComputer,OU=TestBed,OU=Ser... ; 5G#cnz94&;Oq1 29.09.2017 13:30:42
@mczerniawski
mczerniawski / LAPS_CreateGroups.ps1
Last active September 11, 2017 15:16
Create AD groups for LAPS
$Share_GPOInstalls_RGroupProps = @{
Name = 'GPOInstalls_R'
SamAccountName = 'GPOInstalls_R'
Description = 'Members allowed to read from Share GPOInstalls'
DisplayName = 'GPOInstalls_R'
GroupCategory = 'Security'
GroupScope= 'Universal'
Path = 'OU=AD,OU=Security Groups,DC=contoso,DC=com'
}
New-ADGroup @Share_GPOInstalls_RGroupProps