Powershell
Powershell Script to Restart Services & Email
Reading Time: < 1 minuteSome servers, for one reason or another, need to have services restarted periodically. This script does just that, and has the ability to grab multiple service names using a wildcard populated array. After it’s complete, it sends an email from the script letting you know it’s complete. It’s commented out, but also has the ability to attach anything you’d like (eg. a command result output file) to the email as well.
It’s fairly simple, but it can be extremely helpful.
https://gallery.technet.microsoft.com/Restart-and-Email-Script-6f2dec66
Upgrade SCOM 2012 R2 From Eval To Full Edition License
Reading Time: < 1 minuteBy default, when SCOM 2012 R2 is installed, it uses an eval license (hence the yellow warning when you install the management server). When you go to the “Administration” workspace there is a center page link to technet to “Upgrade SCOM to full version”.
Here’s the simple way to add that product key from powershell.
import-module OperationsManager
set-SCOMLicense -ProductId “insert product key here”
stop-service cshost; stop-service omsdk; stop-service healthservice
start-service cshost; start-service omsdk; start-service healthservice
Alternatively, you can reboot the management server.
After that, to verify the key is install you can take the following steps.
Launch the Operations Manager Console > Go to “Help” and click “About” > Next to the Version information it should now say Retail. *Note that it’s okay if the Product ID is blank.
I hope this makes your day at least a little bit easier.
Thanks,
Disable Windows Firewall With PowerShell
Reading Time: < 1 minuteWelcome all, to the age of the gui-less windows server. As more and more people spin up labs with command-line only boxes, this command can be helpful.
Remember to only turn off your firewall in lab environments where you know you’re not exposing yourself to additional risk.
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
To do this using netsh in cmd, you can use the following command.
netsh advfirewall set allprofiles state off
I hope this makes your day at least a little bit easier.
Thanks,
Powershell command to show names of all machines in SCOM
Reading Time: < 1 minuteSimple one-liner, very helpful though!
Import-Module OperationsManager; Get-SCOMGroup -DisplayName “All Windows Computers” | Get-SCOMClassInstance | sort DisplayName | FT DisplayName
This will output just the names of all machines in the “All Windows Computers” group, you can change that name to output the machine names of any other group as well.
Powershell Script to Test SMTP
Reading Time: < 1 minuteThis one is going to be short and sweet, I’ve been testing SMTP with and without encryption and wanted a good script for that.
Here are the lines that you’ll want to look at configuring:
- Line 5: “$smtpServer =”InsertYourSmtpServerHere”
- Line 12: Change the $false value to $true if you want to encrypt your SMTP with SSL
- Line 13: If you’re using a non-default SMTP port, change the “25” to whatever you’re using
- Line 15: Only change this if you need to enter credentials for authentication
- Line 18/19: Change these to who you want to say the email is from, and to whom it is being delivered.
- Line 21: Change this to whatever you want your email title to be
- Line 25: Change this to say whatever you want the body of the email to say
There are also some write-host’s in there to let you know the values that are being run and whether or not they were successful, which will print to the powershell console.
https://gallery.technet.microsoft.com/Powershell-SMTP-Test-Tool-621b07ae
Quick n’ Dirty Network Latency Graph using Powershell
Reading Time: 2 minutesThis will be very short, sweet and to the point.
I was on a project recently where I was unable to access (and therefore monitor) any of the networking equipment and the WAN links thereof. Noticing that the issues that were occurring were due to a network problem I spoke with the folks who ran that particular network — they were no help. They gave me as little information as possible and punted the issue back to me saying it was a server problem. So here I am, no access to the network equipment, can’t monitor or log the WAN links, workstation in branch office having intermittent issues reaching the server in the main office. Enter powershell.
#-----Start-----
do {
#Ping google.com and select only the response time then output to file
test-connection google.com | Select-Object -Property ResponseTime >> pingoutput.csv
#Sleep for 10 seconds
Start-Sleep -s 10
#Write the time to the file
get-date >> pingoutput.csv
#Set the Time variable for the end while condition
$Time = (Get-Date).Hour
}
#While loop end condition states continue only if time is less than 5pm (24 hour clock)
while ($Time -le 17)
#-----End-----
The comments in the script state how it works and what each line does. After 5pm (the while loop end condition) you can grab that output .csv file and pull it in to excel. Once there you select your data real quick and you’ve got yourself a nice little graph of network latency in milliseconds over the period of the day.
As you can tell there were some problems with this particular link.
There ya go!