Skip to content

Instantly share code, notes, and snippets.

View sub314xxl's full-sized avatar

Konstantin Mokhnatkin sub314xxl

  • Moscow, Russian Federation
View GitHub Profile
@sub314xxl
sub314xxl / ThreadPing.ps1
Created October 18, 2016 19:56
multithreading network scanner
Param (
[string[]]$Address = $(1..20 | %{"192.168.1.$_"}),
[int]$Threads = 5
)
write-host "Distributing addresses around jobs"
$JobAddresses = @{}
$CurJob = 0
$CurAddress = 0
while ($CurAddress -lt $Address.count)
@sub314xxl
sub314xxl / Multitheading.ps1
Last active March 13, 2017 19:44
PowerShell Multitheading Example
cls
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$folderLocation = [System.IO.Path]::Combine($scriptPath, "PowerShellMultiThreading_SimpleExample")
if (Test-Path $folderLocation)
{
Remove-Item $folderLocation -Recurse -Force
}
New-Item -Path $folderLocation -ItemType directory -Force > $null
# This script block will download a file from the web and create a local version
(Get-WmiObject -ComputerName . -Class Win32_Printer -Filter "Name='PRINTERNAME'").SetDefaultPrinter()
#Import-Module ActiveDirectory
Invoke-Command {pnputil.exe -a "d:\Downloads\upd-pcl6-x64-6.3.0.21178\hpcu190u.inf"}
Add-PrinterDriver -Name "HP Universal Printing PCL 6"
Get-PrinterDriver
Add-PrinterPort -Name "IP_10.64.128.157" -PrinterHostAddress "10.64.128.157"
Start-Sleep 10
Add-Printer -Name "HP M725" -PortName IP_10.64.128.157 -DriverName "HP Universal Printing PCL 6"
write-Host "*******Decrapifying Windows 10...*******"
write-Host "***Removing App Packages...***"
#I recommend running this script on a fresh install, though it should work fine anyways. Should ;)
#This part removes all the apps. By default, it removes every except the calculator and the store. To remove all apps, comment out this part...
Get-AppxPackage -AllUsers | where-object {$_.name -notlike "*Microsoft.WindowsStore*"} | where-object {$_.name -notlike "*Microsoft.WindowsCalculator*"} | Remove-AppxPackage
Get-AppxProvisionedPackage -online | where-object {$_.packagename -notlike "*Microsoft.WindowsStore*"} | where-object {$_.packagename -notlike "*Microsoft.WindowsCalculator*"} | Remove-AppxProvisionedPackage -online
function Enable-Privilege {
param($Privilege)
$Definition = @'
using System;
using System.Runtime.InteropServices;
public class AdjPriv {
[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr rele);
[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
sc config storsvc type= own
rem ACP User Service
sc config amdacpusrsvc start= disabled
rem AdaptiveSleepService
sc config AdaptiveSleepService start= disabled
rem Adobe Flash Player Update Service
sc config AdobeFlashPlayerUpdateSvc start= disabled
$Path = "C:\123\" # Путь к корневому каталогу с подкаталогами сканирования, которые нельзя удалять
$Dirs = Get-ChildItem -Path $Path # Занесение списка неудаляемых каталогов в массив для дальнейшей обработки
ForEach ($Dir in $Dirs) {$SubDirs = Get-ChildItem $Dir.PSPath | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue} # Удаление содержимого неудаляемых каталогов методом перебора всех каталогов из массива
#defrag
Optimize-Volume -DriveLetter C -CimSession ***pc_name*** -Defrag -Verbose
#set gerial number
get-ciminstance -classname win32_bios -computername ИМЯ_ПК | format-list serialnumber
#get print queue
Get-WMIObject -ComputerName Win32_PerfFormattedData_Spooler_PrintQueue | Select Name, @{Expression={$_.jobs};Label="CurrentJobs"}, TotalJobsPrinted, JobErrors
# Capturing a screenshot
Param(
[Parameter(Mandatory = $true)][string]$Path
)
$FileName = "$env:COMPUTERNAME - $(get-date -f yyyy-MM-dd_HHmmss).bmp"
$File = "$Path\$FileName"
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing
# Gather Screen resolution information
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
@sub314xxl
sub314xxl / gist:e6539e6c0969e90860bcd9a63609bcbc
Created December 7, 2017 12:10
GeneratePrintJobAccountingReports.ps1
<#
GeneratePrintJobAccountingReports.ps1
ver. 2014-09-26-01
This script reads event log ID 307 and ID 805 from the log "Applications and Services Logs > Microsoft > Windows > PrintService"
from the specified server and for the specified time period and then calculates print job and total page count data from these
event log entries.
It then writes the output to two .CSV files, one showing by-print job data and the other showing by-user print job data.