Yearly Archives: 2018

/2018

Sending email message

I was reading my last blog post Monitoring disk drives and realized, what if I don’t have a monitoring system? I would want the notifications, right?

Well, of course we want to know if our disk drives are getting full in time.
The quick solution, send email message.

I’m going to create a function and use the function from the Monitoring disk drives as the message to send with the email, so I assume we have already run the function and have it already in our session.
(more…)

By |2018-10-18T20:02:43+00:00October 18th, 2018|Common, Email, Operating System|0 Comments

Monitoring disk drives

Hello all, being active to make up for some lost time last month.

The noise, the annoyance, what is happening now…
Disk drives tend to fill up fast, windows updates are taking more and more disk space and servers not getting rebooted won’t cleanup the winsxs folder.

I’ve written a simple function to monitor disk drives, run it with parameters to monitor multiple disks and monitor with your monitoring software, me, I prefer nagios.

I use exit codes for nagios which will give me the results for “OK”, “Warning” and “Critical”, which is the threshold you can define in this function
(more…)

By |2018-10-15T23:08:41+00:00October 15th, 2018|Common, Operating System|0 Comments

Automating AD processes

Finally – forgive me everybody, it has been to long since my last post.

Every System Administrator has to deal with Active Directory (most Windows Administrators at least), so automating repeating processes can be very useful.

I recommend using functions with parameters to generalize the function and can be shared among administrators, even though AD structure is can be different.

Wandering off – talking about function, best practices is to use a Verb-Noun (like Get-ADUser) and never in plural, always single.

Getting on point here again.

First of all, creating users from csv, very useful when dealing with multiple user creation.

Create a CSV file including all the AD attributes you want to include in the user creation, I’m going with simple ones and save it in a location like C:\Temp

"FirstName","LastName","UserName","EmailAddress"
"Hallgrimur","Test","hallgrimur.test","hallgrimur@test.com"
"Finn","AnotherTest","finn.test","finn@test.com"

(more…)

By |2018-10-12T00:58:18+00:00October 12th, 2018|Active Directory|0 Comments

Cleaning up

Who doesn’t love cleaning up old files, don’t worry, Powershell comes to the rescue.

We all know that shared network drives collect all kind of garbage, and usually around 90% could actually be missed.

I’ve recently been working on cleaning up files which were created a long time ago, thanks to Powershell, we can script this action and make Powershell work for us.

What I do here is to look at the creation date of the files and delete them if they are older than 2 years old, so we set a limit to target only those who are old enough to be removed.

I recommend having backup of the files before running these Powershell scripts.

Logging the output is also recommending

(more…)

By |2018-08-09T22:30:51+00:00August 9th, 2018|Common, File|0 Comments

Playing with functions

Today I’m going to play around with functions.

I use functions to do repetitive admin tasks to make my life easier.

Functions can be simple and complex depending on your need, sometimes it’s static and won’t need any dynamic parameters.

Function Reset-WUFolder {
# Stop Windows update and BITS services
Stop-Service -Name wuauserv
Stop-Service -Name BITS
# Remove WU Folder
Remove-Item -Path $env:SystemRoot\SoftwareDistribution -Force
# Start Windows update and BITS services again
Start-Service -Name wuauserv
Start-Service -Name BITS
}

Run the code and you can call your function from the command line.

(more…)

By |2019-03-29T23:15:13+00:00August 3rd, 2018|Common, Operating System|0 Comments

Always check first

As a System Administrator I’m always looking for automation and easier or faster ways to do my job properly. When I’m creating scripts which involve of creating or checking if something exists it prevents errors in output and is a nicer and cleaner way to go about doing scripts, why would you want to create something exists anyways? Writing scripts or snippets I use the command Test-Path combined with an if statement and it depends what I want to do if I’m going to use the negative “NOT”, let me give you an example.
$path = "C:\temp"
if(Test-Path -Path $path) {
 Write-Host "The path `"$path`" already exists"
} else {
 New-Item -Path $path -ItemType Directory
}
(more…)
By |2018-08-03T00:44:33+00:00July 23rd, 2018|Common, File|0 Comments

First post

Welcome and thank you for visiting my first attempt to blog. I’m a Powershell script enthusiast and would like to share my experience and script snippets with you, get comments on how to improve and help others who want to use my scripts. Feel free to contact me if you have any questions, requests or you simply want to chat. My contact info is here Email: halli@powershell.is Facebook: https://www.facebook.com/hallgrimur LinkedIn: https://www.linkedin.com/in/hallgrimurf Slack: https://powershellis.slack.com Hope I’ll hear from any of you and hopefully you can enjoy or even use some of my snippets. Hallgrimur #TheMachine
By |2018-08-02T11:05:22+00:00July 20th, 2018|Common|0 Comments