Category: Powershell
Instaliraj Powershell na Ubuntu 22.04
sudo apt-get update sudo apt-get install -y wget apt-transport-https software-properties-common wget -q "https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb" sudo dpkg -i packages-microsoft-prod.deb sudo apt-get update sudo apt-get install -y powershell…
Epoch date time u ljudski oblik
powershell.ps1 $UnixTime = 1711000300 $epoch = [DateTime]::new(1970, 1, 1, 0, 0, 0, [DateTimeKind]::UTC) $date = $epoch.AddSeconds($UnixTime).ToLocalTime() python.py (hex epoch) import datetime VrijemeHex = "61a73207" VrijemeDec…
Powershell – All history
Get-Content ((Get-PSReadlineOption).HistorySavePath) posh pwsh powershell history all xposh xpwsh xpowershell xhistory xall
Powershell – Prikaži dugačku poruku
[System.Reflection.Assembly]::LoadWithPartialName(‘System.Windows.Forms’) [System.Windows.Forms.MessageBox]::Show("’….-….1….-….2….-….3….-….4….-….5….-….6….-….7….-….8….-….9….-…100…-….1….-….2….-….3….-….4….-….5….-….6….-….7….-….8….-….9….-…200…-….1….-….2….-….3….-….4….-….5….-….6….-….7….-….8….-….9….-..300","NASLOV")
OCR .PDF datoteke
ocrmypdf -O 3 –tesseract-oem=3 –language=hrv –force-ocr –output-type pdf –sidecar OCR.txt inputFile.pdf temp.pdf Po završetku će datoteka “OCR.txt” imati tekst iz datoteke “inputFile.pdf”. Datoteka “temp.pdf” je…
PDF kontrast i to
magick convert -monitor -density 150 $inputFile -auto-level -gamma .4 -compress JPEG -quality 80 -adaptive-sharpen 2 -antialias -compress JPEG $outputFile https://imagemagick.org/ pdf xpdf jpg xjpg jpeg…
Powershell full history
type (Get-PSReadlineOption).HistorySavePath pwsh xpwsh xpowershell xhistory xfull sve xsve xall all xtotal total
Windows firewall i Powershell
New-NetFirewallRule -DisplayName "BlokirajOut443" -Direction outbound -Profile Any -Action Block -RemotePort 443,567-678 -Protocol TCP -Program C:\Windows\Notepad.exe Remove-NetFirewallRule -DisplayName "BlokirajOut443" pwsh ps xpwsh xps firewall xfirewall fw…
Skriven prozor
batch.cmd cmd /c start /min "" pwsh -WindowStyle Hidden -ExecutionPolicy Bypass -command "$nestonesto=neštonešto" powershell.ps1 pwsh -WindowStyle Hidden -ExecutionPolicy Bypass -command "$nestonesto=neštonešto"
Štoperica / stopwatch
powershell.ps1 Štoperica 4 sekunde: $stoperica = new-object system.diagnostics.stopwatch ; $stoperica.start() ; while ($stoperica.elapsed.Seconds –lt 4) {$null}; write-host "Kraj" ; $stoperica.stop()
Nextcloud – Batch upload
Import iz commandlineta u NextCloud: curl -u <%USERNAME%>:<%LOZINKA%> -T X:\Proba123.pdf http://sljedecioblak.server.tld/remote.php/dav/files/datotetke/ xcurl xnextcloud upload batch cli commandline command line xcli xcommandline script xscript
Koja je boja teksta i podloge u konzoli?
powershell.ps1 [System.Console]::ForegroundColor [System.Console]::BackgroundColor xps1 xforegroundcolorx xBackgroundColorx xcolorx xcursorx xboja xtekst xpodloga xpozadina boja teksta boja podloge boja pozadine
Popis svih ekstenzija u poddirektorjima
powershell.ps1 $ekstenzije = @{}; Get-ChildItem *.* -Recurse | ForEach-Object { $ekstenzije[$_.Extension]++ }; Write-Output $ekstenzije Rezultat: .gif 14 .tif 15 .pdf 1200 .jpg 1267 .png 90…
Prebroj datoteke
powershell.ps1 (Get-ChildItem "neštonešto*.txt" -File | Measure-Object | %{$_.Count}) prebrojavanje datoteka xprebrojavanje xdatoteka count files xcount xfiles number of files broj datoteka
Izmišljatelju lozinaka, izmisli mi lozinku
Generiraj alfanumaričku lozinku od 24 znaka bash.sh …(jednoga dana)… powershell.ps1 -join ((65..90) + (97..122) + (48..57)| Get-Random -Count 24 | ForEach-Object {[char]$_}) python.py …(jednoga dana,…
Kako izračunati CRC SHA
powershell.ps1 Get-FileHash -Path datoteka.zip # default=SHA256 Get-FileHash -Path datoteka.zip -Algorithm SHA1 batch.cmd certutil.exe -hashfile datoteka.zip SHA256 certutil.exe -hashfile datoteka.zip SHA1 bash.sh sha256sum datoteka.zip sha1sum…
Powershell Write-Host – Preusmjeravanje ispisa u datoteku
Iz Powershella ne možeš uobičajenim opcijama preusmjeriti ispis u datoteku jerbo Write-Host, logičko zar ne, piše na – host! ALI… zato ovo radi: pwsh -file…
Postoji li datoteka ili ne, pitanje je tad
bash.sh if [ -f "datoteka.txt" ]; then echo "Postoji" ; fi if [ ! -f "datoteka.xyz" ]; then echo "Ne postoji"; fi batch.cmd if …
if .. then .. else i
Ima li CLI argumenta i koliko?
bash.sh if [ $# -eq 0 ] then echo "Nema argumenata. Le kraj." exit 99 fi if [ -z $1 ] # provjeri je li…
Parametri naredbenog retka iliti
command line parameters
bash.sh #!/bin/bash argumentum1=$1 agrumenat2=$2 echo $argumentum1 $argumenat2 echo Naziv/path skripte jest 0: $0 batch.cmd @echo off set argumentum1=%1 set argumenat2=%2 echo %argumentum1% %argumenat2% echo Naziv/path…