tag:blogger.com,1999:blog-378197352024-03-13T17:01:32.548+01:00JBs PowershellThis is the place where I put various small PowerShell bits'n pieces. I hope they can be of use to others. Feel free to use my scripts, but please give credit to the source.Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.comBlogger71125tag:blogger.com,1999:blog-37819735.post-24794879185549932682014-12-12T22:56:00.000+01:002014-12-12T22:59:33.851+01:00Collecting computer/server inventoryA while back I wrote this handy little function for collecting inventory from the computers in my household. Somehow I never got around to posting it on my blog, for which I apologize ;-)
The function uses WMI to collect the following information from computers running windows:
Hostname and description
Serial number
Operations system
Uptime
Hardware: Mainboard, BIOS version, CPU, ram size and Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com0tag:blogger.com,1999:blog-37819735.post-27112884285097868582013-01-10T21:22:00.001+01:002013-01-10T21:36:22.550+01:00Executing tasks in parallel in PowerShellLet's pretend that we need to write a script that can test to see if 10 different webpages are available.
While this could be accomplished by retrieving the webpages one at a time, it does take some time to do this. Often something like 0.5 to 2 seconds for each page.
Now imagine that you needed to test 50 pages or 100 - that would take quite a while...
The following function "Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com0tag:blogger.com,1999:blog-37819735.post-31891802941513751162012-10-02T10:27:00.000+02:002014-12-12T23:00:42.065+01:00Windows Process Affinity
Yesterday I had a new challenge: to change the Processor Affinity through PowerShell.
Processor Affinity in another term for "what cores can my process use". By limiting a CPU hungry process to just use some of the available cores, it is possible to let other processes run more smoothly.
This can easily be accomplished by right-clicking a process in TaskManager, but can it be done by a script?Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com0tag:blogger.com,1999:blog-37819735.post-50561859092081611572012-07-26T13:57:00.002+02:002012-07-26T13:57:54.770+02:00Get-LocalDBMy first attempt at creating LocalDB specific PowerShell code, is a function to extract a list of LocalDB instances. This is not very exciting code, PowerShell-wise, but I wanted to share it anyways:
Function Get-LocalDB { Param() $ldb_version = Invoke-Expression "sqllocaldb v" if ($ldb_version -notlike "*(11.0*)") { &Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com0tag:blogger.com,1999:blog-37819735.post-49969260423861359032012-07-26T13:46:00.000+02:002012-07-26T13:46:27.053+02:00SQL Server 2012 LocalDBI've been playing around with the new LocalDB edition of SQL Server 2012 (read about it here).
In short LocalDB is an edition of SQL Server 2012, comparable in features with express edition, but running as a user process not a service. LocalDB is targeted developers, but I could think of a few other uses for it.
LocalDB automatically creates an instance called "v11.0" - the full name of this Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com1tag:blogger.com,1999:blog-37819735.post-53398269997566009112012-07-20T19:28:00.001+02:002012-07-20T19:29:19.264+02:00Start remote process through WMIThere are many ways to execute a process remotely on a Windows based computer. It is possible use Remote Desktop (RDP/MSTSC) to log onto the desktop of the computer, but this is slow and not easily automated.
You can use the excellent Sysinternals tools PSEXEC, provided by Microsoft or you can use PowerShell 2.0's support for WinRM.
While all of the options above might be good in any Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com2tag:blogger.com,1999:blog-37819735.post-54803984376428476892012-07-14T14:19:00.000+02:002012-07-14T14:19:54.728+02:00SQL Server Product Key - updateIn the past, I've posted a few scripts to extract the Windows and/or SQL Server license keys.
Since these posts have been some of the most popular* posts on my blog, I've decided to update those scripts, and make them more compatible with newer version of Windows and SQL Server.
* I've received more than 100 emails and comments about just those scripts.
The script below has been tested againstJakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com3tag:blogger.com,1999:blog-37819735.post-81329589794088841682012-07-14T13:33:00.000+02:002012-07-14T13:33:13.745+02:00Creating a Firewall opening using PowershellHere is a quick solution to the challenge of creating a firewall opening on a Windows 7 or Windows 2008R2 server (should work on different version from Vista and above too ...).
Several settings are hardcoded, and others only support a limited number of settings (the function only supports TCP and UDP openings), but it can easily be extended if needed.
Function New-FirewallRule {
 Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com0tag:blogger.com,1999:blog-37819735.post-64487852720531906002011-08-11T09:03:00.003+02:002011-08-11T09:20:01.878+02:00Collect WWNDue to recent works on migrating a large number of servers and SAN LUNs, I threw together this small script to collect WWN numbers (see WWN on Wikipedia) from servers. Maybe it can be useful for someone else?
Save the lines below as wwn.ps1 :
## WWN version 1.1
## Script to determine HBA WWNs on remote servers (Win 2003+)
## Usage: .\wwn.ps1 servername.domain.com
Param ($servername)
$data = Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com4tag:blogger.com,1999:blog-37819735.post-60362323714244971972011-04-17T19:26:00.002+02:002011-04-17T19:36:47.197+02:00Secunia PSI & PowershellI been using Secunia's Personal Software Inspector since it was in beta. This is a free product that I highly recommend. It is currently in version 2.0.For those of you who don't know PSI:The Secunia PSI is a FREE security tool designed to detect vulnerable and out-dated programs and plug-ins which expose your PC to attacks. Attacks exploiting vulnerable programs and plug-ins are rarely blocked Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com0tag:blogger.com,1999:blog-37819735.post-75587904622729746682010-11-15T20:48:00.001+01:002010-11-15T20:50:28.105+01:00SQL Server Product Key - SS 2005In order to extract the Product key from SQL Server 2005, change the following two lines in the previous post: $regPath = "SOFTWARE\Microsoft\Microsoft SQL Server\100\Tools\Setup" $regValue1 = "DigitalProductId"To: $regPath = "SOFTWARE\Microsoft\Microsoft SQL Server\90\ProductID" $regValue1 = "Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com0tag:blogger.com,1999:blog-37819735.post-38519878562948951922010-11-11T16:57:00.004+01:002010-11-11T17:03:42.820+01:00SQL Server Product KeyA while back I wrote a small script to retrieve the Windows license key. Since then I've been asked several times how to retrieve the product key of an SQL Server.So today I threw together this small script to do just thatfunction Get-SQLserverKey { ## function to retrieve the license key of a SQL 2008 Server. ## by Jakob Bindslet (jakob@bindslet.dk)&Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com45tag:blogger.com,1999:blog-37819735.post-72690363730868712532009-12-13T21:28:00.004+01:002009-12-13T21:35:43.635+01:00SQLmonkeysA friend and colleague of mine has just launched a new site - go to www.sqlmonkeys.com to have a look.I'm not sure what contest will be added to the site, but I guess it will mainly be about SQL ... and monkeys ...Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com0tag:blogger.com,1999:blog-37819735.post-56472277921684279442009-12-13T21:20:00.003+01:002009-12-13T21:28:20.206+01:00SQL: Poor man's auditMost DBAs have had to examine unknown database/instances in order to evaluate their configuration.I recently had to examine a few SQL servers for a client in order to offer advice on improvement - mainly in the area of "best practice configuration". This is a (simplified) version of a script I wrote in order to do a quick survey of misconfigurations. Please excuse the simple script - it is more Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com0tag:blogger.com,1999:blog-37819735.post-74307252919723314512009-10-19T10:35:00.000+02:002009-10-19T10:36:51.803+02:00PowerShell v2 Launch PartyPowerShell v2 finally launches October 22nd: http://powerscripting.wordpress.com/2009/10/16/powershell-v2-virtual-launch-party/Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com0tag:blogger.com,1999:blog-37819735.post-71319246787720665652009-06-05T14:50:00.004+02:002009-06-05T14:54:52.239+02:00Virtual Windows & PowerShellI'm playing around whit Windows 7 and the Virtual Windows feature at the momemt.Naturally I've tried to manipulate Virtual Windows PC through PowerShell. At the moment the possibilities are apparently limited to using COM - with a namespace similar to Virtual PC/Virtual Server:### Virtual Windows (Virtual PC) com object ###$vpc = new-object -com VirtualPC.Application$vms = $Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com0tag:blogger.com,1999:blog-37819735.post-5887114630961120622009-05-20T19:41:00.008+02:002009-05-20T20:36:20.828+02:00Getting informationon installed CPUs, Cores and SocketsA friend and former colleague asked me about a way to obtain rather detailed information on the type and number of CPUs installed in a server, as well as the number of cores present.This is the function I came up with.Please note that this function is incapable of coping nicely with limitations implemented using /NUMPROC in boot.iniThe function should work on Windows 2000 Server and Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com1tag:blogger.com,1999:blog-37819735.post-7161527801543758122009-05-08T15:09:00.007+02:002009-06-06T19:21:33.526+02:00Testing WinRAR 3.90 betaI recently had to evaluate the preformance of the Rarsofts new beta of WinRAR.WinRAR is a powerful GUI and CLI archiever that handles many archieve formats.In order to test the preformance I installed WinRAR 3.80 as well as WinRAR 3.90beta1 (in both 32 and 64-bit versions).Here is a light version of the PowerShell script I came up with (please adjust file paths and $source according to your own Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com7tag:blogger.com,1999:blog-37819735.post-6661237018906981212009-02-23T19:09:00.005+01:002009-02-23T19:15:20.261+01:00WebServer investigatedI recently spend some time playing around with creating a bunch of scripts to monitor changes in a web page. While doing this I needed to determine what kind of webserver a given site was hosted on. This is a somewhat simplified version of my solution:function Get-WebServer { param ($target) if (-not ($target -like "http://*")) { &Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com0tag:blogger.com,1999:blog-37819735.post-69294970664730143182009-02-09T20:40:00.003+01:002014-02-13T15:46:55.736+01:00CLI Menu in PowerShell
There are a lot of WPF-based PowerShell menu functions and demos available in various places, but for some reason I feel that PowerShell really needs a good, ol' fashion CLI menu.
So, here is a quick, sort of hack'ish CLI menu for PowerShell (dont worry, I just made up the individual menu options - can you tell I just reread BOFH recently?).
Use the up and down arrows to navigate the menu, andJakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com7tag:blogger.com,1999:blog-37819735.post-73330149701789340582009-02-09T00:02:00.001+01:002009-02-09T00:03:57.068+01:00Trapping errors in PowershellI just stumbled across this sweet little introduction to trapping errors in PowerShell:http://powershell.com/cs/blogs/tobias/archive/2008/09/29/trapping-errors.aspxJakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com0tag:blogger.com,1999:blog-37819735.post-59417848144724569062009-02-07T21:48:00.008+01:002009-02-07T22:13:39.686+01:00Retrieveing the Windows Product KeyI was recently asked if I knew of a tool capable of retrieving the Product Key from an installed instance of Windows Vista. While there are several such tools available (use google), my solution - naturally - was to write a PowerShell script that can do just that.The script below is based on information from "The Custodian" on Everything2: http://everything2.com/node/1058074I've tested the Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com41tag:blogger.com,1999:blog-37819735.post-49688818634411029522009-02-05T20:04:00.002+01:002009-02-05T20:13:55.064+01:00T-SQL query with object-based resultTwo small functions that can be used to make an T-SQL query, and have the result returned as a standard PowerShell object. This can be useful if - for some reason - you would like to use Sort-Object or similar on the result afterwards.function ConnectSQL { Param ($server, $query, $database) $conn = new-object ('System.Data.SqlClient.SqlConnection')&Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com2tag:blogger.com,1999:blog-37819735.post-3102101808995722342008-09-16T21:19:00.001+02:002008-09-16T22:06:59.749+02:00Read The Transactionlog of SQL Server from PowerShellYes, the header is correct. Thanks to Quest Software, the ability to read individual transactions from the transaction log of SQL Server has arrived!If you want to try it out, I've written this very brief quick start guide:Start by downloading the trial version of Quest's LiteSpeed product: www.quest.com (products -> all products -> LiteSpeed)Install the LiteSpeed trial you've just Jakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com2tag:blogger.com,1999:blog-37819735.post-71994848365468197252008-08-22T19:51:00.001+02:002008-08-22T19:59:45.388+02:00Call for inspiration: PowerShell + SQLI was wondering if anyone out there has any good suggestions for SQL related PowerShell automation that just needs doing?Any suggestions are welcome - if I can find the time, I might even try to create a solution.PSThis blog is now listed at PowerShellComunity.orgJakob Bindslethttp://www.blogger.com/profile/15991115017499294057noreply@blogger.com1