Category Archives: PowerShell

PowerShell: Extract Files from Zip Archive

Here’s a quick PowerShell snippet to extract files from a .zip archive: Add-Type -Assembly System.IO.Compression.FileSystem   $PathToZipFile = "C:\temp\myarchive.zip" $ExtractPattern = "*.log" $ExtractDirectory = "C:\temp\extracted"   New-Item -ItemType Directory -Path $ExtractDirectory -Force | Out-Null   $ZipFile = [IO.Compression.ZipFile]::OpenRead($PathToZipFile) $ZipFile.Entries | … Continue reading

Posted in PowerShell | Leave a comment

Azure PowerShell: Copy All Files in Blob Storage to Local Directory

Here’s a Azure PowerShell script that downloads all blobs in a storage container to your local disk:   $storageAccountName = "mysuperstorage" $containerName = ‘my-blobs’ $destinationFolder = ‘C:\temp\my-blobs’   New-Item -ItemType Directory -Force -Path $destinationFolder   Login-AzureRmAccount   $storageAccountContext = (Get-AzureRmStorageAccount … Continue reading

Posted in Azure, PowerShell | Leave a comment

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 | 1 Comment