• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Clatent

Technology | Fitness | Food

  • About
  • Resources
  • Contact

Windows Server

Read-Only Friday August 4, 2023 End Of Life Server 2012R2 and managing EOL

August 4, 2023 by ClaytonT Leave a Comment

Read-Only Friday August 4, 2023

Do you still have any Windows Server 2012R2 or earlier in production? This is a friendly reminder that they will be going End Of Life October 10 of this year. If you do have any in production, what is your plan to decommission them? Do you still need the server, or will you be spinning up a new upgraded VM? Do you have the licensing to upgrade? What are your next steps?

Talking about End Of Life, how do you manage and track your equipment and licensing for this scenario? Do you have special asset/license management software, SharePoint list, SQL Database, Excel workbook, or even a csv with dates and costs?

If you’ve made it this far, I’m hoping this isn’t a surprise and this is only a reminder to keep following your plan, but if this is the first time you’re hearing this, please look at this now and put a plan in place, especially if you will need to purchase new licensing. While you are at it, I’d check those servers running 2012R2 and see how much of the services you really need running now, as a lot has probably changed since you first put them into production. Also, do you have enough resources to run both at the same time, or do you have to take a current backup(test to make sure the backup works), delete(or turn off and hope you don’t accidently turn it on while new server is on) your current 2012R2, then build the new on?

Good luck with your migrations and as always if there is anyway I can help, feel free to reach out! Have a great Friday, and remember no unscheduled changes today.

Tagged With: Automation, Documentation, PowerShell, Read-Only Friday, Reporting, Windows Server

One-Liner Wednesday July 26, 2023

July 26, 2023 by ClaytonT 1 Comment

Ever needed to check a computer or server and see how much disk space is being used? It could be for multiple reasons such as are any disks too low on space, too much available space assigned(think VMs where you need storage for a new server, but assume all of your storage is tied up), or you just need to see drives that have more than a certain amount of free space due to company standards.

This little one-liner is a great template for you then. This one liner will show any drive on the current computer that has more than 30gb of space free. You could easily change the “-gt” to “-lt” and only show drives with less than 30gb of space free.

Get-PSDrive -PSProvider 'FileSystem' | Where-Object { ($_.Free / 1GB) -gt 30 } | Format-Table -AutoSize

I know your thinking, I can easily click on my computer and check hard drive space, but what about if you have 10, 100, or 1000+ devices you have to manage? Do you really want to do all of those clicks? You could even set this up as a scheduled task and have it notify you, send to teams/discord/etc, or even email a Distribution List with a report. That sounds like a lot better idea than wasting time clicking around.

If your curious on how to have this capture multiple computers, one way is:

$Computers = 'Computer1', 'Computer2', 'Computer3'  # Replace with your computer names or IPs

$ScriptBlock = {
    Get-PSDrive -PSProvider 'FileSystem' | 
    Where-Object { ($_.Free / 1GB) -gt 30 } | 
    Format-Table -AutoSize
}

foreach ($Computer in $Computers) {
    Invoke-Command -ComputerName $Computer -ScriptBlock $ScriptBlock
}

I hope you found this one-liner useful, and would love to hear how you use it or have used it in the past! And as always if you have any questions, please feel free to reach out and if I can’t help you out, and I can find someone that can.

Tagged With: Automation, Disk Usage, One Liner Wednesday, PowerShell, Reporting, Windows Server

Creating a Company Standard Naming Computers with PowerShell

April 21, 2023 by ClaytonT Leave a Comment

Tired of guessing or remembering which prefix to use when setting up a new computer? Or what about when you by accident fat finger it, and you have to redo it? Or even, you have multiple people in your department, and you want to make sure everyone is creating them the same way?

This function I created will solve all of these issues, and you can customize it to your company standards very easily.

I’ll break it down to smaller parts, then we will put it all together.

function Rename-ComputerWithTag {   

First we name our function with the function “verb-noun” naming convention then the { and we will add a closing one below it(If you are using VSCode it will automatically create it).

[CmdletBinding(SupportsShouldProcess=$true)]
param (

Then we add [CmdletBinding(SupportShouldProcess=true)], to make it an advanced function and also to support -WhatIf and -Confirm, which I highly recommend when you are changing(adding/deleteting) anything with PowerShell. WhatIf will show you what is going on without actually doing it and Confirm will ask you to confirm that is what you really want to do.

[Parameter(Mandatory = $true, Position = 0)]
[ValidateSet('CA', 'MA', 'NC', 'NY', 'FL')]
[string]$Prefix,

Next we have have the parameters for the function. The mandatory = $true, means you can’t go any farther unless this is filled out. The position 0 means that it muse be the first or only unnamed parameter. A quick example that would work is Rename-ComputerWithTag NY-23221, but if you did Rename-ComputerWithTag 9322 NY-23221, where the 9322 is the asset tag number, this wouldn’t work because the computer name isn’t first.

Then we have one of my favorites, ValidateSet. It is exactly what you think it is, if you don’t put in one of those values, you can’t go any further. This is great for a couple of reasons; you can ensure the user is inputting a company approved value and it gives them tab completion, so if they can’t remember the exact spelling, they can just press tab and it will tab through each option for that parameter. This has saved me many times!

Finally, we get to the variable, where you see [string] right before it. The reason for that is to define what type of variable it is and so that PowerShell knows to handle that value as a string, and not like a date. I always define the type, as I’ve been burned before when I wasn’t getting the expected results and troubleshooted longer than I’d like to admit!

[Parameter(Mandatory = $false, Position = 1)]
[string]$AssetTag,

Here you can see that the $AssetTag parameter isn’t required, and should be in the 2nd position. I know it’s a little confusing at first if your new to PowerShell/Coding, but I promise you’ll learn quickly. Again, you see that we used the string type for the asset tag as it could have both letters and numbers in it.

[Parameter(Mandatory = $true)]
[string]$ComputerName

For the final parameter in the function, you can see that the computer name is mandatory, but there is no required position for it. You can also just put (Mandatory) instead of Mandatory = $true, if you want. I’m just use to still doing the = $true, but both ways work.

$ComputerStatus = Test-Connection -ComputerName $ComputerName -Count 1 -Quiet

The next part of this script is making sure the computer you want to change of the of is reachable. Make sure that the computer you are trying to change the name of can be pinged, if not it will fail. Test-Connection is what sends the ping, -Count is how many times do you want to try and ping the computer, and -Quiet makes it so it returns back $true or $false depending on the state of the computer. Then it is saved into the $ComputerStatus variable for future use.

if ($ComputerStatus -eq $true) {
       Write-Verbose -Message "$ComputerName was found. Beginning Rename Process"
    }

What this does is take the result from $ComputerStatus, and if it returns $true, then write a message if -Verbose is used, to say that it was found and it will begin renaming the computer.

else {
        Write-Error "The computer $ComputerName is offline. Please try again when the computer is online."
    }

And this will write an error that the computer is offline if the $ComputerStatus comes back as $flase

if (-not $AssetTag) {
        $AssetTag = (Get-CimInstance -ClassName Win32_BIOS).SerialNumber
    }

Now that we know if we’ve gotten this far that the computer is online. Now we will check if an Asset Tag was given, if not it will find the computer’s serial number and use that.

$NewName = '{0}-{1}' -f $Prefix, $AssetTag

This will combine the Prefix and the AssetTag(or serial) with a hyphen inbetween, and save it to the $NewName variable. It knows to format it like this due to the -f and assigns the Prefix the 0 position and the AssetTag the 1 position.

if ($PSCmdlet.ShouldProcess($ComputerName, $NewName, "Rename-Computer")) {
        Rename-Computer -ComputerName $ComputerName -NewName $NewName -Force
    }

Now the part we have all been waiting for… the actual renaming of the computer! What this does is makes sure that the -WhatIf and -Confirm do work, and we have it so it will force the renaming. This will not automatically reboot the computer, it will ask you to, but if you wanted to, you could add that feature in.

Write-Verbose -Message "$ComputerName changed to $NewName"
    $NewName

And this will write that the computer name has changed if you use -verbose, and if you don’t this will just show the computer’s new name.

I didn’t go line by line on the Help for it, but I’ll do another Blog Post specifically on help and it’s importance(It’s very important!)

Hoping you found this useful, as it it makes it very easy to make sure everyone follows the same procedures when naming computers.

If you have any questions or see anyway to improve the function, please reach out!

Below is the full function, and here is the link to the GitHub

PowerShellGeneral/Rename-ComputerWithTag.ps1 at main · DevClate/PowerShellGeneral

<#
.SYNOPSIS
Renames a computer with a prefix and asset tag.

.DESCRIPTION
This function renames the local computer with a prefix of CA, MA, NC, NY, or FL followed by a hyphen and an asset tag. If an asset tag isn't given, it uses the computer's serial number with CIM.

.PARAMETER Prefix
The prefix to use for the new computer name.

.PARAMETER AssetTag
The asset tag to use for the new computer name. Optional.

.PARAMETER ComputerName
Computer you want to change the name of. Local or Remote.

.PARAMETER WhatIf
Displays what the command would do if run, without actually running the command.

.PARAMETER Confirm
Prompts you for confirmation before running the command.

.EXAMPLE
Rename-ComputerWithTag -Prefix CA -AssetTag 900123 -Confirm

This prompts you for confirmation before renaming the computer with the prefix "CA" and the asset tag "900123".

.EXAMPLE
Rename-ComputerWithTag -Prefix FL -WhatIf

This displays what the command would do if run, without actually renaming the computer. The new computer name will have the prefix "FL" and the asset tag set to the computer's serial number.

.EXAMPLE
Rename-ComputerWithTag -Prefix NC -AssetTag 900134 -ComputerName DESKTOP-4I9DF1

This prompts you for confirmation before renaming the remote computer "DESKTOP-4I9DF1" with the prefix "NC" and the asset tag "900134".

#>

function Rename-ComputerWithTag {
    [CmdletBinding(SupportsShouldProcess=$true)]
    param (
        [Parameter(Mandatory = $true, Position = 0)]
        [ValidateSet('CA', 'MA', 'NC', 'NY', 'FL')]
        [string]$Prefix,

        [Parameter(Mandatory = $false, Position = 1)]
        [string]$AssetTag,

        [Parameter(Mandatory = $true)]
        [string]$ComputerName
    )

    #Check if the computer is online
    $ComputerStatus = Test-Connection -ComputerName $ComputerName -Count 1 -Quiet

    #If the computer is online, proceed with the name change
    if ($ComputerStatus -eq $true) {
        #Write that computer was found and beginning renaming process
        Write-Verbose -Message "$ComputerName was found. Beginning Rename Process"
    }

    #If the computer is offline, display an error message
    else {
        Write-Error "The computer $ComputerName is offline. Please try again when the computer is online."
    }

    # Get the computer's serial number with CIM if an asset tag isn't given
    if (-not $AssetTag) {
        $AssetTag = (Get-CimInstance -ClassName Win32_BIOS).SerialNumber
    }

    # Build the new computer name
    $NewName = '{0}-{1}' -f $Prefix, $AssetTag

    # Rename the computer
    if ($PSCmdlet.ShouldProcess($ComputerName, $NewName, "Rename-Computer")) {
        Rename-Computer -ComputerName $ComputerName -NewName $NewName -Force
    }

    # Output the new computer name
    Write-Verbose -Message "$ComputerName changed to $NewName"
    $NewName
}

Tagged With: AD, Automation, PowerShell, Windows Server

One-Liner Wednesday March 29, 2023

March 29, 2023 by ClaytonT 2 Comments

Can you believe it’s Wednesday already? I can’t either, week is flying by. Could it be the excitement of the PowerShell + Devops Global Summit coming up in a few weeks? Quite possibly! If you haven’t gotten your ticket yet, I highly recommend it. With that said, these next 3 weeks I’ll be highlighting speakers and topics from the summit.

Today’s one-liner is a great one for troubleshooting from Jeff Hicks. He will be heading the Onramp program for attendees who are just getting into IT. It is such a great program and wished it was around when I was getting into IT!

Get-WinEvent -FilterHashtable @{Logname = 'System';Level=1} -MaxEvents 10 | sort-Object ProviderName,TimeCreated

What this one-liner does is searches the System Event Log for the last 10 “Critical” events. Then sorts them by the Provider name and date/time. You could change the level for “lesser” events if needed. Also if you need to check on a remote computer you can add the -ComputerName parameter, but remember that it only takes 1 computer at a time. If you need to connect to multiple computers, you can use ForEach to reach out to all computers needed.

Hope this one-liner helps you out and hope to see you at the PowerShell + DevOps Summit!

Jeff Hicks:
Blog

PowerShell + DevOps Global Summit:
Global Summit

Microsoft Learn:
Get-WinEvent

Tagged With: Automation, Event Log, One Liner Wednesday, PowerShell, Reporting, Windows, Windows Server

Read-Only Friday March 10, 2023

March 10, 2023 by ClaytonT Leave a Comment

It’s Friday, and I’m going to keep this one short in sweet copy. I’ve mentioned this module before, but it is so helpful if you use any of the products, that I want to make sure you don’t miss out on it! Yes, I know it’s Read-Only Friday, but this module will step up your documentation game ten fold.

AsBuiltReport on Github or you can find them on asbuiltreport.com.

What they have created is multiple modules depending on the product you need documentation on, and with one quick line of code, you get a full breakdown of the product you requesting information on. How about a 144 page document on your Active Directory? Not bad, right?

Check them out, and let me know what you think!

GitHub:
https://github.com/AsBuiltReport

Website:
https://www.asbuiltreport.com/

Tagged With: AD, Automation, Documentation, Fortigate, Fortinet, Module Monday, PowerShell, Read-Only Friday, Reporting, Veeam, VMWare, Windows Server

One-Liner Wednesday March 8, 2023

March 8, 2023 by ClaytonT Leave a Comment

Are you using VMWare? Ever had to troubleshoot why a VM isn’t working? Or need to know the status of a virtual machine? If you haven’t used PowerCLI before(I know I’ve mentioned it previously), check out this one liner.

 get-vm servername | select-object name, powerstate, usedspacegb, provisionedspacegb

What this does is first finds the server you are looking for with “servername.” Then it shows the server name, whether it is turned on or off, how much storage space is used, and finally how much storage is provisioned. This gives you a very quick overview of the status of the server.

I know, very simple, but it works… and you can expand on this. You could not put a servername in, and it will show all of your virtual machines with the information above.

What about if you have 100s or even 1,000s of servers, you could export to gridview or even better to excel with the importexcel module for filtering.

Hope you found this useful, and if your not already using the PowerCLI module to start using it and make your life easier.

PowerShell Gallery:
PowerCLI

Tagged With: Automation, Documentation, PowerCLI, PowerShell, Reporting, VMWare, Windows Server

  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to Next Page »

Primary Sidebar

Clayton Tyger

Tech enthusiast dad who has lost 100lbs and now sometimes has crazy running/biking ideas. Read More…

Find Me On

  • Email
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter

Recent Posts

  • New Feature Announcement for 365AutomatedLab
  • How ChatGPT saved our company $1500 in less than 15 minutes
  • Read-Only Friday August 4, 2023 End Of Life Server 2012R2 and managing EOL
  • One-Liner Wednesday August 2, 2023
  • Module Monday July 31, 2023

Categories

  • 365
  • Active Directory
  • AI
  • AzureAD
  • Cim
  • Dashboards
  • Documentation
  • Get-WMI
  • Learning
  • Module Monday
  • Nutanix
  • One Liner Wednesday
  • Passwords
  • PDF
  • PowerShell
  • Read-Only Friday
  • Reporting
  • Security
  • Windows
  • WSUS

© 2023 Clatent