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
XenDesktop

Citrix XenDesktop SQL Database: Display all client connections

One of my customers came up to me and asked me how to query the Citrix XenDesktop Database using SQL queries to get a list of all connections that have been made.
The first thing to keep in mind is, that XenDesktop stores the information only for a couple of days – depending on your license (Enterprise or Platinum licenses). So if you’re interested in a long-term solution, then you should put the output / result of my query into another database or file for archiving.

Read More
PowerShell Windows

Creating PowerShell scripts with a GUI

I’ve created several PowerShell scripts that utilize Windows Presentation Foundation (WPF) for displaying a graphical user interface (GUI). The ability to use WPF GUIs enables you to combine PowerShell scripting and professional-looking GUIs – not like the old-school HTA GUIs in VBScripts.

WPF-Application

WPF is completely being build on XML / XAML files – and these files can be build using the graphical forms designer in Visual Studio Community Edition

Read More
PowerShell

Script-Gallery: Fix-Printer.ps1

#######################################################################
## (C) 2015 Michael Miklis (michaelmiklis.de)
##
##
## Filename:      Fix-Printer.ps1
##
## Version:       1.0
##
## Release:       Final
##
## Requirements:  -none-
##
## Description:   Script for fixing fqdn during computer domain
##                movement.
##
## 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 Fix-Printer {
    <#
    .SYNOPSIS
    Fixes printer fqdn references in registry 

    .DESCRIPTION
    The Fix-Printer CMDlet fixes the serverName, uNCName and url registry key
    for the windows spooler service

    .PARAMETER OldDomain
    FQDN of the old domain

    .PARAMETER NewDomain
    FQDN of the new domain

    .EXAMPLE
    Fix-Printer -OldDomain "olddomain.com" -NewDomain "newdomain.com"

    .NOTES
    You need to run this CMDlet with elevated permissions
    #>
    
    param (
        [parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]$OldDomain,
        [parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]$NewDomain
    )

    foreach ($printer in (Get-ChildItem -Path HKLM:SYSTEMCurrentControlSetControlPrintPrinters)) {
    
        if ((Test-RegistryValue -Path ("HKLM:SYSTEMCurrentControlSetControlPrintPrinters" + $printer.PSChildName + "DsSpooler") -Value ("serverName")) -eq $true) {
            $strOldVal = (Get-ItemProperty -Path ("HKLM:SYSTEMCurrentControlSetControlPrintPrinters" + $printer.PSChildName + "DsSpooler")).serverName
            Set-ItemProperty -Path ("HKLM:SYSTEMCurrentControlSetControlPrintPrinters" + $printer.PSChildName + "DsSpooler") -Name "serverName" -Value $strOldVal.Replace($olddomain, $newdomain)
        }
        
        if ((Test-RegistryValue -Path ("HKLM:SYSTEMCurrentControlSetControlPrintPrinters" + $printer.PSChildName + "DsSpooler") -Value ("uNCName")) -eq $true) {
            $strOldVal = (Get-ItemProperty -Path ("HKLM:SYSTEMCurrentControlSetControlPrintPrinters" + $printer.PSChildName + "DsSpooler")).uNCName
            Set-ItemProperty -Path ("HKLM:SYSTEMCurrentControlSetControlPrintPrinters" + $printer.PSChildName + "DsSpooler") -Name "uNCName" -Value $strOldVal.Replace($olddomain, $newdomain)
        }
        
        if ((Test-RegistryValue -Path ("HKLM:SYSTEMCurrentControlSetControlPrintPrinters" + $printer.PSChildName + "DsSpooler") -Value ("url")) -eq $true) {
            $strOldVal = (Get-ItemProperty -Path ("HKLM:SYSTEMCurrentControlSetControlPrintPrinters" + $printer.PSChildName + "DsSpooler")).url
            Set-ItemProperty -Path ("HKLM:SYSTEMCurrentControlSetControlPrintPrinters" + $printer.PSChildName + "DsSpooler") -Name "url" -Value $strOldVal.Replace($olddomain, $newdomain)
        }
    }
}

#___________________________________________________________________

function Test-RegistryValue {
    <#
    .SYNOPSIS
    Tests existence of regisry value (C) by Jonathan Medd

    .DESCRIPTION
    The Test-RegistryValue CMDlet was created by Jonathan Medd

    .PARAMETER Path
    Registry path

    .PARAMETER Value
    Registry value

    .EXAMPLE
    Test-RegistryValue -Path "HKCU:Environment" -Value "TEMP"
    #>
    
    param (
        [parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]$Path,
        [parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]$Value
    )

    try {
        Get-ItemProperty -Path $Path | Select-Object -ExpandProperty $Value -ErrorAction Stop | Out-Null
        return $true
    }

    catch {
        return $false
    }
}

Fix-Printer -OldDomain "olddomain.com" -NewDomain "newdomain.com"

Read More
PowerShell Windows

Disable IPv6 in Windows for a specific network connection only

Sometimes you want to disable IPv6 only on a specified network interface, instead of disabling IPv6 completely:

IPv6_Bind

Microsoft has released a KB article how to disable the individual IPv6 components in Windows – but not for an individual interface:
https://support.microsoft.com/en-us/kb/929852

I wrote a small PowerShell script that unbinds the IPv6 protocol. The PowerShell script is modifying the bindings in the registry – therefore a reboot is needed for this setting to take effect:

$UnbindID = $(Get-WmiObject -Class 'Win32_NetworkAdapter' | Where-Object {$_.NetConnectionID -eq 'Ethernet'}).GUID
$LinkageKey = $(Get-ItemProperty -Path 'HKLM:SYSTEMCurrentControlSetservicesTcpip6Linkage').Bind | Select-String -Pattern $UnbindID -NotMatch -SimpleMatch
Set-ItemProperty -Path 'HKLM:SYSTEMCurrentControlSetservicesTcpip6Linkage' -Name 'Bind' -Type MultiString -Value $LinkageKey

Note: According to your environment and operating system version and language, you may need to change the network connection name (‘Ethernet’ in my example’) to fit your interface / connection name.

Read More
Synology

Synology DS Photo+ DLNA Mirroring Reverse Engineering Part 1

I’m using my Synology DS214play NAS for storing all my family pictures and videos on it. Therefore, I’m using the Synology Photo Station application on the NAS. It is a great app for organizing all my photos and videos – especially the wide platform support including apps for iOS, Android, Windows, Mac OS X and also a browser based web client is something I really love.
Being an IT guy, I found some major problems regarding Synology Photo Station that I’m willing to investigate and maybe fix them. First issue in this blog series:

  • Mirror a photo that is displayed in DS Photo+ app to my Samsung TV
  • DS_Photo_DLNA

    Read More
    Mac OS X Office 365

    Microsoft Outlook for Mac 15.x activation error -805240834

    I just installed an EFI update on my Apple Mac and figured out, that Outlook for Mac 15 wasn’t activated anymore. I simply tried to reactivate Outlook so I started the activation wizard, entered my email address and password… but there was an error:

    Outlook_for_Mac_activation_error
    After a little search via google I found the solution – you have to run these commands in the Terminal application:

    killall "Office365ServiceV2"
    sudo killall "Office365ServiceV2”"
    cd ~/Library/Group Containers/UBF8T346G9.Office
    ls -a | perl -n -e 'print if m/^[e|c]w/' | xargs rm
    
    Read More
    PowerShell Windows

    PowerShell Best Practices: Set-StrictMode

    During some research for PowerShell best practices I came across the following blog post on the Hey Scripting Guy Blog from Microsoft:
    http://blogs.technet.com/b/heyscriptingguy/archive/2014/12/03/enforce-better-script-practices-by-using-set-strictmode.aspx

    By using the Set-StrictMode cmdlet, we can enforce some common “best practice” coding techniques that you can use with your scripts. In yesterday’s post, I used the –Strict parameter with Set-PSDebug. This enforces the variable declaration in a script. But with Set-StrictMode, we get that plus a little more. The scope is limited to the current scope and child scopes. By default, Set-StrictMode is turned off to prevent error messages while you are writing the script.

    From now on, all my PowerShell scripts will start with “Set-StrictMode -Version latest” and “Set-PSDebug -Strict”:

    Set-PSDebug -Strict
    Set-StrictMode -Version latest
    
    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
    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
    1 2 3 4 5