Thursday, July 7, 2016

Preventing Screen Saver with PowerShell

Here's a short bit of PowerShell you can have run when you log in to a machine (or manually)...
Function Prevent-ScreenSaver
{
    [CmdletBinding()]
    Param(
        [int]$IntervalSeconds = 60,
        [string]$KeyToSend = "{F15}"
    )
    $Shell = New-Object -COM “WScript.Shell”
    While ($True)
    {
        Write-Verbose "Sending key '$KeyToSend'..."
        $Shell.SendKeys($KeyToSend)
     
        Write-Verbose "`t...waiting $IntervalSeconds seconds..."
     
        Start-Sleep $IntervalSeconds
    }
}

Save that to a file, then have it start on login (via shortcut in Startup folder)...





Inspired by: https://dmitrysotnikov.wordpress.com/2009/06/29/prevent-desktop-lock-or-screensaver-with-powershell/

There's an alternative little utility, called Screen Slayer. As of 7/7/2016, links and info can be found here: http://daniel-lange.com/archives/34-Disabling-a-group-policyd-screensaver-on-Windows.html


Wednesday, July 6, 2016

SharePoint URL De-muck Utility

SharePoint links/urls for pages and such, are ridiculously unfriendly for human consumption, or even putting in emails and documents.


I threw together a quick utility over at jsfiddle.net where you can paste a URL, and it will attempt to make it simpler, getting rid of gunk and muck as much as possible, while still staying functional.

https://jsfiddle.net/mrstevec/jux51s0b/


Friday, July 1, 2016

Shrink SQL DBs with PowerShell

Here's a little nugget that will iterate over DBs larger than specified size, and shrink them.

$shrinkDBsLargerThan = 50
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | Out-Null
$sqlsrv = New-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
$db = New-Object Microsoft.SqlServer.Management.Smo.Database
$sqlsrv.Databases | ? Size -GT $shrinkDBsLargerThan | % {
    Write-Host "DB: $($_.Name)"
    Write-Host "`tInitial Size(MB): $($_.Size)"
    $_.Shrink(20, [Microsoft.SqlServer.Management.Smo.ShrinkMethod]'Default')
    $_.Refresh()
    Write-Host "`t Shrunk Size(MB): $($_.Size)"
}