Możesz tutaj znaleźć moje skrypty w PowerShellu, które służą do różnych celów. Powinny raczej działać na Windowsie i Linuxie (w PowerShell Core), chyba że używają jakichś typowo windowsowych API. Miej na uwadze, że nie wszystkie skrypty testowałem na Linuxie, więc mogą nie działać, albo działać w nieprzewidywalny sposób.
Do rozpakowania archiwów 7z potrzebne Ci będzie bezpłatne narzędzie 7-zip.
Poniżej znajdziesz dwie sekcje - narzędzia i gry.
Wszystkie moje programy i gry są dostępne jedynie w angielskiej wersji językowej.
Narzędzia
Proste narzędzie do kodowania i dekodowania plików używając kodowania base64. Działa tylko na Windowsie, ponieważ używa certutil.exe, który jest standardowym elementem instalacji Windows 10.
Użycie:
input folder - tutaj wrzuć pliki, które chcesz zakodować
encoded folder - tutaj pojawią się zakodowane pliki
decoded folder - tutaj pojawią się rozkodowane pliki, które skrypt weźmie z folderu encoded
pwsh_encode_file_v2.ps1 kod źródłowy:
Remove-Item "./encoded/*"
Remove-Item "./decoded/*"
$files = Get-ChildItem -path "./input/*"
ForEach ($file in $files){
$filename = $file.BaseName+$file.Extension
Write-Host "---------------------"
Write-Host "Encoding: "$filename
Write-Host ""
certutil -encode ("./input/"+$filename) ("./encoded/"+$filename+".b64")
Write-Host ($filename+".b64")"file Encoded Successfully!"
Write-Host "---------------------"
}
Write-Host ""
Read-Host "Press enter to exit"
pwsh_decode_file_v2.ps1 kod źródłowy:
$files = Get-ChildItem -path "./encoded/*"
ForEach ($file in $files){
$filename = $file.BaseName+$file.Extension
Write-Host "---------------------"
Write-Host "Decoding: "$filename
Write-Host ""
certutil -decode ("./encoded/"+$filename) ("./decoded/"+$filename.Substring(0,$filename.Length-4))
Write-Host ($filename)"file decoded Successfully!"
Write-Host "---------------------"
}
Remove-Item "./encoded/*"
Write-Host ""
Read-Host "Press enter to exit"
Jest to narzędzie do łączenia i dzielenia plików PDF. Używa ono modułu PSWritePDF, który należy najpierw zainstalować.
Użycie:
Zanim uruchomisz pierwszy raz:
Otwórz PowerShella jako administrator i użyj polecenia: Install-Module -Name PSWritePDF
Następnie:
1) Przygotuj pliki:
Input folder - tutaj umieść plik(i) PDF do podziału lub połączenia ze sobą (kiedy są łączone, skrypt łączy je według alfabetu)
Output folder - folder, gdzie znajdziesz plik(i) końcowy(e)
2) Odpal skrypt poprzez start.bat
start.bat kod źródłowy:
powershell.exe -ExecutionPolicy unrestricted -NoExit -command "Start-Process powershell ./pdf-tools.ps1"
pdf-tools.ps1 kod źródłowy:
$global:extension_pdf = ".pdf"
$global:path_output = $PSScriptRoot.ToString()+"\output\"
$global:path_input = $PSScriptRoot.ToString()+"\input\"
function menu{
Clear-Host
Write-Host "Welcome to PDF-Tools"
Write-Host ""
Write-Host "Menu:"
Write-Host "1. Merge PDF files into one"
Write-Host "2. Split PDF files into separate pages"
Write-Host "3. Exit program"
Write-Host ""
$choice = Read-Host "Selection: [1],[2],[3]"
if ($choice -eq 1){
merge
}
if ($choice -eq 2){
split
}
if ($choice -eq 3){
Exit
}
else {
Write-Host "Error... incorrect input"
}
Read-Host "Press any key to continue"
}
function merge{
$files = (Get-ChildItem $path_input -File).FullName
Write-Host ($files -join "`n")
Write-Host "This may take a while... be patient"
$file_name = Get-Random -Minimum 0 -Maximum 100000000
Merge-PDF -InputFile $files -OutputFile "$path_output\$file_name$extension_pdf"
Read-Host "Done. Press any key to leave program"
Exit
}
function split{
$file_name = Read-Host "Please enter filename (without extension) which you want to be split: "
Write-Host "This may take a while... be patient"
Split-PDF -FilePath "$path_input$file_name$extension_pdf" -OutputFolder "$path_output"
Read-Host "Done. Press any key to leave program"
Exit
}
while ($true){
menu
}
Prosty monitor interfejsu sieciowego, który podaje ile GB zostało ściągnięte/wysłane. Można ustawić własny okres odświeżenia danych. Nie testowałem na Linuxie, sądzę że działa tylko na Windowsie, ponieważ z tego, co kojarzę miałem jakieś problemy z użyciem Get-NetAdapter na Linuxie.
netstat.ps1 kod źródłowy:
Get-NetAdapter
$ifIndex = Read-Host "Enter ifIndex of network adapter you want to monitor"
$interval = Read-Host "Enter interval in seconds between the stats will update"
while ($true){
Clear-Host
$ReceivedBytes = Get-NetAdapter -ifIndex $ifIndex | Get-NetAdapterStatistics | select ReceivedBytes
$SentBytes = Get-NetAdapter -ifIndex $ifIndex | Get-NetAdapterStatistics | select SentBytes
$ReceivedBytes = $ReceivedBytes -replace "[^0-9]" , ""
$SentBytes = $SentBytes -replace "[^0-9]" , ""
$ReceivedGBytes = $ReceivedBytes / (1024 * 1024 * 1024)
$SentGBytes = $SentBytes / (1024 * 1024* 1024)
Write-Host "Downloaded "$ReceivedGBytes" GB"
Write-Host "Sent "$SentGBytes" GB"
Start-Sleep -seconds $interval
}
Proste windowsowe narzędzie do monitorowanie użycia procesora i ilości wolnego RAMu.
syschk.ps1 kod źródłowy:
$interval = Read-Host "Enter interval in seconds between the stats will update"
while ($true){
Clear-Host
$cpu_usage = Get-WmiObject Win32_Processor | Measure-Object -Property LoadPercentage -Average | Select Average
$cpu_usage = $cpu_usage -replace "[^0-9]" , ""
$ram_usage = Get-CIMInstance Win32_OperatingSystem | Select FreePhysicalMemory
$ram_usage = $ram_usage -replace "[^0-9]" , ""
Write-Host "CPU usage: "$cpu_usage" %"
Write-Host "RAM free: "$($ram_usage/1000)" MB"
Start-Sleep -seconds $interval
}
Proste narzędzie do robienia zrzutów ekranu i zapisywania ich do plików. Można ustawić co ile i jak długo skrypt ma działać. Skrypt przestanie automatycznie działać również kiedy na dysku C: będzie mniej niż 30GB miejsca. Tylko na Windows.
Użycie:
screens folder - tutaj pojawią się screenshoty
screen.ps1 - główny skrypt
screen.ps1 kod źródłowy:
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$Width = $Screen.Width
$Height = $Screen.Height
$Left = $Screen.Left
$Top = $Screen.Top
$path = $PSScriptRoot.ToString()+"\screens\"
$number_taken = 0
$interval = 30
Clear-Host
Write-Host "The script will stop running if there is less that 30GB space left on C drive"
Write-Host "It is thus advisable to run this script from anywhere on drive C"
Start-Sleep -Seconds 5
function Set-Interval($interval_s) {
Read-Host "Please input interval in seconds between screenshots: [integer number]"
}
$interval = Set-Interval
$test = $interval -match '^[0-9]+$'
$time_stop = Read-Host "What time should the screenshoter stop working? [yyyyMMdd_HHmmss_fff]"
$power_off = Read-Host "Should your computer be turned off afterwards? [Y/N]"
if ($test.ToString() -eq "False")
{
Write-Host "Interval must be an integer number of seconds"
Start-Sleep -Seconds 2
}
else
{
do
{
$file_name = Get-Random -Minimum 0 -Maximum 100000000
$time_stamp = Get-Date -Format "yyyyMMdd_HHmmss_fff"
$time_stamp2 = $time_stamp
$path = $path.ToString()
$file_name = $file_name.ToString()+".png"
$time_stamp = $time_stamp.ToString()+"_"
$file_name = $time_stamp+$file_name
$bitmap = New-Object System.Drawing.Bitmap $Width, $Height
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
$graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)
$bitmap.Save($path+$file_name)
$file_size = [INT]((Get-Childitem -Path $path$file_name).Length / 1KB)
$number_taken = $number_taken+1
Write-Host "================================================================================"
Write-Host "[$($number_taken.ToString())] Screenshot saved to:"
Write-Host $path$file_name
Write-Host "Filesize: "$file_size" KB"
$free_space = Get-PSDrive C
Write-Host "Free space left on drive C: "($free_space.Free / 1KB).ToString()"KB"
if (($free_space.Free / 1KB) -le 30000000)
{
Break
}
Write-Host "================================================================================"
Write-Host "Waiting $($interval.ToString()) seconds..."
Start-Sleep -Seconds $interval
Write-Host "Current timestamp: "$time_stamp2.ToString()
Write-Host "Script will run until: "$time_stop.ToString()
if ($power_off -eq "Y")
{
Write-Host "System will shut down once the target is reached"
}
} while ($time_stamp2 -le $time_stop)
if ($power_off -eq "Y")
{
Write-Host "System will power down now"
Write-Host "Written "$number_taken.ToString()" screenshots"
Start-Sleep -Seconds 2
Stop-Computer
}
else
{
Write-Host "Done"
Write-Host "Written "$number_taken.ToString()" screenshots"
}
}
Gry
Uwaga, gra zawiera przekleństwa!
To jest bardzo wczesne stadium rozwoju gry tekstowej z losowo generowanymi pokojami. Bardzo łatwo można ją rozbudowywać o nowe słowa i opisy poprzez edycję plików txt. Na razie działa jedynie generowanie pokojów i chodzenie po nich.
Użycie:
data folder - tutaj są wszystkie pliki z opisami w txt. Raczej nie trzeba wyjaśniać struktury, łatwo idzie się domyślić co dodać/zmienić wedle uznania. Nie zamierzam się zagłębiać w temat.
poweruserdung.ps1 - główny skrypt
poweruserdung.ps1 kod źródłowy:
$global:room_size = Get-Content .\data\room_sizes.txt
$global:room_shape = Get-Content .\data\room_shapes.txt
$global:room_type = Get-Content .\data\room_types.txt
$global:room_exits = Get-Content .\data\room_exits.txt
$global:room_contents = Get-Content .\data\room_contents.txt
$global:room_areas = Get-Content .\data\room_areas.txt
$global:room_floors = Get-Content .\data\room_floors.txt
$global:room_fragnances = Get-Content .\data\room_fragnances.txt
$global:room_walls = Get-Content .\data\room_walls.txt
$global:general_adjectives = Get-Content .\data\general_adjectives.txt
$global:room_size_count = 0
$global:room_shape_count = 0
$global:room_type_count = 0
$global:room_exits_count = 0
$global:room_contents_count = 0
$global:room_areas_count = 0
$global:room_floors_count = 0
$global:room_fragnances_count = 0
$global:room_walls_count = 0
$global:general_adjectives_count = 0
function game_init {
Clear-Host
Write-Host "Loadingu!!!!!1one"
Start-Sleep -Milliseconds 400
foreach ($item in $room_size) {$room_size_count++}
foreach ($item in $room_shape) {$room_shape_count++}
foreach ($item in $room_type) {$room_type_count++}
foreach ($item in $room_exits) {$room_exits_count++}
foreach ($item in $room_contents) {$room_contents_count++}
foreach ($item in $room_areas) {$room_areas_count++}
foreach ($item in $room_floors) {$room_floors_count++}
foreach ($item in $room_fragnances) {$room_fragnances_count++}
foreach ($item in $room_walls) {$room_walls_count++}
foreach ($item in $general_adjectives) {$general_adjectives_count++}
game_menu
}
function load_game{
Write-Host "Not implemented yet."
Read-Host
game_menu
}
function scores{
Write-Host "Not implemented yet."
Read-Host
game_menu
}
function game_menu{
while($true){
Clear-Host
Write-Host "Welcome to PowerUser Dungeon. A random game about tesseract exploration.`n`n"
Write-Host "There are" $room_size_count" different room sizes in the database."
Write-Host "There are" $room_shape_count" different room shapes in the database."
Write-Host "There are" $room_type_count" different room types in the database."
Write-Host "There are" $room_contents_count" different room contents in the database."
Write-Host "There are" $room_areas_count" different room areas in the database."
Write-Host "There are" $room_floors_count" different room floors in the database."
Write-Host "There are" $room_fragnances_count" different room fragnances in the database."
Write-Host "There are" $room_walls_count" different room walls in the database."
Write-Host "There are" $general_adjectives_count" different adjectives in the database."
Write-Host "There are" $room_exits_count" different room exits in the database.`n"
Write-Host "Currently there are"($room_size_count*$room_shape_count*$room_type_count*`
$room_contents_count*$room_areas_count*$room_floors_count*$room_fragnances_count*$room_walls_count`
*$general_adjectives_count*$room_exits_count*$general_adjectives_count)"possible tesseract configurations.`n"
Write-Host "=========Game=Menu=========`n"
Write-Host "1 Start Game"
Write-Host "2 Load Game"
Write-Host "3 Scores"
Write-Host "4 Quit`n"
$selection = Read-Host "Please enter your choice: "
if($selection -eq 1){game_main}
if($selection -eq 2){load_game}
if($selection -eq 3){scores}
if($selection -eq 4){Exit}
else{Write-Host "Wrong selection";Start-Sleep -Seconds 2}
}
}
function game_main{
while($true){
Clear-Host
$choice="A"
Write-Host "You are standing in a"(Get-Random -InputObject $room_size)`
(Get-Random -InputObject $room_shape)`
(Get-Random -InputObject $room_type)"with"(Get-Random -InputObject $general_adjectives)`
(Get-Random -InputObject $room_walls)"There is"(Get-Random -InputObject $room_contents)`
(Get-Random -InputObject $room_areas)
Write-Host "The floor is made of"(Get-Random -InputObject $general_adjectives)`
(Get-Random -InputObject $room_floors)"The whole area"(Get-Random -InputObject $room_fragnances)
$room_ex=(Get-Random -InputObject $room_exits)
Write-Host "`nPossible exit is "$room_ex
$choice = Read-Host "Please input your command: "
if($choice -eq $room_ex){game_main}
else{Write-Host "`nDespite of no obvious way of going the direction you choose, you went"$choice".";
Write-Host "`rMoments later you realized you ended up in a dark void of interspatial nothingness where you gonna spend the rest of your days.";
Read-Host;game_menu}
}
}
game_init
Jest to bardzo wczesny prototyp gry/symulatora? Cóż, czegoś w rodzaju wyobrażenia jak hipotetycznie mógłby wyglądać Internet lat 80-tych w jakiejś alternatywnej rzeczywistości.
Użycie:
help folder - tutaj jest zawarta pomoc, dostępna również z poziomu skryptu
pages folder - tutaj umieszczone są "strony internetowe". Są one w formacie TXT i łatwo można dodawać nowe, własne. Po dodaniu nowej strony nie trzeba niczego zmieniać w skrypcie - on sam wykryje i zaktualizuje dostępne komendy przy uruchomieniu
read_page.ps1 - główny skrypt
wszystkie dostępne komendy są opisane po użyciu polecenia help w skrypcie
read_page.ps1 kod źródłowy:
$global:path = $PSScriptRoot.ToString()+"\pages\"
$global:block_filename = "block.txt"
function read_page ($page){
$page_name = $page
$lines = Get-Content -Path $global:path$page_name -Raw
$block_char = Get-Content -Path $global:path$global:block_filename -Raw -Encoding utf8
$interpreted = $lines -replace "#", $block_char
Write-Host ""
Write-Host $interpreted
Write-Host ""
}
function web_directory{
Write-Host "Currently there are following pages available online: "
Write-Host ""
Get-ChildItem $global:path -Exclude $global:block_filename | ForEach-Object -Process {[System.IO.Path]::GetFileNameWithoutExtension($_)}
Write-Host ""
}
function browser{
$page = Read-Host "Please enter the webpage name you want to visit: "
$page = $page+".txt"
Write-Host $page
Read-Host "Press any key to continue..."
read_page($page)
}
function help{
$help_path = $PSScriptRoot.ToString()+"\help\"
$help_txt ="help_site.txt"
$lines = Get-Content -Path $help_path$help_txt -Raw
Write-Host $lines
Write-Host ""
}
while ($true){
Clear-Host
Write-Host "Welcome to NECOnet v0.5. Available commands are: browser, netdir, help, exit"
Write-Host ""
$command = Read-Host "Command: "
if ($command -eq "browser"){
browser
}
if ($command -eq "help"){
help
}
if ($command -eq "exit"){
Exit
}
if ($command -eq "netdir"){
web_directory
}
Read-Host "Press any key to continue..."
}
To by było na tyle póki co. Pamiętaj, że używasz tych skryptów na własną odpowiedzialność! W przypadku jakichkolwiek pytań, wal śmiało.