Skip to content

Instantly share code, notes, and snippets.

View Laim's full-sized avatar
😍
.NET

Laim Laim

😍
.NET
View GitHub Profile
@Laim
Laim / MT.vbs
Created April 22, 2020 12:39
machinetype
strName = "." 'Computer name, if local just use a period.
Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strName & "\root\cimv2")
For Each obj in objWMI.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each strChassisType in obj.ChassisTypes
Wscript.Echo strChassisType
Next
Next
@Laim
Laim / RestoreSQLServerDatabase.sql
Last active May 27, 2020 12:29
Restore SQL Server Database
-- Take the database offline before restoring
ALTER DATABASE [DatabaseName]
SET OFFLINE WITH ROLLBACK IMMEDIATE
-- Restore the database
RESTORE DATABASE DatabaseName FROM DISK = '\\FileServer\directory\servername\database\database_backup.bak'
-- Bring it back online, this should be automatic but just incase.
ALTER DATABASE [DatabaseName]
SET ONLINE
@Laim
Laim / feed.xml
Last active February 8, 2021 11:20
Jekyll working RSS feed.xml
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ site.name | xml_escape }}</title>
<description>{{ site.description | xml_escape }}</description>
<link>{{ site.url }}</link>
<atom:link href="{{ site.url }}/feed.xml" rel="self" type="application/rss+xml" />
{% for post in site.posts limit:10 %}
<item>
<title>{{ post.title }}</title>
@Laim
Laim / sp_who2_filter.sql
Last active May 7, 2021 15:48
sp_who2 filtering
/*
Author: Laim McKenzie
Date: 30-04-2021
Updated: 07-05-2021
https://laim.scot
*/
/* Create temp table to populate with data */
CREATE TABLE #sp_who2
(
@Laim
Laim / versions.ps1
Last active May 7, 2021 17:52
PowerShell, .NET and SQL Instance Versions in PowerShell
# START : Get SQL Instance Version #
cls # prevents the script itself from echoing out into ISE
"---------------------------------------------------------------------"
$inst = (get-itemproperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances # Gets the installed SQL instances
$sqlInstanceCount = 0; # loop for the foreach
foreach ($i in $inst)
-- Custom Fields
SELECT C.Name, COUNT(CF.CID) AS [CustomFieldCount] FROM SnowLicenseManager.dbo.tblCustomField CF
INNER JOIN SnowLicenseManager.dbo.tblCID C ON CF.CID = C.CID
GROUP BY C.Name
-- Custom Compare Values
SELECT C.Name, COUNT(CCV.CID) AS [CCVCount] FROM SnowLicenseManager.dbo.tblCustomCompareValues CCV
INNER JOIN SnowLicenseManager.dbo.tblCID C ON CCV.CID = C.CID
GROUP BY C.Name
@Laim
Laim / hide_unassigned.sql
Last active June 4, 2021 15:32
Mass hide Unassigned Software in Snow License Manager to prevent SMACC lag
/*
Author: Laim McKenzie
Website: https://laim.scot
Version: 1.0
You can view the Hidden Software count using this script
SELECT COUNT(*) FROM SnowLicenseManager.dbo.tblSoftware WHERE IsHidden = 1
*/
/*
Modified version of https://blog.sqlauthority.com/2017/03/12/get-status-running-backup-restore-sql-server-interview-question-week-113/
Author: Laim McKenzie
Available from https://gist.github.com/laim
Copyright (c) 2021 laim.scot
*/
SELECT r.session_id AS [Session_Id]
,r.command AS [command]
@Laim
Laim / CopyLogFiles.ps1
Last active July 29, 2021 13:53
Copy Log files from Source Directory to Destination Directory via PowerShell
#<----------------------------------------->#
# > Author: Laim McKenzie
# > Date: 29-07-2021
# > Description: This script can be ran under a Scheduled Task and collect log files from the Source Directory and copy to the Destination Directory
# > Pre-requisites:
# > 1. You need to ensure the Source Directory exists
# > 2. You need to ensure the Desitnation Directory exists
# > 3. The account running the scheduled task (if ran under one) needs to have access to both directories
# > Copyright (c) 2021 Laim McKenzie
#<----------------------------------------->#
@Laim
Laim / lmu_del_sql_jobs.sql
Last active November 15, 2021 17:47
Delete all SQL Jobs that are assigned to LicenseManagerUser
/*
Author: Laim McKenzie
Website: https://laim.scot
Version: 1.0
Modified version of https://sqlgeekspro.com/script-to-delete-sql-agent-jobs/
*/
DECLARE @SQLStatement VARCHAR(200)
DECLARE @jobName SYSNAME