Showing entries 11 to 20
« 10 Newer Entries
Displaying posts with tag: PowerShell (reset)
Windows PerfCounters and Powershell - Raw vs. Formatted values


How to interpret Raw data from Windows performance counters.
Tip: An alias for Get-CimInstance is GCim and alias for Get-WmiObject is GWmi.

In the first blog post, I covered what WMI/CIM is and how to get info from there. Last I talked about was RawData counters:
Get-CimInstance -Class Win32_PerfRawData_PerfOS_Processor

Name : _Total
...
PercentIdleTime : 78061457390


Understanding RawData:By itself, a RawData value is a sample but important thing is to determine what concrete sample value actually is and how to convert it to a form we understand. In this example, MSDN tells us PercentIdleTime is a counter of type 542180608:

[Read more]
Windows PerfCounters and Powershell - Infrastructure

In this series of blogs, I will cover Windows performance counters infrastructure, collecting and interpreting the data and, in final blog, provide the Powershell script built on this. I should note that I am very new to Powershell so take my empirical findings with grain of salt. Also, coming from Linux bash, I found Powershell confusing at first but, after getting comfortable with concept of passing Objects down the pipe, I have to say I like it a lot.

It all starts in WDM framework (Windows Driver Model) where metrics is collected for WMI-for-WDM enabled device drivers. The classes created by the WDM provider to represent device driver data reside in the "Root\WMI" namespace. I will talk of namespaces shortly.
So, the WDM provider records information about WDM operations in the …

[Read more]
Communication between Powershell script and Jobs

I had an interesting task of collecting and displaying some runtime metrics during the benchmark. Since data was clearly divided between OS and processes, I opted for separate background jobs in which case no task will stall the other. However, this means I had to establish communication between main script code and jobs which is tricky in Powershell (see this bug for example). Immediately, I thought of using named pipes or files (as I do have small, ever changing set of data). Further investigation revealed 4 ways of accomplishing this:

  1. Using files
  • pros:
    • Tried and tested; works everywhere.
    • Intuitive.
    • File management routines are mature.
[Read more]
Regular checks before running Powershell script + Write-Error replacement

On occasion, one will produce the script that will not work in _ISE or on some particular version of Powershell. So, before allowing script to run, I always do several checks depending on the task at hand. Here's the code:

       
#region Check
if ($host.Name -ne 'ConsoleHost')
{
#Running in ISE
$host.UI.WriteErrorLine("`t Script can not be run in _ISE. Exiting.")
Exit 1
}

if (($PSVersionTable).PSVersion.Major -lt 3) {
$host.UI.WriteErrorLine("`t Script can not be run in PS 2. Exiting.")
Exit 2
}

$clrV =
((Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse |
Get-ItemProperty -name Version,Release -EA 0 |
Where { $_.PSChildName -match '^(?!S)\p{L}'} |
Select Version | Sort Version -Desc | Select -First 1).Version).Split('.')[0]
if ( $clrV -lt 4) {
$host.UI.WriteErrorLine("`t Script can …
[Read more]
Handling keyboard input and CTRL+C in Powershell without pausing

Recently, I had a requirement to update my script console output depending on user key-press. Since calculation was done by background threads, I also wanted to prevent CTRL+C from stopping the script without proper cleanup.
However, looks like seamless handling of key-press along with handling special sequences is not available in Powershell. This was to be expected given that [system.console]::readkey is designed for accepting the user input which is mostly answers to flow control questions. Register-EngineEvent does not help either.

Anyway, let's tackle both problems one by one:
1) Disable CTRL+C from stopping the script:

       
[console]::TreatControlCAsInput = $true

Note that CTRL+BREAK will end the session entirely and do …

[Read more]
Log Buffer #441: A Carnival of the Vanities for DBAs

This Log Buffer Edition dives deep into the ocean of blogosphere and surfaces with some cool blog posts from Oracle, SQL Server and MySQL.

Oracle:

  • Lets Talk DB Perth
  • The Fundamental Challenge of Computer System Performance
  • Index Advanced Compression: Multi-Column Index
  • Middleware Diagnostics Advisor (MDA) Setup
  • Most people are now aware that in 12c, a …
[Read more]
Log Buffer #431: A Carnival of the Vanities for DBAs

This Log buffer edition covers Oracle, SQL Server and MySQL blog posts about new features, tips, tricks and best practices.

Oracle:

  • Traditionally, assigning specific processes to a certain set of CPUs has been done by using processor sets (and resource pools). This is quite useful, but it requires the hard partitioning of processors in the system. That means, we can’t restrict process A to run on CPUs 1,2,3 and process B to run on CPUs 3,4,5, because these partitions overlap.
  • Parallel_Degree_Limit, Parallel_Max_Degree, Maximum DOP? Confused?
  • JDeveloper 12c – …
[Read more]
Pillars of PowerShell: SQL Server – Part 1

Introduction

This is the sixth and final post in the series on the Pillars of PowerShell, at least part one of the final post. The previous posts in the series are:

  1. Interacting
  2. Commanding
  3. Debugging
  4. Profiling
  5. Windows OS

PowerShell + SQL Server is just cool! You will see folks talk about the ability to perform a task against multiple servers at a time, automate implementing a configuration or database change, or just obtaining a bit of consistency when doing certain processes. I tend to use it just because I can, and it is fun to see what I can do. There are a …

[Read more]
Summary of Blog Posts for Week of July 18

 

1. Monitis–Where You Can Monitor Exchange 2010 with PowerShell
We’ve recently published a list of posts showing a variety of ways to monitor any application using the Monitis API. Microsoft Exchange is no exception. Here we go over how to use Management Shell or Management Console to speak to the Monitis API and feed data into a custom monitor. You can then generate charts and alert settings on this data.

2. Monitoring files and directories with Monitis
Things can go horribly wrong …

[Read more]
PowerShell + MySql

Today, doing one small task I thought: “Why can’t I do it with PowerShell?”
So, here is a small example:

[void][system.reflection.Assembly]::LoadFrom("c:\devel\mysql\ps\MySQL.Data.dll")

$myconnection = New-Object MySql.Data.MySqlClient.MySqlConnection
$myconnection.ConnectionString = "server=localhost;user id=test;password=test;database=test;pooling=false"
$myconnection.Open()

$mycommand = New-Object MySql.Data.MySqlClient.MySqlCommand
$mycommand.Connection = $myconnection
$mycommand.CommandText = "SHOW TABLES"

$myreader = $mycommand.ExecuteReader()

while($myreader.Read()){ $myreader.GetString(0) }

--
c:\devel\mysql\ps\MySQL.Data.dll - that is a connector

PowerShell is a quiet new thing, so I believe it could be helpfull.

Showing entries 11 to 20
« 10 Newer Entries