Skip to content

Instantly share code, notes, and snippets.

$minutes = Get-Random -Minimum 0 -Maximum 59
$minutes
$restartTime = Get-Date 1:$minutes #adjust hour here
while ((get-date) -lt $restartTime){ Start-Sleep -s 60}
write-host Beginning Restart
#Restart-Computer -Force
@bobfrankly
bobfrankly / PhantomJS_With_Timeout.ps1
Created December 15, 2016 19:44
How to use Selenium with PhantomJS and a custom timeout (instead of 60 seconds)
$dllroot = "C:\selenium-dotnet-3.0.0\net35\"
Add-Type -Path (join-path $dllroot Selenium.WebDriverBackedSelenium.dll)
Add-Type -Path (join-path $dllRoot ThoughtWorks.Selenium.Core.dll)
Add-Type -Path (join-path $dllRoot WebDriver.dll)
Add-Type -Path (join-path $dllRoot WebDriver.Support.dll)
$pjsOptions = New-Object OpenQA.Selenium.PhantomJS.PhantomJSOptions # Needs to have an object of this type
$timeout = [timespan]::FromMinutes(12) # Set for 12 minutes
$driver = New-Object OpenQA.Selenium.PhantomJS.PhantomJSDriver -ArgumentList ('C:\scripts\ruckusPollSelenium\',$obj,$timeout)
@bobfrankly
bobfrankly / Get-ExchangeDBData.ps1
Created August 21, 2017 22:05
Exchange 2010 Database filespace details
function Get-DBData{
$mailBoxDBs = Get-Mailboxdatabase -status | select *
foreach ($mbdb in $mailBoxDBs){
$thisDBdrive = $mbdb.edbfilepath.tostring().split(":")[0]
$thisDriveFree = invoke-command -ComputerName $mbdb.server -ArgumentList $thisDBdrive -ScriptBlock {param($drive) get-PSDrive $drive | select @{name="FreeGB";expression={[math]::round(($_.free / 1GB),2)}}} | select -expand FreeGB
$mbdb | select name, Databasesize, AvailableNewMailboxSpace, @{name="DriveFreeGB";expression={$thisdrivefree}}, server
}
}
@bobfrankly
bobfrankly / Example-InfluxSubmit.ps1
Last active September 5, 2017 21:39
Example script for sending data to influx db
# Configure InfluxDB
$idbRootUrl = "http://192.168.1.1:8086"
$idbstring = "/write?db=MYFIRSTDB" # Change MYFIRSTDB to reflect your DB name
$hostname = "FakeServer1"
# Gather Data
$one = Get-Random -Minimum 1 -Maximum 100
$two = Get-Random -Minimum 1 -Maximum 1000
# Format Data
function Get-ADUserWithGroups{
param ($user)
get-aduser $User -Properties memberof | select *, @{name="Groups";expression = {$_.memberof | foreach {([regex]"[^CN=]{3}([^,]*)").match($_).value}}}
}
@bobfrankly
bobfrankly / Get-ConsumedSpace.ps1
Last active November 7, 2017 17:30
Function to return consumed space in regular and compressed values, for windows deduplication
function Get-ConsumedSpace
{
#.Synopsis
# Get folders, and space consumed by each
[cmdletbinding()]
param(
# Target Location
[Parameter(Mandatory=$True)]
[string]$folder,
[switch]$inGB
const shell = require('node-powershell');
let ps = new shell({
executionPolicy: 'Bypass',
noProfile: true
});
function psPing(thisIP) {
sendMessage: function (clientInfo, roomId, msg, opts, card){
opts = (opts && opts.options) || {};
return request(clientInfo, {
method: 'POST',
resource: '/room/' + roomId + '/notification',
body: {
message: msg,
message_format: (opts.format ? opts.format : 'html'),
color: (opts.color ? opts.color : 'yellow'),
notify: (opts.notify ? opts.notify : false),
@bobfrankly
bobfrankly / Get-StarWarsNameAD.ps1
Created April 18, 2018 22:41
Star Wars Name Generator in Powershell for use against AD
function Get-StarWarsName
{
[cmdletbinding()]
param
(
$user
)
# Get user
try { $foundUser = Get-ADuser $user -properties title }
@bobfrankly
bobfrankly / Reset_OutLookProfile.ps1
Created December 3, 2019 15:35
Reset outlook profile
$profilePath = "HKCU:\Software\Microsoft\Office\15.0\Outlook\Profiles"
$folders = Get-ChildItem $profilePath
foreach ($folder in $folders) {
$folder | Remove-Item -force -Recurse -Confirm:$false
New-Item -path $profilePath -ItemType Folder -Name $folder.pschildname
}