This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | |
function EnsureDirectory($exportFolderPath) { | |
if ( -not (Test-Path $exportFolderPath) ) {New-Item $exportFolderPath -Type Directory | Out-Null} | |
} | |
function ExportAllWebParts($siteUrl,$pageUrl,$exportFolderPath) | |
{ | |
$web = Get-SPWeb $siteUrl | |
$wpm = $web.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH cte AS ( | |
SELECT [Col1], [Col2], | |
row_number() OVER(PARTITION BY Col1, Col2 ORDER BY ColByWhichFirstInOrderIsRemoved) AS [rn] | |
FROM [TableName] | |
) | |
DELETE cte WHERE [rn] > 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assuming jQuery is loaded: | |
// Dump all lists in web site | |
$.ajax({url:"/_api/web/lists?$expand=defaultView",headers:{"Accept":"application/json;odata=verbose"},success:function(r){r.d.results.forEach(function(l){console.log(l.Id+"|"+l.Title+"|"+l.DefaultView.ServerRelativeUrl);});}}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Show group memberships for specified user | |
Get-WmiObject -Query "ASSOCIATORS OF {Win32_Account.Name='mikpla',Domain='CONTOSO'} WHERE ResultRole=GroupComponent ResultClass=Win32_Account" | select Name | |
# Show creation date for a specified user | |
Get-ADUser -Identity mikeplate -Properties WhenCreated |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$sourcePath = 'C:\Code\Projects' | |
$destinationPath = 'I:\Backup' | |
$zipExe = 'C:\Program Files\7-Zip\7z.exe' | |
function GetLastWriteTime { | |
$last = (Get-Date).AddYears(-100) | |
foreach ($file in Get-ChildItem -Recurse $args[0]) { | |
if ($file.LastWriteTime -gt $last) { | |
$last = $file.LastWriteTime | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function QSequence($q) { | |
var _callbacks = []; | |
var _preCallbacks = []; | |
var _current = 0; | |
var _data = {}; | |
function dispatch(deferred) { | |
var callback = _callbacks[_current]; | |
for (var i = 0; i < _preCallbacks.length; i++) { | |
_preCallbacks[i](_data, callback.name); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE master | |
GO | |
DECLARE @kill varchar(8000) = ''; | |
SELECT @kill = @kill + 'kill ' + CONVERT(varchar(5), spid) + ';' | |
FROM master..sysprocesses | |
WHERE dbid = db_id('MyDB') | |
EXEC(@kill); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @username varchar(256) | |
set @username = 'flowchart' | |
declare @name varchar(256) | |
declare db_cursor cursor for | |
select name from master.dbo.sysdatabases where name not in ('master','model','msdb','tempdb') | |
open db_cursor fetch next from db_cursor into @name | |
while @@fetch_status = 0 | |
begin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @path nvarchar(256) | |
declare @files table (subdirectory nvarchar(256), depth int, [file] int) | |
declare @sourcepath nvarchar(256) | |
set @sourcepath = 'C:\Code\AutoFlow\Installed\Databases' | |
-- Determine default data path | |
select @path = SUBSTRING(physical_name, 1, CHARINDEX(N'master.mdf', LOWER(physical_name)) - 1) | |
from master.sys.master_files | |
where database_id = 1 AND file_id = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT OBJECT_NAME(id) | |
FROM SYSCOMMENTS | |
WHERE [text] LIKE '%Foo%' | |
AND OBJECTPROPERTY(id, 'IsProcedure') = 1 | |
GROUP BY OBJECT_NAME(id) |