Skip to content

Instantly share code, notes, and snippets.

View wictorwilen's full-sized avatar
😀

Wictor Wilén wictorwilen

😀
View GitHub Profile
@wictorwilen
wictorwilen / QuickEditAlternateCss.js
Created January 21, 2015 12:21
Quickly edit AlternateCSSUrl in SharePoint
// Copy and paste this into the Console window in any browser debugging tool to edit the Alternate CSS for a site
var context = SP.ClientContext.get_current()
var web = context.get_web()
web.set_alternateCssUrl('assets/test.css')
web.update()
context.executeQueryAsync(
function(){
alert('CSS Updated')
},
function() {
@wictorwilen
wictorwilen / ShowAlternateCSSUrl.js
Created January 21, 2015 12:42
Show the current confgured Alternate CSS Url
// Copy and paste this into the Console window in any browser debugging tool to show the Alternate CSS for a site
var context = SP.ClientContext.get_current()
var web = context.get_web()
context.load(web)
context.executeQueryAsync(
function(){
alert('Value is: ' + web.get_alternateCssUrl())
},
function() {
alert('Error')
@wictorwilen
wictorwilen / gist:d3c082852a81b051ca07
Last active August 29, 2015 14:13
Create a non Hyper-V boot entry for Windows 8
# Copy the current entry to a new (called No Hyper-V)
bcdedit /copy {current} /d "No Hyper-V"
# Note the Id from the command result above
bcdedit /set <ID> hypervisorlaunchtype off
# Set the default one to the newly created entry
bcdedit /default /ID <ID>
@wictorwilen
wictorwilen / RemoveField.js
Created January 30, 2015 11:52
Remove a field programatically from a list using JSOM
var context = SP.ClientContext.get_current()
var web = context.get_web()
var lists = web.get_lists()
var list = lists.getByTitle('Test') // Replace with title of list
var cols = list.get_fields()
var col = cols.getByInternalNameOrTitle('XYZ') // replace with title or internal name of column
col.deleteObject()
context.executeQueryAsync(
function(){
alert('Done')
@wictorwilen
wictorwilen / changeTitle.js
Created January 30, 2015 12:51
Change the "new item" link in SharePoint 2013 using CSR with MDS support
// Modify the lines with TODO comments below
Type.registerNamespace('Wictor')
Wictor.Demos = Wictor.Demos || {};
Wictor.Demos.Functions = Wictor.Demos.Functions || {}
Wictor.Demos.OnPostRender = function (context) {
var wpTable = $get("Hero-" + context.wpq);
if (wpTable != null) {
var children = wpTable.getElementsByTagName("a");
@wictorwilen
wictorwilen / Get-SPSiteSizeReport.ps1
Created February 4, 2015 11:18
SharePoint: Site Collection size report
asnp *sh*
get-spsite -limit all| select url, @{label="Size in MB";Expression={$_.usage.storage/1MB}}, @{label="Content Database"; Expression={$_.ContentDatabase.Name}}, @{label="Quota Max"; expression={$_.Quota.StorageMaximumLevel/1MB}}, @{label="Created"; expression={$_.RootWeb.Created}} | Sort-Object -Descending -Property "Size in MB" | ConvertTo-Csv | Set-Content c:\temp\scsize.csv
@wictorwilen
wictorwilen / secure-channel-logging.ps1
Created February 4, 2015 11:20
Secure Channel logging
# http://support.microsoft.com/kb/260729
# 0x0000 0 Do not log
# 0x0001 1 Log error messages
# 0x0002 2 Log warnings
# 0x0004 4 Log informational and success events
Set-ItemProperty HKLM:\System\CurrentControlSet\Control\SecurityProviders\SCHANNEL -Name "EventLogging" -Value "4"
Write-Host -ForegroundColor Red "You need to reboot the server"
@wictorwilen
wictorwilen / Reset-SPCache.ps1
Created February 4, 2015 11:21
Reset SharePoint Cache on all servers in the farm
asnp microsoft.sharepoint.powershell
Get-SPServer | ?{$_.Role -eq "Application"} | %{
Write-Host -ForegroundColor Green "Updating $_ ..."
Invoke-Command -ComputerName $_.Name {
Stop-Service SPTimerV4
Stop-Service SPAdminV4
Get-ChildItem $env:ALLUSERSPROFILE\Microsoft\SharePoint\Config | ?{$_.Name.Contains("-")} | Get-ChildItem | ?{$_.Extension -eq ".xml"} | Remove-Item
$ini = Get-ChildItem $env:ALLUSERSPROFILE\Microsoft\SharePoint\Config | ?{$_.Name.Contains("-")} | Get-ChildItem | ?{$_.Extension -eq ".ini"}
@wictorwilen
wictorwilen / officegraphcsomsample.cs
Created February 6, 2015 10:45
Office Graph CSOM sample
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
List<OfficeGraphResult> graphResult = new List<OfficeGraphResult>();
using (var clientContext = spContext.CreateUserClientContextForSPHost())
{
if (clientContext != null)
{
var keywordQuery = new KeywordQuery(clientContext)
{
QueryText ="*",
RowLimit = 10
@wictorwilen
wictorwilen / azuread-authn.cs
Created February 12, 2015 10:05
Azure AD AuthN stuff
string resourceId = "<resource id>";
// Can be:
// For SharePoint (CSOM), tenant Url: https://tenant.sharepoint.com
// For Azure AD Graph: https://graph.windows.net
// For Office 365 Discovery: https://api.office.com/discovery/
// For Exchange Online: https://outlook.office365.com/
string secret = "<App client secret>"; // a generated guid
Uri redirectUri = new Uri("<App redirect Uri>"); // for instance app://my-app