Källa
!OBS! Ta bort nedersta raden, den gör bara namnbyte på filerna enligt mitt eget tycke!
# Batch convert all .ppt/.pptx files encountered in folder and all its subfolders
# The produced PDF files are stored in the invocation folder
#
# Adapted from http://stackoverflow.com/questions/16534292/basic-powershell-batch-convert-word-docx-to-pdf
# Thanks to MFT, takabanana, ComFreek
#
# If PowerShell exits with an error, check if unsigned scripts are allowed in your system.
# You can allow them by calling PowerShell as an Administrator and typing
# ```
# Set-ExecutionPolicy Unrestricted
# ```
# Get invocation path
$curr_path = Split-Path -parent $MyInvocation.MyCommand.Path
# Create a PowerPoint object
$ppt_app = New-Object -ComObject PowerPoint.Application
# Get all objects of type .ppt? in $curr_path and its subfolders
Get-ChildItem -Path $curr_path -Recurse -Filter *.ppt? | ForEach-Object {
Write-Host "Processing" $_.FullName "..."
# Open it in PowerPoint
$document = $ppt_app.Presentations.Open($_.FullName)
# Create a name for the PDF document; they are stored in the invocation folder!
# If you want them to be created locally in the folders containing the source PowerPoint file, replace $curr_path with $_.DirectoryName
$pdf_filename = "$($curr_path)\$($_.BaseName).pdf"
# Save as PDF -- 17 is the literal value of `wdFormatPDF`
$opt= [Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType]::ppSaveAsPDF
$document.SaveAs($pdf_filename, $opt)
# Close PowerPoint file
$document.Close()
}
# Exit and release the PowerPoint object
$ppt_app.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($ppt_app)
Get-ChildItem -Filter "*Chp*.pdf" -Recurse | Rename-Item -NewName {$_.name -replace 'Chp','Kapitel_'}
param(
[string]$PdfOutputDir = 'C:\temp\'
)
Add-Type -AssemblyName System.Windows.Forms
$openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$openFileDialog.Multiselect = $true
$openFileDialog.Filter = "Word Documents (*.docx)|*.docx"
$result = $openFileDialog.ShowDialog()
if ($result -ne [System.Windows.Forms.DialogResult]::OK) {
Write-Host "No file selected."
exit
}
$DocInputs = $openFileDialog.FileNames
Add-type -AssemblyName Microsoft.Office.Interop.Word
function WordToPdf($wdApplication, [string]$wdSourceFile, [string]$wdExportFile) {
# ... [rest of your existing function parameters]
$wdExportFormat = [Microsoft.Office.Interop.Word.WdExportFormat]::wdExportFormatPDF
$wdOpenAfterExport = $false
$wdExportOptimizeFor = [Microsoft.Office.Interop.Word.WdExportOptimizeFor]::wdExportOptimizeForOnScreen
$wdExportRange = [Microsoft.Office.Interop.Word.WdExportRange]::wdExportAllDocument
$wdStartPage = 0
$wdEndPage = 0
$wdExportItem = [Microsoft.Office.Interop.Word.WdExportItem]::wdExportDocumentContent
$wdIncludeDocProps = $true
$wdKeepIRM = $true
$wdCreateBookmarks = [Microsoft.Office.Interop.Word.WdExportCreateBookmarks]::wdExportCreateHeadingBookmarks
$wdDocStructureTags = $true
$wdBitmapMissingFonts = $true
$wdUseISO19005_1 = $false
$wdDocument = $null;
try {
$wdDocument = $wdApplication.Documents.Open($wdSourceFile, $null, $true)
$wdDocument.ExportAsFixedFormat(
$wdExportFile,
$wdExportFormat,
$wdOpenAfterExport,
$wdExportOptimizeFor,
$wdExportRange,
$wdStartPage,
$wdEndPage,
$wdExportItem,
$wdIncludeDocProps,
$wdKeepIRM,
$wdCreateBookmarks,
$wdDocStructureTags,
$wdBitmapMissingFonts,
$wdUseISO19005_1
)
}
catch {
$wshShell = New-Object -ComObject WScript.Shell
$wshShell.Popup($_.Exception.ToString(), 0, "Error", 0)
$wshShell = $null
}
finally {
if ($wdDocument) {
$wdDocument.Close($doNotSaveChanges)
$wdDocument = $null
}
# Do not quit the Word application here
}
}
try {
$wdApplication = New-Object -ComObject "Word.Application"
$wdApplication.DisplayAlerts = [Microsoft.Office.Interop.Word.WdAlertLevel]::wdAlertsNone
foreach ($DocInput in $DocInputs) {
$FullInput = (Get-Item $DocInput).FullName
$PdfFileName = [System.IO.Path]::GetFileNameWithoutExtension($DocInput) + ".pdf"
$FullOutput = Join-Path -Path $PdfOutputDir -ChildPath $PdfFileName
Write-Host "Converting $FullInput to $FullOutput..."
WordToPdf $wdApplication $FullInput $FullOutput
}
}
finally {
if ($wdApplication) {
$wdApplication.DisplayAlerts = [Microsoft.Office.Interop.Word.WdAlertLevel]::wdAlertsAll
$wdApplication.Quit()
$wdApplication = $null
}
[GC]::Collect()
[GC]::WaitForPendingFinalizers()
}
#This is a bash script to check ssh services on hosts
#You need a host file with each IP-address on a separate row
#The source file for the text is used as an argument, ie ./ssh-check.sh ip.txt
#Edit the nc row to alter the port you are testing for, in this case its ssh=22
#Results are output to screen and a text file in the same directory
#!/bin/bash
echo "=================================="
rm results.txt
while read p; do
nc -znv -w3 $p 22
if [ $? -ne 0 ]
then
echo "No connection" | tee -a results.txt
else
echo "OK" | tee -a results.txt
fi
done < $1
# This is a bash script to generate qrcodes by reading a text string
# from a file and adding a human readable text part below the qr code
# The source file for the text is used as an argument, ie ./qrcodes.sh hosts.txt
#!/bin/bash
echo "=================================="
while read p; do
if echo "$p" | grep '*\|\/'; then
echo "Illegal entry in hosts.txt file"
break
else
qrencode -s 5 -i $p -o $p-QR.png
convert $p-QR.png -pointsize 24 label:"$p" -gravity center -append $p.png
rm $p-QR.png
fi
done < $1
Behöver:
Sorterar orginalfilerna enligt labb-nummer, ha inga andra filer förutom blank.pdf i startkatalogen. Saknar just nu försättsbladet dock!
#!/bin/bash
i=0
while read pdf; do
pages=$(pdfinfo "$pdf" 2>&1 | grep -- ^Pages | tr -dc '[0-9]')
if [ $((pages%2)) != 0 ] && [ $((pages)) -gt 1 ]
then
printf "%s %d\n" "$pdf" "$pages"
((i=i+1))
is=$(printf "%02d" $i)
pdftk "$pdf" blank.pdf cat output out/lab"$is".pdf
else
if [ "$pdf" != './blank.pdf' ]
then
((i=i+1))
is=$(printf "%02d" $i)
cp "$pdf" out/lab"$is".pdf
fi
fi
done < <(find -name "*.pdf" -type f | sort -V)
pdftk out/lab*.pdf output out/hafte.pdf
grep -E '[0-9]{12}' rawstudents | tr -d '\t' | rev | cut -f 3- -d' ' | sed 's/ /,/1' | rev > students
// 1. behövs för att köra vm-ware modulen i windows då den är "tredjepart"
Set-ExecutionPolicy remotesigned
// 2. -Scope begränsar installation till inloggad användare
install-module -Name VMware.PowerCLI -Scope CurrentUser
// 3. Kommer att fråga om dina credentials, använd samma som gui inloggningen
Connect-VIServer -server vcenter-b.cnap.hv.se
// 4. länk till object som är h6 hosten (till exempel)
$myVMHost = Get-VMHost -name esxi-h6.cnap.hv.se
!! VA RIKTIGT RIKTIGT SÄKER PÅ ATT DET ÄR HÄR DU VILL PILLA !!
// 5. länk till vswitch som skall pillas på
$vswitch = Get-VirtualSwitch -vmhost $myVMHost -name vSwitch1
// 6. Skapar VLAN med namn "VLAN20XX" och vlan id 20XX
for ($i=2004; $i -le 2038; $i++) {New-VirtualPortGroup -VirtualSwitch $vswitch -name "VLAN$i" -VLanId $i}
// 7. tar bort portgroups "VLAN2037-VLAN2038" på vswitchen som definieras i steg >>5<<
// OBS! -confirm:$false stänger av en "are you sure, dummy" fråga. Är du inte säker, ta bort detta ur raden! OBS!
for ($i=2037; $i -le 2038; $i++) {Get-VirtualPortGroup -VirtualSwitch $vswitch -name "VLAN$i" | Remove-VirtualPortGroup -confirm:$false}
// Bryt kopplingen till vcentret
Disconnect-VIServer
$remove_vms = Read-Host -Prompt 'Input the server match string to remove from disk'
Write-Host "The entered string was: '$remove_vms'"
$select_confirm = Read-Host -Prompt 'Confirm your selection string (y/n)'
if($select_confirm -eq 'y') {
$VMs = Get-VM $remove_vms
foreach($VM in $VMs) {
Write-Host $VM
}
Write-Host "The listed VMs above will be permanently deleted from disk!"
Write-Host "Are you absolutely sure you want to do this?"
$nuclearoption = Read-Host -Prompt 'Type in "DELETE" to confirm this operation!'
if($nuclearoption -eq 'DELETE') {
Write-Host "Deleting..."
foreach($active in $VMs) {
if($active.Powerstate -eq "PoweredOn") {
Stop-VM -VM $active -Confirm:$false -RunAsync | Out-Null
Start-Sleep -Seconds 7
}
}
foreach($delete in $VMs) {
Remove-VM -VM $delete -DeleteFromDisk -Confirm:$false -RunAsync | Out-Null
}
}
}
Testing the Notification
The resulting command at the bottom should look something like this:
curl -X POST -H "Content-Type: application/json" -d '{"value1":"Meddelande här!"}' https://maker.ifttt.com/trigger/notify/with/key/DIN_API_NYCKEL_HÄR
Kort bash function för att skicka ett custom meddelande
cli-2-phone()
{
printf -v message '{"value1":"%s"}' "$*"
$1 && curl -X POST -H "Content-Type: application/json" -d "$message" https://maker.ifttt.com/trigger/notify/with/key/DIN_API_NYCKEL_HÄR > /dev/null 2>&1 ; return
$0 && echo "You need to specify a message!"; return
}
Tar bort alla rader mellan INT202_START och INT202_END raderna, för enkel rensning av zonfilen
sed -i.bak '/^;INT202_START/,/^;INT202_END/{//!d}' db.rev236
För nästa INT202 omgång, klistra bara in de nya grupperna mellan INT202_ raderna.
term=HT25; convert canvas_cover.jpg -gravity South -font P052-Bold -pointsize 128 -fill black -annotate +5+40 "GDA103 - $term" -fill white -annotate +0+45 "GDA103 - $term" output.jpg
Utgå från bilden canvas_cover på Onedrive, kontrollera term= variabeln och kör sedan i maskin som har ImageMagick installerad