This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Param([ | |
| parameter( | |
| Mandatory=$true, | |
| Position=0, | |
| ValueFromPipelineByPropertyName=$true, | |
| ValueFromPipeline=$true, | |
| HelpMessage="Enter one or more User names separated by commas.") | |
| ] | |
| [ValidateNotNullOrEmpty()] | |
| [alias("UN","User")] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| os.system('cls') # on windows | |
| os.system('clear') # on linux / os x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, |