Archive for the ‘Powershell’ Category

Using Powershell to increment the computers date

Here’s a little snippet of Powershell code I used recently to test some TSQL that runs according to a two week schedule. This code will increment the date by one day, up to the maximum specified in $days, sleeping in between for a short while. The date is set back correctly at the end. Far […]

Testing a Failover Cluster with Powershell

Just a quick Powershell snippet that I’m going to use to run validation tests on one of my staging Failover Clusters during OOH. The script below will take some services offline, run the validation tests, before bringing the appropriate cluster groups back online. The report will be saved using the date as the name. To […]

Domain user password expiry with Powershell

I needed to figure out a method for producing alerts when a domain account is approaching the password reset date. Here it is in a few lines of Powershell… ?View Code POWERSHELL# Set name here $name = "Rhys Campbell"; $user = Get-ADUser -LDAPFilter "(Name=$name)" -Properties PasswordLastSet; $days = $(Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge; $expires = $user.PasswordLastSet + $days; $days_left […]

Checking Disk alignment with Powershell

Disk alignment has been well discussed on the web and the methods to check this always seem to use wmic or DISKPART. I’ve always loathed wmi so here’s a few lines of Powershell that achieves the same thing; ?View Code POWERSHELL$sqlserver = "sqlinstance"; # Get disk partitions $partitions = Get-WmiObject -ComputerName $sqlserver -Class Win32_DiskPartition; $partitions […]

Audit VLFs on your SQL Server

I’ve been reading a bit about VLFs (Virtual Log Files) this week. I’ve found quite a few interesting links, especially this one, informing us that there’s such a thing as too few or too many VLFs. We can view details about VLFs using the DBCC LOGINFO TSQL command. This only works against the current database […]