Monday, July 8, 2019

Error handling for dnote & snote

After reviewing the current progress of both dnote and nnote. I've decided to break down the scripts into separate functions, subscribing to the idea of micro processes, as opposed to larger monolithic scripts.

However, I did modify the existing scripts to catch / error handle both x64-bit and x86-bit applications; below is the source code I utilized for both dnote and nnote (specifically the Daily Note version, obviously for the Named Note version, I modified for the $NamedNotesDir & $NamedNote variables).

The next iterations of these scripts will include creating separate functions. First for determining the type of note (daily or named), then creating/modifying the specified note, and finally for opening/calling the specified note.


1
2
3
4
5
6
7
8
9
try { 
    Start-Process -FilePath ((Get-ChildItem Env:\ProgramFiles).Value + '\Notepad++\notepad++.exe') -Argument ($DailyNotesDir + $Date + ".txt")
}
catch {
    Start-Process -FilePath ((Get-ChildItem Env:\ProgramFiles`(x86`)).Value + '\Notepad++\notepad++.exe') -Argument ($DailyNotesDir + $Date + ".txt")
}
finally {
    Write-Host "Ensure Notepad++ is installed in the default location" -ForegroundColor Red -BackgroundColor Black
}

Tuesday, July 2, 2019

Take Note (named)!

In the last blog post, I published a short script to create / append the date/time to a simple text file. Which I use to keep track of tasks I've worked on throughout the day. However, what if I wanted to keep notes while training on a particular product, or keep notes on a client project. Digging through dozens of daily note files could become unwieldy. As they say on TV, "There's gotta be a better way!" And so there is, and here's my shot at it:

The same caveats from the last blog post apply here (won't detect x86-bit applications, if installed on a x64-bit OS; I'm using an auto-save plug-in for Notepad++, so no data is lost; and you must create a "notes\named" directory in your Documents folder, or change that variable to your desired path).

In the next iteration, I want to create a single application that detects whether or not you've supplied a name for the note, and if not create a daily note; and provide error handling for x86-bit applications on x64-bit OS's.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<#
####################
Author: Sam Dye
Date: 2019-07-02
Version: 1

####################
Pre-requisites:
1) Add script location to "Path" environment variable
2) Set PowerShell Execution Policy to RemoteSigned
3) Launch "Run.exe" and type: "nnote.ps1"
#>

param(
[Parameter(Mandatory=$true)]
[string]$NamedNote
)

$DateTime = Get-Date -UFormat %Y-%m-%d.%H:%M
$NamedNotesDir = ("C:\Users\" + ((Get-ChildItem Env:\USERNAME).Value) + "\Documents\notes\named\")

Add-Content -Path ($NamedNotesDir + $NamedNote + ".txt") `
"
#=====================#
$($DateTime)
#=====================#"

Start-Process -FilePath ((Get-ChildItem Env:\ProgramFiles).Value + '\Notepad++\notepad++.exe') -Argument ($NamedNotesDir + $NamedNote + ".txt")

Wednesday, June 19, 2019

Take Note (daily)!

Created this simple PowerShell script this afternoon to create a txt file, and append the date and time, in order to make tracking my time easier.

A couple of notes:
- Script will auto-detect environment variable for default "ProgramFiles" location. However, it has no error handling if you are running x64-bit Windows, but an x86-bit Application.
- I am using an auto save plugin for Notepad++, so no data is lost when I run this multiple times per day to input the most recent timestamp.
- You must either create a \notes\daily directory in your Documents folder, or change that variable to reflect your desired location.

- This is v1, so be ruthless with your testing and please let me know of issues.

<#
####################
Author: Sam Dye
Date: 2019-06-19
Version: 1

####################
Pre-requisites:
1) Add script location to "Path" environment variable
2) Set PowerShell Execution Policy to RemoteSigned
3) Launch "Run.exe" and type: "dnote.ps1"

#>

$Date = Get-Date -UFormat %Y-%m-%d
$DateTime = Get-Date -UFormat %Y-%m-%d.%H:%M
$DailyNotesDir = ("C:\Users\" + ((Get-ChildItem Env:\USERNAME).Value) + "\Documents\notes\daily\")

Add-Content -Path ($DailyNotesDir + $Date + ".txt") `
"
#=====================#
$($DateTime)
#=====================#"

Start-Process -FilePath ((Get-ChildItem Env:\ProgramFiles).Value + '\Notepad++\notepad++.exe') -Argument ($DailyNotesDir + $Date + ".txt")

Thursday, March 7, 2019

automate away the repetitive work: veeam log gathering, part 1

As part of my day job I am responsible for managing backups; which means interacting with Veeam support (our backup vendor) and providing logs. While most of the log gathering is automated through the Veeam software, that isn't the case for Veeam agent for Windows (which we only use for physical machines). And while Veeam has a very helpful KB2404 to gather those logs, this work is mindless and boring; which is a perfect thing to script away!

Over the course of this series I'll walk thru my process of scripting these steps, provide the updated script and notate any issues I encounter.

This Veeam KB has 4 steps and we'll automate them in the order listed the KB. So with no further delay the first step is: Gathering Veeam Agent Guest Logs.


I wrote the following PowerShell script to do just that:

1
2
3
4
5
6
7
$ProgramDataLocation = (Get-ChildItem env:programdata).Value
$EndpointPath = Join-Path -path $ProgramDataLocation -ChildPath "\veeam\endpoint"
$ServerName = (Get-ChildItem env:computername).Value
$Date = Get-Date -Format FileDate
$EndpointDestination = ("C:\veeam\logs\" + $Date + "_" + $ServerName + "_endpoint.zip")

Compress-Archive -Path $EndpointPath -DestinationPath $EndpointDestination -CompressionLevel Optimal

Line 1: defines the variable $ProgramDataLocation, which finds the environment variable "programdata" location, and returns the value of that object to the variable.
Line 2: defines the location of the Veeam Endpoint folder by joining the location specified in line one, with the standard folder structure specified by Veeam.
Line 3: defines the variable $ServerName, which finds the environment variable "computername", and returns the value of that object to the variable.
Line 4: defines the variable $Date, by using the module Get-Date and storing that date in the YYYYMMDD format.
Line 5: defines the variable $EndpointDestination, which will be the location for the archived/zipped folder to upload to Veeam.
Line 6: whitespace for formatting.
Line 7: Runs the Compress-Archive module specifying the input path as the variable $EndpointPath (defined in line 2), and the destination path as the $EndpointDestination (defined in line 5), further specifying the compression level as maximum.

And if I run this script I am currently encountering the current error: ZipArchiveHelper : The process cannot access the file 'C:\ProgramData\veeam\endpoint\Endpoint.Transport.log' because it is being used by another process.

So in the next blog post we'll determine how to address this issue and modify the script to accommodate it.

Saturday, February 16, 2019

networking: LLDP-MED

LLDP-MED – LLDP-Media Endpoint Devices:

This protocol enables advanced LLDP features in a Voice over IP (VoIP) network. Whereas LLDP enables network discovery between Network Connectivity devices, LLDP-MED enables network discovery between Network Connectivity devices and media Endpoints (ie. VoIP phones).


Example Configuration String (this is entered on the Network Connectivity devices / switch):

lldp med network-policy application voice tagged vlan 30 priority 5 dscp 46 ports ethe 1/1/1 to 1/1/48

With this string configured, it specifies VLAN 30 as the voice vlan, assigns the 802.1p/Q Priority Code Point of 5 to that VLAN, and assigns the DSCP value of 46 also to that VLAN (each of which are the highest categories).

Example:

Tuesday, January 29, 2019

networking: LLDP

LLDP - Link Layer Discovery Protocol: is a vendor-neutural, standards-based protocol used to advertise and discover directly connected devices (IEEE 802.1ab).

Informed via LLDP Data Units which contain at least the three following TLV’s (type-length-value):

  • Chassis ID
  • Port ID
  • Time-to-Live (TTL)

LLDP is the standards-based protocol that allows for the discovery and communication between directly connected devices, while TLV's standardize what information can be exchanged.

Example of LLDP TLV's from a Ruckus Switch:

Wednesday, January 9, 2019

Office 365 Migration Issue

While migrating a client to O365 Exchange Online, I encountered an issue with mailboxes not syncing. After some quick troubleshooting it was determined they lacked the "UserName@DomainName.mail.onmicrosoft.com" proxy address, required for the sync.

Below is the PowerShell script I wrote to add a proxyAddress to all users in the specified OU:

Import-Module ActiveDirectory 
$searchbase = "OU=OrgUnit,DC=DomainName,DC=Suffix"
$newdomain = '@DomainName.mail.onmicrosoft.com'
$users = Get-ADUser -SearchBase $searchbase -Filter * -Properties SamAccountName
 
ForEach ($user in $users) {
    $SamAccountName = $user.SamAccountName
    Set-ADUser -Identity "$SamAccountName" -Add @{
        'proxyAddresses' = "smtp:$SamAccountName‎" + $newdomain
    }
    Write-Host "Adding proxyAddress to $SamAccountName"
}