Skip to main content

3 posts tagged with "PowerShell"

View All Tags

Configure Azure PowerShell

· 2 min read
Mecken Swyter
Passionate technologist and lifelong learner

Using the Azure Portal to create and manage resources can be beneficial for one-off tasks and learning about different services offered in Azure; however, it becomes more practical to take advantage of a scripting language such as PowerShell for management of tasks as it allows the use of one-liner syntax, piping outputs, and scripting.

info

It is recommended to use PowerShell 7. If not already installed on the management machine, instuctions on installing the latest version of PowerShell 7 can be found here.

Install Azure PowerShell

Navigate to PowerShell, Run as an administrator, and install the Azure PowerShell module using the following command:

Install-Module az -Scope AllUsers -Force

Authenticate to Azure

Authenticate to an Azure tenant. This method will involve the Az PowerShell module opening a web browser window to authenticate with an account that has rights to a Azure subscription.

Connect-AzAccount

The following cmdlets can be useful to confirm the context of the tenant and subscription actively being managed as one account can be used to manage multiple tenants and Azure subscriptions.

Get-AzContext
Get-AzContext -ListAvailable
Get-AzSubscription

Find Azure commands

Here we will use the Get-Command cmdlet to retrieve available cmdlets that contain the Get verb, AzVM contained in the noun, and are apart of the Az.Compute module.

Get-Command -Verb Get -Noun AzVM* -Module Az.Compute
CommandType     Name                                               Version    Source
----------- ---- ------- ------
Alias Get-AzVmssDiskEncryptionStatus 7.1.1 Az.Compute
Alias Get-AzVmssVMDiskEncryptionStatus 7.1.1 Az.Compute
Cmdlet Get-AzVM 7.1.1 Az.Compute
Cmdlet Get-AzVMAccessExtension 7.1.1 Az.Compute
Cmdlet Get-AzVMADDomainExtension 7.1.1 Az.Compute
Cmdlet Get-AzVMAEMExtension 7.1.1 Az.Compute
Cmdlet Get-AzVMBootDiagnosticsData 7.1.1 Az.Compute
Cmdlet Get-AzVMChefExtension 7.1.1 Az.Compute
Cmdlet Get-AzVMCustomScriptExtension 7.1.1 Az.Compute
Cmdlet Get-AzVMDiagnosticsExtension 7.1.1 Az.Compute
Cmdlet Get-AzVMDiskEncryptionStatus 7.1.1 Az.Compute
Cmdlet Get-AzVMDscExtension 7.1.1 Az.Compute
Cmdlet Get-AzVMDscExtensionStatus 7.1.1 Az.Compute
Cmdlet Get-AzVMExtension 7.1.1 Az.Compute
Cmdlet Get-AzVMExtensionImage 7.1.1 Az.Compute
Cmdlet Get-AzVMExtensionImageType 7.1.1 Az.Compute
Cmdlet Get-AzVMImage 7.1.1 Az.Compute
Cmdlet Get-AzVMImageOffer 7.1.1 Az.Compute
Cmdlet Get-AzVMImagePublisher 7.1.1 Az.Compute
Cmdlet Get-AzVMImageSku 7.1.1 Az.Compute
Cmdlet Get-AzVMRunCommand 7.1.1 Az.Compute
Cmdlet Get-AzVMRunCommandDocument 7.1.1 Az.Compute
Cmdlet Get-AzVMSize 7.1.1 Az.Compute
Cmdlet Get-AzVMSqlServerExtension 7.1.1 Az.Compute
Cmdlet Get-AzVmss 7.1.1 Az.Compute
Cmdlet Get-AzVmssDiskEncryption 7.1.1 Az.Compute
Cmdlet Get-AzVmssRollingUpgrade 7.1.1 Az.Compute
Cmdlet Get-AzVmssSku 7.1.1 Az.Compute
Cmdlet Get-AzVmssVM 7.1.1 Az.Compute
Cmdlet Get-AzVmssVMDiskEncryption 7.1.1 Az.Compute
Cmdlet Get-AzVmssVMRunCommand 7.1.1 Az.Compute
Cmdlet Get-AzVMUsage 7.1.1 Az.Compute

Configure Active Directory using PowerShell

· One min read
Mecken Swyter
Passionate technologist and lifelong learner
New-Item -Path "c:\" -Name "PowerLab" -ItemType "directory"
'P@$$w0rd12' | ConvertTo-SecureString -Force -AsPlainText | Export-Clixml -Path C:\PowerLab\SafeModeAdministratorPassword.xml

$safeModePw = Import-Clixml -Path C:\PowerLab\SafeModeAdministratorPassword.xml

Install-windowsfeature -Name AD-Domain-Services

$forestParams = @{
DomainName = 'techuplab.local'
DomainMode = 'WinThreshold'
ForestMode = 'WinThreshold'
Confirm = $false
SafeModeAdministratorPassword = $safeModePw
WarningAction = 'Ignore'
}

$null = Install-ADDSForest @forestParams

Configure Storage Spaces Direct (S2D)

· 3 min read
Mecken Swyter
Passionate technologist and lifelong learner

In this guide we will be configuring Storage Spaces Direct (S2D) on a 2-node Windows Failover Cluster. This Home Lab consists of 2 HP EliteDesk 800 35W G3 Desktop Mini PCs.

note

In this scenario, we only have 2 physical machines available for our lab, and Failover Cluster nodes must be joined to a domain. Initially, each node was made a domain controller - and this is a supported scenario with Windows Failover Cluster; however, it was discovered that Storage Spaces Direct can not be configured on domain controllers.

To circumvent this, we will create a domain controller as a VM using Hyper-V on the physical machine, join the nodes to the domain, then later on move the VM(s) to the cluster for high availability.

info

If Hyper-V hasn't already been enabled, it can be enabled running the cmdlet below in PowerShell as an Administrator.

PowerShell
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart

Step 1: Configure Windows Failover Cluster

  1. Install the Windows Failover Cluster feature
PowerShell
Install-WindowsFeature –Name Failover-Clustering –IncludeManagementTools
  1. Validate the cluster nodes to confirm all hardware is ready for Failover Clustering and Storage Spaces Direct.
PowerShell
Test-Cluster -Node hci-svr1, hci-svr2 -Include "Storage Spaces Direct", Inventory, Network, "System Configuration"
note

Warnings are to be expected - especially if using consumer grade hardware as in this lab. As long as the validation does not report any failures, the cluster and S2D storage pool shouldn't have any problems being created.

tip

In this lab scenario, the disks to be included in the Storage Spaces Direct storage pool had to be unallocated with no form of partitioning or files systems before the disks became eligible.

  1. Create the cluster and assign an IP address. Do not attach storage to the cluster - this will be configured in a subsequent step using Storage Spaces Direct.
PowerShell
New-Cluster -Name S2DCluster -Node hci-svr1, hci-svr2 -NoStorage -StaticAddress 192.168.10.14

Step 2: Create an S2D storage pool and add eligible disks

  1. Enable an S2D cluster.
PowerShell
Enable-ClusterS2D -CacheState Disabled -Autoconfig:0 -SkipEligibilityChecks -Confirm:$false

This Cmdlet is disabling the S2D caching functionality, declining the autoconfig, and skipping any eligibility checks. This deployment does not support the minimum number of disks to enable caching; however, in an all NVMe deployment, it would be recommended to disable caching anyway as it is best utilized when there is a mix of different types of drives.

  1. Create a Storage Pool
PowerShell
New-StoragePool -StorageSubSystemName S2DCluster.techuplab.local -FriendlyName S2DStoragePool -ProvisioningTypeDefault Fixed -ResiliencySettingNameDefault Mirror -PhysicalDisks (Get-StorageSubSystem -Name S2DCluster.techuplab.local | Get-PhysicalDisk)
  1. Create a Cluster Shared Volume (CSV).
PowerShell
New-Volume -StoragePoolFriendlyName S2DStoragePool -FriendlyName "CSV2" -FileSystem CSVFS_ReFS -Size 100GB

We can now create a VM using the CSV and add it as a Role in the Failover Cluster to make it highly available.