14 April 2023

Automatic update of Chocolatey packages

 If you are installed some software using https://chocolatey.org and want to keep it up to date, then open administrative Command Prompt (cmd.exe as administrator) and paste this line there:

schtasks /create /tn choco-update /tr "cup all -y" /sc daily /st 02:46 /ru SYSTEM /rl HIGHEST

This will create a scheduled task, which runs every day at 02:46 (nighttime) and updates all chocolatey packages (the command "cup all -y" does that).

To see all scheduled tasks, open taskschd.msc and see it for yourself:

To see log file, what actually has happened during last nightly sessions, open this file:


05 April 2023

Create CAA record using PowerShell in Windows DNS

 Because CAA records are not natively supported in Windows Server DNS service, then you need to do this manually. I created a PowerShell script for that:

$zone = 'yourdomain.com'

$provider = 'letsencrypt.org'

$caa = "00056973737565" + ([BitConverter]::ToString($provider.ToCharArray())).Replace("-", "")

Add-DnsServerResourceRecord -ZoneName $zone -Name '@' -Type 257 -RecordData $caa

This script must be executed in Windows Server, where DNS service is installed and contains your external DNS zone.

Your zone name must be written on the first line and your provider name must be on next line

To verify your CAA record in internet, search for CAA checker page and type there your domain name and hit the Check button.

08 August 2022

Read IIS log file using PowerShell

 Actually you need just few lines

$file = '\\iisserver\c$\inetpub\logs\LogFiles\W3SVC1\u_ex220808.log'
$headers = (Get-Content $file | Select-Object -Skip 3 -First 1).Split(' ') | Select-Object -Skip 1
$result = Import-Csv $file ' ' -Header $headers | Where-Object date -NotLike '#*'
$result | ConvertTo-Csv -Delimiter `t -NoTypeInformation | Set-Clipboard

Output will be in clipboard (in this case it will be with tab separated for easy pasting into Excel or similar)

21 June 2022

Resize partition using PowerShell

 Resize using this command line (PowerShell as Administrator):

Get-Partition -DriveLetter c | Resize-Partition -Size 96GB

21 February 2022

Start service on remote machine using PowerShell

If you just want remotely use mmc, then start services.msc and connect to remote computer

If you want to use PowerShell, use the following command (atagateway is one example service and serverX is example server name):

Get-Service atagateway -ComputerName serverX | Set-Service -Status running

If you have remote PowerShell enabled, then you can also use this command:

Invoke-Command serverX {Start-Service atagateway}

03 February 2022

Upload domain joined computer bitlocker key to Active Directory

To upload already encrypted drive bitlocker key to AD, you can use this PowerShell oneliner. Remember to use "run as administrator"

Backup-BitLockerKeyProtector c: ((Get-BitLockerVolume c:).KeyProtector | ? KeyProtectorType -eq RecoveryPassword).KeyProtectorId

If you already have the information in AD, then it doesn't hurt, it will not create any duplicates in AD

08 December 2021

Get all subnets in you Active Directory

 To get all subnets in your Active Directory, use this PowerShell oneliner: