Drop this in a .ps1 file and watch it go:
phishandchips.dev
Ramblings of a tech addict powershell nerd and a place to share and compare my notes and scripts!
Removing tiered storage spaces - Windows Server 2022
Drop this in a .ps1 file and watch it go:
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:
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:
Creating tiered storage spaces - Windows Server 2022 - Getting the best performance on your home server
- https://datacenteroverlords.com/2018/12/17/microsoft-storage-spaces-is-hot-garbage-for-parity-storage/
- https://storagespaceswarstories.com/storage-spaces-and-slow-parity-performance/#more-63
- https://wasteofserver.com/storage-spaces-with-parity-very-slow-writes-solved/
- https://jackharvest.com/index.php/2022/03/10/storage-spaces-parity-on-server-2022-is-finally-good-enough-to-use/
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.
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
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...
-
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....
-
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 yo...
-
NotMyFault v4.20 Notmyfault is a tool that you can use to crash, hang, and cause kernel memory leaks on your Windows system. It’...