Skip to content

Instantly share code, notes, and snippets.

View h3nryza's full-sized avatar

H3nryza h3nryza

View GitHub Profile
@h3nryza
h3nryza / powerShellDiskSpace.ps1
Created July 17, 2018 17:32
Powershell get disk space
$arrDisk = Get-WmiObject -class Win32_LogicalDisk
foreach($Item in $arrDisk)
{
$Name = $Item.DeviceID
$Caption = $item.VolumeName
$PercentFree = [math]::round( ( ($item.FreeSpace /$item.Size)*100),2)
$PercentUsed = [math]::round( (( $item.Size - $item.FreeSpace )/$item.Size)*100,2)
$FreeSpace = [math]::round($item.FreeSpace/1gb,2)
$UsedSpace = [math]::round(($item.Size/1gb - $item.FreeSpace/1gb ),2)
$TotalSize = [math]::round($item.Size/1gb,2)
@h3nryza
h3nryza / powerShellEpocToHuman.ps1
Created July 17, 2018 17:31
Powershell Epoch to human time
#Get EPOCH time ( Unix Time)
#The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
[int][double]::Parse((Get-Date (get-date).touniversaltime() -UFormat %s))
#Convert from Epoch to human time
$origin = New-Object -Type DateTime -ArgumentList 1970, 1, 1, 0, 0, 0, 0
$whatIWant = $origin.AddSeconds($unixTime)
@h3nryza
h3nryza / powerShellHashes.ps1
Created July 17, 2018 17:31
Powershell encryption decryption
Get-FileHash -Algorithm SHA1
Get-FileHash -Algorithm SHA256
Get-FileHash -Algorithm SHA384
Get-FileHash -Algorithm SHA512
Get-FileHash -Algorithm MACTripleDES
Get-FileHash -Algorithm MD5
Get-FileHash -Algorithm RIPEMD160
@h3nryza
h3nryza / powerShellAutoElevate.ps1
Created July 17, 2018 17:28
Powershell AutoElevate a script
#Elevate to Admin
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
#Your code here
@h3nryza
h3nryza / powershellIPInformation.ps1
Created July 17, 2018 17:27
PowerShell get IP Information
#Get all Valid IPV4
Get-CimInstance Win32_NetworkAdapterConfiguration | where{$_.ipenabled -like "True"}| Select -ExpandProperty IPAddress | where{$_ -like "*.*.*"}
#Select first valid V4
Get-CimInstance Win32_NetworkAdapterConfiguration | where{$_.ipenabled -like "True"}| Select -ExpandProperty IPAddress | where{$_ -like "*.*.*"} | Select -first 1
#Quick method
$localIpAddress=((ipconfig | findstr [0-9].\.)[0]).Split()[-1]
#Longer Method
$ipaddress=([System.Net.DNS]::GetHostAddresses('PasteMachineNameHere')|Where-Object {$_.AddressFamily -eq "InterNetwork"} | select-object IPAddressToString)[0].IPAddressToString
@h3nryza
h3nryza / powershellParams.ps1
Created July 17, 2018 17:26
Powershell Params example
Param([
parameter(
Mandatory=$true,
Position=0,
ValueFromPipelineByPropertyName=$true,
ValueFromPipeline=$true,
HelpMessage="Enter one or more User names separated by commas.")
]
[ValidateNotNullOrEmpty()]
[alias("UN","User")]
@h3nryza
h3nryza / pythonClearScreen.py
Created July 17, 2018 17:25
Python clear screen
import os
os.system('cls') # on windows
os.system('clear') # on linux / os x
@h3nryza
h3nryza / sqlTableStats.sql
Created July 17, 2018 17:23
Sql Table stats
USER_LOOKUPS,
USER_UPDATES
FROM SYS.DM_DB_INDEX_USAGE_STATS AS S
INNER JOIN SYS.INDEXES AS I ON I.[OBJECT_ID] = S.[OBJECT_ID]
AND I.INDEX_ID = S.INDEX_ID
Join sys.Databases d on s.database_id = d.database_id
WHERE OBJECTPROPERTY(S.[OBJECT_ID],'IsUserTable') = 1
Order by USER_SEEKS + USER_SCANS + USER_LOOKUPS + USER_UPDATES desc
@h3nryza
h3nryza / sqlTableSpace.sql
Created July 17, 2018 17:23
Sql return table space
SELECT
t.NAME AS TableName,
s.Name AS SchemaName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB,
CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB
@h3nryza
h3nryza / sqlTableLocks.sql
Created July 17, 2018 17:22
Sql return table locks
SELECT L.request_session_id AS SPID,
DB_NAME(L.resource_database_id) AS DatabaseName,
O.Name AS LockedObjectName,
P.object_id AS LockedObjectId,
L.resource_type AS LockedResource,
L.request_mode AS LockType,
ST.text AS SqlStatementText,
ES.login_name AS LoginName,
ES.host_name AS HostName,
TST.is_user_transaction as IsUserTransaction,