Skip to content

Instantly share code, notes, and snippets.

@automationhaus
automationhaus / Remove-UserProfiles.ps1
Created November 4, 2016 12:28
PowerShell script to remove user profiles from Citrix or RDS session host servers
$Exclusions = "NetworkService","LocalService","systemprofile"
Get-CimInstance win32_UserProfile | ?{$Exclusions -notcontains $(Split-Path -Path $_.LocalPath -Leaf)} | Remove-CimInstance
@automationhaus
automationhaus / Remove-UserProfilesRemote.ps1
Last active January 21, 2017 02:00
Remotely Remove User Profiles from RDS or Citrix Session Host Servers
<#
I broke out the Get-CIMInstance and Get-WMIObject types for a couple of reasons. 1. Because I kept running into issues on 2008 R2
where CIM wasn't working due to the fact they aren't configured for remoting out of the box like 2012 servers are. 2. In order to
train system admins on how to use both versions in case one or the other doesn't work for them. Here, I break down the two based
on the version of the OS but you can elect to use one or the other depening on your environment. In CIM you can specify the protocol
type which could help eliminate the need for the WMI version but the WMI version will be supported on servers with older versions
of PowerShell.
#>
#Specifying the EAP
$ErrorActionPreference = "Stop"
@automationhaus
automationhaus / Write-Tee.ps1
Last active December 16, 2016 15:16
Write Output to the Screen and to File
function Write-Tee
{
<#
.SYNOPSIS
Write output to the screen and to file simultaneously
.DESCRIPTION
Simply write your screen output to a file with automatic coloring based with special sytax between square brackets. Enable debugging and produce debugging only ouptut.
.EXAMPLE
Write-Tee "[=] This is the first task in my loop"
.EXAMPLE
@automationhaus
automationhaus / Get-Catch.ps1
Last active December 13, 2016 18:11
Simple Function to Create your Error Output in a Try Catch
function Get-Catch
{
<#
.SYNOPSIS
Allows you to use a single line of code for your catch
.DESCRIPTION
Creates consistent repeatable error output in your try / catch
.EXAMPLE
try { Get-Process | ?{$_.ProcessName -match "w3wp"} } catch { Get-Catch }
.LINK
@automationhaus
automationhaus / Get-SecurityLogs.ps1
Last active January 21, 2017 02:03
PowerShell function used to collect security events from a list of servers using a start date, end date, username or domain as needed
function Get-SecurityLogs
{
<#
.SYNOPSIS
Pulls security logs from the given list of computers using the given date range
.DESCRIPTION
Using the computername, startdate and enddate parameters you can pull the event logs for the given computers. Once the data is collected to a variable you can alter the output as needed.
.EXAMPLE
PS>Get-SecurityLogs
Collects the security logs for the last day on the local machine
@automationhaus
automationhaus / Start-DataMigration.ps1
Last active November 22, 2016 21:50
Function utilizing Robocopy to mirror data from one location to another
function Start-DataMigration
{
<#
.SYNOPSIS
Simple data migration function using Robocopy
.DESCRIPTION
Using Robocopy and designed for scheduled incremental data migration to mirron the source with the destination
.EXAMPLE
Example of how to use this cmdlet
PS>Start-DataMigration -Name "UserMigration" -Source "\\SERVER1\Share" -Destination "E:\Share" -ExcludeFiles "*.vmdk","*.mp3","*.iso"
@automationhaus
automationhaus / Start-ProfileMigration.ps1
Last active December 8, 2016 15:25
Advanced multi source and destination profile migration function
function Start-ProfileMigration
{
<#
.SYNOPSIS
Advanced data migration function using Robocopy
.DESCRIPTION
Using Robocopy and designed for scheduling multiple incremental data migrations to mirror the source with the destination
.PARAMETER Name
Job name string to use in labeling log files and output
.PARAMETER Source
@automationhaus
automationhaus / Get-InstalledPrinters.ps1
Last active December 9, 2016 15:50
Uses WMI to pull locally installed printer information for output to CSV or other destination
function Get-InstalledPrinters
{
<#
.SYNOPSIS
Simple function to grab details regarding locally installed printers on servers
.DESCRIPTION
Uses WMI to pull locally installed printer information for output to CSV or other destination
.EXAMPLE
PS>Get-InstalledPrinters "SERVER1","SERVER2","SERVER3" -Unique
.PARAMETER Computers
@automationhaus
automationhaus / Get-RDSCurrentSession.ps1
Last active December 13, 2016 18:00
Function to get the client information for the RDS session running the command - Client Name, IP Address, Session Host, Session ID...
function Get-RDSCurrentSession
{
<#
.SYNOPSIS
Provides information about the current logged in session on the session host
.DESCRIPTION
Using Cassia .NET Library gathers information on the current logged in user/client on the local session host
.EXAMPLE
PS>Get-RDSCurrentSession
.OUTPUTS
@automationhaus
automationhaus / Config.json
Last active December 15, 2016 14:49
Saves and restores client printer default settings based on the locale of the client IP address. For use in logon/logoff scripts with users who float from site to site within an organization.
{
"Locales":{
"Datacenter":"10.11.16",
"Marietta":"10.0.1",
"Atlanta":"10.5.20"
}
}