Skip to content

Instantly share code, notes, and snippets.

View VimalShekar's full-sized avatar

Vimal Shekar VimalShekar

View GitHub Profile
@VimalShekar
VimalShekar / gist:c781ed8a9d638270b88634ad3eaada72
Last active February 27, 2023 07:30
Instantiating IInternetSecurityManager interface in PowerShell
# Define CoCreateInstance function and IInternetSecurityManager interface
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
public class NativeMethods
{
private const string CLSID_InternetSecurityManager = "7b8a2d94-0ac9-11d1-896c-00c04fb6bfc4";
@VimalShekar
VimalShekar / ReadOSVer.bat
Created April 26, 2018 06:21
Read the OS version and description in a batch script.
REM read OS version x.y.z.p
for /f "usebackq tokens=*" %%n in (`WMIC.exe os get Version ^| findstr /v /r "^$"`) do (
SET OSVersion=%%n )
 
REM read Description : Ex: Windows 10 Professional N
for /f "usebackq tokens=*" %%n in (`WMIC.exe os get Caption ^| findstr /v /r "^$"`) do (
SET OSName=%%n )
 
REM read type... 1=> workstation, 2=> domain controller , 3=> server
for /f "usebackq tokens=*" %%n in (`WMIC.exe os get ProductType ^| findstr /v /r "^$"`) do (
@VimalShekar
VimalShekar / UrlEncodeDecode.ps1
Last active January 27, 2018 07:59
Helper functions to help in URL encoding and Decoding
#
# Typically the standard practice during HTTP communication requires you to encode, certain characters that are not allowed
# in the URI naming convention. System.Web.HttpUtility class has methods to help you conver these characters to the encoded
# format. Here's a helper function in powershell.
#
[Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null
function EncodeUrl( [string] $URL )
<#
.SYNOPSIS
<Overview of script>
.DESCRIPTION
<Brief description of script>
.PARAMETER <Parameter Names, zero or more>
<Brief description of parameter input required. Repeat this attribute if required>
@VimalShekar
VimalShekar / ConfigureEventChannel.ps1
Created January 15, 2018 18:01
Enabling or Disabling a given Event Viewer Channel using Powershell
#
# Function to enable or disable Event channels in Windows
#
function ConfigureEventChannel
{
param(
[string] $logName,
[switch] $Disable
)
@VimalShekar
VimalShekar / UnlinkAndDeleteGPO.ps1
Created January 15, 2018 17:14
Unlink a GPO and delete it.
#
# If given GPO is linked to any OU, it deletes the links and then attempts to delete the GPO.
#
function Delete-GPOByName
{
param(
[string]$GPOName,
[string]$DomainName
)
@VimalShekar
VimalShekar / TCP-SendRcv.ps1
Created January 15, 2018 17:03
Send and Receive sample using PowerShell
function TcpSendRecv()
{
param(
[int] $Port = 5005,
$IP = "127.0.0.1" ,
$Message = "TRUN ." + "A"*6000 +". "
)
$Address = [system.net.IPAddress]::Parse($IP)
@VimalShekar
VimalShekar / EnableWinRM-WG.ps1
Created January 15, 2018 16:57
Enable WinRM on a workgroup machine and allow connections from any remote host
# WinRM only works on Private and Domain networks, it is disabled on public networks.
# Detect and modify any networks which are set to Public, ensure that every network is private.
# First, set CategoryType to 1 under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles
# Then create an instance of {DCB00C01-570F-4A9B-8D69-199FDBA5723B}, get connections and set the category!
function Enable-WinRMOnWorkGroupMachine {
$Private:ConnectionProfiles = Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles'
foreach ($ConnProf in $Private:ConnectionProfiles) {
@VimalShekar
VimalShekar / GetCredManCreds_1.ps1
Created January 12, 2018 18:03
Retrieve user names and passwords from Credential Manager using powershell
#-- For full script, refer: https://github.com/VimalShekar/PowerShell/blob/master/GetCredmanCreds.ps1
# This script uses CredEnum Windows API, to retrieve stored usernames and passwords from Windows credential manager.
#
# Function to compile C Sharp code into an assembly
#
function Compile-Csharp ()
{
param(
@VimalShekar
VimalShekar / DeleteGPO.ps1
Created January 12, 2018 17:27
Delete a GPO and remove any linkages
# Adding as GIST, to make it easier to link to my blog.
# Visit: vimalshekar.ml for more interesting scripts.
#
# If given GPO is linked to any OU, it deletes the links and then attempts to delete the GPO.
#
function Delete-GPOByName
{
param(