In some cases you may be getting the following error when running Step 2 of the SQLWATCH-LOGGER-DISK-UTILISATION Agent Job:
Cannot open database "SQLWATCH" requested by the login. The login failed. Login failed for user 'HOME\SQL-TEST-1$'
This is because PowerShell jobs run under a SQL Agent context and this means they may not have permissions to the SQL Server and the SQLWATCH database.
SQLWATCH will not alter your server security configuration or permissions or create any accounts. If you do encounter this error you will have to fix it manually. Depending on your environment, there may be different ways to address this, some more appropriate and some less, again, depending on your setup.
The recomended and most secure way is to create a SQL Agent Proxy Account and grant this account db_datawriter and db_datareader roles in the SQLWATCH database. This account will need appropriate access to read OS disks. This account will ONLY have access you have created.
An alternative and slightly easier way is to grant
db_datareader roles to the login reported in the error in the SQLWATCH database. However, in this case, we may be granting permission to the SQLWATCH database to an account that perhaps should not have such access. Please be sure you are familiar with the security configuration in your environment. In our example this would be:
USE [master]GOCREATE LOGIN [HOME\SQL-TEST-1$] FROM WINDOWSGOUSE [SQLWATCH]GOCREATE USER [HOME\SQL-TEST-1$] FOR LOGIN [HOME\SQL-TEST-1$]GOALTER ROLE [db_datawriter] ADD MEMBER [HOME\SQL-TEST-1$]GOALTER ROLE [db_datareader] ADD MEMBER [HOME\SQL-TEST-1$]GO