Skip to content

Instantly share code, notes, and snippets.

View kpatnayakuni's full-sized avatar
🏠
Working from home

Kiran Patnayakuni kpatnayakuni

🏠
Working from home
View GitHub Profile
@kpatnayakuni
kpatnayakuni / Get-Synonym.ps1
Last active October 30, 2017 17:48
Get synonyms and antonyms for a given word from thesaurus.com using PowerShell
Function Get-Synonym
{
Param
(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[String] $Word
)
$Uri = "http://www.thesaurus.com/browse/$Word"
$ElementTagName = 'span'
@kpatnayakuni
kpatnayakuni / Get-Meaning.ps1
Created October 30, 2017 18:09
Get meaning for a given word from dictionary.com using PowerShell
function Get-Meaning
{
Param
(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[String] $Word
)
$Uri = "http://www.dictionary.com/browse/$Word"
$ElementTagName = 'div'
$ClassName = 'def-content'
@kpatnayakuni
kpatnayakuni / Test-ADCredentials.ps1
Created November 6, 2017 15:29
Validates domain credentials
function Test-ADCredential
{
$Credentials = Get-Credential -Message 'Enter your domain credentials'
$UserName = $Credentials.UserName
$Password = $Credentials.GetNetworkCredential().Password
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('domain')
try
{
$Status = $DS.ValidateCredentials($UserName, $Password)
@kpatnayakuni
kpatnayakuni / Get-ARMVMPIP.ps1
Created December 25, 2018 12:46
Retrieves the public ip of an AzureVM, Starts the VM if the VM is not running and connect to RDP session.
<#
.SYNOPSIS
Retrieves public ip of an AzureVM.
.DESCRIPTION
Retrieves the public ip of an AzureVM, Starts the VM if the VM is not running and connect to RDP session.
.PARAMETER ResourceGroupName
@kpatnayakuni
kpatnayakuni / Create-SQLServerObject.ps1
Last active December 25, 2018 15:32
SQL Serve PSObject - Working with SQL Server using PowerShell
# Create an object
$SQLServerObject = New-Object -TypeName psobject
# Basic properties
$SQLServerObject | Add-Member -MemberType NoteProperty -Name ServerName -Value 'SQLServer' # Server Name
$SQLServerObject | Add-Member -MemberType NoteProperty -Name DefaultPort -Value 1433 # Port
$SQLServerObject | Add-Member -MemberType NoteProperty -Name Database -Value 'master' # Database
$SQLServerObject | Add-Member -MemberType NoteProperty -Name ConnectionTimeOut -Value 15 # Connection Timeout
$SQLServerObject | Add-Member -MemberType NoteProperty -Name QueryTimeOut -Value 15 # Query Timeout
$SQLServerObject | Add-Member -MemberType NoteProperty -Name SQLQuery -Value '' # SQL Query
@kpatnayakuni
kpatnayakuni / Get-AzVMImageSku2.ps1
Created December 28, 2018 10:51
Get-AzVMImageSku2.ps1
#requires -Module Az
# Please connect to Azure using Connect-AzAccount
# Get the complete list of Azure service locations
Get-AzLocation
<#
Get-AzLocation | Where-Object -FilterScript {$_.Location -match 'india'}
Function Empty-RecycleBin
{
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact = 'High')]
param
(
[Parameter(Mandatory=$false)]
[switch] $Force # Without confirmation
)
if($IsWindows -eq $false) { return } # Exit the script if the OS is other than Windows
@kpatnayakuni
kpatnayakuni / Demo-Choices.ps1
Last active March 14, 2024 22:37
Prompt for choice in PowerShell
# PromptForChoice Args
$Title = "Do you want to proceed further?"
$Prompt = "Enter your choice"
$Choices = [System.Management.Automation.Host.ChoiceDescription[]] @("&Yes", "&No", "&Cancel")
$Default = 1
# Prompt for the choice
$Choice = $host.UI.PromptForChoice($Title, $Prompt, $Choices, $Default)
# Action based on the choice
$File = 'C:\Windows\Temp\delete.csv'
$Content = Get-Content -Path $File
<# File content
GroupA,GroupB,GroupC,1,2
GroupB,GroupC,GroupD,1,2,3,4,5
GroupA,GroupC,GroupE,1
GroupA,GroupB,GroupE,1,2,3,4
GroupC,GroupD,GroupE,1,2,3
#>
function Update-SystemType
{
$Mastercsv = Import-Csv "C:\Windows\Temp\CSV1.csv"
$Productinfo = Import-Csv "C:\Windows\Temp\CSV2.csv"
foreach($record in $Mastercsv)
{
$SysType = ($Productinfo | where {$_.Code -eq $record.code}).type
if ([string]::IsNullOrEmpty($SysType))
{
$sysType = 'Unknown, due to non-matching code'