This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The following is an example, it's not a function, it's not meant to be run | |
# as is, I just wrote it to show how creating a scheduled tak on an event | |
# can be done in PowerShell. I wrote a small post about how it came to be, that | |
# can be read at https://xavier.plantefeve.fr/posts/SchdTskOnEvent | |
$class = Get-cimclass -ClassName MSFT_TaskEventTrigger -Namespace root/Microsoft/Windows/TaskScheduler | |
$trigger = $class | New-CimInstance -ClientOnly | |
$trigger.Enabled = $true | |
$trigger.Subscription = '<QueryList><Query Id="0" Path="Microsoft-Windows-NetworkProfile/Operational"><Select ` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-Profiles | |
{ | |
<# | |
.SYNOPSIS | |
Gives a list of locally saved user profiles. | |
.DESCRIPTION | |
Gets a list of locally used profiles according to the registry and | |
returns an object with information about the profile. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-LastDOW { | |
<# | |
.SYNOPSIS | |
Returns the date of the last day of week you select. | |
.DESCRIPTION | |
Get-LastDOW will return the date of the last day of the week you select, | |
up to one week in the past (between one week ago and yesterday). Useful, | |
as an example, to search in logs for events only happening once a week. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ComputerName = $env:ComputerName | |
$test = Import-Csv -Path "log:\computers\${ComputerName}.log" -Delimiter ' ' -header @('user','date','time') | |
$t2 = $test | | |
select user,date,@{ | |
name='logonage'; | |
expression={ | |
1 / ((Get-Date) - [DateTime]$_.date).Days} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Start-ManagementConsole { | |
Param( [string]$ComputerName = '.' ) | |
Start-Process -FilePath "${env:windir}\System32\mmc.exe" ` | |
-ArgumentList "compmgmt.msc /computer:\\${ComputerName}" | |
} | |
New-Alias -Name manage -Value "Start-ManagementConsole" -Scope Global |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Topic: NBA All Stars | |
Owners: Foo Owners | |
Users: User 1 | |
Users: User 2 | |
Topic: NFL MVPs | |
Owners: Bar Owners | |
Users: Tony Stark | |
Users: Mitch Hedberg | |
Users: Someone Else | |
Topic: NBA MVPs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$domainControllers = Get-ADDomainController -Filter * | |
Get-ADGroupMember -Identity 'Domain Admins' -Recursive | ForEach-Object -Process { | |
$user = $_ | |
$domainControllers | | |
ForEach-Object -Process { | |
Get-ADUser $user.SamAccountName -Server $_.Name -Properties lastLogon, cn, employeeNumber, accountExpires, PasswordNeverExpires, Enabled, LockedOut, pwdLastSet | |
} | | |
Sort-Object -Property LastLogon | | |
Select-Object -Last 1 -Property SamAccountName, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region ExcelFunctions | |
function Get-NormalizedPath ( $Path ) { | |
if ( ( Split-Path $Path ) -match '^(\.|)$' ) { | |
$Path = Join-Path -Path ( Get-Location ) -ChildPath ( Split-Path -Path $Path -Leaf ) | |
} | |
return $Path | |
} | |
$MethodImportCSVtoSheet = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
MIT License | |
Copyright (c) 2016 Xavier Plantefeve | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
Creates a timer with display | |
.DESCRIPTION | |
Creates a timer that writes the progress of the current action and the estimated remaining time. | |
Suppose you have $Items, an array of items to process. | |
First, you create a timer initialized to the number of items in the array: | |
$MyTimer = New-Timer -TotalItems $Items.count -Activity 'Processing items' |