Removing tiered storage spaces - Windows Server 2022

As part of the work I have done in my homelab with tiered storage on Server 2022 storage spaces, here is a script I created that allows you to easily remove a tiered storage space, so you can start again from scratch with your pool of disks

Drop this in a .ps1 file and watch it go:

#Provided by Luke Varley - www.Phishandchips.dev
#orignal creator Joe Freeman
#Credit: https://github.com/freemansoft/win10-storage-spaces
#Variables names here MUST MATCH create-storage-space.ps1
#check if elevation is required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
    if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
     
     write-output "
    =================================================================  
    SCRIPT REQUIRES ELEVATION, PLEASE RUN FROM AN ADMINISTRATIVE
    POWERSHELL WINDOW. RUN AS ADMINISTRATOR.
    =================================================================
    "
    Pause
    Exit
         }
        }
  Pause
#start
$StoragePoolName = "VMStoreHDDCache"
$SSDTierName = "SSDTier-VMStoreHDD"
$HDDTierName = "HDDTier-VMStoreHDD"
$TieredDiskName = "VMStoreHDDCacheVD"

# Make sure they really want to do this!
$choices  = '&Yes', '&No'
$decision = $Host.UI.PromptForChoice('Remove Storage Space', 'Are you sure you wish to remove the storage space named "' + $TieredDiskName + '"?' + [Environment]::NewLine + 'ALL DATA WILL BE PERMANENTLY LOST', $choices, 1)
if ($decision -ne 0) {
    exit
}

# In reverse order of creation
if ((Get-VirtualDisk -FriendlyName $TieredDiskName) -ne $null){
    Write-Output "Removing drive: $TieredDiskName"
    Get-VirtualDisk -FriendlyName $TieredDiskName
    Remove-virtualdisk -friendlyName $TieredDiskName -Confirm:$false
} else {
    Write-Output "Drive does not exist: $TieredDiskName"
}

# Remove Storage Tier
if ((Get-StorageTier -FriendlyName $HDDTierName) -ne $null){
    Write-Output "Removing storage tiers: $HDDTierName"
    Get-StorageTier -FriendlyName $HDDTierName | FT FriendlyName, MediaType, Size -AutoSize
    Remove-StorageTier -FriendlyName $HDDTierName -Confirm:$false
} else {
    Write-Output "Tier does not exist: $HDDTierName"
}
if ((Get-StorageTier -FriendlyName $SSDTierName) -ne $null){
    Write-Output "Removing storage tiers: $SSDTierName"
    Get-StorageTier -FriendlyName $SSDTierName | FT FriendlyName, MediaType, Size -AutoSize
    Remove-StorageTier -FriendlyName $SSDTierName -Confirm:$false
} else {
    Write-Output "Tier does not exist: $SSDTierName"
}
Get-StorageTier

# Remove the Storage Pool
if ((Get-StoragePool -FriendlyName $StoragePoolName) -ne $null){
    Write-Output "Removing storage pool: $StoragePoolName"
    Get-StoragePool -FriendlyName $StoragePoolName | Get-PhysicalDisk | FT FriendlyName, MediaType
    Remove-StoragePool -FriendlyName $StoragePoolName -Confirm:$false
} else {
    Write-Output "Storage Pool does not exist: $StoragePoolName"
}
# Show just the primoridal pool
Write-Output "Poolable drives after cleanup"
Get-StoragePool | Get-PhysicalDisk -CanPool:$True

Write-Output "Operation complete"

Finding the max size of a tiered storage space - Windows Server 2022

As part of the work I have done in my homelab with tiered storage on Server 2022 storage spaces, here is a script I created that allows you to easily find the max size of a tiered storage space

Drop this in a .ps1 file and watch it go:

#start
write-output "
=================================================================
Welcome to the EASYTIERSIZEMAX script.

By Luke Varley  - www.phishandchips.dev

This script will allow you to easily Calculate the max size of a Tiered Storage Spaces
Virtual Disk when you add new a SSD or HDD.

Read the comments in the script for instructions

#Created with knowledge obtained from
 Philippe Tschumi
#Credit: https://techblog.ptschumi.ch/automation-scripting/storage-spaces-direct-query-maximum-tier-size-storage-tiers/
=================================================================
"

$vdisks = Get-VirtualDisk
$diskdata=@()
 
foreach ($vdisk in $vdisks){
    $storagetiers = Get-StorageTier -VirtualDisk $vdisk
    $i=0
 
    foreach ($storagetier in $storagetiers){
        # ResiliencySettingName can be Mirror, Simple or Parity depending on your deployment
        $tier = $storagetier | Get-StorageTierSupportedSize -ResiliencySettingName Simple # edit ResiliencySettingName
        $tiermin = ($tier.TierSizeMin/1GB)
        $tiermax = ($tier.TierSizeMax)/1GB
        $tierdivisor = ($tier.TierSizeDivisor)/1GB
        $object = New-Object -TypeName PSObject -Property (@{
            'vDisk'= $vdisk.FriendlyName;
            'StorageTier'= $storagetier.FriendlyName
            'TierSizeMin'= $tiermin;
            'TierSizeMax'= $tiermax;
            'TierSizeDivisor'= $tierdivisor
        })
        $diskdata += $object
        $i++
    }
}
$diskdata | Select-Object vDisk, StorageTier, TierSizeMin, TierSizeDivisor, TierSizeMax | ft -AutoSize

Extending tiered storage spaces - Windows Server 2022

 As part of the work I have done in my homelab with tiered storage on Server 2022 storage spaces, here is a script I created that allows you to easily extend a tiered storage space, so you can expand your storage pool size when you add more disks or even replace your current disks with higher capacity ones

Drop this in a .ps1 file and watch it go:

#start
write-output "
=================================================================
Welcome to the EASYExtendTieredVD script.

By Luke Varley  - www.Phishandchips.dev

This script will allow you to easily extend a Tiered Storage Spaces
Virtual Disk when you add new a SSD or HDD

Read the comments in the script for instructions

#Created with knowlegde obtained from
nils.schimmelmann
#Credit: https://nils.schimmelmann.us/post/153541254987/intel-smart-response-technology-vs-windows-10
Joe Freeman
#Credit: https://github.com/freemansoft/win10-storage-spaces
=================================================================
"
# https://nils.schimmelmann.us/post/153541254987/intel-smart-response-technology-vs-windows-10
#check if elevation is required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
    if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
     
     write-output "
    =================================================================  
    SCRIPT REQUIRES ELEVATION, PLEASE RUN FROM AN ADMINISTRATIVE
    POWERSHELL WINDOW. RUN AS ADMINISTRATOR.
    =================================================================
    "
    Pause
    Exit
         }
        }
  Pause
#start
#
#Number of columns in your VD is the number of disks you need to add before you can utilise the extra capacity of those disks
    #so if you have 3 columns, you wont be able to exend capacity of your VD until you add an extra 3 disks
        #OR you replace all disks in your storage tier with disks of a higher capacity e.g. 8TB - 4 x 2TB disks, replace each disk 1 by 1 to 4 x 4tb disks for 16TB capacity
#Tiers in the storage pool
#Find these by running get-StorageTier
$SSDTierName = "VMStoreHDDCacheVD-SSDTier-VMStoreHDD"
$HDDTierName = "VMStoreHDDCacheVD-HDDTier-VMStoreHDD"

#Override the default sizing here - useful if have two different size SSDs or HDDs - set to smallest of pair
#These must be Equal or smaller than the disk size available in that tier SSD and HDD
#SSD:cache  -    HDD:data
#set to $null to calculate the max size, not always working... better to manually specify a size
#set to $null the tier you dont want to extend, to extend both populate both with the apropriate value
$SSDTierSize = 508GB
$HDDTierSize = 7.22TB
#Drives cannot always be fully allocated - probably broken for drives < 10GB
#Dont change this
$UsableSpace = 0.99
#Set tier Resilency setting
$SSDTierResiliency = "Simple"
$HDDTierResiliency = "Simple"

#Calculate tier sizes within this storage pool
#Can override by setting sizes at top
if ($SSDTierSize -eq $null){
    $SSDTierSize = (Get-StorageTierSupportedSize -FriendlyName $SSDTierName -ResiliencySettingName $SSDTierResiliency).TierSizeMax
    $SSDTierSize = [int64]($SSDTierSize * $UsableSpace)
}
if ($HDDTierSize -eq $null){
    $HDDTierSize = (Get-StorageTierSupportedSize -FriendlyName $HDDTierName -ResiliencySettingName $HDDTierResiliency).TierSizeMax
    $HDDTierSize = [int64]($HDDTierSize * $UsableSpace)
}
Write-Output "TierSizes: ( $SSDTierSize , $HDDTierSize )"

$HDDTierSizeBytes = $HDDTierSize / 1GB
$HDDTierSizeGB = "$HDDTierSizeBytes" + "GB"
$SSDTierSizeBytes = $SSDTierSize / 1GB
$SSDTierSizeGB = "$SSDTierSizeBytes" + "GB"

#Extend two tiers in the Storage Pool created. One for SSD disks and one for HDD disks
Write-Output "Extend $SSDTierName by:"
$SSDTierSizeGB
Resize-StorageTier -FriendlyName $SSDTierName -size $SSDTierSize
Write-Output "Extend $HDDTierName by:"
$HDDTierSizeGB
Resize-StorageTier -FriendlyName $HDDTierName -size $HDDTierSize
Write-Output "Operation complete"

Creating tiered storage spaces - Windows Server 2022 - Getting the best performance on your home server

Ever since I rebuilt my homelab during the covid pandemic, I was never happy with the performance I was getting for the hardware that I had. Homelab 2.0 as I dubbed it has changed to something different than I originally designed, moving from VMware vcenter to Hyper-V 2022 being one of the biggest changes! Frustratingly, I have rebuilt this lab about 3 or 4 times now to get things working as well as it should.

The final issue I’m battling is dreadful storage write and read speeds in storage spaces on server 2022.

If you have been using storage spaces in your homelab, you probably had performance issues. Google it and you will see there’s tons of discussion and blogs about this topic online.

Like most things designed for enterprise, things are not always as simple as they seem. When it comes to storage spaces and getting the most out of your hardware, there are some best practices that need to be followed, the problem is they aren't very well documented by MS and as a result most people have had issues and had to figure it out by themselves. Thankfully, there are other people like me who blog their findings and share knowledge online for others, filling that documentation void.

There's a severe lack of documentation on a lot of MS storage spaces stuff. for the most part I resorted to going back to basics, doing what we do in vendor support, creating a lab vm and testing things out !

This was accompanied by a LOT of research, I would recommend that you check out the following resources, these guys do a way better job of explaining this than I could:


The summary of it is you have to carefully match your interleave, column and allocation unit size:

Allocation Unit size = Parity calculation: ($number_of_columns - 1) * $interleave
                                    Double parity Calculation: ($number_of_columns - 2) * $interleave
                                    Simple Calculation: ($number_of_columns) * $interleave

My original plan was to use SSD caching in my server as I thought that would solve my issues. I bought some SSDs on prime day and set out to configure it. Originally, I thought that storagebus cache would be the best solution, I already run server 2022 and do not have clustering, should be simple right.

In the end I decided against this... the severe lack of documentation and no information about this online make it a dangerous prospect. My original plan was again to lab this feature out and see how it works, but I had so many issues getting this to work in a VM that I decided it was too risky to put data in this configuration without knowing how I would handle drive failures and general DR related scenarios. I am not sure if my failures were due to me trying to do this in a VM or not, but I saw other people online who blogged about it and did have it working in a VM. I was confused to say the least.

New and unproven technology with little info online is a risky data storage solution. Furthermore, when comparing it with the old storage tiers type setup for SSD caching there was no real information about any benefits to using storagebus cache over tiers. Plus, there’s a lot more information out there about storage tiers configuration with PowerShell, so I decided that would be the best option and got to work writing a script in the lab to configure this.

It took a while to get working but I started out by taking the knowledge obtained from nils schimmelmann (https://nils.schimmelmann.us/post/153541254987/intel-smart-response-technology-vs-windows-10) and Joe Freeman (https://github.com/freemansoft/win10-storage-spaces) then building on that to create my own scripts.

I have provided a script below that you can use to create a tiered storage space and adjust the allocation unit size, columns and interleave sizes to suit your setup.

The beauty of it is that you can create SSD (performance) tier and a HDD (Capacity) tier and set different Resiliency settings, Interleave and Column sizes to suit how many disks you have of each type.

For example in my script below i configure a volume that has 2 HDD's and 1 SSD, therefore i needed to set different Interleave and Column sizes to match my Allocation unit size of 64K on REFS.

(I also created some scripts to extend or remove a tired storage space, as well as check the max size space you can create based on the type of array you have.)

Drop this in a .ps1 file and watch it go:

#start
write-output "
=================================================================
Welcome to the EASYSTOREAGESPACEWITHTIERS script.

By Luke Varley  - www.phishandchips.dev

This script will allow you to easily create a Tiered Storage Spaces
Virtual Disk

Read the comments in the script for instructions

#Created with knowledge obtained from
nils.schimmelmann
#Credit: https://nils.schimmelmann.us/post/153541254987/intel-smart-response-technology-vs-windows-10
Joe Freeman
#Credit: https://github.com/freemansoft/win10-storage-spaces
=================================================================
"
#check if elevation is required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
    if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
     
     write-output "
    =================================================================  
    SCRIPT REQUIRES ELEVATION, PLEASE RUN FROM AN ADMINISTRATIVE
    POWERSHELL WINDOW. RUN AS ADMINISTRATOR.
    =================================================================
    "
    Pause
    Exit
         }
        }
  Pause
#start
#Pool that will suck in all drives
$StoragePoolName = "VMStoreTiered"
#Tiers in the storage pool
$SSDTierName = "SSDTier-VMStoreTiered"
$HDDTierName = "HDDTier-VMStoreTiered"
#Virtual Disk Name made up of disks in both tiers
$TieredDiskName = "VMStoreTieredVD"

#Set Mirror, Simple, or Parity Resiliency type. Simple = striped.  Mirror only works if both can mirror AFIK
#https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/dn387076(v=ws.11)
$SSDTierResiliency = "Simple"
$HDDTierResiliency = "Simple"
#$ntfs_aus = Parity calculation: ($number_of_columns - 1) * $interleave
#            Double parity Calculation: ($number_of_columns - 2) * $interleave
#            Simple Calculation: ($number_of_columns) * $interleave
$SSDInterleave = "65536" #in Bytes
$HDDInterleave = "32768" #in Bytes
$AllocationUnitSize = "65536" #in Bytes
#
$NumberOfHDDColumns = "2"
$NumberOfSSDColumns = "1"

#Change to suit - drive later and the label name
$TieredDriveLetter = "H"
$TieredDriveLabel = "VMStoreTiered"

#Override the default sizing here - useful if have two different size SSDs or HDDs - set to smallest of pair
#These must be Equal or smaller than the disk size available in that tier SSD and HDD
#SSD:cache  -    HDD:data
#set to null so copy/paste to command prompt doesn't have previous run values
$SSDTierSize = $null
$HDDTierSize = $null
#Drives cannot always be fully allocated - probably broken for drives < 10GB
$UsableSpace = 0.99

#Uncomment and put your HDD type here if it shows up as unspecified with "Get-PhysicalDisk -CanPool $True
#    If your HDDs show up as Unspecified instead of HDD
#$UseUnspecifiedDriveIsHDD = "Yes"

#List all disks that can be pooled and output in table format (format-table)
Get-PhysicalDisk -CanPool $True | ft FriendlyName, OperationalStatus, Size, MediaType

#Store all physical disks that can be pooled into a variable, $PhysicalDisks
#    This assumes you want all raw / unpartitioned disks to end up in your pool -
#    Add a clause like the example with your drive name to stop that drive from being included
#    Example  " | Where FriendlyName -NE "ATA LITEONIT LCS-256"
if ($UseUnspecifiedDriveIsHDD -ne $null){
    $DisksToChange = (Get-PhysicalDisk -CanPool $True | where MediaType -eq Unspecified)
    Get-PhysicalDisk -CanPool $True | where MediaType -eq Unspecified | Set-PhysicalDisk -MediaType HDD
    # show the type changed
    Get-PhysicalDisk -CanPool $True | ft FriendlyName, OperationalStatus, Size, MediaType
}
$PhysicalDisks = (Get-PhysicalDisk -CanPool $True | Where MediaType -NE UnSpecified)
if ($PhysicalDisks -eq $null){
    throw "Abort! No physical Disks available"
}      

#Create a new Storage Pool using the disks in variable $PhysicalDisks with a name of My Storage Pool
$SubSysName = (Get-StorageSubSystem).FriendlyName
New-StoragePool -PhysicalDisks $PhysicalDisks -StorageSubSystemFriendlyName $SubSysName -FriendlyName $StoragePoolName
#View the disks in the Storage Pool just created
Get-StoragePool -FriendlyName $StoragePoolName | Get-PhysicalDisk | Select FriendlyName, MediaType

#Create two tiers in the Storage Pool created. One for SSD disks and one for HDD disks
$SSDTier = New-StorageTier -StoragePoolFriendlyName $StoragePoolName -FriendlyName $SSDTierName -MediaType SSD -NumberOfColumns $NumberOfSSDColumns -Interleave $SSDInterleave -ResiliencySettingName $SSDTierResiliency
$HDDTier = New-StorageTier -StoragePoolFriendlyName $StoragePoolName -FriendlyName $HDDTierName -MediaType HDD -NumberOfColumns $NumberOfHDDColumns -Interleave $HDDInterleave -ResiliencySettingName $HDDTierResiliency

#Calculate tier sizes within this storage pool
#Can override by setting sizes at top
if ($SSDTierSize -eq $null){
    $SSDTierSize = (Get-StorageTierSupportedSize -FriendlyName $SSDTierName -ResiliencySettingName $SSDTierResiliency).TierSizeMax
    $SSDTierSize = [int64]($SSDTierSize * $UsableSpace)
}
if ($HDDTierSize -eq $null){
    $HDDTierSize = (Get-StorageTierSupportedSize -FriendlyName $HDDTierName -ResiliencySettingName $HDDTierResiliency).TierSizeMax
    $HDDTierSize = [int64]($HDDTierSize * $UsableSpace)
}
Write-Output "TierSizes: ( $SSDTierSize , $HDDTierSize )"

# you can end up with different number of columns in SSD - Ex: With Simple 1SSD and 2HDD could end up with SSD-1Col, HDD-2Col

New-VirtualDisk -StoragePoolFriendlyName $StoragePoolName -FriendlyName $TieredDiskName -StorageTiers @($SSDTier, $HDDTier) -StorageTierSizes @($SSDTierSize, $HDDTierSize) -WriteCacheSize 0GB

# initialize the disk, format and mount as a single volume
Write-Output "preparing volume"
Get-VirtualDisk $TieredDiskName | Get-Disk | Initialize-Disk -PartitionStyle GPT
# This will be Partition 2.  Storage pool metadata is in Partition 1
Get-VirtualDisk $TieredDiskName | Get-Disk | New-Partition -DriveLetter $TieredDriveLetter -UseMaximumSize
Initialize-Volume -DriveLetter $TieredDriveLetter -FileSystem REFS -AllocationUnitSize $AllocationUnitSize -Confirm:$false -NewFileSystemLabel $TieredDriveLabel
Get-Volume -DriveLetter $TieredDriveLetter
$TieredDriveLetterPath = "$TieredDriveLetter" + ":\"
Write-Output "Setting REFS File integrity on:"
$TieredDriveLetterPath
Set-FileIntegrity $TieredDriveLetterPath -Enable $True

Write-Output "Operation complete"

EASYGETSID - An easy to use script to look up users or group SID's from AD

 

Hey Everyone,

A while back i needed a way to easily look up Group or User SID's for ad users. I needed to do this in a repetitive way where i could over and over look up individual SID's and just keep a Powershell window open on the side for when i wanted to do it, i could literally just paste in the username and hit enter and then boom, here's your SID !

I knocked up this script within about 20 mins that allows me to do it without having to remember any commands or import any Powershell modules.

It was handy for me a while back when i was working on a project so maybe it will be useful for someone else too.

How to move SQL database files (MDF and LDF) to another location

Pre-requisites

In case a database is being used by any Windows services or other resources, these must be stopped in order to allow altering SQL database files. Also, any existing connections to a database must be closed. Before the first step, make sure to locate the appropriate MDF and LDF files for a database you want to work with. By default, these names are in the following format:

    • Database_name_Data.mdf – for MDF file
    • Database_name_log.ldf – for LDF file

The above mentioned format does not need to be necessarily used, so make sure you are targeting correct files.

Moving database files to another location

    • Run the following SQL script to set a new location for SQL database files:
    •  

ALTER DATABASE AdventureWorks2014  

    MODIFY FILE ( NAME = AdventureWorks2014_Data,  

                  FILENAME = 'E:\New_location\AdventureWorks2014_Data.mdf');  

GO

 

ALTER DATABASE AdventureWorks2014  

    MODIFY FILE ( NAME = AdventureWorks2014_Log,  

                  FILENAME = 'E:\New_location\AdventureWorks2014_Log.ldf');  

GO

The New_location is a folder created on a separate drive (in this specific case, we will change from a default C to E drive on a local machine) with sufficient disk space for SQL database files. Specified folder must be created first, in order to be used as a new location for SQL database files in the above SQL statement

    • Run the following SQL script to take a SQL database offline:
    •  

ALTER DATABASE AdventureWorks2014 SET OFFLINE;  

GO

This is important in order to perform the next step. If a database is being used by any application, this step cannot be accomplished, unless all connections to a database are closed.

    • Move MDF and LDF files of the specific SQL database to a new location specified in the statement above. This means to simply cut mentioned files from the existing location and to move them to a newly specified one.

Important note: Make sure that SQL Server can access the specified location. Otherwise, the following error will appears:

Msg 5120, Level 16, State 101, Line 13

Unable to open the physical file “E:\New_location\AdventureWorks2014_Data.mdf”. Operating system error 5: “5(Access is denied.)”.

To fix this:

    • Start SQL Server Configuration Manager
    • Right click a SQL Server instance that hosts a database which files are moved to a new location and choose the Properties option from the drop-down list:

Instead of the current account, switch to the one that has access to a drive where files are moved:

    • Once this is done, a database can be set online by running the following query to get back a database online:
    •  

ALTER DATABASE AdventureWorks2014 SET ONLINE;  

GO

    • To verify that the process is finished successfully run the following query:
      •  

SELECT name, physical_name AS NewLocation, state_desc AS OnlineStatus

FROM sys.master_files  

WHERE database_id = DB_ID(N'AdventureWorks2014')  

GO

This should give the following result:

Once this is done, a SQL database will be hosted on a drive with sufficient free space and the user can continue using it.

 

From <https://www.sqlshack.com/move-sql-database-files-mdf-ldf-another-location/>

 

 

Created with OneNote.

Could not locate file 'mydatabase' for database 'mydatabase' in sys.database_files. The file either does not exist, or was dropped

 

 

Could not locate file 'mydatabase' for database 'mydatabase' in sys.database_files. The file either does not exist, or was dropped

18 October 2022

02:54

dbcc shrinkfile('mydatabase',113311) fails with following error

Could not locate file 'mydatabase' for database 'mydatabase' in sys.database_files. The file either does not exist, or was dropped

 

I managed to resolve it by renaming the logical name of the log file:

USE [clientdatabase];
ALTERDATABASE clientdatabase MODIFY FILE
(NAME =clientdatabase_log, NEWNAME =clientdatabase_log_1);

Running the script

USE [clientTdatawarehouse]
GO
DBCC SHRINKFILE (clientTDataWarehouse_log_1, 1024)
GO

 

From <https://stackoverflow.com/questions/12644312/could-not-locate-file-mydatabase-for-database-mydatabase-in-sys-database-fil>

 

Created with OneNote.

Turn On or Off Aero Shake for Current User using a REG file

The downloadable .reg files below will add and modify the DWORD values in the registry keys below.

 

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced

 

DisallowShaking DWORD

 

0 = Enable

1 = Disable

 

From <https://www.tenforums.com/tutorials/4417-how-enable-disable-aero-shake-windows-10-a.html>

 

 

 

 

 

 

Created with OneNote.

MsiExec cheat sheet

MsiExec.exe Command-Line Parameters

 

InstallShield 2019

 

MsiExec.exeis the executable program of the Windows Installer used to interpret installation packages and install products on target systems. After you build your release, you can install your Windows Installer package (.msi) from the command line.

 

Your Windows Installer package can be accessed from the folder that contains your built release. The default location is as follows:

 

C:\InstallShield 2019 Projects\ProjectName\ReleaseName\DiskImages\Disk1\ProductName.msi

 

After building a release of your product, you can install it from the command line:

 

msiexec /i "C:\InstallShield 2019 Projects\ProjectName\ReleaseName\DiskImages\Disk1\ProductName.msi"

 

The table below provides a detailed description of MsiExec.execommand-line parameters.


 Parameter

Description

/i <package> or <product code>

Use this format to install the product Othello:

msiexec /i "C:\InstallShield 2019 Projects\Othello\Trial Version\Release\DiskImages\Disk1\Othello Beta.msi"

Product Code refers to the GUID that is automatically generated in the Product Code property of your product’s project view.

Wget in powershell

 Basic Usage

At it’s most basic, the Invoke-WebRequest cmdlet sends an HTTP request method to an endpoint such as a URI or URL. The cmdlet supports all of the common request methods.

By far, the most common method is the GET method. This method reads information such as information from a website or maybe querying a REST API. The method is defined by using the Method parameter. Since we need an endpoint to query, we’ll also need a URI as well. To keep this easy, I’ll pick any website. To shamelessly promote TechSnips, I’ll choose techsnips.io.

Let’s say I want to get a listing of all of the latest published videos as shown below.

Example webpage

I can get an HTML representation of this page by running Invoke-WebRequest -Uri 'https://techsnips.io' -Method GET. When I do this, Invoke-WebRequest downloads the entire web page and returns an output with various parsed information around the elements of the page.

Invoke-WebRequest response

To get the videos, I’ll need to do some digging. When I look at the links property I see a commonality that all of the video links have a class of ng-binding as shown below.

$result.Links | where {$_.class -eq ‘ng-binding’}

Once I know this, I can then find all of those elements and only return the innerHTML property and voila!

$result.links | where {$_.class -eq ‘ng-binding’} | Select-Object innerHtml

Downloading Files with Invoke-WebRequest

We can also use Invoke-WebRequest to download files from the web as well and it’s really easy! We can download files by simply pointing Invoke-WebRequest at a URI of a file and using the OutFile parameter to tell the cmdlet to save the file to local disk.

As an example, below I’m downloading the SysInternals Handle utility and expanding the zip file once downloaded. It’s really that easy!

Invoke-WebRequest-Uri 'https://download.sysinternals.com/files/Handle.zip'-OutFile C:\handle.zi Expand-Archive-Path C:\handle.zip

Submitting a Form and Working with Sessions

We can use Invoke-WebRequest to also fill forms. To do this though, we commonly need to work with web sessions. HTTP is a naturally stateless protocol and your browser (in this case PowerShell) must be able to create a session which will be used to track things like cookies, for example. A common form is a login/password form so let’s login to a fictional website!

Let’s say our fictional login form is at the URL http://somewebsite.com. We’d first need to run Invoke-WebRequest to download the HTML structure and create a session.

$response= Invoke-WebRequest-Uri 'http://somewebsite.com'-SessionVariable rb

Once we do this, the response will have a Forms property we can then populate with a username and password. In this case, the username is represented by a field called user and the password should be in a field called password. This will depend on the webpage.

$form= $response.Forms[0]$form.Fields["user"]= "username"$form.Fields["password"]= "password"

Once the form has been populated, we can then use Invoke-WebRequest again but this time re-use the session we just created and automatically figure out the URI to send it to by reading the Action property that’s on the form as shown below.

$response= Invoke-WebRequest-Uri $form.Action -WebSession $rb-Method POST

If you’ve got all of the appropriate field names right and the webpage isn’t doing any fancy, you should be logged in with the username and password inside of the $rb web session. At this point, you can read various pages behind that authentication if you use the $rb web session variable.

Resolving Short URIs

Finally, another great use of Invoke-WebRequest is resolving short URIs. Perhaps you need to know what’s behind that shortened URL but don’t want to click on it to find out! No problem. Using Invoke-WebRequest, we can read the AbsoluteUri property from the parsed response it gives us!

Notice below I’m also using the UseBasicParsing parameter. By default, Invoke-WebRequest tries to use Internet Explorer (IE) to parse the HTML returned. This doesn’t work on systems without IE. To get around that, we can use the UseBasicParsing parameter to still download the content but only lightly parse it.

$Url= 'buff.ly/2sWvPOH'$Web= Invoke-WebRequest-Uri $Url-UseBasicParsing
$Web.BaseResponse.ResponseUri.AbsoluteUri

Summary

The Invoke-WebRequest cmdlet is one of the most versatile cmdlets that come with PowerShell. If there’s an action that can be performed via a typical graphical browser, the Invoke-WebRequest cmdlet can do it too. You can find an example of using this cmdlet by taking a look at this article on monitoring REST APIs.

 

From <https://adamtheautomator.com/invoke-webrequest/>

 

Created with OneNote.

Force BSOD

NotMyFault v4.20


Notmyfault is a tool that you can use to crash, hang, and cause kernel memory leaks on your Windows system. It’s useful for learning how to identify and diagnose device driver and hardware problems, and you can also use it to generate blue screen dump files on misbehaving systems. The download file includes 32-bit and 64-bit versions, as well as a command-line version that works on Nano Server. Chapter 7 in Windows Internals uses Notmyfault to demonstrate pool leak troubleshooting and Chapter 14 uses it for crash analysis examples.

Screenshots

Usage

You can use the GUI versions or the command-line version. Notmyfault requires administrative privileges.

Usage:

notmyfaultc.exe crash crash_type_num

Shell

    crash type:
      0x01: High IRQL fault (Kernel-mode)
      0x02: Buffer overflow
      0x03: Code overwrite
      0x04: Stack trash
      0x05: High IRQL fault (User-mode)
      0x06: Stack overflow
      0x07: Hardcoded breakpoint
      0x08: Double Free

Or  notmyfaultc.exe hang hang_type_num

Shell

    hang type:
      0x01: Hang with IRP
      0x02: Hang with DPC

Download NotMyFault (1 MB)

 

From <https://docs.microsoft.com/en-us/sysinternals/downloads/notmyfault>

 

Created with OneNote.

IIS log time zone

Which time zone IIS logs are recorded in?

 

IIS logs are helpful in troubleshooting various web application issues. However, they may mislead server administrators by showing the logs in a time zone different than what the server uses. This is because IIS uses UTC time zone by default.

 

Time zone options for IIS logs

There are 3 log file formats in IIS. The time zone of the logs is determined by these log file formats:

  1. W3C (default format): UTC time zone
  2. IIS: Local time
  3. NCSA: Local time zone

If you want IIS to log in your server’s time zone, you can change the log file format to IIS or NCSA in the Logging feature of IIS. This change won’t affect IIS. However, it may affect the third-part monitoring tools because the order of the columns and data formats change in the log file.

Not seeing logs for your requests? It might be because of missing bindings in IIS. Here is the solution: Missing bindings in IIS (net.tcp, net.pipe, net.msmq, msmq.formatname)

Sample logs for each log file format (Reference):

W3C:

#Software: Internet Information Services 6.0
#Version: 1.0
#Date: 2001-05-02 17:42:15
#Fields: time c-ip cs-method cs-uri-stem sc-status cs-version
17:42:15 172.16.255.255 GET /default.htm 200 HTTP/1.0

IIS:

192.168.114.201, -, 03/20/01, 7:55:20, W3SVC2, SALES1, 172.21.13.45, 4502, 163, 3223, 200, 0, GET, /DeptLogo.gif, -,
172.16.255.255, anonymous, 03/20/01, 23:58:11, MSFTPSVC, SALES1, 172.16.255.255, 60, 275, 0, 0, 0, PASS, /Intro.htm, -,

NCSA:

172.21.13.45 - Microsoft\fred [08/Apr/2001:17:39:04 -0800] "GET /scripts/iisadmin/ism.dll?http/serv HTTP/1.0" 200 3401

If you choose IIS or NCSA and the log time zone is still not what you want it to be, you will need to change the Regional Settings of your server which may affect IIS.

 

From <https://port135.com/which-time-zone-iis-logs-are-recorded-in/>

 

Created with OneNote.

Find Dot NET Version using PowerShell

Using the following steps, you can use PowerShell to check the Dot Net version on your computer.

 

  • On your computer click Start and launch PowerShell as administrator.
  • In the PowerShell window, copy the below command and press enter key.
  • The output contains the list of .NET Framework versions installed on your computer.

 

Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name version -EA 0 | Where { $_.PSChildName -Match '^(?!S)\p{L}'} | Select PSChildName, version

 

 

If you look at the output, you can see all the client version number and full version. Full version indicates the latest installed Dot NET framework version.

There is another way to check the .NET Framework version using PowerShell. Run the below command in the PowerShell window to determine the release number.

 

(Get-ItemProperty "HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full").Release

 

When you run the above command, it shows the release value. The Release value represents the version of .NET Framework installed.

 

From <https://www.prajwal.org/find-dot-net-version-using-powershell/>

 

 

 

 

 

Created with OneNote.

Hyper-V VM disk types and controllers

 

 Hyper-V IDE or SCSI? What’s Performing Better, Faster?

 

If you wonder whether to use IDE or SCSI controllers for your Hyper-V virtual machines, the short answer is: IDE is fine.

 

There is no need to go for SCSI, it won’t be any faster. Note that you need to have a IDE connected virtual disk in order to boot.

 

If you want better performance, the virtual machines will run much faster if you:

 

  1. Use pass through disks instead
  2. Use fixed sized VHDs
  3. Refrain from using snapshots / checkpoints
  4. Refrain from using dynamically expanding disks
  5. Have at least 15% free space inside the VM at all times, and at least 10GB free. It’s an old characteristic of NTFS….
  6. Use paging files on a separate VHD, ideally hosted on a separate drive
  7. Use fixed-sized paging files
  8. Use 4KB NTFS cluster size on the host

 

In addition, you would want to use the VHDX format instead because it provides faster access to the disk due to its block size on newer hard drives.

 

From <https://hyper-v-backup.backupchain.com/hyper-v-ide-or-scsi-whats-performing-better-faster/>

 

Created with OneNote.

Removing tiered storage spaces - Windows Server 2022

As part of the work I have done in my homelab with tiered storage on Server 2022 storage spaces , here is a script I created that allows you...