Snippets

Admin check, just run Test-IsAdmin to call the function and output true or false. I use this for logging. If you want a hard fail for lack of admin use #Requires -RunAsAdministrator

function Test-IsAdmin {
    try {
        $identity = [Security.Principal.WindowsIdentity]::GetCurrent()
        $principal = New-Object Security.Principal.WindowsPrincipal -ArgumentList $identity
        return $principal.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator )
    } catch {
        throw "Failed to determine if the current user has elevated privileges. The error was: '{0}'." -f $_
    }
}

Start service on remote machine

Get-Service -ComputerName <machine> -Name <service> | Set-Service -Status Running

Grep

| findstr -i <term>

Connect to Sharepoint online

# the name appearing in the URL of your sharepoint site before sharepoint.com
$orgName=""
# connect without using get-credential so that the modern prompt is generated allowing 2FA
Connect-SPOService -Url https://$orgName-admin.sharepoint.com```
Back to top