Skip to content

Instantly share code, notes, and snippets.

View perXautomatik's full-sized avatar

perXautomatik

View GitHub Profile
@perXautomatik
perXautomatik / Disclaimer.md
Last active October 14, 2024 00:37
How to Self-Elevate a PowerShell Script | The EXPTA {blog}

Update: I updated the code below so it works correctly when there are spaces in the path or script name. Thanks to Pat Richard for performance and deprecation improvements.

Most of the scripts I write require elevation -- they must be run from an elevated PowerShell prompt because they make changes to Windows that require Administrator access. The following code snippet will self-elevate a PowerShell script with this added to the beginning of the script. I honestly can't remember where I found the original code, but I updated it to work with Windows 10 and Windows Server 2016 and later build numbers.

Of course, you should ALWAYS confirm that your script is running properly before allowing it to self-elevate. I take no responsibility for the scripts that run using this code.

Simply add this snippet at the beginning of a script that requires elevation to run properly. It works by starting a new elevated PowerShell window and then re-executes the script in this new window, if necessary. If U

@perXautomatik
perXautomatik / Folder Structures
Last active August 31, 2024 03:51
[Reverse Engineering research notes] - OneNote 2016
how does oneNote store backups of local notes?
is it suitable to sync oneNote 2016 by OneDrive?
is it only possible to synk notes through office 365?
there can only be 1 onetoc2 file in each folder?
the content of the .onetoc2 file is dependendent of the .one files surrounding it and or in folders "bellow it"
it's therefore not safe to remove a .onetoc2 file if it doesn't show it's sibling files, it's just a sign that this files might be missplaced
and won't be shown by other onetoc2 files unless they're reffered specificly.
@perXautomatik
perXautomatik / InitializeUserProfile.ps1
Last active August 26, 2024 04:49
How to create permanent PowerShell Aliases - Stack Overflow
cd $env:USERPROFILE\Documents
md WindowsPowerShell -ErrorAction SilentlyContinue
cd WindowsPowerShell
New-Item Microsoft.PowerShell_profile.ps1 -ItemType "file" -ErrorAction SilentlyContinue
powershell_ise.exe .\Microsoft.PowerShell_profile.ps1
@perXautomatik
perXautomatik / source
Last active August 26, 2024 04:49
Take Ownership of a File / Folder through Command Prompt in Windows 10/11
Url: https://thegeekpage.com/take-ownership-of-a-file-folder-through-command-prompt-in-windows-10/
@perXautomatik
perXautomatik / htmlExportToMd
Last active August 23, 2024 09:05
ChromeExtensions
Url: http://rendera.herokuapp.com/
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Extensions</title>
<meta name="viewport" content="width=device-width">
<style>
body {
margin: 0;
@perXautomatik
perXautomatik / WorkEdgePersonalExtensions
Last active February 26, 2024 07:12
WorkEdgePersonalExtensions
{"browser":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.1185.44","version":"0.0.4","createDate":1651570362463,"bookmarks":[{"children":[{"children":[{"title":"Active Forks","url":"https://chrome.google.com/webstore/detail/bpjmkkjkcligjfbanmjnlkjffalbehpb"},{"title":"Adjust Screen Brightness","url":"https://chrome.google.com/webstore/detail/micpnhaohgdkjldlgjnpdpoafhohehbi"},{"title":"Apps Launcher for Microsoft Edge","url":"https://chrome.google.com/webstore/detail/diaoccpbblefojbbmhjgfkfdilamfhjp"},{"title":"Audio Equalizer with Volume Booster","url":"https://chrome.google.com/webstore/detail/oekedbgpagcndgdffdonbgmmjhmjocnl"},{"title":"BMStats - Stats for your bookmarks","url":"https://chrome.google.com/webstore/detail/ogdcicncikokgpojepfdikmpeghoepig"},{"title":"Bookmark Walker","url":"https://chrome.google.com/webstore/detail/jolkcmlidbppgpplmcmpkdhlefemacfd"},{"title":"Chrome Editor","url":"https://chrome.google.com/websto
@perXautomatik
perXautomatik / .DS_Store
Last active February 14, 2024 10:33 — forked from LittleNewton/Microsoft.PowerShell_profile.ps1
PowerShell 7.1 启动命令
@perXautomatik
perXautomatik / sql-pass-temp-table-to-exec-sp_execute.sql
Last active January 29, 2024 13:34
sql - Pass temp table to EXEC sp_executesql - Stack Overflow
/*What you have here is not Temporary Table, but a Table-Valued Parameter.
--Url: https://stackoverflow.com/questions/38823690/pass-temp-table-to-exec-sp-executesql#:~:text=You%20can%20use%20table-valued%20parameters%20to%20send%20multiple,parameters%2C%20but%20they%20must%20be%20of%20declared%20type.
Table-valued parameters are declared by using user-defined table types. You can use table-valued parameters to send multiple rows of data to a Transact-SQL statement or a routine, such as a stored procedure or function, without creating a temporary table or many parameters.
sp_executesql does support table-valued parameters, but they must be of declared type.
*/
-- So, first we must declare User-Defined Table Type
CREATE TYPE udtYB_Test AS TABLE(GSName nvarchar(100), THour time, NumOfTransactions int);
GO
@perXautomatik
perXautomatik / files-in-a-folder.sql
Last active January 29, 2024 13:34
T-SQL Query to get the list of files in a folder | SansSQL Url: https://www.sanssql.com/2013/02/t-sql-query-to-get-list-of-files-in.html
DECLARE @Path nvarchar(500) = 'E:\Test' --Change the path
DECLARE @FindFile TABLE
(FileNames nvarchar(500)
,depth int
,isFile int)
INSERT INTO @FindFile
EXEC xp_DirTree @Path,1,1