Skip to content

Instantly share code, notes, and snippets.

@joerodgers
joerodgers / Update-LastLogonTimestamp.ps1
Created October 6, 2020 14:00
Trick to force an update to the LastLogon Timestamp for an Active Directory account. This is sometimes necessary for the portal cache accounts if a companies AD team disables accounts based on the LastLogon timestamp of a user.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
function Update-LastLogonTimestamp
{
[CmdletBinding()]
param
(
[parameter(Position=0, Mandatory=$true)][string]$UserName
)
#requires -Modules @{ ModuleName="PnP.PowerShell"; ModuleVersion="1.12.0" }
function Find-SharedWithEveryoneOrEEEUContent
{
[CmdletBinding(DefaultParameterSetName="SharePoint")]
param
(
[Parameter(Mandatory=$true,ParameterSetName="SharePoint")]
[switch]
$IncludeSharePointOnline,
#requires -modules "PnP.PowerShell"
function Test-ListItemPath
{
[CmdletBinding()]
param
(
[parameter(mandatory=$true)]
[string]
#requires -modules "PnP.PowerShell"
function Get-ItemAnalytics
{
[CmdletBinding()]
param
(
[parameter(mandatory=$true)]
[string]
$ItemDriveUrl,
@joerodgers
joerodgers / Test-CodeSign.ps1
Created March 26, 2024 20:34
Testing PowerShell Script Signing using a self-signed cert
function Test-CodeSign
{
write-Host "HELLO WORLD"
}
<#
$params = @{
Subject = "CN=PowerShell Script Code Signing"
Type = "CodeSigningCert"
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking -ErrorAction Stop
# tenant name
$tenant = $env:O365_TENANT
# define a list of users or groups to report. Use UPN for user objects and ObjectId for group objects
$identities = "jane.doe@contoso.com", "john.doe@contoso.com", "986b904f-0de9-416d-9fd9-7e5d8402e7c0"
if( -not $credential )
{
@joerodgers
joerodgers / Invoke-ListPermissionInheritanceReset.ps1
Last active March 22, 2024 09:20
Script to reset permission inheritance on lists in a site collection in SharePoint Online.
#requires -modules "PnP.PowerShell"
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
function Invoke-FolderPermissionInheritanceReset
{
[CmdletBinding()]
param
(
@joerodgers
joerodgers / Update-SiteLibrariesMajorVersionCount.ps1
Last active March 22, 2024 08:47
Enables version history on all document libraries and sets the major version limit to configured value
#requires -modules "PnP.PowerShell"
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
function Set-MajorVersionCount
{
[CmdletBinding()]
param
@joerodgers
joerodgers / New-Password.ps1
Last active March 14, 2024 21:40
PowerShell 5+ cryptographically secure password generator. It's a port of the legacy System.Web.Security.Membership.GeneratePassword(Int32, Int32) function
function New-Password
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true)]
[ValidateRange(2,128)]
[int]
$Length,
function ConvertTo-Base64UrlEncodedString
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true)]
[byte[]]
$Bytes
)