Skip to content

Instantly share code, notes, and snippets.

View markekraus's full-sized avatar
😀

Mark Kraus markekraus

😀
View GitHub Profile
$OS = (Get-WMIObject Win32_OperatingSystem).Caption
$DaysToDelete = 30
if(($OS -like "*2008*") -or ($OS -like "*2012*")){
$diskbefore = GWMI -Class win32_LogicalDisk -Filter "DeviceID = 'C:'" | Select-Object @{ n = "$OS"; e = {$_.PSComputerName}}, @{ n = "FreeSpace(GB) Before" ; e = {"{0:N1}" -f( $_.Freespace / 1gb ) } }, @{ n = "PercentFree Before" ; e = {"{0:P1}" -f( $_.FreeSpace / $_.Size ) } } | Out-String
Write-Output "$diskbefore"
}
else{
write-host @"
@markekraus
markekraus / Add-SharePointSiteExternalUser.ps1
Last active May 7, 2021 13:56
PowerShell function to invite an external user or list of external users to a SharePoint site
<#
.SYNOPSIS
Invites an external user or list of external users to a SharePoint site.
.DESCRIPTION
Invites an external user or list of external users to a SharePoint site.
External users can be granted View, Edit, or Owner permissions within
the site. A custom e-mail message can be included or the invitation email
can be suppressed.
.PARAMETER SiteURL
URL string of the SharePoint site to which the user(s) will be invited.
@markekraus
markekraus / Patch-NotPetya.ps1
Last active June 28, 2017 18:51
Patch AD Computers for NotPetya. Supports multiple runs to skip previously patched machines and provides detailed logging objects.
#Requires -Modules PoshRSJob, ActiveDirectory
# create this file as read-Only before running script
$SourceFile = "C:\perfc"
$ServerFilter = {enabled -eq $True -and DnsHostName -like "*" -and operatingSystem -like "*windows*"}
$SearchBase = "dc=adatum,dc=com"
$LogFile = "C:\NotPetyaPatch.xml"
$Throttle = 40
class MockedWebResponseAsyncResult : System.IAsyncResult {
[System.Net.WebRequest] $Request;
[Object]$state
MockedWebResponseAsyncResult([System.Net.WebRequest] $request, [object]$State) {
$this.Request = $request
$This.State = $State
}
[bool] get_IsCompleted () {
@markekraus
markekraus / Sort-DotSpelling.ps1
Last active September 20, 2017 23:40
Sorts .spelling file for Powershel/Powershell
$File = (Get-Content .\.spelling)
$Head = $File[0..4]
$Count = 0
$Dictionary = foreach($Line in $File[5..($File.Count -1)]){
$Count ++
if($Line -Match '^#region ' -or [string]::IsNullOrEmpty($line)){continue}
if($line -match '^ -|^#endregion'){break}
$line
}
$Dictionary = $Dictionary | Sort-Object
@markekraus
markekraus / express.js
Last active December 9, 2017 22:18
Test scripts and progranm for IRM memory leak troubleshooting
const express = require('express')
const app = express()
app.get('/api', function (req, res)
{
res.send('0')
})
app.listen(5001, function ()
{
Install-Module PSRAW -Scope CurrentUser
Import-Module PSRAW
# Go here https://ssl.reddit.com/prefs/apps
# use https://127.0.0.1 for redirect uri
# register Script App and note client id and secret
Connect-Reddit
$Params = @{
@markekraus
markekraus / StyleCopErrors.txt
Created December 21, 2017 13:40
Web Cmdlet StyleCop Issues
.\commands\utility\WebCmdlet\StreamHelper.cs(279,27): error SA1204: Static members should appear before non-static members
.\commands\utility\WebCmdlet\FormObject.cs(40,16): error SA1201: A constructor should not follow a property
.\commands\utility\WebCmdlet\FormObject.cs(17,23): error SA1609: Property documentation should have value
.\commands\utility\WebCmdlet\FormObject.cs(22,23): error SA1609: Property documentation should have value
.\commands\utility\WebCmdlet\FormObject.cs(27,23): error SA1609: Property documentation should have value
.\commands\utility\WebCmdlet\FormObject.cs(32,43): error SA1609: Property documentation should have value
.\commands\utility\WebCmdlet\FormObjectCollection.cs(19,13): error SA1616: Element return value documentation should have text
.\commands\utility\WebCmdlet\FormObjectCollection.cs(18,13): error SA1614: Element parameter documentation should have text
.\commands\utility\WebCmdlet\Common\BasicHtmlWebResponseObject.Common.cs(5,1): error SA1200: Using directive should ap
@markekraus
markekraus / CodeCommitEvent.cs
Last active February 13, 2018 21:03
CodeCommitEvent Model for Receiving CodeCommit Events in C# AWS Lambdas
using System;
namespace Lambda
{
public class CodeCommitEventCodecommitReference
{
public string commit;
public bool created = false;
public string @ref;
@markekraus
markekraus / ConvertKMSEncryptedStrings.ps1
Created February 18, 2018 19:41
PowerShell Functions to convert a string to a base64 representation of the KMS encryoted string and to convert back to an unencrypted string
function ConvertTo-Base64KMSEncryptedString {
[CmdletBinding()]
param (
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[String[]]
$String,