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