Skip to content

Instantly share code, notes, and snippets.

View lazywinadmin's full-sized avatar

François-Xavier Cat lazywinadmin

View GitHub Profile
@lazywinadmin
lazywinadmin / RamReport.ps1
Created August 18, 2015 02:44
RAM Report
#https://www.reddit.com/r/PowerShell/comments/3hdjyt/need_help_with_if_statement/
$ServerList = "C:\lazywinadmin\servers.txt"
$Output = "C:\LazyWinAdmin\RAMReport.txt"
$PercentUsageLimit = 5
Get-Content $ServerList | ForEach-Object -Process {
# Test the connection
IF (Test-Connection $_ -Count 1 -Quiet)
{
@lazywinadmin
lazywinadmin / Expand-ISEAliases.ps1
Created August 17, 2015 00:37
Expand Aliases in PowerShell ISE Scripts and add an add-on
#Source http://blogs.technet.com/b/pstips/archive/2015/02/04/don-t-use-aliases-in-your-scripts.aspx
function Expand-Aliases {
$ast = [System.Management.Automation.PSParser]::Tokenize(
$psISE.CurrentFile.Editor.Text, [ref]$null)
$commands = $ast | Where-Object {
$_.Type -eq [System.Management.Automation.PSTokenType]::Command }
$after = $psISE.CurrentFile.Editor.Text -split [System.Environment]::NewLine
@lazywinadmin
lazywinadmin / keep_powershell_ontop.ps1
Last active December 8, 2022 23:14
Keep PowerShell window on top
$signature = @'
[DllImport("user32.dll")]
public static extern bool SetWindowPos(
IntPtr hWnd,
IntPtr hWndInsertAfter,
int X,
int Y,
int cx,
int cy,
uint uFlags);
$text = "die Nacht, die Nächte".split()
$text2 = (Get-Content file.txt).split()
function Remove-StringLatinCharacters
{
PARAM ([string[]]$String)
foreach ($text in $string)
{
[Text.Encoding]::ASCII.GetString([Text.Encoding]::GetEncoding("Cyrillic").GetBytes($text))
}
@lazywinadmin
lazywinadmin / Get-ADSecurityGroup.ps1
Last active August 29, 2015 14:22
Get all the AD security Groups
# https://msdn.microsoft.com/en-us/library/aa746475%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
# ADS_GROUP_TYPE_SECURITY_ENABLED
get-adgroup -LDAPFilter "(&(objectCategory=group)(groupType:1.2.840.113556.1.4.803:=2147483648))"
@lazywinadmin
lazywinadmin / Get-ADUserMemberShips_recurse.ps1
Created June 4, 2015 17:35
Get all the direct and recursive groups a user is memberof
Get-ADGroup -LDAPFilter ("(member:1.2.840.113556.1.4.1941:={0})" -f $((Get-Aduser <SamAccount>).distinguishedname))
@lazywinadmin
lazywinadmin / String_Validation_NullOrEmpty.ps1
Created June 1, 2015 13:58
Validate String is empty or null
[string]::IsNullOrEmpty("")
True
[string]::IsNullOrEmpty("Hello World")
False
@lazywinadmin
lazywinadmin / Remove-StringLatinCharacters.ps1
Created May 31, 2015 13:43
Remove accents from a String
function Remove-StringLatinCharacters
{
PARAM([string]$String)
[Text.Encoding]::ASCII.GetString([Text.Encoding]::GetEncoding("Cyrillic").GetBytes($String))
}
@lazywinadmin
lazywinadmin / Get-Date_Format_Milliseconds.ps1
Created May 30, 2015 21:08
Get-Date -Format with the milliseconds
get-date -for "yyyy-MM-dd HH:mm:ss.fffffff"
2015-05-30 17:07:25.2352256
@lazywinadmin
lazywinadmin / Migrate_PrinterQueues.ps1
Created May 27, 2015 00:38
Copy Printers queues, from one server to another
# This need to be run on the destination server
# Drivers must be installed already
# Get the printers from the source server
$printers = Get-Printer -ComputerName <SERVERSOURCE> | Select-Object -property *
#foreach printer in the file:
foreach ($printer in $printers) {
# Create the Printer Port
Add-PrinterPort -Name $printer.Name -PrinterHostAddress $printer.PortName