Skip to content

Instantly share code, notes, and snippets.

View Delete-ADDisabledUserProfile.ps1
$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()
}
}
View Invoke-CommandAs.ps1
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.
View Advent_of_code_2017_Day2.ps1
$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
View Advent_of_code_2017_Day1.ps1
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]){
View menu.ps1
function menu($functionName) {
$AST = [System.Management.Automation.Language.Parser]::ParseFile(
'C:\Temp\profile.ps1',
[ref]$null,
[ref]$Null
)
$functions = @($AST.FindAll({
$args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst]}
, $true) | ForEach-Object {
View Get-FileAuditInfoDetails.ps1
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.
View Get-ChildItem.Polyfill.ps1
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')]
View Test-Hostname.ps1
# 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"
View Test-ADUserProperties.ps1
$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{
@amnich
amnich / sprawdzenieStatusuPodmiotuWVAT.js
Last active Jul 1, 2017 — forked from srsbiz/sprawdzenieStatusuPodmiotuWVAT.js
Skrypt do sprawdzenia statusu płatnika VAT w PhantomJS
View sprawdzenieStatusuPodmiotuWVAT.js
"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) {