Instantly share code, notes, and snippets.

View Find_Current_Queries.sql
SELECT sqltext.TEXT
, req.session_id
, req.status
, req.command
, req.cpu_time
, req.total_elapsed_time
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_sql_text(sql_handle)
AS sqltext
View NI_Checker.PS1
Add-Type -AssemblyName System.Windows.Forms
$NIChecker = New-Object system.Windows.Forms.Form
$NIChecker.Text = "Form"
$NIChecker.TopMost = $true
$NIChecker.Width = 304
$NIChecker.Height = 289
$Label = New-Object system.windows.Forms.Label
$Label.Text = "Enter the National Insurance Number below"
View Staff_Photos.ps1
<#
######
IMPORT PHOTOS EN-MASSE BASED ON THE PHOTOS BEING NAMED AFTER THE RELEVANT USERS
e.g. for staff members Alan Alanson, Barry Barryson, Charles Charleson,
the photos would need to be name "Alan Alanson.jpg", "Barry Barryson.jpg", "Charles Charleson.jpg".
#####
#>
$PhotoPath = "\\SERVER\SHARE\photos\Outlook\*.*"
ForEach ($PhotoFile in gci $PhotoPath)
View What_Machine_User_Logged_In_To.ps1
Import-Module activedirectory
write-host "**************************************************************"
Write-Host "`nThis script will tell you what computer a user is logged in to" -ForegroundColor Yellow -BackgroundColor Black
write-host "`n**************************************************************"
$i = 0
#sets up credentials
$myusername = "**DOMAIN**\" + [Environment]::UserName
View Capitalise_User_Details.ps1
$users = get-aduser -Filter * -SearchBase #"ou=OU,dc=MYD,dc=local"
foreach ($user in $users)
{
$person = get-aduser $user -Properties title, department, givenname, surname, displayname | select displayname, title, department, givenname, surname
$displayname = ($person.displayname).ToString()
$title = ($person.title).ToString()
$department = ($person.department).ToString()
$givenname = ($person.givenname).ToString()
View Get_Computer_Info.ps1
Function Model
{
$Description = Get-WmiObject -Class Win32_OperatingSystem -Computer $Computer -Credential $Credentials
$Model = get-wmiobject -class "Win32_Computersystem" -computer $Computer -Credential $Credentials
$Ram = ($Model.TotalPhysicalMemory/1GB)
$Ram = [Math]::Round($Ram, 2)
Write-host
Write-host "Computer :" $Model.Name.ToUpper()