I'm not aware of how to use Google, how do I do this basic thing in Language X?
tagged coding, question
edited by Grammar Nazi (2.5M), asked by 1337z0r (2)
A small collection specialised scripts for Active Directory.
Includes:
using namespace System.Collections.Generic; using namespace System.Linq | |
function Get-FileEncoding { | |
<# | |
.SYNOPSIS | |
Attempt to determine a file type based on a BOM or file header. | |
.DESCRIPTION | |
This script attempts to determine file types based on a byte sequence at the beginning of the file. | |
If an identifiable byte sequence is not present the file type cannot be determined using this method. |
<# | |
Prerequisites: PowerShell v5.1 and above (verified; may also work in earlier versions) | |
License: MIT | |
Author: Michael Klement <[email protected]> | |
DOWNLOAD and DEFINITION OF THE FUNCTION: | |
irm https://gist.github.com/mklement0/9e1f13978620b09ab2d15da5535d1b27/raw/Time-Command.ps1 | iex |
$Path = 'c:\temp\test.long' | |
$content = [Byte[]]::new(50MB) | |
[Array]::Copy( | |
[Byte[]][Char[]]'Hello world', | |
0, | |
$content, | |
10, | |
11 | |
) |
function ConvertFrom-EventLogRecord | |
{ | |
param( | |
[Parameter(Mandatory=$true,ValueFromPipeline=$true)] | |
[System.Diagnostics.Eventing.Reader.EventLogRecord[]] | |
$InputEvent, | |
[Parameter(Mandatory=$true,Position=1)] | |
[ValidateNotNullOrEmpty()] | |
[string[]] |
function Enter-PSSessionWithEdit { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory)] | |
[ValidateNotNullOrEmpty()] | |
[string] $ComputerName | |
) | |
end { | |
$enterEventName = 'RemoteSessionEditor.Enter' | |
if (-not $Host.Runspace.Events.GetEventSubscribers($enterEventName)) { |
In PowerShell there is a callback ("Action") that is called when a command lookup fails through normal means. The purpose of this callback is to allow you to add your own command-resolution, and there are a lot of community hacks out there already:
using namespace System.Net.Sockets; using namespace System.IO | |
function Watch-StarWars { | |
[CmdletBinding()] | |
param ( ) | |
try { | |
$tcpClient = [TcpClient]::new() | |
$tcpClient.Connect('towel.blinkenlights.nl', 23) |
function Measure-ChildItem { | |
<# | |
.SYNOPSIS | |
Recursively measures the size of a directory. | |
.DESCRIPTION | |
Recursively measures the size of a directory. | |
Measure-ChildItem uses win32 functions, returning a minimal amount of information to gain speed. Once started, the operation cannot be interrupted by using Control and C. The more items present in a directory structure the longer this command will take. | |
This command supports paths longer than 260 characters. |