Comparing versions in PowerShell

Was recently asked on twitter how to compare properties of an object in the version format  (ie 1.2.3.4 >= 3.2.1.1). Well, as the property was string, which came into my mind was to remove the point. Something like

(Get-WmiObject win32_pnpsigneddriver |
Where-Object {(($_.DriverVersion).replace(‘.’,”)) -ge ’3211′}).DriverVersion

Well, this solution will fail in some cases , as if you have NULL or other chars in the property. So, doing a better research, I found a post from Shay Levy (Actually he helped someone else)

https://www.cupfighter.net/2009/06/powershell-comparing-version-numbers

You can use the [version] type in Powershell to perform the operation Alegre (as showing in the post above)

(Get-WmiObject win32_pnpsigneddriver |
Where-Object {[version]$_.DriverVersion -ge [version]’1.0.20′}).DriverVersion

Awesome !!!

Posted in Powershell | Leave a comment

Pré-Conferência no SQLRally Amsterdã–PowerShell e SQL Server

Pois é pessoal, to muito feliz e honrado pelo convite do grande amigo Andre Kamman para fazer uma pre-conference no SQLRally Amsterdã em outubro.

O SQLRally é uma conferencia intermediária entre o SQLSaturday e o SQLPASS Summit, tendo 3 dias de conferencia com os melhores profissionais do mundo e eu vou ter o prazer de apresentar uma pre-conferencia de 8 horas no dia 2. As pre-conferencias são mini cursos que são feitas antes do evento propriamente dito, pois são pagas.

É uma oportunidade verdadeiramente unica podem ter certeza  Alegre. Será muito bom rever os amigos #sqlfamily da Europa e principalmente estar novamente nessa cidade linda e com gente tão amigável que é Amsterdã.

Minha pre-con sera :

Mastering PowerShell for SQL Server

Some people say magic, others say supernatural. I’d prefer to say top technology. That’s what PowerShell is today for the Microsoft stack. An Advanced technology built into the top of the operability of windows based operating systems , which allow us to a complete automation platform based, or not, on scripts. But what’s its relationship with SQL Server ? What can I really run , automate and manage in the SQL Server using PowerShell ?
If you are looking for those answers, this course is for you .
It will be split into 2 parts : The first with basic / intermediate fundamentals of programming in PowerShell , as using variables, what are hashtables , custom tables , custom objects , script modules , functions , advanced functions and their attributes and many other concepts .
In the second part , we will see the host of PowerShell in SQL Server ( SQLPS ) , what is SMO, how to use it and how to create your framework to SQL Server using the concepts we’ve seen .
Prepare yourself for a full day of deep PowerShell coding, concepts , fundamentals and lot, but a lot of magic.

sqlrally

Posted in Algo que Esqueci de Categorizar | Leave a comment

Pre-Con in SQLRally Amsterdam–PowerShell and SQL Server

I am very happy, honored and missing words to thanks my good friend Andre Kamman (and all the SQLRally Amsterdam board) by the invitation to present a Pre-Conference in SQLRally Amsterdam on October, 2th.

The SQLRally will be on 2th,3th and 4th October. My pre-con will be on 2th. 8 hours of pure PowerShell and SQL Server.

It will be just AMAZING return to the Wonderful Amstedam and the gentle people live there, also see the #sqlfamily Europe again. I am very excited Alegre

Hope to see you there.

Mastering PowerShell for SQL Server

Some people say magic, others say supernatural. I’d prefer to say top technology. That’s what PowerShell is today for the Microsoft stack. An Advanced technology built into the top of the operability of windows based operating systems , which allow us to a complete automation platform based, or not, on scripts. But what’s its relationship with SQL Server ? What can I really run , automate and manage in the SQL Server using PowerShell ?
If you are looking for those answers, this course is for you .
It will be split into 2 parts : The first with basic / intermediate fundamentals of programming in PowerShell , as using variables, what are hashtables , custom tables , custom objects , pipeline, script modules , functions , advanced functions and their attributes and many other concepts .
In the second part , we will see the host of PowerShell in SQL Server ( SQLPS ) , what is SMO, how to use it and how to create your framework to SQL Server using the concepts we’ve seen .
Prepare yourself for a full day of deep PowerShell coding, concepts , fundamentals and lot, but a lot of magic.

sqlrally

Posted in Algo que Esqueci de Categorizar | Leave a comment

PASS New Role – Virtual Chapter Mentor

I am delighted to announce my new role in PASS. Virtual Chapter Mentor.

It  has been a great honor for me all those past years working with PASS (previosly PASS Regional Mentor for Brasil and currently Co-Lead of the PowerShell PASS Virtual Chapter) and now I have these fantastic opportunity.

I will keep doing my best for sure :)

Thanks to PASS, Karla, Jen and all SQL Server Community

Posted in Algo que Esqueci de Categorizar | Leave a comment

SQL Saturday Chicago #291 – 2014 – I’m speaking

I am very honored to say that I am speaking at SQL Saturday Chicago 2014. A LOT, really a LOT, of  very well known-names in the SQL Server Community will be there and I have the opportunity to be there with them.

My Session will be :

How to properly gather performance counter data using Windows PowerShell

We DBA´s know how important it is to collect performance data. In this session, I will show to you how to properly use the native Get-Counter PowerShell cmdlet to get all information you need from your servers. It has never been as easy to collect performance counter data and save it to a CSV file or a SQL Server table for baselining and later analysis. You may be thinking “But I don’t know nothing about PowerShell and explicitly using .NET classes in my code”. Don’t worry; you don’t need to know this to collect counters. Although this is a 100-level session, you’ll be producing 400-level results and your scripts will scale as the number of servers increase, because we’ll use asynchronous collection and processing. And better yet, we’ll schedule all of it. All this using native PowerShell cmdlets and a minimal amount of script code

Hope to see you there :)

Thanks again for the SQLSaturday Chicago Staff.

http://www.sqlsaturday.com/eventhome.aspx

 

Posted in Algo que Esqueci de Categorizar | Leave a comment

PowerShell 4.0 PipelineVariable, With or Without, I can´t live…..Without you.

I am writing my new Simple-Talk article of the series The Posh DBA. This one is how to properly use Get-Counter to gathering Performance Counters (windows/SQL/.net..etc) and save to a csv or a SQL Server Table. While writing , I came across an cool example of how to use the new common parameter.

In this article, I am showing that you dont need to know .net classes or even have a intermediate knowldge of PowerShell to write your script to collect the counters. Why ?

Because we are using only the native cmdlets of PowerShell 3.0 and with a script code level 100, I will show to you how to write a process level 400, as collect the data for several servers in asynchronous mode and in background or  even better,  scheduling the entire process using PowerShell 3.0 Scheduled Jobs. I ´ve submitted a session showing all this process to SQLBITS and SQLPASS as well. Fingers crossed

Welll, but this post is about the new PowerShell 4.0 common parameter pipelinevariable. My fellow PowerShell MVP and guru Keith Hill already wrote about it and his EXCELLENT  post is plenty of examples. You should read it before this one, because I am only showing a practical example that I am using.

Keith Hill – PowerShell V4 – PipelineVariable Common Parameter

Generally speaking, this new common parameter allows you to store in a variable  the current pipeline object to use in the further pipeline process. Why that is so F Awesome Amazing Cool ? Just because I dont need to use , as in my example, a Foreach-Object just to create the variable to store the current pipeline object.

Lets see my code without PipelineVariable :

Get-Counter -ListSet 'LogicalDisk','SQLServer:Buffer Manager','SQLServer:Memory Manager' | ForEach-Object { $CounterCategory = $_ $CounterCategory | Select-Object -ExpandProperty Counter | ForEach-Object { $CounterName = $_ $CounterName | Where-Object {$CounterName -match '(sec/Transfer|Avg. Disk Queue Length|Buffer Cache|CheckPoint|Target Server|Total)'} | Select-Object @{E={$CounterCategory.CounterSetName};N="CounterSetName"}, @{E={$CounterCategory.Description};N="Description"}, @{E={$CounterName};N="Counter"} } } | Export-csv C:\temp\BaselineCounters.csv -NoClobber -NoTypeInformation

In this example I need to store the first pipeline to $CounterCategory and the second one in $CounterName variables , but I need to use Foreach-Objects , to allow me to use the information for these objects in the further pipeline with Select-Object. If I dont do that I dont have the information of my first  and second pipeline objects :(

With the New Super UItra Yo-Bro PipelineVariable common parameter that is possible and I dont need to use Foreach-Objects, because the current pipeline object is stored in the variable defined in the pipelinevariable parameter :) :

Get-Counter -ListSet 'LogicalDisk','SQLServer:Buffer Manager','SQLServer:Memory Manager' -PipelineVariable CounterCategory | Select-Object -ExpandProperty Counter -PipelineVariable CounterName | Where-Object {$CounterName -match '(sec/Transfer|Avg. Disk Queue Length|Buffer Cache|CheckPoint|Target Server|Total)'} | Select-Object @{E={$CounterCategory.CounterSetName};N="CounterSetName"}, @{E={$CounterCategory.Description};N="Description"}, @{E={$CounterName};N="Counter"} | Export-csv C:\temp\BaselineCounters.csv -NoClobber -NoTypeInformation -Append

PipelineVariable,

With or without you
With or without you
I can’t live

……. without you

Posted in Algo que Esqueci de Categorizar | Leave a comment

PASS PowerShell VC Meeting of March with Kendal Van Dyke

SQL AGENT JOB STATUS REPORTING WITH WINDOWS POWERSHELL

A critical, yet tedious, task DBAs perform on a daily basis is making sure SQL Agent jobs have run properly. Manually checking each instance is slow and doesn’t scale beyond a handful of servers. Agent alerts are helpful but can easily get lost and forgotten in your inbox; Monitoring tools make things a little easier – provided every one of your instances is monitored. What we really just need is a simple and efficient way to see the status of jobs across all instances. Windows PowerShell is a perfect fit for the task, and in this session you’ll learn how to automate building a daily report so that you can see what’s happening with SQL Agent jobs in one place.

Kendal Van Dyke is a practiced IT professional with over a decade of experience in SQL Server development and administration. He is currently a principal consultant with UpSearch SQL, where he helps companies keep their SQL Servers running in high gear. Kendal is a Microsoft MVP for SQL Server, a Microsoft Certified Professional in SQL Server 2008 and 2012, and president of MagicPASS (South Orlando’s PASS Chapter). He also serves as a Regional Mentor for the US Southeast Region of PASS.

 

Link to Register :

http://powershell.sqlpass.org/

Posted in Algo que Esqueci de Categorizar | Leave a comment