cannotfindserver.co.uk

Skunky Beats

Android Phones – Bulk Configuration

Recently I was tasked with configuring 27 Android smart phones for various people spread across the country. These phones were a mixture between Samsung Galaxy A3’s, A3 2006 version, S6 and S7 Edge models all supplied by EE.
Rather than hand out these phones un-configured and expect the users to set them up themselves I took it upon myself to have them as ready as possible. This involved removing or hiding the pre-installed bloatware and installing a few extra apps.

To do this on the cheap (read: free) you will need:

  • The Android Debug Bridge (ADB) from here.
  • Drivers for your phone. As we’ll have the phone in debug mode the normal Windows drivers aren’t enough. Google’s OEM device driver list.
  • A method of gaining the .apk file for the apps you want to install. An existing Android phone with an app backup app or a website such as APK Mirror will do.
  • A batch file you can run quickly and easily for each phone which I’ll go into later.

Next:

  1. Run through the phone’s initial configuration wizard. I skipped everything apart from joining the wifi.
  2. Make sure the phone is running the latest firmware version.
  3. Enable Developer Options by tapping repeatedly on the “Build Number” option under “About phone”.
  4. Turn on USB Debugging in the Developer Options menu, connect the phone to your computer and trust the device.

Now, open a command prompt and type: adb devices and you should get the phone’s serial number with “device” beside it. This means adb is working properly, if you don’t get anything listed check you’ve got the drivers installed properly. It’s always the drivers :).

adbdevices

Now we can start doing the fun stuff!

adb shell pm list packages -f

Lists all of the packages and their associated file. There will be masses of stuff here and may be truncated so you can output the results to a text file for easy searching:

adb shell pm list packages -f > packages.txt

In my case I wanted to uninstall various apps but unfortunately as carriers bake apps into their ROMs they can only be disabled/hidden. This has the effect of hiding the icon from the app drawer so your users should be none the wiser.
Once you’ve found the package’s name you can do the following:

adb shell pm hide com.facebook.katana

Which will hide the Facebook app.
Make a list of each package you want to hide but be careful not to hide any system packages as this can cause problems. Something to note here is that if you specify a package that does not exist or make a spelling mistake it will still return “hidden: true” so make sure it really is hidden!

Next, grab the .apk files of the apps you want to install. ADB should be in your environment path variable, otherwise put the apk’s in the folder beside ADB.

adb install AdobeAcrobat_16.2.apk

Will install Adobe Acrobat.

You can use: adb push file.ext /mnt/sdcard/directory/file.ext to copy files to the phone. I used this to copy our corporate branded wallpaper.

Finally, compile all the bits and pieces together into a simple Windows batch file, as below:

@ECHO OFF
adb devices
pause
REM This gives you a chance to ensure the phone
REM is properly detected and quit if not.

adb shell pm hide uk.co.ee.myee
adb shell pm hide com.amazon.mp3
adb shell pm hide com.dropbox.android
adb shell pm hide com.facebook.katana
adb shell pm hide com.instagram.android
adb shell pm hide com.amazon.kindle
adb shell pm hide com.lookout
adb shell pm hide uk.amazon.mShop.android
adb shell pm hide com.microsoft.skydrive
adb shell pm hide com.samsunguk.mygalaxy
adb shell pm hide com.sec.android.widgetapp.samsungapps
ECHO Bloatware hidden

adb install AdobeAcrobat_16.2.apk
adb install Excel_16.0.7127.1010.apk
adb install Outlook_2.1.43.apk
adb install Word_16.0.7127.1010.apk

adb push wallpaper.jpg /mnt/sdcard/directory/wallpaper.jpg

adb reboot

So there you go. It’s not elegant and still requires some manual intervention but it should save you a fair bit of time.

Windows Server Backup Checker PowerShell Script

This PowerShell script was written with the intention of automating the manual checking of Windows Server Backup on 10 or so physical Windows servers running Server 2012 and 2008 scattered across the country. Generally these backups run without issue so I decided it would be best to be alerted only to failures while keeping a log of every outcome.

The script will take a list of server names in two plain text files; one for servers running Windows Server 2012 and the other for those running 2008, aptly named 2012servers.txt and 2008servers.txt. It will then run the Get-WBSummary cmdlet against each of the servers in the text files and check the contents of LastBackupResultHR. 0 is a successful backup and anything else is a failure of some sort. If a failure is spotted the script will then email these results along with the error description (which may or may not be helpful) and the server’s name. A .csv is created and each outcome is appended to this log.

# Backup checker script
# Ross Sutherland 2016

$2012servers = Get-Content 2012servers.txt
$2008servers = Get-Content 2008servers.txt

$emailSMTP = "smtp.your.domain.com" 
$emailTo = "Your Name <your.name@your.domain.com>" 
$emailFrom = "Backup Admin <backups@your.domain.com>" 
$emailSubject = "Backup report"

foreach($2012server in $2012servers){    
        $backupResults = Invoke-Command -ScriptBlock { Get-WBSummary } -ComputerName $2012server -ErrorAction SilentlyContinue
        $backupResults | Export-Csv -Path .\$($2012server)_backuplog.csv -Append
    if($backupResults -eq $null){
        Write-Host "Something went wrong while retreiving backup summary from $2012server :(" -BackgroundColor Yellow -ForegroundColor Red
    }else{
        if($backupResults.LastBackupResultHR -ne 0){
            Write-Host "Backup on $($backupResults.PSComputerName) failed :(" -ForegroundColor Red
            Send-MailMessage -SmtpServer $emailSMTP -To $emailTo -From $emailFrom -Subject $emailSubject -Body `
            "Backup on $($backupResults.PSComputerName) failed with error: $($backupResults.DetailedMessage)" -BodyAsHtml -Priority high
        }else{
            Write-Host "Backup on $($backupResults.PSComputerName) completed successfully on $($backupResults.LastSuccessfulBackupTime) :)" -ForegroundColor Green
        }
    }
}

foreach($2008server in $2008servers){    
        $backupResults = Invoke-Command -ScriptBlock { add-pssnapin windows.serverbackup; Get-WBSummary } -ComputerName $2008server -ErrorAction SilentlyContinue
        $backupResults | Export-Csv -Path .\$($2008server)_backuplog.csv -Append
    if($backupResults -eq $null){
        Write-Host "Something went wrong while retreiving backup summary from $2008server :(" -BackgroundColor Yellow -ForegroundColor Red
    }else{
        if($backupResults.LastBackupResultHR -ne 0){
            Write-Host "Backup on $($backupResults.PSComputerName) failed :(" -ForegroundColor Red
            Send-MailMessage -SmtpServer $emailSMTP -To $emailTo -From $emailFrom -Subject $emailSubject -Body `
            "Backup on $($backupResults.PSComputerName) failed with error: $($backupResults.DetailedMessage)" -BodyAsHtml -Priority high
        }else{
            Write-Host "Backup on $($backupResults.PSComputerName) completed successfully on $($backupResults.LastSuccessfulBackupTime) :)" -ForegroundColor Green
        }
    }
}

As you can see the script essentially runs twice for each version of Windows Server. This is simply because the windows.serverbackup snappin must be loaded on Server 2008 for the Get-WBSummary cmdlet to run but loading this snappin on 2012 throws an error. There might be a nice way of having PowerShell detect the version of Windows the server is running before issuing the command but that’s a little beyond me at this stage.

backup_email

Backup failure sample email

If you’d like to run this in your own environment you must have the following:

  • An SMTP server to relay through (without authentication)
  • Permissions to administer backups

Ideas for improvement:

  • Ability to email through secure SMTP servers
  • Better error handling if Get-WBSummary fails
  • Rotate the log file after a certain amount of time or when it reaches a certain size
  • Detect the Windows version and run the appropriate command

Latest picks

Tracks

Misoo – 9 A.M.mp3
Adam Beyer & Alan Fitzpatrick – Human Reason (Len Faki Remix).mp3
Silver Shower – 1 (Original Mix).mp3
Cleric – Blitz (Original Mix).mp3
Clouds – Chained To A Dead Camel.mp3
Mark Broom, Gary Beck – Red (Original Mix).mp3
Gary Beck- Get Together feat. Debra Debs (Original Mix).mp3
Gary Beck – Video Siren.mp3
Laurent Garnier – Crispy Bacon (Original Mix).mp3
Green Velvet – Flash (The Advent and Industrialyzer Remix).mp3
Daryl Stay – Musica.mp3
Daryl Stay – Ploy.mp3
Manic Brothers – Sledgehammer.mp3
N’to – Trauma (Worakls Remix).mp3
Luigi Madonna – Unconditional Beauty.mp3
Raffaele Rizzi – T1000.mp3
Virulent – Cruelty (Original Mix).mp3

 

My picks of the week

Tracks

Slam – Movement
Stranger (To Stability) (Len Faki Podium Mix)
Victor Rulz, Alex Stein – Thoughts
Spartaque – Egomaniac (Original Mix)

Sets

Dario Coiro – Room Session #1