Category Archives: PowerShell

PowerShell: Read Secure String and Convert Back to Plain Text

Here’s a quick way to read in a secure string and then convert it back to plain text: $SecureString = Read-Host -Prompt "What is the secret?" -AsSecureString $ClearTextString = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString)) Also, take a look at the ConvertTo-SecureString and ConvertFrom-SecureString functions … Continue reading

Posted in PowerShell | Leave a comment

PowerShell: Generate a Pseudo-Random String

Here’s a quick way to generate a pseudo-random string with PowerShell: $Length = 20 $AllowedCharacters = "abcdefghijklmnopqrstuvwxyz0123456789".ToCharArray() $MyRandomString = -join (Get-Random -Count $Length -InputObject $AllowedCharacters) Hope this helps!

Posted in PowerShell | Leave a comment

PowerShell: Parse all Text Files in a Directory for a String Pattern

Here’s a snippet of PowerShell that goes through all files in a directory looking for a string. Those files that match the string pattern are then moved to another directory. Set-Location C:\somewhere Get-ChildItem -Recurse | Select-String -pattern "Delivery Status Notification" … Continue reading

Posted in PowerShell | Leave a comment

PowerShell DSC: Get Product IDs of Installed Products

The PowerShell DSC Package resource requires a ProductId and the exact product name. If you aren’t sure what product id or product name associated with the software you wish to install, you can try this method: Install the software manually … Continue reading

Posted in PowerShell, PowerShell DSC | Leave a comment

Azure: Run Windows Custom Script Extension with VM Credentials

By default, the Windows Custom Script Extension in Azure will run as Local System. Here’s how you can pass your VM credentials from your Azure Resource Manager (ARM) template to the custom script extension and ensure they are not easily … Continue reading

Posted in Azure, PowerShell | Leave a comment

Azure SDK Installation Issues

If you are trying to install the Azure SDK with the Web Platform Installer and the process gets “stuck” on step two, run the following from an administrative command prompt to remove and recreate the SQL localdb instance: Delete the … Continue reading

Posted in Azure, PowerShell | Leave a comment