Category : Programming

NetAtmo Programming

Netatmo Weather Station Shell Script

I got a lot of feedback for my blog post Read NetAtmo weather station data via Script and Export NetAtmo weather station data to CSV / Excel. A lot of people seem to be interested by using the data from thier Netatmo weather station.

Bernd G. – one of my blog readers, extended my scripts and build a complete Linux shell wrapper around it. That makes it much easier and adds more flexibility to the scripts. Bernd allowed me to post his script on my blog to share it.

Read More
PowerShell Programming Windows

Change DNS settings on multiple Windows Servers and Workstations

During several Active Directory migration projects I needed to change the DNS server IP addresses on several computers if the DNS service was installed on the Active Directory Domain Controller. Therefore I wrote a little PowerShell script to connect to remote computer and change the DNS server IP address in the network connection via WMI to the onces specified in the script.

This makes changing the IP address of a DNS server much easier because all Windows systems based on Windows Server 2008 / Vista or newer can be edited by using this PowerShell script.

Read More
Programming Synology

Edit Synology Photo Station Album Permissions via Script

I’m using Synology Photo Station for storing all my pictures and share access to all family members. Being an IT-Guy I’m very concerned about security and especially the access rights to all albums. Unfortunately, Synology marks a new album always as public. Instructing my family to set the correct album permissions didn’t work because they’re normal users and they don’t want to do any settings for albums. They just want to access and upload their photos.

Synology Photo Station Permissions

At this point, I decided to have a look on the Postgres SQL Database that is being used

Read More
PowerShell Programming

Update environment variables in current process

Currently, I’m involved in a huge PowerShell based deployment project for one of our major customers. The whole deployment process including several WPF-based GUIs are written in PowerShell. This week we had a new issue to fix regarding environment variables. First of all some background knowledge about environment variables in Windows.

Environment Variables are stored inside the registry and each process will read them from the registry and store the variables in its own environment. Each new process (called sub-process) that will be started from another process will inherit the environment variables from its parent process.
The problem will be if the parent process starts several sub-processes and each of them will subsequently change / expand environment variables like the %PATH% variable. Sub-Process #2 is not aware of the changes Sub-Process #1 made to the environment variables.

To work around this issue, I wrote a small PowerShell function which utilizes .NET Framework Methods to re-read the environment variables and store them for the current process:

#####################################################################
##
## (C) 2015 Michael Miklis (michaelmiklis.de)
##
##
## Filename:      Update-Environment.ps1
##
## Version:       1.0
##
## Release:       Final
##
## Requirements:  -none-
##
## Description:   Refresh the current environment variables
##
## This script is provided 'AS-IS'.  The author does not provide
## any guarantee or warranty, stated or implied.  Use at your own
## risk. You are free to reproduce, copy & modify the code, but
## please give the author credit.
##
####################################################################
Set-PSDebug -Strict
set-strictMode -version latest

function Update-Environment {
    <#
    .SYNOPSIS
    Refresh all environment variables

    .DESCRIPTION
    Reads all environement variables from registry for scope user and machine
    and updates the current process environment variables
        
    .EXAMPLE
    Update-Environment
    #>


    # first update the environment variables from the machine scope
    $ENV_MACHINE = ([Environment]::GetEnvironmentVariables('Machine'))
    foreach ($EnvVar in $ENV_MACHINE.keys) {
        Set-Item "Env:$($EnvVar)" -Value $ENV_MACHINE[$EnvVar]
    }

    # second update the environment variables from the user scope
    $ENV_USER = ([Environment]::GetEnvironmentVariables('User'))
    foreach ($EnvVar in $ENV_USER.keys) {
        Set-Item "Env:$($EnvVar)" -Value $ENV_USER[$EnvVar]
    }

    # now Update the Path variable (path variable gets
    # combined by User:Path and Machine:Path
    # User:Path has precedence over Machine:Path
    if ($ENV_USER.ContainsKey('Path')) {
        Set-Item env:Path -Value ((($ENV_USER.Path -split ";") + ($ENV_MACHINE.Path -split ";") | select -Unique) -join ";")
    }

}

#_____________________________________________________________________________________________

#call Update-Environment() function
Update-Environment

We’ve added the function to our framework – this will be the first function that we’re calling after every external process (Start-Process), we’ve started.

Read More
Mac OS X Programming

Evernote Backup using Apple Script

Today I’ve created a small Apple Script to export all my Evernote notes into a folder and compress the notes to a tar.gz archive for storing on my NAS. Feel free to use this script and customize for your own environment.

[UPDATE] Fixed an issued causing the export to fail if empty notebooks are present. Thanks to Darryl for the solution in the comments.

Read More
NetAtmo Programming

Read NetAtmo weather station data via Script

Based on the feedback for my previous blog post Export NetAtmo weather station data to CSV / Excel I created a small script to get the module, device ID, temperature, humidity and also all sensor data from your NetAtmo weather station and modules.

NetAtmo_JSON_JQ

This scripts also uses curl to login to the web page and then download the device data using the NetAtmo Web API. This script will return all the information in JSON format.

Read More
NetAtmo Programming Synology

Export NetAtmo weather station data to CSV / Excel

I’m a proud owner of a NetAtmo weather station for a couple of months and I think it’s the best wheater station with a great user experience you can get:

NetAtmo_Dashboard

Some days ago I noticed the option in the web dashboard to export all my weather data into a comma-separated (CSV) or Microsoft Excel file. That’s a great feature for archiving your measured data….but wait – how could this be done in an automated way?

Read More
Programming System Center

SCCM 2012 Extension: Remove a Computer from all Collections

Recently one of our customers wanted to have an extension for his Microsoft System Center Configuration Management 2012 Console to be able to remove a computer from all collections to which it was assigned to.

This was truly my first scripting and programming job regarding SSCM 2012. I did a little research on google and figured out how to do this. And this is how it looks like:

Miklis-SCCM-Extensions

There are two main components:

  • A script or application which will do the work
  • A XML file which actually adds the script or application to the context menu

The XML file needs to be placed in the following folder:
[SCCM-Directory]AdminUIXmlStorageExtensionsActions7ba8bf44-2344-4035-bdb4-16630291dcf6

The script or application can be put anywhere you want – you’ll only need to modify the path within the XML file:

SCCM-Extension-XML
 
 

DOWNLOAD
Miklis-SCCM-Extensions.zip
 

Read More
Lotus Notes Programming Windows

LotusScript: Move all items without a view into Inbox Folder

After working some years with IBM Lotus Notes and moving lots of mails and other items between folders you’ll be surprised how may ‘invisible’ items are reseeding in your mailbox database.

To make this items visable I found a script some years ago somewhere on the internet. Unfortunatelly I don’t know the original programmer to contribute his work. You can just put the Script into the Notes Script Editor an execute.

Sub Click(Source As Button)
Dim s As New notessession
Dim db As notesdatabase
Dim fDoc As NotesDocument ' Document in folder
Dim ad As notesview ' All Documents view
Dim aDoc As notesdocument ' document in All Docs view
Dim fUNID() As String ' array of UNID's of docs in folders
Dim i As Integer ' UNID array index
Dim deldate As notesitem
Dim Chair1 As notesitem

i =0
Set db = s.CurrentDatabase

Redim fUNID(0)
' Build UNID array by looping through folders, then their documents
Forall view In db.views
If view.IsFolder And Not view.Name=("($All)") Then
Set fDoc = view.GetFirstDocument
While Not fDoc Is Nothing
Redim Preserve fUNID(i)
fUNID(i) = fDoc.UniversalID
i=i+1
Set fDoc = view.GetNextDocument(fDoc)
Wend
End If
End Forall
' Loop through docs in the All Documents view and compare UNIDs to each doc in the array
Set ad = db.GetView("($All)")
Set aDoc = ad.GetFirstDocument
While Not aDoc Is Nothing
i = 0
Do While i &lt;= Ubound(fUNID)
If fUNID(i) = aDoc.UniversalID Then
Exit Do
End If
i = i + 1
Loop
Set deldate = adoc.getfirstitem("delivereddate")
Set Chair1 = adoc.getfirstitem("CHAIR")
If i &gt; Ubound(fUNID) And Not deldate Is Nothing And Chair1 Is Nothing Then
Call adoc.PutInFolder( "($Inbox)")
End If
Set aDoc = ad.GetNextDocument(adoc)
Wend
End Sub
Read More
Programming Windows

VBScript: Change Word Document Template

During most of my Infrastructure and Migration projects, most customers have the same issue. After migrating the file data to a new server, old documents may try to access their original document template on which they are based on.
Unfortunately, the referenced path is not a mapped network drive or a relative path – it is a UNC Path containing the old server name.

Therefore, I wrote a little script that will process all Word Documents within a given path and replace the old Server and or Share name with the new ones. After that, the launch of these old documents will be much faster.
You need write permissions to all Word Documents which should be changed and of course you need to have Microsoft Word (I used Word 2010) installed:

' #####################################################################
' ##
' ## (C) 2012 Michael Miklis (michaelmiklis.de)
' ##
' ##
' ## Filename:      ChangeWordDocumentTemplate.vbs
' ##
' ## Version:	    1.0
' ##
' ## Release:	    Final
' ##
' ## Requirements:  -none-
' ##
' ## Description:   Changes the template in doc files
' ##
' ## This script is provided 'AS-IS'.  The author does not provide
' ## any guarantee or warranty, stated or implied.  Use at your own
' ## risk. You are free to reproduce, copy & modify the code, but
' ## please give the author credit.
' ##
' ####################################################################
Option Explicit

Dim strFilePath
Dim strPath
Dim intCounter
Dim strFileName
Dim OldServer
Dim NewServer
Dim objDoc
Dim objTemplate
Dim dlgTemplate
Dim objWord
Dim strFileArr
Dim objFs
Dim i

Const wdDialogToolsTemplates = 87

Set objFS = CreateObject("Scripting.Filesystemobject")

Set objWord = CreateObject("Word.Application")
objWord.Visible = false

strFilePath = "C:Usersmichaeldesktop"
OldServer = "vv"
NewServer = "OLD-FILESERVERsharefolder1"

If Right(strFilePath, 1) = "" Then strFilePath = Left(strFilePath, Len(strFilePath) - 1)

strFileArr = Split(CreateFileList(objFS.GetFolder(strFilePath),true), vbCr)

For i=0 to UBound(strFileArr)
	If NOT strFileArr(i) = "" then
		strFileName = strFileArr(i)

		wscript.echo "--------------------------------------------------"
		wscript.echo "Processing File: " & strFilename

		Set objDoc = objWord.Documents.Open(strFileName)
		Set objTemplate = objDoc.AttachedTemplate
		Set dlgTemplate = objWord.Dialogs(wdDialogToolsTemplates)
		strPath = dlgTemplate.Template

		wscript.echo "Old Template Name: " & strPath

		'// Only process templates based on old server
		If LCase(Left(strPath, Len(OldServer))) = LCase(OldServer) Then
			wscript.echo "Template needs to be changed..."
			'objDoc.AttachedTemplate = NewServer & Mid(strPath, Len(OldServer) + 1)
			wscript.echo "New Template Name: " & NewServer & Mid(strPath, Len(OldServer) + 1)
		End If

		objDoc.Save
		objDoc.Close

		wscript.echo "--------------------------------------------------"
		wscript.echo ""
	End If
Next

Set objDoc = Nothing
Set objTemplate = Nothing
Set dlgTemplate = Nothing

'// Close Word
objWord.Quit (False)

'______________________FUNCTIONS & SUB ROUTINES_______________________

Function CreateFileList(objFolder, bRecursive)
	'//
<summary> '// Creates a List containing all Files
 '// </summary>
	'//Root-Folder for searching
	'//Search recursive
	Dim objFile, objSubFolder

        For each objFile in objFolder.Files
		If Right(lcase(objFile),4) = ".doc" OR Right(lcase(objFile),5) = ".docx" AND NOT Left(objFile.Name,1) = "~" then
	        	CreateFileList = CreateFileList & objFile.Path & vbCr
		End If
	Next

	If bRecursive = true then
		For each objSubFolder in objFolder.Subfolders
			CreateFileList = CreateFileList & CreateFileList(objSubFolder, true)
	        Next
	End If
End Function
Read More
1 2