DBAs and Dinosaurs

DBAs and Dinosaurs

You have to admit that title is catchier than yet another “Death of the DBA” blog.  And that was exactly the direction I was headed until I ran a quick search to find a reference that not only exposed actual predictions of the death of the DBA as a profession but...

Testing UNC Paths

Testing UNC Paths

Test-Path can test whether or not a given file or folder exists. This works fine for paths that use a drive letter, but can fail with pure UNC paths. At its simplest, this should return $true, and it does (provided you did not disable your administrative shares):...

Testing UNC Paths

Exporting and Importing Credentials in PowerShell

Credential objects contain a username and a password. You can create them using Get-Credential, and then supply this object to any cmdlet that has the -Credential parameter. However, what do you do if you want your scripts to run without user intervention yet...

Testing UNC Paths

Use $PSScriptRoot to Load Resources

Beginning in PowerShell 3.0, there is a new automatic variable available called $PSScriptRoot. This variable previously was only available within modules. It always points to the folder the current script is located in (so it only starts to be useful once you actually...

Testing UNC Paths

Changing FireMonkey style at runtime

Last month Sarina DuPont blogged about loading custom FireMonkey styles on a mobile device at runtime ("How to load custom styles at runtime"). That's a very interesting approach to compile a custom style as a resource into the mobile app. This week...

Testing UNC Paths

Getting More Than 1000 Active Directory Results

By default, Active Directory returns only the first 1000 search results when you use an ADSISearcher. This is a security mechanism designed to prevent unspecific LDAP queries from causing domain controller load. If you do need all search results and know that it will...

Testing UNC Paths

Converting Binary SID to String SID

Converting SID from Binary to String Active Directory accounts contain the SID in binary form. To convert the byte array into a string representation, use a .NET function like this: # get current user $searcher =...

Testing UNC Paths

Converting Excel CSV to UTF8

When you export Microsoft Excel spreadsheets to CSV files, Excel by default saves CSV files in ANSI encoding. That's bad because special characters will break once you import the data into PowerShell using Import-Csv. Ensuring UTF-8 Encoding for CSV Files To make sure...

Testing UNC Paths

Enabling Visual Styles

When you use Windows Forms dialogs and windows, you may have noticed that they show differently, depending on whether you launched your script from within the ISE editor or from the powershell.exe console. This is because the ISE editor enables visual styles by...

Testing UNC Paths

Test Local User Account Credentials

Verifying a Local User Account Here is a snippet that verifies a local user account. Simply submit a username and a password. You get back either $true or $false: $username = 'Administrator' $password = 'P@ssw0rd' $computer = $env:COMPUTERNAME Add-Type -AssemblyName...

Testing UNC Paths

Using RegEx to Filter Files

Get-ChildItem supports basic wildcards, but it does not support the rich feature set of regular expressions. If you combine Get-ChildItem with Where-Object, you can easily add this functionality. Filtering DLL Files by Name Pattern in PowerShell This example lists all...

Testing UNC Paths

Finding User Account with WMI

WMI represents all kinds of physical and logical entities on your machine. It also has classes that represent user accounts which include both local and domain accounts. Retrieving the Currently Logged-On User This piece of code returns the user account of the...

Testing UNC Paths

Increase SQL Server Performance Using Multiple Files

By default, SQL Server databases are comprised of two files: the primary data file (or .mdf) and the log file (or .ldf). It is, however, possible to configure SQL Server databases to use additional files – which can be an effective means of increasing SQL Server...

Testing UNC Paths

Change Order of CSV Columns

If you have a CSV file and would like to change the order of columns, simply import it into PowerShell, use Select-Object to change the order, and then re-export the CSV file again! $Path = "c:\somepathtocsv.csv" (Import-CSV -Path $Path) | Select-Object -Property...

Testing UNC Paths

Check Windows License Status

In a previous tip we explained how you can use slmgr, a built-in VBScript, to check Windows licensing state. Accessing the Raw Licensing Data in PowerShell The core information used by this VBScript actually comes from WMI, so in PowerShell, you can directly access...

Testing UNC Paths

Tips for Optimizing XML in SQL Server

I’ve worked on a project that used XML heavily inside SQL Server. We really utilized SQL Server’s XML support almost to the full extent, but with some repercussions. As we did our load testing, performance did degrade and we had to step back and adjust how...

Testing UNC Paths

Stripping Decimals Without Rounding

Extracting the Integer Part of a Division Result When you divide numbers and just want the decimals before the decimal point, you could cast the result to integer. However, this would also round the result: PS> 18 / 5 3.6 PS> [Int](18/5) 4 Removing Decimals...

Testing UNC Paths

Removing Multiple White Spaces

Removing multiple white spaces from text is easy in PowerShell. -replace operator Simply use -replace operator and look for whitespaces ("\s") that occur one or more time ("+"), then replace them all with just one whitespace: PS> '[ Man, it works! ]' -replace...