Tag Archives: Scripting

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
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
PowerShell Windows XenDesktop

Get running processes including CPU and memory usage

One of my customers needed a PowerShell script to get all running processes with their corresponding CPU load. This was script should be triggered by their monitoring system if the system total CPU usage exceeds a configured threshold.

They’re running a mid-sized Citrix XenDesktop farm with Server-OS (formerly known as XenApp a.k.a. terminal services) and sometimes applications are using a high CPU amount.

This is the small script I wrote for them:

#####################################################################
##
## (C) 2015 Michael Miklis (michaelmiklis.de)
##
##
## Filename:      Get-Tasks.ps1
##
## Version:       1.0
##
## Release:       Final
##
## Requirements:  -none-
##
## Description:   PowerShell Tasklist with CPU usage and memory
##                usage
##
## 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.
##
####################################################################

<#
.SYNOPSIS
Lists all running task including cpu and memory usage

.DESCRIPTION
The Get-Tasks function uses Windows Management Instrumentation (WMI) to retrieve process Name, ProcessId, SessionId,
VirtualSizeMB, Handles, Owner, PercentProcessorTime and ThreadCount

.PARAMETER computerName
Computername or IP Adress of the computer to query

.PARAMETER credential
Credentials to query computer as System.Management.Automation.PSCredential

.EXAMPLE
Get-Tasks
Get-Tasks -computerName "server.domain.com" -credential $credential

.NOTES
You need to run this CMDlet with elevated permissions
#>

function Get-Tasks {
    [CmdletBinding()]
    param (
        [parameter(Mandatory=$true,ValueFromPipeline=$false)]
        [string]$computername,

        [parameter(Mandatory=$true,ValueFromPipeline=$false)]
        [System.Management.Automation.PSCredential]$credential      
    )

    PROCESS {
        $colProcs = Get-wmiobject win32_process -computername $computername  -Credential $credential | select *,@{Name=”Owner”;Expression={($_.GetOwner()).User}}
        $colPerfs = Get-wmiobject win32_perfformatteddata_perfproc_process -computername $computername  -Credential $credential 
        $colTasklist = @()

        foreach ($proc in $colProcs) {
            $process = New-Object System.Object

            $perf = $colPerfs | Where-Object { $_.IDProcess -eq $proc.ProcessId }

            $process | Add-Member -type NoteProperty -name "Name" -value $proc.Name       
            $process | Add-Member -type NoteProperty -name "ProcessId" -value $proc.ProcessId
            $process | Add-Member -type NoteProperty -name "SessionId" -value $proc.SessionId
            $process | Add-Member -type NoteProperty -name "VirtualSizeMB" -value ([math]::Round(($proc.VirtualSize / 1024 /1024), 2))
            $process | Add-Member -type NoteProperty -name "Handles" -value $proc.Handles
            $process | Add-Member -type NoteProperty -name "Owner" -value $proc.Owner
            $process | Add-Member -type NoteProperty -name "PercentProcessorTime" -value $perf.PercentProcessorTime
            $process | Add-Member -type NoteProperty -name "ThreadCount" -value $perf.ThreadCount

            $colTasklist += $process
        }

        $colTasklist | Sort-Object PercentProcessorTime -Desc

        return $colTasklist
    }
}
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
Programming Windows

VBScript: List all installed applications

Just a simple inventory script. This script does NOT query the WMI Installed_Product table, which an be quite time and CPU consuming. Instead, my script queries the Uninstall-Registry key to generate the list of installed apps which makes it lot faster:

' #####################################################################
' ##
' ## (C) 2010 Michael Miklis (michaelmiklis.de)
' ##
' ## 
' ## Filename:      GetInstalledApplications.vbs
' ##
' ## Version:	    1.0
' ##
' ## Release:	    Final 
' ##
' ## Requirements:  -none-
' ## 
' ## Description:   List installed applications based on uninstall key
' ##
' ## 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 &amp; modify the code, but 
' ## please give the author credit. 
' ##
' ####################################################################
Option Explicit


wscript.echo GetInstalledApplications


'______________________FUNCTIONS &amp; SUB ROUTINES_______________________

Function GetInstalledApplications
	'// &lt;summary&gt; 
	'// List installed applications
	'// &lt;/summary&gt;
	'// &lt;param name=&quot;strComputername&quot;&gt;Computername&lt;/param&gt;
 
	Const HKLM = &amp;H80000002		'HKEY_LOCAL_MACHINE

	Dim objREG			'Registry Object
	Dim strBaseKey			'Uninstall Key
	Dim intRet			'Return Code
	Dim arSubKeys			'Reg-Key Array
	Dim strKey			'Reg-Key Element
	Dim strValue			'Reg-Value

	Set objREG = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!./root/default:StdRegProv&quot;)
	strBaseKey = &quot;SOFTWAREMicrosoftWindowsCurrentVersionUninstall&quot;

	intRet = objREG.EnumKey(HKLM, strBaseKey, arSubKeys)

	For Each strKey In arSubKeys
		intRet = objREG.GetStringValue(HKLM, strBaseKey &amp; strKey, &quot;DisplayName&quot;, strValue)

		If intRet &lt;&gt; 0 Then
			objREG.GetStringValue HKLM, strBaseKey &amp; strKey, &quot;QuietDisplayName&quot;, strValue
		End If

		If strValue &lt;&gt; &quot;&quot; Then
			GetInstalledApplications = GetInstalledApplications &amp; strValue &amp; vbCrLf
		End If
	Next
End Function
Read More
1 2