Add and remove lines in text based config files with PowerShell

7. April 2017

blog.feldmann.io

PowerShell Version: >4 
Modules: none

I want to take some text file and look for a specific line, then delete that line and add some other line at the end of the file. Here’s how I made it work:

Share on LinkedIn
Linkedin
Share on Google+
Google+
0Share on Reddit
Reddit
0Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Email this to someone
email
Print this page
Print

Backup HP ProCurve Switches via SSH, TFTP and PowerShell

15. February 2017

blog.feldmann.io

PowerShell Version: >4 
Modules: Posh-SSH

So, this is a pretty specific one! I have been tasked to backup old and new ProCurve Switches and of course I am using PowerShell for this 😉 I found a script about doing this via SFTP where you enable ip ssh filetransfer on the switches and get the files from there but unfortunately two of the 2610’s in the environment do a reboot on every sftp connection…so…that is not an option here 😉 The only good alternative I came up with was to SSH on the client and use TFTP to copy the configs where you want them. The tftp client is enabled on the ProCurve’s by default so what you need to do this is PowerShell with Posh-SSH, and a TFTP Server:

As for the creds I chose a password file as secure-string – not the safest but fairly easy to work with:

 

Share on LinkedIn
Linkedin
Share on Google+
Google+
0Share on Reddit
Reddit
0Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Email this to someone
email
Print this page
Print

Monitor scheduled Tasks using PowerShell and check_mk

2. February 2017

blog.feldmann.io

PowerShell Version: >1 
Modules: none

As I am focused on a new check_mk implementation there might be a lot of PowerShell/check_mk around here for a bit 😉 This time I wrote something to monitor the result of a scheduled task the oldschool way. With PowerShell >4 you can use the Get-ScheduledTask function as shown here but as I want this to run even on PowerShell v1 I used the old schtasks /query command line function:

 

Share on LinkedIn
Linkedin
Share on Google+
Google+
0Share on Reddit
Reddit
0Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Email this to someone
email
Print this page
Print

Using PowerShell and check_mk to monitor Citrix Licensing Usage

24. January 2017

blog.feldmann.io

PowerShell Version: >4 
Modules: none

 

I just wrote a custom local check for check_mk to get the Citrix Licensing Usage checked. All you need to do is fill in the $license_server and maybe customize $percent_warning and $percent_critical. The check reads the licensing WMI and gives you OK / WARNING / CRIT in check_mk for the corresponding variables. It will also show the actual used licenses as performance data:

Share on LinkedIn
Linkedin
Share on Google+
Google+
0Share on Reddit
Reddit
0Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Email this to someone
email
Print this page
Print

Removing vCenter Snapshots with PowerShell and VMware vSphere PowerCLI

24. November 2016

blog.feldmann.io

PowerShell Version: >4 
Modules: VMware vSphere PowerCLI

While having issues with HP Data Protector and VMware backups I created a script that logs in to different vCenter Servers and checks for Data Protector Snapshots that are older than x and removes them. This script can easily be customized to suite your environment and needs.

Share on LinkedIn
Linkedin
Share on Google+
Google+
0Share on Reddit
Reddit
0Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Email this to someone
email
Print this page
Print

Look for unused GPOs with PowerShell

blog.feldmann.io

PowerShell Version: 4 
Modules: GroupPolicy

If you find yourself lost in the jungle of existing GPOs in your environment use some PowerShell to sort out the ones that might not be needed anymore.

Share on LinkedIn
Linkedin
Share on Google+
Google+
0Share on Reddit
Reddit
0Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Email this to someone
email
Print this page
Print

Create check_mk host checks with PowerShell

4. December 2015

blog.feldmann.io

PowerShell Version: >2 
Modules: none

If you use check_mk to monitor your environment you are able to create simple local host checks using PowerShell.

Your check_mk agent should be installed on the target host in a specific location, such as C:\Program Files (x86)\check_mk

After the agent installation you should have a local folder (C:\Program Files (x86)\check_mk\local) in which you can put a simple PowerShell Get-Content script to return whatever you have scripted in a check_mk readable format:

To achieve the check_mk readable format make sure to print your scripted output into something like this:

<<<local>>>
0 CHECK_NAME – OK – CHECK_OUTPUT|PERF_DATA_DESCRIPTION=CHECK_OUTPUT(INT)

I created a short example with a folder count:

The output to file C:\Program Files (x86)\check_mk\tmp\xxxx.log is:

<<<local>>>
0 FOLDER-COUNT-C – OK – We have 40 folders on drive C|folders_on_c=40

You are now able to do a short cmk -II hostname && cmk -R on your check_mk server and the new check should appear on your host.

The next step would be different states for different results:

<<<local>>>
0 CHECK_NAME – OKCHECK_OUTPUT|PERF_DATA_DESCRIPTION=CHECK_OUTPUT(INT)

<<<local>>>
1 CHECK_NAME – WARNING CHECK_OUTPUT|PERF_DATA_DESCRIPTION=CHECK_OUTPUT(INT)

<<<local>>>
2 CHECK_NAME – CRITICAL CHECK_OUTPUT|PERF_DATA_DESCRIPTION=CHECK_OUTPUT(INT)

With a simple if we could generate different outputs for different cases:

It is important to give only the second Out-File an Append, so that the output will be overwritten every time the script is running.

You could now create a local task, running the script once a week/day/hour to generate the output for check_mk.

Share on LinkedIn
Linkedin
Share on Google+
Google+
0Share on Reddit
Reddit
0Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Email this to someone
email
Print this page
Print

Restart host after certain days of uptime

3. December 2015

blog.feldmann.io

PowerShell Version: >1
Modules: none

Nobody wants Windows hosts with too much uptime so this script combined with a planned task during the weekly maintenance downtime might help:

You might want to use the -force parameter on Restart-Computer for an immediate restart.

Share on LinkedIn
Linkedin
Share on Google+
Google+
0Share on Reddit
Reddit
0Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Email this to someone
email
Print this page
Print

Receive gateway from local network interface with PowerShell

25. November 2015

blog.feldmann.io

PowerShell Version: >1
Modules: none

I needed a way to log the first local interface’s gateway for debugging reasons, here is how I did it:

Share on LinkedIn
Linkedin
Share on Google+
Google+
0Share on Reddit
Reddit
0Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Email this to someone
email
Print this page
Print

Enable Users to log off their own RDP TS session with PowerShell

24. November 2015

ps

PowerShell Version: >1
Modules: none

This script will check your TS servers for a session with $env:Username and logoff that session. This of course only works if $env:username on client and TS are the same 😉 Also I made an effort to make it work on PS v1 for all clients to be able to execute this.

Share on LinkedIn
Linkedin
Share on Google+
Google+
0Share on Reddit
Reddit
0Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Email this to someone
email
Print this page
Print
← Previous Page