Skip to content

Instantly share code, notes, and snippets.

@sannae
sannae / New-GitCommit.ps1
Last active August 13, 2021 13:28
One-liner to add, commit and push to remote Git
function New-GitCommit {
[cmdletbinding()]
param(
[Parameter(Mandatory=$true)]
[string]$CommitMessage
)
Write-Host "Git - Adding all changes..." -ForeGroundColor Green
git add --all
@sannae
sannae / Basic_vagrantfile
Created August 18, 2021 14:56
Very simple vagrantfile to spin up a WinServ2019 VM with Chocolatey and VS Code
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Box
config.vm.box = "StefanScherer/windows_2019"
# Additional parameters to communicate with Windows
config.vm.boot_timeout = 60
@sannae
sannae / Get-NetstatProcess.ps1
Created August 19, 2021 15:05
PowerShell function to get the list of active connections, grouped or not
<#
.SYNOPSIS
It produces a list of the active connections and outputs to a file.
.DESCRIPTION
The script basically calls the Get-NetTcpConnection cmdlet to have a picture of the active connections.
Each connection is retrieved with all the details about the owning process.
The $Grouped switch let you group the results and sort them descending by amount of active connections.
The amount of free dynamic ports and the OS uptime are also printed.
.PARAMETER DESTINATIONFILEPATH
String containing the output file path.
Set-Location C:\
$global:desktop = $( Get-item '~\desktop' ).FullName
Set-PSReadLineOption -Colors @{ "string"="cyan" }
Import-Module oh-my-posh
Import-Module Terminal-Icons
Set-PoshPrompt -Theme space
@sannae
sannae / Get-MSaccessData.py
Created October 6, 2022 09:15
Python script to quickly read from MS Access
import pyodbc
conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\Ron\Desktop\Test\test_database.accdb;')
cursor = conn.cursor()
cursor.execute('select * from DESTINATARI')
for row in cursor.fetchall():
print (row)
@sannae
sannae / Rename-MultipleItemsWithPattern.ps1
Created October 24, 2022 08:18
The script renames all the files (found recursively from a root path) whose filename matches the pattern specified
# Root folder
$Path = "\YOUR-PATH-HERE"
# Regex pattern (in this example, something like "(2022_10_10 08_30 UTC)"
$pattern = ".[0-9]+_[0-9]+_[0-9]+ [0-9]+_[0-9]+ UTC."
foreach ($file in $(get-childitem $Path -Recurse) ) {
if ($file.Name -match $pattern){
Rename-iTem $File.FullName $($($file.FullName).Replace($Matches[0],""))
}
@sannae
sannae / Get-ServicesAndApplicationsFromFolder.ps1
Created November 24, 2022 09:09
Gets all the services and web application whose physical path resides in a specific root folder
$RootFolder = "ROOT_FOLDER_NAME"
# Services whose path contains $RootFolder
Get-CimInstance -ClassName Win32_service | Where-Object {$_.PathName -like "*$RootFolder*"} | Format-Table
# Web application whose physical path contains $RootFolder
$(Get-IISServerManager).Sites["Default Web Site"].Applications | Where-Object {$_.VirtualDirectories.PhysicalPath -like "*$RootFolder*"} | Format-Table
@sannae
sannae / Add-CsvColumn.ps1
Created December 12, 2022 18:18
Adds a new column to an existing CSV file by specifying NewColumnTitle and NewColumnValue
$NewColumnTitle = 'GRUPPODIP'
$NewColumnValue = ''
Import-csv anagrafica.csv |
Select-object *, @{Name=$NewColumnTitle; Expression={$NewColumnValue}} |
ConvertTo-csv -Delimiter ';' -NoTypeInformation |
Foreach-Object { $_.Replace('"','') } |
out-file anagrafica_GRUPPI.csv -encoding UTF8
@sannae
sannae / Set-EveryoneFullControl.ps1
Created February 20, 2023 15:11
Set FullControl permission on a folder for group Everyone
# Run as administrator!
$sharepath = "YOUR\PATH\HERE"
$Acl = Get-ACL $SharePath
$AccessRule= New-Object System.Security.AccessControl.FileSystemAccessRule("everyone","FullControl","ContainerInherit,Objectinherit","none","Allow")
$Acl.AddAccessRule($AccessRule)
Set-Acl $SharePath $Acl