Skip to content

Instantly share code, notes, and snippets.

View kkbruce's full-sized avatar
🆚
Coding for fun

Bruce Chen kkbruce

🆚
Coding for fun
View GitHub Profile
@kkbruce
kkbruce / Send-FTPSFiles.ps1
Created May 19, 2020 08:10
Provide PowerShell upload .zip file to FTPS script
param (
[string]$sourceDir
)
$ftpaddr = "example.com/upload/"
# option
$assemblies = (
"System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL",
"System.IO, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL",
@kkbruce
kkbruce / nlog.config
Created April 7, 2020 03:16
nlog.config Example
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Info"
internalLogFile="c:\temp\internal-nlog.txt">
<!-- 啟用 ASP.NET Core 排版呈現器 -->
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
@kkbruce
kkbruce / Test-PoshSshWithPS7.ps1
Created March 27, 2020 07:42
Use Posh-Ssh test PowerShell Core 7 - Windows PowerShell compatibility mode
# use pwsh.exe (PS7Now)
Import-Module posh-ssh -UseWindowsPowerShell
$cred = Get-Credential
$remoteDir = "/"
$ftpaddr = "127.0.0.1"
$sourceDir = "D:\zips\*"
$files = Get-ChildItem -Path $sourceDir -Include *.zip
@kkbruce
kkbruce / profiles.json
Last active May 1, 2021 10:03
Windows Terminal profiles.json backup
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"profiles": {
"defaults": {
"fontFace": "Fira Code",
"startingDirectory": "c://",
"colorScheme": "Solarized Dark"
@kkbruce
kkbruce / Push-FoldersToAmazonS3.ps1
Created January 20, 2020 08:43
Upload folders to Amazon S3 service.
# Example:
# .\Push-FoldersToAmazonS3.ps1 -BucketName kkbruce -ProfileName default -LocalPath D:\Amazon -PrefixName "uploaded_fieds"
[CmdletBinding()]
param (
[string]$BucketName,
[string]$ProfileName,
[string]$LocalPath,
[string]$PrefixName,
[switch]$UseProxy
)
@kkbruce
kkbruce / Base64withPowerShellDemo.ps1
Created November 13, 2019 08:00
Encoding and Decoding for Base64 with PowerShell
$Text = "Hello world!"
$EncodedUniText =[Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($Text))
$EncodedUniText
$EncodedASCText =[Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($Text))
$EncodedASCText
$DecodedUniText = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($EncodedUniText))
$DecodedUniText
$DecodedASCText = [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($EncodedASCText))
$DecodedASCText
@kkbruce
kkbruce / gist:cad715cabb6fe9e0627f4e31342131b3
Last active September 25, 2019 10:07
Delete invalid Windows folder or file
REM Run cmd.exe first
del "\\?\x:\folder_name\invalid_filename"
rd "\\?\x:\folder_name\invalid_filename"
@kkbruce
kkbruce / atp.bat
Last active July 7, 2024 09:25
Run WSL - Ubuntu "atp update && atp upgrade" command from Windows command line
REM wsl.exe -d Ubuntu-18.04
wsl sudo apt update && sudo apt upgrade
@kkbruce
kkbruce / Get-NetFrameworkVersion.ps1
Created July 29, 2019 03:14
PowerShell: Determine .NET Framework Which Versions Are Installed
# Ref: https://docs.microsoft.com/zh-tw/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed
$netInfo = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\" -Name Release
$netVerKey = $netInfo.Release
if ($netVerKey -ge 528040) {
Write-Output "4.8 or later"
}
if ($netVerKey -ge 461808) {
Write-Output "4.7.2"
@kkbruce
kkbruce / Start-RemoteService.ps1
Created June 4, 2019 08:51
Start Remote Computer Service by PowerShell Script
Get-Service -ComputerName "ComputerName" -Name "ServiceName" | `
Where-Object {$_.Status -eq "Stopped"} | `
Set-Service -Status Running