Skip to content

Instantly share code, notes, and snippets.

View VimalShekar's full-sized avatar

Vimal Shekar VimalShekar

View GitHub Profile
@VimalShekar
VimalShekar / IsUserValid.ps1
Last active January 12, 2018 15:39
Checking if given username and password is valid in PowerShell
# -- Get the full script here : https://github.com/VimalShekar/PowerShell/blob/master/CheckIsUserValid_1.ps1
function IsLocalUserNamePasswordValid()
{
param(
[String]$UserName,
[String]$Password
)
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('machine',$ComputerName)
$bReturn = $DS.ValidateCredentials($UserName, $Password)
# -- Get the full script here : https://github.com/VimalShekar/PowerShell/blob/master/CheckIsUserValid.ps1
# This is used by some of the functions below
$logonUserSignature =
@'
[DllImport( "advapi32.dll" )]
public static extern bool LogonUser( String lpszUserName,
String lpszDomain,
String lpszPassword,
int dwLogonType,
@VimalShekar
VimalShekar / CheckDotNet3.5.ps1
Created January 12, 2018 15:52
Check if .NET 3.5 or later is present on the machine in PowerShell
#-- Get the full script here:https://github.com/VimalShekar/PowerShell/blob/master/CheckDotNet.ps1
Function IsDotNet35orGreater {
# Check if .NET version 3.5 or greater is present
[bool] $bVersionPresent = $false
$Frameworks = Get-ChildItem "HKLM:\Software\Microsoft\NET Framework Setup\NDP"
foreach($FWver in $Frameworks) {
@VimalShekar
VimalShekar / CheckDotNet2.0.ps1
Created January 12, 2018 15:57
Checks if .NET framework v2.0 or newer is available on the machine using PowerShell
#-- Get the full script here:https://github.com/VimalShekar/PowerShell/blob/master/CheckDotNet.ps1
Function IsDotNet2orGreater {
# Check if .NET version 2.0 or greater is present
[bool] $bVersionPresent = $false
$Frameworks = Get-ChildItem "HKLM:\Software\Microsoft\NET Framework Setup\NDP"
foreach($FWver in $Frameworks) {
# if it matches v[0-9].+ and is >= v2.0 then requisite is met
@VimalShekar
VimalShekar / GetCredManCreds.ps1
Last active October 14, 2021 12:11
Retrieve username and passwords of Web Credentials stored in Credential Manager using PowerShell
#-- Get the full script here : https://github.com/VimalShekar/PowerShell/blob/master/GetCredmanCreds.ps1
#
# Function to read the IE/Edge password vault (Web Credentials portion of credential manager)
#
function Get-PasswordVaultCredentials {
#initilize empty array
$CRED_MANAGER_CREDS_LST = @()
@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(
@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 / 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 / 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 / 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
)