Setting Network Interface Priority On Windows 8 with PowerShell

Yesterday I posted a blog on Setting Network Interface Priority on Windows 8 with the GUI, today I am going to show you how to do it with PowerShell.

Firstly you are going to have to run PowerShell at an elevated prompt, to do this, simply right click on the icon and click “Run as Administrator”

Type Get-NetIPInterface to get a list of all the network interfaces on your system. The 2 interfaces we are looking for are Ethernet and Wi-Fi, both on IPv4

Get-NetIPInterface


The Interface Metric is set to auto, and have been assigned 10 for the Ethernet and 20 for the Wi-Fi

To change this type the following to set the interface metric on the Ethernet interface to 5

Set-NetIPInterface -InterfaceAlias Ethernet -AddressFamily IPv4 -InterfaceMetric 5


Now change the Wi-Fi interface to 1

Set-NetIPInterface -InterfaceAlias Wi-Fi -AddressFamily IPv4 -InterfaceMetric 1


Now if we check the Get-NetIPInterface you will see that the interface metric for the adaptors Ethernet and Wi-Fi have changed to 5 and 1 respectively


You can also specify either IP4 or IP6 by changing the AddressFamily to either IPv4 or IPv6

Remember: You must do this for all active NICs to make sure they are in the right order.

@PCVirus_AU
Titan Solutions

Setting Network Interface Priority On Windows 8 with the GUI

Since upgrading to Windows 8, I have had problems with applications working with the proxy at work, ISA 2004.

As ISA 2004 is going to be decommissioned in the next couple of months, and the fact I have way too much work on, I opted for the easy way out, get my internet access from the guest wireless while using my wired connection for my domain related activities.

First type “view network connections” and click on the first option. This will throw you out to the Desktop and open the Network Connections window.

ViewNetworkConnections       NetworkConnections

Right click and select Properties for the network adaptor that you wish to change the priority for.

Scroll down to Internet Protocol Version 4 (TCP/IPv4), if that is what your using and click “Properties”

Next click the “Advanced…” button in the bottom right hand corner

EthernetProperties         InternetProtocolVersion4Properties

Untick the “Automatic metric” and type a number in the “Interface metric” box. The lower the number the higher the preference.

AdvancedTCPIPSettings        AdvancedTCPIPSettingsInterfaceMetric

Click “OK” on all the windows to close them out and your done.

In my configuration, I set the wired connection to 5 and the wifi connection to 1.

Remember: You must do this for all active NICs to make sure they are in the right order.

@PCVirus_AU
Titan Solutions

Selecting and Moving Tapes in a Media Set

The nightly backups at work crossed the LTO5 capacity and moved onto a 2nd tape recently, and with the annual disaster recovery test looming over my head, I didn’t want to have to restore 2 tapes to get the critical systems up and running.

What I needed to do was modify the 2 backup jobs that I have running to shuffle what server backs up to what tape. Ok, so what’s the easiest way to do that? Create a 2nd media set, easy right? Of course. Now I need to move the tapes into 1 of the 2 media sets I now have. Ok, ok, that’s pretty easy too. I’m trying to make things sound interesting here!

So if you know anything about me you know I am going to do what I need to do with Backup Exec PowerShell module BEMCLI.

Firstly, I am going to create the new media set (See Modifying media sets in Backup Exec 2012 with PowerShell for my reasoning for setting these overwrite and append times):

New-BEMediaSet -Name "Keep Data for 4 Weeks – Daily Tape 1" -OverwriteProtectionPeriodHours 648 -AppendPeriodHours 12

Next I have to select the tapes that that I want to move to the new media set. The tapes at work are named “MON101″, “TUE101”, etc for the first tapes in the daily backups and “MON102”, “TUE102”, etc for the 2nd tape in the daily backups, so the “01” and “02” are what I want to select. To select all first tapes in the daily I would use this command:

Get-BEMedia -MediaSet "Keep Data for 4 Weeks" | Where-Object {$_.Name -like "*01*"}

Then move the selected tapes into the media set by using the move command.

Move-BEMediaToMediaSet -MediaSet "Keep Data for 4 Weeks – Daily Tape 1"

Unless you use a variable on the Get-BEMedia command, you will need to pipe the 2 commands for it to work like this:

Get-BEMedia -MediaSet "Keep Data for 4 Weeks" | Where-Object {$_.Name -like "*01*"} | Move-BEMediaToMediaSet -MediaSet "Keep Data for 4 Weeks – Daily Tape 1"

Finally, you can rename the original media set.


Rename-BeMediaSet -InputObject "Keep Data for 4 Weeks" -NewName "Keep Data for 4 Weeks – Daily Tape 2"

And there you have it. Comments and questions are always welcome.

@PCVirus_AU
Titan Solutions

Mobile Phone Dynamic Distribution Group

The other day, the boss came to me and asked me to setup a distribution list for everyone who has a company issued phone.

GREAT, I don’t want to manage this distribution list.

Luckily for me, only users who have been issued company phones have their mobile numbers in Active Directory, so off to PowerShell I go.

All I need to do is create a dynamic distribution group, which with the GUI in Exchange 2010 is pretty limited, so as previously mentioned, I’ll have to use PowerShell. But what is a dynamic distribution group? I’ll let Microsoft Explain it:

Dynamic distribution groups are mail-enabled Active Directory group objects that are created to expedite the mass sending of email messages and other information within a Microsoft Exchange organization.

Unlike regular distribution groups that contain a defined set of members, the membership list for dynamic distribution groups is calculated each time a message is sent to the group, based on the filters and conditions that you define. When an email message is sent to a dynamic distribution group, it’s delivered to all recipients in the organization that match the criteria defined for that group.

So there you have it, this is exactly what I am looking for, and PowerShell is the way I am going to do it.

Firstly, I’ll give a name of the dynamic distribution group, in this case “iUsers Mobile”

Get-DynamicDistributionGroup "iUsers Mobile"

Now, I’ll need to set the filter that I want for this dynamic distribution group, in this case, obviously it will be the mobile number. Since all mobile numbers start with a 0, using –like “0*” will match all numbers in the MobilePhone AD field with a wildcard for any combination of numbers after the leading 0.

Set-DynamicDistributionGroup -RecipientFilter {MobilePhone -like "0*"}

Pipe them both together and now I have a 1 liner that will assist with my desire to NOT have to manage this distribution group.

Get-DynamicDistributionGroup "iUsers Mobile" | Set-DynamicDistributionGroup -RecipientFilter {MobilePhone -like "0*"}

So there you have it, any comments and questions are welcome.

@PCVirus_AU
Titan Solutions

2012 Scripting Games Beginner Event 6: Compute Uptime for Local Computer

This script was my 2nd 5 star script of the games and certainly the most used by myself.

This scenario was to calculate the uptime of a computer in days, hours, minutes and seconds. The full details can be found here

The design points for this one are pretty simple too

  • Your solution only needs to run locally.
  • Your script should be easy to read and easy to understand.
  • Your script is only concerned with the uptime for the local server, calculated with the current time. Do not worry about time zones or about comparing up times with different computers.
  • Pay attention to the formatting of the output and the script itself.

Firstly you need to set the variable for the WMI class

$W32OS = Get-WmiObject -Class Win32_OperatingSystem

Next you need to use the CovertToDateTime script method to convert the current time output into something more reasonable.

$CurrentTime=$W32OS.ConvertToDateTime($W32OS.LocalDateTime)

You use the same script method to convert the timedate of the last bootup time.

$Uptime=$W32OS.ConvertToDateTime($W32OS.LocalDateTime) – $W32OS.ConvertToDateTime($W32OS.LastBootUpTime)

Finally with the output of the script, you combine all the variables to give us the information that we are looking for.

"The computer $env:computername has been up for $($Uptime.Days) days $($Uptime.Hours) hours $($Uptime.Minutes) minutes, $($Uptime.Seconds) seconds as of $($CurrentTime)"

Once it is all combined all together the finished script looks like this

$W32OS = Get-WmiObject -Class Win32_OperatingSystem

$CurrentTime=$W32OS.ConvertToDateTime($W32OS.LocalDateTime)

$Uptime=$W32OS.ConvertToDateTime($W32OS.LocalDateTime) – $W32OS.ConvertToDateTime($W32OS.LastBootUpTime)

"The computer $env:computername has been up for $($Uptime.Days) days $($Uptime.Hours) hours $($Uptime.Minutes) minutes, $($Uptime.Seconds) seconds as of $($CurrentTime)"

And that’s it. I know its not anywhere near complete in how I worked out all the cmdlets. I really wish I had blogged about this as I was doing it.

There you have it, my 5 star script for Beginner Event 6 of the 2012 Scripting Games

2012 Scripting Games Beginner Event 4: Compare Two Folders

Or “My first 5 star script”

The scenario in this event was to compare 2 the contents of 2 folders to make sure that the files where being copied across successfully. The full scenario is listed here

The design points are listed below and quite easy to fulfil.

  • You should return file information objects as the result of your comparison.
  • You only need to compare file names, not file sizes, dates, or contents.
  • Your output should list files that exist in one folder, but not in the other folder.
  • Because the object is to prove to your boss that your backup works, you do not need to write a complicated script. Unnecessary complexity will cost you points.
  • Extra points for using native Windows PowerShell cmdlets, and for simplicity of code.
    The cmdlet we need for this is
    Compare-Object

Now we need to add in the reference and difference objects

Compare-Object -ReferenceObject C:\2 -DifferenceObject C:\1

This will only show that folders 1 and 2 are different, so what we need to do is get the contents of the folder

Compare-Object -ReferenceObject (Get-ChildItem C:\2)
-DifferenceObject (Get-ChildItem C:\1)

(Get-ChildItem C:\2) will process the contents of the folder before comparing them. This gets around having to create a variable and making the script unnecessarily complex.

Finally we add in the –PassThru to pass through the output to the console

Compare-Object -ReferenceObject (Get-ChildItem C:\2)
-DifferenceObject (Get-ChildItem C:\1) –PassThru

 

And there is my 5 star script for Beginner Event 4 of the 2012 Scripting Games

2012 Scripting Games Wrap Up

A couple of weeks ago I got an email from Ed “Scripting Guy” Wilson at Microsoft, It was this nice certificate of participation in the 2012 Scripting Games.

While I cant say that I killed it in the games, personally I think I did pretty well for myself. I entered into the beginner category as I have only really just started scripting. I also wasn’t sure what to expect and figured it was the safe bet.

I missed out on Event 8 mostly because I was trying to overthink it and just gave up. So out of the 9 events, 4 scripts received 5 stars, 1 was given 4.5 stars and 1 was given 4 stars, which to me seems pretty good for a first time go!

While I haven’t really made any use out of the scripts that I created for the games (expect for the server uptime script), it has given me a better understanding of how things work in PowerShell and enabled me to write some other scripts that I use for work.

I can most certainly say that I will be participating in next years games (Hopefully in the Advanced category)

 

image

Moving Media with PowerShell and Backup Exec 2012

Last week I blew away my old backup server which was running Backup Exec 2010 R3, installed some new disk and installed Backup Exec 2012, everything went well as expected, but I noticed that the tapes weren’t overwriting each night and waiting for manual confirmation.

Upon further investigation, i found that when Backup Exec runs its inventory it moves the new tape into “Backup Exec and Windows NT Backup Media” which has the wonderful values “Keep indefinitely” and “No append”.

Of course, my first thought is, how can I use automate moving it to the “Scratch Media” set. My second? What if it doesn’t put it into “Backup Exec and Windows NT Backup Media” and puts it somewhere else instead.

Luckily PowerShell is the answer to both of those questions, and even better, you can do it in a 1 liner.

The command breaks down into 3 parts, first we need to get all online media in the tape library:

Get-BEMedia

Next we need to filter the media that we don’t want to move into “Scratch Media”, this might be cleaning tapes or additional tapes that might be in the left in the library. I used $_.MediaSet -ne “Cleaning Media” to filter out any tapes in the “Cleaning Media” media set,  $_.MediaSet -ne “Keep Data for 4 Weeks” to filter out anything in the “Keep Data for 4 Weeks” media set as that is where all tapes are moved to after a backup has been completed. Finally I only want online media (media currently in the library or drive) to be moved, for that I used $_.MediaVault -eq “Online Tape/Disk Cartridge Media”:

Where-Object {$_.MediaSet -ne "Cleaning Media" -and $_.MediaSet -ne 
"Keep Data for 4 Weeks" -and $_.MediaVault -eq "Online Tape/Disk Cartridge Media"}

Lastly we need to move the media that we have selected to the required media set

Move-BEMediaToMediaSet -MediaSet "Scratch Media"

When you put it all together, the script/ 1 liner looks like this:

Get-BEMedia | Where-Object {$_.MediaSet -ne "Cleaning Media" -and $_.MediaSet -ne 
"Keep Data for 4 Weeks" -and $_.MediaVault -eq "Online Tape/Disk Cartridge Media"} |
 Move-BEMediaToMediaSet -MediaSet "Scratch Media"

Set it up on a schedule sometime after the inventory completes, but before your tape backup starts and you won’t need to worry about it not being written to and screwing up your daily backup schedule.

 

Modifying a schedule for an existing job in Backup Exec 2012 with PowerShell

With PowerShell for Backup Exec, you can get a list of jobs from Backup Exec 2012 by typing Get-BEJob, which will give you a list of all the jobs in Backup Exec as in the below example. (This might also be a good time to make sure that all your backup jobs are descriptive enough as to identify individual ones)

image

The name of the job is listed under Name, the –Full appended to the end is automatically added by Backup Exec 2012 to indicate the backup task.

As you can see, the backup job for Test 2 only runs once a week, on a Friday at 11pm, this really doesn’t suit my needs for a production server, so I want to change it to match the same schedule as Test. To do this I need to type in the following command.

Get-BEBackupDefinition -Name “Test 2” | Set-BEFullBackupTask -Name Full -Schedule (New-BESchedule -Weekdays -StartingAt “10:00PM 19/3/12”) | Save-BEBackupDefinition

image

Get-BEBackupDefinition – Name is looking for the name of the backup job, while Set-BEFullBackupTask – Name is looking for the TaskName, both of which you get from the Get-BEJob command.

You can also use 24 hour time and date formats such as dd/mm/yyyy (or mm/dd/yyyy) depending on your locale

Once you have modified your schedule you can get it by running Get-BEJob again and seeing the schedule.

image

Backup Exec 2012 and PowerShell–It all starts with one little command

Symantec has introduced PowerShell in Backup Exec 2012, and all it takes is one little command;

Import-Module –Name BEMCLI

Just run that command and you will be able to access all the Backup Exec PowerShell goodness!

The BEMCLI module allows you to access 203 Cmdlets with a few alias and functions thrown in too.

image

Symantec has also released a chm file to download with all the PowerShell commands for Backup Exec in it. You can download it from the link below:

http://www.symantec.com/docs/DOC5438

I’m looking forward to playing with PowerShell in Backup Exec 2012 and seeing how it can be utilized within my workplace.