Skip to content

Instantly share code, notes, and snippets.

View PrateekKumarSingh's full-sized avatar

Prateek Singh PrateekKumarSingh

View GitHub Profile
Install-Module Coin -Force
$Date = Get-Date
# define parameters for splatting
$param = @{
FromSymbol ='BTC'
ToSymbol ='USD'
DataInterval ='Day'
Since = $Date.AddDays(-7)
# install the modules from PowerShell Gallery
Install-Module Graphical, Coin -Force
$Date = Get-Date
# define parameters for splatting
$param = @{
FromSymbol ='BTC'
ToSymbol ='USD'
DataInterval ='Day'
# 1. Enable Windows Feature:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
# alternatively: Appwiz.cpl > Turn Windows Feature On/Off > Windows Subsystem for Linux
# 2. Restart your machine when prompted
Restart-Computer
# 3. Go to MicroSoft store and find a Suitable Linux Distribution. Install It.
# 4. Once the Installation is complete, Launch the WSL (Windows Subsystem for Linux)
$password = ConvertTo-SecureString 'Password@123' -AsPlainText -Force
New-Object System.Management.Automation.PSCredential ('Administrator', $password)
# Alternatively create credentials using the type accelerator
[PSCredential]::new('Adminstrator', $password)
# method 1 - Enviroment Variables
$env:PROCESSOR_ARCHITECTURE
[Environment]::Is64BitOperatingSystem
# method 2 - WMI and CIM classes
(Get-WmiObject Win32_OperatingSystem).OSArchitecture
(Get-CimInStance CIM_OperatingSystem).OSArchitecture
(Get-WmiObject Win32_Processor).AddressWidth
# method 3 - Native CMD commands
# Using New-Object and hashtables
$properties = @{
firstname = 'Prateek'
lastname = 'Singh'
}
$o = New-Object psobject -Property $properties; $o
$obj = New-Object -TypeName psobject
$obj | Add-Member -MemberType NoteProperty -Name firstname -Value 'Prateek'
$obj | Add-Member -MemberType NoteProperty -Name lastname -Value 'Singh'
# add a method to an object
$obj | Add-Member -MemberType ScriptMethod -Name "GetName" -Value {$this.firstname +' '+$this.lastname}
Select-Object @{n='firstname';e={'Prateek'}},@{n='lastname';e={'Singh'}} -InputObject ''
# alternatively
'' | Select-Object @{n='firstname';e={'Prateek'}},@{n='lastname';e={'Singh'}}
[pscustomobject]@{
firstname = 'Prateek'
lastname = 'Singh'
}
# substring using .substring() method
$string = "My name is Prateek Singh`nI`'m from India"
$string.Substring(11,7) # output: 'Prateek'
$string.Substring(25,14) # output: 'I'm from India'
$string.Substring(11,13) # output: 'Prateek Singh'