Skip to content

Instantly share code, notes, and snippets.

@iqwirty
iqwirty / gist:4398438
Last active December 10, 2015 06:59
This script uses the Quest cmdlet Get-QADUser to find/display all disabled user objects.
Get-QADUser -Disabled `
| Select Name, DisplayName, Department, WhenChanged `
| Sort DisplayName `
| Format-Table
@iqwirty
iqwirty / GetExchangeMailboxStatisticsForUserList.ps1
Created March 20, 2014 16:38
Gets Exchange mailbox statistics for a list of users specified in a text file. Writes the statistics to an output .csv file.
# Load the Exchange management cmdlets.
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Support
# Import all the modules located in:
# %windir%\System32\WindowsPowerShell\v1.0\Modules
ImportSystemModules
$usersFromFile = Get-Content "users.txt"
@iqwirty
iqwirty / GetFriendlyGroupNamesForUser.ps1
Created March 26, 2014 16:20
Get the friendly group names for a user
# Load a handy Quest snap-in for Active Directory cmdlets
Add-PSSnapin Quest.ActiveRoles.ADManagement
Get-QADUser tommy.test | Select -ExpandProperty memberof | `
ForEach-Object { ($_.split(','))[0].replace('CN=','') } | `
Sort $_ | `
Out-GridView
@iqwirty
iqwirty / ShowGroupMembersFromArray.ps1
Created March 26, 2014 18:53
Show group membership in Excel for each group listed in an array
#
# Get the group members for each group from an array, and export the member list
# to a .csv file. Then open all the .csv files in Excel.
#
Clear-Host
$outputFolder = "c:\tempo"
$groupList = @("Group1",
"Group2",
@iqwirty
iqwirty / Microsoft.PowerShell_profile.ps1
Last active August 29, 2015 13:57
My PowerShell profile init file
#
# %userprofile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
#
#
# Load some snap-ins
#
Add-PSSnapin Quest.ActiveRoles.ADManagement
#
@iqwirty
iqwirty / CopyMatchingFilesUniquely.ps1
Created March 28, 2014 15:08
Copy all files matching a pattern from one folder to another. A counter is pre-pended to ensure unique destination file names.
#
# Copy all files matching a pattern from one folder to another. A counter is pre-pended to
# ensure unique destination file names.
#
Clear-Host
$sourceFolderFullPath = "C:\SOURCE_PATH"
$destinationFolderFullPath = "C:\DESTINATION_PATH"
$filter = "FILTER*.TXT"
$count = 1
@iqwirty
iqwirty / ShowRecentlyDisabledUsers10Days.ps1
Created April 7, 2014 14:13
Show a list of user accounts disabled in the last 10 days
# Depends on the Quest snap-in for Active Directory management
Add-PSSnapin Quest.ActiveRoles.ADManagement
Get-QADUser -Disabled -ShowProgress -PageSize 1000 -SizeLimit 0 | `
Where { $_.WhenChanged -gt (Get-Date).AddDays(-10) } | `
Select DisplayName, Name, Department, Title, WhenChanged | `
Sort DisplayName | `
Format-Table
@iqwirty
iqwirty / FlattenFolder.ps1
Created April 9, 2014 11:56
Flattens a folder tree by moving all files to a new destination folder
# Flatten a folder tree by moving contents of the source path
# recursively to the destination path.
#
# If there is a collision in the destination due to two files
# having the same name, then a timestamp is appended to the
# base name of the file being moved to create a new unique name.
Clear-Host
$sourceFolderFullPath = "c:\source"
@iqwirty
iqwirty / EmailScriptReport.ps1
Created April 16, 2014 19:44
Sends an email from a script with an optional attachment. Includes path of currently running script in body.
Function EmailScriptReport
{
# Sends an email using the specified to/from, subject, body, and
# and SMTP server. Allows an attachment to be included. Also includes
# in the body the source path of the running script to improve
# traceability.
Param (
[string]$To,
[string]$From,
@iqwirty
iqwirty / GetStoredProcedureResult.ps1
Created April 16, 2014 19:46
Gets an array of objects representing the return value of a stored procedure.
Function GetStoredProcedureResult
{
# Gets an array of objects representing the return value of the
# specified stored procedure. This function allows up to one
# (optional) named SQL integer parameter to be provided.
Param (
[string]$Server = $(Throw "No SQL server specified."),
[string]$Database = $(Throw "No database name specified."),
[string]$StoredProcedure = $(Throw "No stored procedure name specified."),