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
$profiles = Get-WmiObject -Class Win32_UserProfile | |
foreach ($prof in $profiles){ | |
$sid = $prof.sid | |
$ADUser = Get-ADUser -Filter {SID -eq $sid} | |
if ($ADUser.enabled -eq $false){ | |
#delete profile | |
"Delete $($ADUser.name)" | |
$prof.delete() | |
} | |
} |
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 Invoke-CommandAs { | |
<# | |
.SYNOPSIS | |
Invoke Command using ScheduledJob with Credential on remote computer. | |
.DESCRIPTION | |
Invoke a ScheduledJob on machine (Remote if ComputerName/Session is provided). | |
ScheduledJob will be executed with current user credentials if no -As credential are provided. | |
Because the ScheduledJob is executed by the Task Scheduler, it runs as if it was ran locally. And not from within the Powershell Session. | |
Resolving the Double Hop limitations by Powershell Remote Sessions. |
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
$in = Get-Content C:\temp\day2.txt | |
#Day 2-1 | |
$checksum = 0 | |
foreach ($row in $in){ | |
$row = $row -split "`t" | ForEach-Object {[int]$PSItem} | Sort-Object | |
$checksum += $row[-1] - $row[0] | |
} | |
$checksum | |
#Day 2-2 | |
$checksum = 0 |
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 Day1 { | |
param ($sequence, $offset) | |
[int]$sum = 0 | |
for ($i=0; $i -lt $sequence.Length; $i++){ | |
$k = $i + $offset | |
if ($k -ge $sequence.Length){ | |
$k = $k - $sequence.Length | |
} | |
if ([int]$sequence[$i] -eq [int]$sequence[$k]){ |
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-FileAuditInfoDetails { | |
<# | |
.SYNOPSIS | |
Gets detailed information from Get-EventLog (Event 4663) or Get-FileAuditInfo | |
like UserName, Filename and Action. | |
.DESCRIPTION | |
Gets detailed information from Get-EventLog (Event 4663) or Get-FileAuditInfo | |
like UserName, Filename and Action. | |
The original object is returned in EventObject property. |
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
if ((Get-Command Get-ChildItem).parameters.Keys -notcontains "File") { | |
function global:Get-ChildItem { | |
[CmdletBinding(DefaultParameterSetName = 'Items', SupportsTransactions = $true)] | |
param( | |
[Parameter(ParameterSetName = 'Items', Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] | |
[string[]] | |
${Path}, | |
[Parameter(ParameterSetName = 'LiteralItems', Mandatory = $true, ValueFromPipelineByPropertyName = $true)] | |
[Alias('PSPath')] |
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
# Monitor hostname ip change | |
# First create CSV | |
# Resolve-Host -HostName HostName | Export-Csv -Path $hosts_csv_path -Encoding UTF8 | |
# or Add hosts | |
# Resolve-Host -HostName AnotherHostname | Export-Csv -Path $hosts_csv_path -Encoding UTF8 -Append | |
function Resolve-Host { | |
param($HostName) | |
BEGIN { | |
Write-verbose "In function Resolve-Host" |
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
$user = Get-ADUser TestUser -Properties * | |
$props = $user.psobject.properties.name | |
$users = Get-ADUser User1 | |
# or test all AD Users | |
# $users = Get-ADUser -Filter * | |
foreach ($user in $users){ | |
try { | |
$User | Get-ADUser -Properties * | Out-Null | |
} | |
catch{ |
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
"use strict"; | |
function waitFor(testFunction, readyFunction, timeOutMillis) { | |
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3000, | |
start = new Date().getTime(), | |
condition = false, | |
interval = setInterval(function() { | |
if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) { | |
condition = (typeof(testFunction) === "string" ? eval(testFunction) : testFunction()); | |
} else { | |
if(!condition) { |