Install SCOM agent without the GUI?

SCOM can be a bit of a bear to the newcomer, there are several components that are quirky at best and if its not set up correctly or if you don’t know what you are doing things could go awry very quickly. Thank goodness there is a plethora of PowerShell commandlets for SCOM management and install to make things easier for us.
On the SCOM management server I experimented with the Install-SCOMAgent commandlet, what I found was that with the right parameters I could very quickly install the agent on remote servers with very little input. Lets look at this one liner that installs the SCOM agent on FileServer1 without the need to launch the SCOM console and run the discovery wizard:

Install-SCOMAgent -DNSHostName FileServer1.Domain.com -PrimaryManagementServer SCOM1.Domain.com

Just like that the agent installs immediately on FileServer1, no need to wait, no wizard to run, no hassle.

But wait… what if I didn’t have to log onto the SCOM server at all to install the client? Below is a simple function I created which allows you to install the SCOM agent from your desktop using PSRemoting, the only thing you need to know is the name of the SCOM server, and the target server name.

Function Install-SCOMClient{            
Param ([string]$Computer,            
    [String]$SCOMServer)            
    $RMSSession = New-PSSession –ComputerName $SCOMServer ;             
    Invoke-Command -Session $RMSsession -ScriptBlock {Add-PSSnapin “Microsoft.EnterpriseManagement.OperationsManager.Client”} ;             
    Invoke-Command -Session $RMSsession -ScriptBlock {Install-SCOMAgent -DNSHostName ($args[0] + '.' + $env:USERDNSDOMAIN) -PrimaryManagementServer (Get-SCOMManagementServer) -Verbose} -ArgumentList $computer;            
    Remove-PSSession $RMSSession            
    }
Install-SCOMClient -Computer FileServer1 -SCOMServer SCOM01

It’s one I like to put into my $Profile so its easily accessible to me on my client desktop.

Are those files being accessed?

Building a new file server I wanted to check to see if a particular drive was being used during the day. Luckily Since the days of Server 2003, Windows Server has shipped with an executable openfiles.exe that we can leverage. The bad news is that the executable was written to output the data to the command console and to be discarded, luckily we can use the PowerShell pipeline to interpret the output of openfiles.exe and format it. I have made a PowerShell “One Liner” to quickly retrieve the open files on a server:

$OpenFiles = openfiles /query /fo CSV | Select-Object -Skip 9 | ConvertFrom-Csv -Header "ID","AccessedBy","Type","OpenFile"

The script saves the output of openfiles.exe to the variable $OpenFiles
Let’s dive into the rest of it…
openfiles /query /fo CSV this is the command that can be used with PowerShell or in a command console to export the results to a .csv file (but we don’t really want to save a file)
Select-Object -Skip 9 states that we want to ignore the first 9 lines of the input (like I said, the openfiles.exe command was meant to display on the screen so there’s a bunch of junk in there )
ConvertFrom-Csv -Header “ID”,“AccessedBy”,“Type”,“OpenFile” takes the CSV formatted data and converts it to a PowerShell object so we can manage the data.
So lets run the command on FileServer1 and see if there are any open files on the X:\ drive…

$OpenFiles = openfiles /query /fo CSV | Select-Object -Skip 9 | ConvertFrom-Csv -Header "ID","AccessedBy","Type","OpenFile"            
$OpenFiles | where {$_.OpenFile -like "X:\*"}


Or we could see what a particular user is viewing:
$OpenFiles | where {$_. AccessedBy -like “McCann*”}

Yes you could use the MMC, add the computer management snap in, navigate through, sort, etc, etc…. but the great thing about PowerShell is its remote capabilities, let’s see what we get when we format the script to run remotely on FileServer1…

Invoke-Command -ComputerName FileServer1 -ScriptBlock {            
    $OpenFiles = openfiles /query /fo CSV | Select-Object -Skip 9 | ConvertFrom-Csv -Header "ID","AccessedBy","Type","OpenFile"            
    $OpenFiles | where {$_.OpenFile -like "X:\*"} | Format-Table            
    }


Aren’t computers neat?
-JoshuaÂ

Print Server Migration

Recently I had to retire an end of life Windows 2008 R2 print server, as you will see from the image below the number of drivers on the server was significant compared to the number of printers deployed:

Over the years drivers had been migrated with each server upgrade as well as when a new driver was updated by the manufacturer. Moving forward there is the question of how do I migrate the printers without bringing over all of the crap that I don’t need?

A: A few lines of code and some know how:
1. On the old server open an administrative command prompt and set the current directory to the printer tools directory
cd “C:\Windows\System32\Spool\Tools
2. run Printbrm -b -f Printserverconfig.printerexport in the same window, this will take some time to complete especially if you have a large number of drivers, wait for the tool to fully complete its task.

-sidenote I have seen this tool not work as expected when using PowerShell to be safe when using printbrm.exe you should use it in an administrative command prompt.
3. create a child folder in the current tools directory, I named mine “Migrate” Continue reading “Print Server Migration”