Skip to content

Instantly share code, notes, and snippets.

View PrateekKumarSingh's full-sized avatar

Prateek Singh PrateekKumarSingh

View GitHub Profile
# substring\slicing as a character array using range ':' operator
string = "My name is Prateek Singh\nI\'m from India"
# slicing the string from a specific index to another
string[11:18] # output: Prateek
string[11:24] # output: Prateek Singh
# slicing up to last index
string[25:] # output: I'm f rom India
# substring\slicing as a character array using range '..' operator
$string = "My name is Prateek Singh`nI`'m from India"
# slicing the string from a specific index to another
$string[11..17] -join '' # output: Prateek
$string[11..23] -join '' # output: Prateek Singh
# slicing up to last index
$string[25..($string.Length-1)] -join '' # output: I'm from India
Function Get-ShortURL
{
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True, ValueFromPipeline = $true)][string] $URL
)
Write-Verbose "Creating Short URL for $URL"
Invoke-RestMethod -Uri "https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyDne5JQP_6F0aBsnz9RcItd3zeO1v6J734" `
# encoding the URL
[System.Web.HTTPUtility]::UrlEncode("https://RidiCurious.com")
# decoding the URL
[System.Web.HTTPUtility]::UrlDecode("https%3a%2f%2fRidiCurious.com")
# formatting strings
# when placeholders are empty without numbers, then
# default sequence of arguments from .format(arg1,arg2) is picked
'firstname:{} lastname:{}'.format('prateek','singh')
# use numbers in braces to define sequence of arguments consumed by the string
'a:{0} b:{2} c:{1}'.format('red','green','blue')
# adding leading zero
'{0:03d}'.format(5)
# using dictionaries for formatting
coor = {'latitude': '31.24E', 'longitude': '-125.81N'}
# formatting strings
# no numbers in braces will throw formatting ERROR in powershell
'firstname:{} lastname:{}' -f 'prateek','singh'
# use numbers in braces to define sequence of arguments consumed by the string
'a:{0} b:{2} c:{1}' -f 'red','green','blue'
# adding leading zero
'{0:d3}' -f 5
# using hashtables for formatting
$coor = @{'latitude'= '31.24E'; 'longitude'= '-125.81N'}
"Coordinates: {0}, {1}" -f [System.Object[]]$coor.Values
PS1="\[\033[1;92m\]\u\[\e[m\] \[\033[0;96m\]\w\[\e[m\] \\$ "
$data = Invoke-WebRequest https://www.sqlshack.com/top-50-powershell-bloggers-of-2018/
$data.Links.Where({ $_.href -like "*http*" -and
$_.href -notlike "*twitter*" -and
$_.href -notlike "*sql*" -and
$_.href -notlike "*creativecomm*" -and
$_.href -notlike "*microsoft*"
}) | Select-Object href -Unique -ExpandProperty href
(Invoke-RestMethod "http://data.alexa.com/data?cli=10&dat=s&url=RidiCurious.com").alexa.sd[1].Reach.Rank
(Invoke-RestMethod "http://data.alexa.com/data?cli=10&dat=s&url=RidiCurious.com").alexa.sd[1].Popularity.Text
# Top-50 PowerShell Blogs in the world
$topblogs = "https://blogs.msmvps.com/russel/about/","https://kevinmarquette.github.io/blog/","https://sid-500.com/","http://mspsug.com/","https://mikefrobbins.com/","https://learn-powershell.net/about/","https://www.darkoperator.com/","http://www.realcajunrecipes.com/","https://blog.netnerds.net/","https://www.sconstantinou.com/powershell-scripts/","https://www.jonathanmedd.net/","http://ramblingcookiemonster.github.io/Pages/PowerShellResources/","https://richardspowershellblog.wordpress.com/","https://jdhitsolutions.com/blog/","http://www.leeholmes.com/blog/","http://www.lucd.info/","https://mickitblog.blogspot.com/","https://p0w3rsh3ll.wordpress.com/","http://powershellblogger.com/","https://blog.tyang.org/","https://workingsysadmin.com/","https://wragg.io/","https://www.cgoosen.com/category/powershell/","https://lazywinadmin.github.io/","https://sqlpowershell.blog/","http://fredrikwall.se/","http://mctexpert.blogspot.com/","http://powershelldistrict.com/","https://po