Monthly Archives: August 2016

PowerShell: Initialize Raw Disk, Partition, Assign Drive Letter and Format

Here’s a quick script that initializes a raw disk, then partitions, assigns a drive letter, and formats the drive with NTFS. Get-Disk | ` Where PartitionStyle -eq ‘RAW’ | ` Initialize-Disk -PartitionStyle MBR -PassThru | ` New-Partition -AssignDriveLetter -UseMaximumSize | … Continue reading

Posted in PowerShell | Leave a comment

T-SQL: Count of Tables, Stored Procedures, and Functions in All User Databases

This query uses the undocumented Microsoft stored procedure master.sys.sp_MSforeachdb to iterate over all user databases (user databases always start with IDs > 4) and count the number of tables, stored procedures and functions. You can use this same pattern to … Continue reading

Posted in T-SQL | Leave a comment

PowerShell DSC: Script Resources to Download and Install .Net 4.6.2

Here’s a snippet from a PowerShell Desired State Configuration file that uses a Script Resource to download and install the .Net Framework 4.6.2. You can incorporate this into an existing DSC configuration file to ensure .Net 4.6.2 is installed. …. … Continue reading

Posted in PowerShell, PowerShell DSC | Leave a comment

Azure PowerShell: Set Custom Script Extension on VM

Here’s a script that sets/runs an existing custom script extension on a VM in Azure: $ResourceGroupName = "MyResourceGroup" $StorageAccountName = "mystorage" $VmName = "MyWinVm01"   $ExtensionName = "TestScriptExtension" $ExtensionContainerName = "extensions" $ExtensionFileName = "test\TestScriptExtension.ps1"   $ResourceGroupLocation = (Get-AzureRmResourceGroup -Name $ResourceGroupName)[0].Location … Continue reading

Posted in Azure, PowerShell | Leave a comment

Azure PowerShell: Copy Local File to Blob Storage

Here’s a simple script that copies a local file to Azure blob storage: $ResourceGroupName = "MyResourceGroup" $StorageAccountName = "mysstorageaccount" $File = "C:\TestExtension.ps1" $Container = "extensions" $Blob = "test\TestExtension.ps1"   $StorageAccountKey = (Get-AzureRmStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageAccountName)[0].Value $StorageContext = New-AzureStorageContext –StorageAccountName … Continue reading

Posted in Azure, PowerShell | Leave a comment

Azure PowerShell: Attach New Data Disk to Existing VM

Here’s a script that attaches a new data disk to an existing VM in Azure. It determines the appropriate LUN based on the existing data disks associated to the VM. $ResourceGroupName = "MyResourceGRoup" $StorageAccountName = "mysstorageaccount" $VmName = "vm01" $DiskSizeInGB … Continue reading

Posted in Azure, PowerShell | Leave a comment