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.

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...