Skip to content

Instantly share code, notes, and snippets.

@vaderj
vaderj / set_Site_Collection_Admin.ps1
Last active June 11, 2018 20:39
PowerShell - Open prompt as Admin user who has access, set URL var, run command #PowerShell #SharePoint
$url = "."
new-spuser -UserAlias 'domain\userName' -web $url -SiteCollectionAdmin
@vaderj
vaderj / Add-SPUser-to-site.ps1
Last active June 12, 2018 16:55
Add a user to a SharePoint site #PowerShell #SharePoint
$web = Get-SPWeb "http://portal"
function AddGroupToSite ($web, $groupName, $permLevel)
{
$account = $web.SiteGroups[$groupName]
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$role = $web.RoleDefinitions[$permLevel]
$assignment.RoleDefinitionBindings.Add($role);
$web.RoleAssignments.Add($assignment)
}
@vaderj
vaderj / check-spuser-permission.js
Last active June 12, 2018 16:56
check if the current SP user has a specific permission #Javascript #REST #SharePoint
//Permission enumeration : https://msdn.microsoft.com/en-us/library/office/ee556747(v=office.14).aspx
function checkPermissions() {
var call = jQuery.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/effectiveBasePermissions",
type: "GET",
dataType: "json",
headers: {
Accept: "application/json;odata=verbose"
}
@vaderj
vaderj / sp-column-shrinker.css
Last active June 12, 2018 17:05
SharePoint - Make a rediculously huge column shrink to a normal size until hover occurs #css #SharePoint
/* http://sharepoint.stackexchange.com/questions/151473/how-to-truncate-a-multiline-column-in-a-sharepoint-list-2013 */
<style>
.ms-vb2 .ms-rtestate-field{
max-width:250px;
max-height:38px;
overflow:hidden;
}
.ms-vb2 .ms-rtestate-field:hover{
max-height:none;
@vaderj
vaderj / enable-numberedList-in-RichTxtEditor.js
Last active June 12, 2018 16:56
This will enable the numbered list box based on the click event of the specific rich text box, if there is a 'p' tag #Javascript #SharePoint
$(".ms-rtestate-write[id*='Steps']").click(function (){
if ($(".ms-rtestate-write[id*='Steps'] ol").legth > 0)
{
return;
}
else if ($(".ms-rtestate-write[id*='Steps'] p").length > 0)
{
RTE.RichTextEditor.numberedList();
}
});
@vaderj
vaderj / new_gist_file_0
Last active June 12, 2018 17:01
RegEx used for SharePoint search query rulesquery terms must contain all three words: hospital, marketing, guide(?i: = case insensitive #RegEx #SharePoint
^(?i:(?=.*\bhospital\b)(?=.*\bmarketing\b)(?=.*\bguide\b)).+
@vaderj
vaderj / Alternative_Excel_Unlock
Last active June 8, 2021 02:32
#VBA Two methods of unlocking a locked excel sheet:VBA macro for Excel that should unprotect a password protected sheet,Opening the spreadsheet as XML and removing the specific piece
Step 1. Make a copy of the spreadsheet in an empty directory. Rename the extension to .zip
Step 2. Extract the zip file.
Step 3. In the extracted contents, goto the folder \xl\worksheets\
Step 4. There should be one xml file per sheet? I editing "sheet1.xml" with NotePad++. From nearly the very end of the file, remove the tag that starts with:
<sheetProtection
My entire tag was as follows:
<sheetProtection algorithmName="SHA-512" hashValue="ALciNBSIqRcjDiFbCuyWoGk4iOcC/ZRKnEjwEVi1skb6G5JbHhp+QVZ9+rlPVbGILOS7lYiCvJmR4Q7IuSphXA==" saltValue="8OVKXrG0VacLOLVztUpEYw==" spinCount="100000" sheet="1" objects="1" scenarios="1" selectLockedCells="1"/>
Step 5. Save the file. Open the ZIP file in 7zip, find the same file, drag and drop, save, exit, rename the file back to (xlsx) and open
@vaderj
vaderj / new_gist_file_0
Last active June 12, 2018 17:00
PowerShell => MS SQL - just to verify that a connection is correctly setup.This is equivalent to "The UDL trick" #PowerShell #SQL #Windows
# Open a connection to the SQL Server Database Engine
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString = "Server=SQLDB2016\SHAREPOINT;Database=master;Integrated Security=True"
$sqlConnection.Open()
# Query the master database
$sqlCommand = New-Object System.Data.SqlClient.SqlCommand
$sqlCommand.CommandText = "SELECT name FROM [master].[sys].[databases]"
$sqlCommand.Connection = $sqlConnection
@vaderj
vaderj / SPList-REST.html
Last active June 11, 2018 20:40
Utilize a SPList as a lookup.Script includes HTML and JS. List is populated by PowerShell script Field-Org-SQL-TO-SPList.ps1 #Javascript #SharePoint
<style>
</style>
<div class="container-fluid" id="main">
<div id="target">
<span>Select the columns you would like returned: </span> <br>
@vaderj
vaderj / checkoutSPdocumentViaREST.js
Last active June 12, 2018 15:01
Check out a document #Javascript #REST #SharePoint
function checkOutDocument(docId)
{
jQuery.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Resource Library')/items(" + docId + ")/file/CheckOut()",
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val(),
},
success: function(){