Export powershell scripts from intune

Source: Intune/Get-DeviceManagementScripts.ps1 at master · okieselbach/Intune · GitHub
Source: Get back your Intune PowerShell Scripts – Modern IT – Cloud – Workplace (oliverkieselbach.com)

Import-Module Microsoft.Graph.Intune
Connect-MSGraph

####################################################

#region Initialization code

$m = Get-Module -Name Microsoft.Graph.Intune -ListAvailable
if (-not $m)
{
    Install-Module NuGet -Force
    Install-Module Microsoft.Graph.Intune
}
Import-Module Microsoft.Graph.Intune -Global

#endregion

####################################################

Function Get-DeviceManagementScripts(){
<#
.SYNOPSIS
Get all or individual Intune PowerShell scripts and save them in specified folder.
 
.DESCRIPTION
The Get-DeviceManagementScripts cmdlet downloads all or individual PowerShell scripts from Intune to a specified folder.
Initial Author: Oliver Kieselbach (oliverkieselbach.com)
The script is provided "AS IS" with no warranties.
 
.PARAMETER FolderPath
The folder where the script(s) are saved.
.PARAMETER FileName
An optional parameter to specify an explicit PowerShell script to download.
.EXAMPLE
Download all Intune PowerShell scripts to the specified folder
Get-DeviceManagementScripts -FolderPath C:\temp 
.EXAMPLE
Download an individual PowerShell script to the specified folder
Get-DeviceManagementScripts -FolderPath C:\temp -FileName myScript.ps1
#>

    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true)][String] $FolderPath,
        [Parameter(Mandatory=$false)][String] $FileName
    )

    $graphApiVersion = "Beta"
    $graphUrl = "https://graph.microsoft.com/$graphApiVersion"

    $result = Invoke-MSGraphRequest -Url "$graphUrl/deviceManagement/deviceManagementScripts" -HttpMethod GET

    if ($FileName){
        $scriptIds = $result.value | Select-Object id,fileName | Where-Object -Property fileName -eq $FileName
        $script = Invoke-MSGraphRequest -Url "$graphUrl/deviceManagement/deviceManagementScripts/$($scriptId.id)" -HttpMethod GET
        [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($($script.scriptContent))) | Out-File -Encoding ASCII -FilePath $(Join-Path $FolderPath $($script.fileName))
    }
    else{
        $scriptIds = $result.value | Select-Object id,fileName
        foreach($scriptId in $scriptIds){
            $script = Invoke-MSGraphRequest -Url "$graphUrl/deviceManagement/deviceManagementScripts/$($scriptId.id)" -HttpMethod GET
            [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($($script.scriptContent))) | Out-File -Encoding ASCII -FilePath $(Join-Path $FolderPath $($script.fileName))
        }
    }
}

Connect-MSGraph | Out-Null

Get-DeviceManagementScripts -FolderPath C:\temp

Rotate screen raspberry pi

Source: https://howchoo.com/pi/raspberry-pi-display-rotation

Open file

sudo nano /boot/config.txt

Rotate the display

display_rotate=0 # Normal (landscape)
display_rotate=1 # 90 degrees (portrait, upside down)
display_rotate=2 # 180 degrees (landscape)
display_rotate=3 # 270 degrees (portrait, upside down)
display_rotate=0x10000 # horizontal flip
display_rotate=0x20000 # vertical flip

Rotate touch input

lcd_rotate=0 # default (normal landscape)
lcd_rotate=1 # 90 degrees (portrait, upside down)
lcd_rotate=2 # 180 degrees (landscape)
lcd_rotate=3 # 270 degrees (portrait, upside down)

Reboot the device

TTP IP

# TomTech Productions IP
import time, os
import requests, socket, uuid

## INSERT YOUR KEY AND MAIL HERE ##
domain = "" #company domain
mail = "tom.schelles@live.be" #your email
## INSERT YOUR KEY AND MAIL HERE ##

url = 'https://ttpm.be/data/online/post.php'
mac = uuid.getnode()

def get_lan_address():
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(("8.8.8.8", 80))
        return s.getsockname()[0]

while(1):
    lan = get_lan_address()
    name = socket.gethostname()

    myobj = {'lan' : lan, 'mac': mac, 'name': name, 'domain': domain, 'mail': mail }

    try:
        x = requests.post(url, data = myobj)

        if (x.text == "reboot"):
            os.system("shutdown -t 0 -r -f")

        if (x.text == "lock"):
            os.system("shutdown -l")

        if (x.text == "shutdown"):
            os.system("shutdown -t 0 -s -f")

    except:
        print('NO CONNECTION TO SERVICE')
    #update gegevens lokaal om de 10 seconden
    time.sleep(30)

Linux KIOKS mode Chrome

source: https://bloggerbrothers.com/2016/12/27/boot-your-pixel-based-pi-into-chromium-kiosk/

Install following software

sudo apt-get install -y x11-xserver-utils unclutter

Create a new file

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

Copy this code into the file

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
#@xscreensaver -no-splash
#@point-rpi
@xset s off
@xset -dpms
@xset s noblank
@sed -i 's/"exited_cleanly": false/"exited_cleanly": true/' ~/.config/chromium/Default/Preferences
@chromium-browser --incognito --noerrdialogs --kiosk tomtechproductions.be/example
@unclutter -idle 0.1 -root
Backup files linux

Backup files linux

An easy way to backup files to a local share

The example backup’s the files from the /var/www/html directory

#change to website folders
cd /var/www/html/

#find all subsites
for D in *; do
    if [ -d "${D}" ]; then
        echo "Generating backup for $D > " `date +%Y-%m-%d_%H-%M-%S`-${D}   # your processing here
        tar -zcvf "/mnt/srv-ttp-nas/server/"`date +%Y-%m-%d_%H-%M-%S`-${D}.tar.gz ${D}
    fi
done

#remove stale files
find /mnt/srv-ttp-nas/server/* -mtime +14 -exec rm {} \;

Add crontab to run backup every night at 3

sudo crontab -e
0 3 * * * /home/tom/backup_files.sh

Preview of data on share

Backup all mysql databases

Backup all mysql databases

I created an easy way to backup all mysql databases
/mnt/srv-ttp-nas/ is a location on a local NAS

#!/bin/sh
sleep 10

DB_USER="username"
DB_PASS="password"
BACKUP_DIR = "/mnt/srv-ttp-nas/bu/databases"

#find all databasses and backup them
databases=`mysql --user=$DB_USER --password=$DB_PASS -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`

for db in $databases; do
        echo "Dumping database: $db"
        mysqldump $db -u $DB_USER -p --password=$DB_PASS | gzip > "/mnt/srv-ttp-nas/databases/"`date +%Y-%m-%d_%H-%M-%S`-$db.sql.gz
done

#remove files older than one month
find /mnt/srv-ttp-nas/databases/* -mtime +31 -exec rm {} \;

The power of this script is that if you add a new database this will automaticly be added.

Add to crontab to backup every 6 hours.

sudo crontab -e
0 0,6,12,18 * * * /home/tom/backup.sh

Preview of data on share

Secured By miniOrange