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
Function Demo-Splatting
{
param
(
[int] $a,
[int] $b,
[int] $c
)
$PSBoundParameters
# Along with the named paramaters
New-Item -Path C:\Windows\Temp\ -Name Delete.txt -ItemType File -Value "Hello World!" -Force
# With hash table
$paramtable = @{
Path = 'C:\Windows\Temp\'
Name = 'Delete.txt'
ItemType = 'File'
Value = 'Hello World!'
Force = $true
$CSV1 = Import-Csv ".\CSV1.csv"
<#
Code UUID Asset
---- ---- -----
DL1721 MNY07789-D112-E34C-B41D-4ACFB442B60P 23160
HP1023 ABC07789-D112-E34C-B41D-4ACFB442B65D 23145
HP2190 XYZ07789-D112-E34C-B41D-4ACFB442B65E 23146
#>
# Copy a file using named paramaters
Copy-Item -Path $env:windir\Temp\CSV1.csv -Destination $env:TEMP\CSV1.csv -Force
# With array
$paramarray = @("$env:windir\Temp\CSV1.csv", "$env:TEMP\CSV1.csv")
Copy-Item @paramarray -Force
Function Create-NewItem
{
[CmdLetBinding(SupportsShouldProcess)]
param
(
[parameter(mandatory=$true,parametersetname="Path")]
[parameter(mandatory=$false,parametersetname="Name")]
[string]$Path,
[parameter(mandatory=$true,parametersetname="Name")]
[string] $Name,
# Enter your ps script name including path
# And launch application to the script file at the end of the code
# Start-Process -FilePath <yourapplication.exe>
$ScriptFile = 'yourpsfileincludingpath.ps1'
$ShortcutFile = "$Home\Desktop\" + (Get-ChildItem -Path $ScriptFile).BaseName + '.lnk'
$PowerShellPath = "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe"
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $PowerShellPath
#requires -Module Az
## Ensure logged into your Azure account
if([string]::IsNullOrEmpty($(Get-AzContext)))
{ Add-AzAccount }
## Define the required variables
$SubscriptionId = '<SubscriptionId>' # This is your subscription id (ex: 'f34d6539-c45b-4a93-91d9-0b4e6ffb6030')
$ResourceGroupName = 'static-websites-rg' # Resource Group
$Location = 'southindia' # Location
@kpatnayakuni
kpatnayakuni / Demo-Archive.ps1
Created January 31, 2019 09:27
Zip & Unzip files
### Examples are from Microsoft Docs
## Zip the files
# Example 1: Create an archive file
Compress-Archive -LiteralPath C:\Reference\Draftdoc.docx, C:\Reference\Images\diagram2.vsd -CompressionLevel Optimal -DestinationPath C:\Archives\Draft.Zip
# Example 2: Create an archive with wildcard characters
Compress-Archive -Path C:\Reference\* -CompressionLevel Fastest -DestinationPath C:\Archives\Draft
# Example 3: Update an existing archive file
<#
This script returns the current date time from http://worldclockapi.com/ using REST API service.
You can find the latest uri from the site above.
Eastern Standard Time http://worldclockapi.com/api/json/est/now
Coordinated Universal Time http://worldclockapi.com/api/json/utc/now
@kpatnayakuni
kpatnayakuni / profiles.json
Last active January 29, 2023 09:14
Windows Terminal Profiles
{
"globals" :
{
"alwaysShowTabs" : true,
"defaultProfile" : "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"initialCols" : 120,
"initialRows" : 30,
"keybindings" :
[
{