Windows PowerShell: “… .ps1 cannot be loaded because running script is disabled on this system, for more information see about_Execution_Policies at….”

The Error

When executing some PowerShell scripts, this error comes up.

… .ps1 cannot be loaded because running script is disabled on this system, for more information see about_Execution_Policies at https://go,microsoft.com/fwlink/?LinkID=135170

The Fix

1 Enter following command then hit Enter key in PowerShell

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted

2 Enter Y or A to continue when prompted.

3 Now we can run the script again, this time there should be no error returned.


Linux Bash/Shell simple, basic flow control

“if else” and pass variable to the script

if [condition]
 then
     //if block code
 else
     // else block code
 fi
#!/bin/bash
# https://dannyda.com
if [ $1 == $2 ];then
	echo "Numbers are equal ("$1" = "$2")"
elif [ $1 -gt $2 ];then
	echo "1st Number is greater than 2nd Number ("$1" > "$2")"
elif [ $1 -lt $2 ];then
	echo "1st Number is smaller than 2nd Number ("$1" < "$2")"
else
	echo "error"
fi
if else, pass variables to script
if else, pass variables to script

for Loop

for [var] in [list]
do
    //command1
    //command2
done
#!/bin/bash
# https://dannyda.com
for variable in 1 2 3 4 $(echo 7)
do
	echo "The value is: $variable"
done
for i in {1..3}
do
	echo "Loop $i times"
done
echo "2 Done"
echo
for i in {0..10..2}
do 
	echo "Step of 2, $i times"
done
echo "3 Done"
echo
for loop
for loop

while Loop

while [condition]
do
    //command1
    //command2
done
while [condition]; do commands; done
#!/bin/bash
# https://dannyda.com
i=0
while [[ $i<5 ]]
do
    echo $i
    let "i++"
done
echo "Job Done"
echo
i=0
while [[ $i<5 ]]; do echo $1 $((i++)); done
while loop
while loop

while Loop with input (Interactive script)

while read [condition]
do
    //command1
    //command2
done
#!/bin/bash
# https://dannyda.com
echo '<CTRL-D> to exit'
while read input
do
	echo "The number is $input"
done
while with input (interactive script)
while with input (interactive script)

until Loop

Until loop is opposite to while loop, it execute the given commands as long as the given condition evaluates is false

until [condition]
do
    //command1
    //command2
done
#!/bin/bash
# https://dannyda.com
i=0
until [ $i -gt 5 ]
do
  echo Counter: $i
  ((i++))
done
echo "-----------"
i=0
while [ $i -lt 6 ]
do
  echo Counter: $i
  ((i++))
done
until loop
until loop

Infinite while Loop

Use Ctrl + C to stop/exit the loop

while true
do
    //command1
    //command2
done
#!/bin/bash
# https://dannyda.com
while true
do
	echo a
done
infinite while loop
infinite while loop

Infinite for Loop

Use Ctrl + C to stop/exit the loop

for (( ; ; ))
do
    //command1
    //command2
done

infinite for loop
infinite for loop

Options/Case/Switch/Select Case

case  $variable  in
     pattern1)
         command1
         command2
         …
         ….
     ;;
     pattern2)
         command1
         command2
         …
         ….
     ;;
     patternN)
         command1
         command2
         …
         ….
     ;;
     *)
         command1
         command2
         …
         ….
 esac
case  $variable  in
     pattern1|pattern2|pattern3)
         command1
         command2
         …
         ….
     ;;
     pattern4|pattern5|pattern6)
         command1
         command2
         …
         ….
     ;;
     pattern7|pattern8|patternN)
         command1
         command2
         …
         ….
     ;;
     *)
         command1
         command2
         …
         ….
 esac
esacThe EOF for case
)the end of the pattern
*)Else, if doesn’t match anything
;;The end of current case clause
#!/bin/bash
# https://dannyda.com
case $1 in
    a) echo 'Case a'
    ;;
    b) echo 'Case b'
    ;;
    3) echo 'Case 3'
    ;;
    *) echo 'Not Case a or Case b or Case 3'
    ;;
esac
Case
Case

How to: Add/Remove Windows Autopilot devices (And assign group – Windows Autopilot deployment profiles)

Table of contents

  1. Method 1 – Via Microsoft Endpoint Manager admin center
  2. Method 2 – via Microsoft Store for Business
  3. Creating the CSV file
  4. *Bonus – Groups (Windows Autopilot deployment profiles)

Method 1 – Via Microsoft Endpoint Manager admin center

1.1 Navigate to Microsoft Endpoint Manager admin center or Endpoint Management

1.1.1 Login to Microsoft 365 admin center

1.1.2 Click on “Endpoint Management” to open “Microsoft Endpoint Manager admin center” or use this link: https://devicemanagement.microsoft.com/

Microsoft 365 admin center menu - Endpoint Management
Microsoft 365 admin center menu – Endpoint Management

1.1.3 Navigate to “Devices -> Enroll devices -> Windows Enrollment -> Devices”

Microsoft Endpoint Manager admin center - Devices Overview
Microsoft Endpoint Manager admin center – Devices Overview
Microsoft Endpoint Manager admin center - Enroll deices Windows enrollment
Microsoft Endpoint Manager admin center – Enroll deices Windows enrollment

1.2 Click on “Import” button

Microsoft Endpoint Manager admin center - Enroll deices Windows enrollment - Windows Autopilot devices
Microsoft Endpoint Manager admin center – Enroll deices Windows enrollment – Windows Autopilot devices

1.3 It will ask for an CSV file containing

Microsoft Endpoint Manager admin center - Enroll deices Windows enrollment - Windows Autopilot devices - Add Windows Autopilot devices
Microsoft Endpoint Manager admin center – Enroll deices Windows enrollment – Windows Autopilot devices – Add Windows Autopilot devices

1.4 Proceed to Section 3 to generate the CSV file then come back to step 1.3 to upload the CSV file

1.5 Now we can assign group for the device by using Group Tag. (Group needs to be created first in order to assign)

Microsoft Endpoint Manager admin center - Enroll deices Windows enrollment - Windows Autopilot devices - Device properties
Microsoft Endpoint Manager admin center – Enroll deices Windows enrollment – Windows Autopilot devices – Device properties

Method 2 – via Microsoft Store for Business

2.1 Login to Microsoft Store for Business: https://businessstore.microsoft.com/ with administrator account

2.2 Proceed to Section 3 to generate the CSV file then come back to continue with step 2.3 to upload the CSV file

2.3 Navigate to “Devices”, click on “+ Add devices” button

Microsoft Store for Business -> Deices
Microsoft Store for Business -> Deices

2.4 Now we can assign group for the device by using “AutoPilot deployment” button (Group needs to be created first in order to assign)

3 Creating the CSV file

Microsoft Doc -> “Adding devices to Windows Autopilot” “Enroll Windows devices in Intune by using the Windows Autopilot” indicates that using following PowerShell script (Save to get-hwidinfo.ps1, then execute it with PowerShell in admin mode) will save required information in “C:\HWID\AutoPilotHWID.csv”

md c:\HWID
Set-Location c:\HWID
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted
Install-Script -Name Get-WindowsAutoPilotInfo
Get-WindowsAutoPilotInfo.ps1 -OutputFile AutoPilotHWID.csv

What happen is, it may fail at first and at the last step. Here is the fix.

If it’s saying File X:\get-hwidinfo.ps1 cannot be loaded because running script is disabled on this system, for more information see about_Execution_Policies at https://go,microsoft.com/fwlink/?LinkID=135170

Follow this post to resolve it: Windows PowerShell: “… .ps1 cannot be loaded because running script is disabled on this system, for more information see about_Execution_Policies at….”

If getting another error try following Workaround.

The Workaround

3.1 Save the following PowerShell script to “get-hwidinfo.ps1” then execute in PowerShell in admin mode

md c:\HWID
Set-Location c:\HWID
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted
Install-Script -Name Get-WindowsAutoPilotInfo
Get-WindowsAutoPilotInfo.ps1 -OutputFile AutoPilotHWID.csv

3.2 If it fails to output csv file in C:\HWID, save following script to “C:\HWID\Get-WindowsAutoPilotInfo.ps1” (This is version 1.6 not 1.4) (To copy the code, double click the code to select all)

<#PSScriptInfo
 
.VERSION 1.4
 
.GUID ebf446a3-3362-4774-83c0-b7299410b63f
 
.AUTHOR Michael Niehaus
 
.COMPANYNAME Microsoft
 
.COPYRIGHT
 
.TAGS Windows AutoPilot
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
Version 1.0: Original published version.
Version 1.1: Added -Append switch.
Version 1.2: Added -Credential switch.
Version 1.3: Added -Partner switch.
Version 1.4: Switched from Get-WMIObject to Get-CimInstance.
 
#>
<#
.SYNOPSIS
Retrieves the Windows AutoPilot deployment details from one or more computers
.DESCRIPTION
This script uses WMI to retrieve properties needed by the Microsoft Store for Business to support Windows AutoPilot deployment.
.PARAMETER Name
The names of the computers. These can be provided via the pipeline (property name Name or one of the available aliases, DNSHostName, ComputerName, and Computer).
.PARAMETER OutputFile
The name of the CSV file to be created with the details for the computers. If not specified, the details will be returned to the PowerShell
pipeline.
.PARAMETER Append
Switch to specify that new computer details should be appended to the specified output file, instead of overwriting the existing file.
.PARAMETER Credential
Credentials that should be used when connecting to a remote computer (not supported when gathering details from the local computer).
.PARAMETER Partner
Switch to specify that the created CSV file should use the schema for Partner Center (using serial number, make, and model).
.EXAMPLE
.\Get-WindowsAutoPilotInfo.ps1 -ComputerName MYCOMPUTER -OutputFile .\MyComputer.csv
.EXAMPLE
.\Get-WindowsAutoPilotInfo.ps1 -ComputerName MYCOMPUTER -OutputFile .\MyComputer.csv -Append
.EXAMPLE
.\Get-WindowsAutoPilotInfo.ps1 -ComputerName MYCOMPUTER1,MYCOMPUTER2 -OutputFile .\MyComputers.csv
.EXAMPLE
Get-ADComputer -Filter * | .\GetWindowsAutoPilotInfo.ps1 -OutputFile .\MyComputers.csv
.EXAMPLE
Get-CMCollectionMember -CollectionName "All Systems" | .\GetWindowsAutoPilotInfo.ps1 -OutputFile .\MyComputers.csv
.EXAMPLE
.\Get-WindowsAutoPilotInfo.ps1 -ComputerName MYCOMPUTER1,MYCOMPUTER2 -OutputFile .\MyComputers.csv -Partner
 
#>
[CmdletBinding()]
param(
    [Parameter(Mandatory=$False,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True,Position=0)][alias("DNSHostName","ComputerName","Computer")] [String[]] $Name = @("localhost"),
    [Parameter(Mandatory=$False)] [String] $OutputFile = "", 
    [Parameter(Mandatory=$False)] [Switch] $Append = $false,
    [Parameter(Mandatory=$False)] [System.Management.Automation.PSCredential] $Credential = $null,
    [Parameter(Mandatory=$False)] [Switch] $Partner = $false,
    [Parameter(Mandatory=$False)] [Switch] $Force = $false
)
Begin
{
    # Initialize empty list
    $computers = @()
}
Process
{
    foreach ($comp in $Name)
    {
        $bad = $false
        # Get a CIM session
        if ($comp -eq "localhost") {
            $session = New-CimSession
        }
        else
        {
            $session = New-CimSession -ComputerName $comp -Credential $Credential
        }
        # Get the common properties.
        Write-Verbose "Checking $comp"
        $serial = (Get-CimInstance -CimSession $session -Class Win32_BIOS).SerialNumber
        # Get the hash (if available)
        $devDetail = (Get-CimInstance -CimSession $session -Namespace root/cimv2/mdm/dmmap -Class MDM_DevDetail_Ext01 -Filter "InstanceID='Ext' AND ParentID='./DevDetail'")
        if ($devDetail -and (-not $Force))
        {
            $hash = $devDetail.DeviceHardwareData
        }
        else
        {
            $bad = $true
            $hash = ""
        }
        # If the hash isn't available, get the make and model
        if ($bad -or $Force)
        {
            $cs = Get-CimInstance -CimSession $session -Class Win32_ComputerSystem
            $make = $cs.Manufacturer.Trim()
            $model = $cs.Model.Trim()
            if ($Partner)
            {
                $bad = $false
            }
        }
        else
        {
            $make = ""
            $model = ""
        }
        # Getting the PKID is generally problematic for anyone other than OEMs, so let's skip it here
        $product = ""
        # Depending on the format requested, create the necessary object
        if ($Partner)
        {
            # Create a pipeline object
            $c = New-Object psobject -Property @{
                "Device Serial Number" = $serial
                "Windows Product ID" = $product
                "Hardware Hash" = $hash
                "Manufacturer name" = $make
                "Device model" = $model
            }
            # From spec:
            #    "Manufacturer Name" = $make
            #    "Device Name" = $model
        }
        else
        {
            # Create a pipeline object
            $c = New-Object psobject -Property @{
                "Device Serial Number" = $serial
                "Windows Product ID" = $product
                "Hardware Hash" = $hash
            }
        }
        # Write the object to the pipeline or array
        if ($bad)
        {
            # Report an error when the hash isn't available
            Write-Error -Message "Unable to retrieve device hardware data (hash) from computer $comp" -Category DeviceError
        }
        elseif ($OutputFile -eq "")
        {
            $c
        }
        else
        {
            $computers += $c
        }
        Remove-CimSession $session
    }
}
End
{
    if ($OutputFile -ne "")
    {
        if ($Append)
        {
            if (Test-Path $OutputFile)
            {
                $computers += Import-CSV -Path $OutputFile
            }
        }
        if ($Partner)
        {
            $computers | Select "Device Serial Number", "Windows Product ID", "Hardware Hash", "Manufacturer name", "Device model" | ConvertTo-CSV -NoTypeInformation | % {$_ -replace '"',''} | Out-File $OutputFile
            # From spec:
            # $computers | Select "Device Serial Number", "Windows Product ID", "Hardware Hash", "Manufacturer Name", "Device Name" | ConvertTo-CSV -NoTypeInformation | % {$_ -replace '"',''} | Out-File $OutputFile
        }
        else
        {
            $computers | Select "Device Serial Number", "Windows Product ID", "Hardware Hash" | ConvertTo-CSV -NoTypeInformation | % {$_ -replace '"',''} | Out-File $OutputFile
        }
    }
}

3.3 Launch PowerShell in admin mode, use following command to generate the csv file for the device

cd C:\HWID
.\Get-WindowsAutoPilotInfo.ps1-OutputFile AutoPilotHWID.csv

3.4 Now we should be able to see an “AutoPilotHWID.csv” file at “C:\HWID\AutoPilotHWID.csv”

4 *Bonus – Groups (Windows Autopilot deployment profiles)

Autopilot deployment profiles are used to configure the Autopilot devices. You can create up to 350 profiles per tenant.

To Create Profile, follow Step 1.1 to Step 1.1.3 (Instead of click on “Devices” click on “Deployment Profiles”)

For more information on different kind of settings for Profiles refer to Enroll Windows devices in Intune by using the Windows Autopilot

Resources:


How to: Hide/Show Office 365 group from GAL and other address lists using PowerShell

1 Login to Office 365 via PowerShell by following this guide: How to: Connect PowerShell to Office 365 Exchange with Multi-factor authentication (MFA) enabled

2 Use following PowerShell command to hide Office 365 group.

Set-UnifiedGroup -identity "Group Name" -HiddenFromExchangeClientsEnabled:$true

To show Office 365 group in GAL and other address lists use the following command

Set-UnifiedGroup -identity "Group Name" -HiddenFromExchangeClientsEnabled:$false

(The default value is $false, which means show in GAL and other address lists)

Extended Reading

Set-UnifiedGroup

Windows PowerShell change Hard Drive/Media type for Windows Server Storage Space / Storage Pool

1 List all physical disks

Get-PhysicalDisk
Microsoft PowerShell - Get-PhysicalDisk
Microsoft PowerShell – Get-PhysicalDisk

2 If you have multiple physical disks with same name use following command

Get-PhysicalDisk | Select-Object SerialNumber,UniqueId, FriendlyName
Microsodr PowerShell - Get-PhysicalDisk | Select-Object SerialNumber,UniqueId, FriendlyName
Microsodr PowerShell – Get-PhysicalDisk | Select-Object SerialNumber,UniqueId, FriendlyName

3 Find the right “UniqueId” for the physical disk which you want to changedrive/media type for

4 Change the hard drive/media type

For systems with physical disks without same name

Set-PhysicalDisk –FriendlyName "PhysicalDisk6" -MediaType SSD

For systems with physical disks with same name

Set-PhysicalDisk –UniqueId "{016ag017-1cd2-81-mugf-26j28503l5vb}" -MediaType SSD

Bonus

-MediaType: Accepted values: HDD, SSD, SCM

Extra Reading

Set-PhysicalDisk

Use PowerShell to Create Virtual Disk on Windows Storage Pool/Storage Space with specific number of columns

PowerShell

New-VirtualDisk -StoragePoolFriendlyName "Existing Pool Name" -FriendlyName "Name for new virtual disk" -ResiliencySettingName Mirror -Size 10TB -ProvisioningType Fixed -NumberOfColumns 2
ParamaterDescription
-StoragePoolFriendlyNameYour existing pool’s friendly name which you want to create virtual disk on
-FriendlyNameA friendly name you want to give for new virtual disk
-ResiliencySettingNameResiliency type to use: Simple, Mirror, Parity
-SizeSize you want to assign to the new virtual disk
-ProvisioningTypeFixed or Thin
-NumberOfColumnsNumber of columns

Generally, Mirror has better performance than Parity but least storage efficient, Simple has best performance but no redundancy at all. If you have enough physical disks in the storage pool, 2 – 4 columns will give you great performance. Keep in mind that when increasing pool capacity, you can usually achieve optimal pool capacity utilization when you add disks in multiples of the number of disks the storage space needs.

Controlling the Number of Columns

Controlling the Number of Columns
Controlling the Number of Columns

Extended reading:

New-VirtualDisk

Controlling the number of columns


Windows Server Storage Space/Storage Pool Reattach straightway after physical disk retired

Only reattach if you are sure the physical is in good working condition, if not, you really should replace the physical disk for the Storage Pool

See this guide for replacing disk: How to fix: Windows Storage Space/Storage Pool physical disk lost communication, replace dead physical disk

1 Launch PowerShell in admin mode

2 Use “Get-PhysicalDisk” to list all physical disks

Get-PhysicalDisk

3 Use “Get-PhysicalDisk | Select-Object SerialNumber,UniqueID” to get serial number of the physical disk (It’s very useful when you have multiple physical disks with same name)

Get-PhysicalDisk | Select-Object SerialNumber,UniqueID

4 Use “Set-PhysicalDisk -UniqueID “{SerialNumber}” -Usage AutoSelect” to reattach the physical disk

Set-PhysicalDisk -UniqueID "{4a5bbag5-cc77-01ab-a8ba-520c1af8885b}" -Usage AutoSelect

5 Use “Repair-VirtualDisk -FriendlyName ‘Name of the virtual disk within the pool'” to repair the virtual disk

Repair-VirtualDisk -FriendlyName 'Name of the virtual disk within the pool'

6 Use “Optimize-StoragePool -FriendlyName “Pool Name”” to optimize the storage pool

Optimize-StoragePool -FriendlyName "Pool Name"

Configure Squid proxy with php redirector

Squid proxy can be used with different redirectors and rewriters, in this guide we will be using a redirector written with php.

This guide is using Ubuntu 18.04 LTS, your configuration file maybe located differently if using different version or Linux distribution etc.

Note: Before starting following this guide, you have to make sure your squid proxy is configured properly and running without any issue.

Squid configuration

1 Open squid configuration file from

/etc/squid/squid.conf

or

/etc/squid3/squid.conf

For following steps, make sure you are using right path/configuration file (either /squid/ or /squid3/), I will be using /squid/

2 Add following line

url_rewrite_program /usr/bin/php /etc/squid/redirect.php

This indicates that we will be using an redirector/ url write program written in php so that we will need php binary to run the script thus “/usr/bin/php” the redorector file path is “/etc/squid/redirect.php” which means will be putting the “redirect.php” file under “/etc/squid”

PHP url rewrite program/redirector

1 We create a “redirect.php” file under “/etc/squid/”

2 We write necessary script

#!/usr/bin/php
<?php
//By https://dannyda.com
//Modified based on
//http://wiki.squid-cache.org/ConfigExamples/PhpRedirectors
//Using PHP for Redirects
 
//and
 
//https://aacable.wordpress.com/tag/squid-url-redirection/
//------------------------------------------------------------------------------
$temp = array();
// Extend stream timeout to 24 hours
stream_set_timeout(STDIN, 86400);
while ( $input = fgets(STDIN) ) {
  // Split the output (space delimited) from squid into an array.
  $temp = explode(' ', $input);
  // Set the URL from squid to a temporary holder.
  $output = $temp[0] . "\n";
	if(preg_match("/(.*[0-9])\/ABCD\/.*/i", $input)){
		//Replace any url matching xxx.xxx.xxx.xxx/ABCD/aaaaaaaaaaaaaaaaaaaaaa and change to to my.blocked.com/ABCD/aaaaaaaaaaaaaaaaaaaaaa
		$output = "308:".str_replace(parse_url($input,PHP_URL_HOST),'my.blocked.com',strtok($input, ' '))."\n"; //Outout intended modified url (308 Permanent Redirect)
		//file_put_contents("/etc/squid/a.txt", $input,FILE_APPEND); //For debugging we can enable this line, output will be found at /etc/squid/a.txt
		//$output = "302:"."http://www.google.com/"."\n"; //(302 Found, Moved Temporarily)
		
		//We can either output modified url based on ip address, partial url matching, domain matching and modify partialy as well or we can redirect to another url completely
		//Following by more examples
	}
	
	if(preg_match("/(.*[0-9])\/forum\/.*\/sign\=.*\.jpg/i", $input)){
		$output = "308:".str_replace(parse_url($input,PHP_URL_HOST),'mytestforum.com',strtok($input, ' '))."\n";
		// /forum/*/sign
	}
	
	if(preg_match("/(.*[0-9])\/forum\/pic\/item\/.*\.jpg/i", $input)){
		$output = "308:".str_replace(parse_url($input,PHP_URL_HOST),'mytestforum.com',strtok($input, ' '))."\n";
		// /forum/pic/item
	}
	//---------------------------------------------------------------------------
	//Temporarily block URLs based on partial url match with regular expression
	if(preg_match("/ad\.m\.domain\.com(\/.*|$)/i", $input)){
		$output = "308:"."http://255.255.255.255"."\n";
		//adash.m.taobao.com
	}
	if(preg_match("/.*admaster\.com.*/i", $input)){
		$output = "308:"."http://255.255.255.255"."\n";
		//*.admaster.com.cn
	}
	
	if(preg_match("/.*\/AdvertiseInterface\//i", $input)){
		$output = "308:"."http://255.255.255.255"."\n";
		//ad
		//http://albatrosscn.buddylync.com:8080/AdvertiseInterface/
	}
	
	if(preg_match("/.*\/advertise\//i", $input)){
		$output = "308:"."http://255.255.255.255"."\n";
		//ad
		//http://*/advertise/
	}
	
  echo $output;
}

3 We add execute permission

chmod +x /etc/squid/redirect.php

4 We restart squid

~# systemctl restart squid

5 Now we should be able to see the redirector in action

Extended reading

Bonus

Online regular expression testers

Which can help you craft desired regular expression for use within redirector

How to fix: Windows Storage Space/Storage Pool, Virtual Disk not attaching automatically on reboot

1 Launch PowerShell from start menu or “Run” window with admin privilege

2 Use following command to check “-IsManualAttach” attribute

Get-VirtualDisk | Select-Object IsManualAttach

Or use following command to show all virtual disks with “IsManualAttach” attributes

Get-VirtualDisk | Where-Object {$_.IsManualAttach –eq $True}
Windows PowerShell -  Get-VirtualDisk | Select-Object IsManualAttach
Windows PowerShell – Get-VirtualDisk | Select-Object IsManualAttach

3 Use following command to set “IsManualAttach” to false, so that it will attach on reboot

Set-VirtualDisk -FriendlyName "virtual disk name" -IsManualAttach 0

e.g.

Set-VirtualDisk -FriendlyName "my virtual disk" -IsManualAttach 0

Or to use following command to change all virtual disks to auto attach on reboot

Get-VirtualDisk | Where-Object {$_.IsManualAttach –eq $True} | Set-VirtualDisk –IsManualAttach $False

How to: Check Windows Storage Space, Storage pool virtual disk Columns

Using PowerShell

Get-VirtualDisk "name of the virtual disk" | Select-Object *

To get general information, use following command instead

Get-VirtualDisk "name of the virtual disk"

Using Server Manager

1 Launch Windows “Server Manager”

2 In Windows Server 2019, navigate to “Server Manager -> File and Storage Services -> Storage Pools -> Virtual Disks”

3 Right click on the virtual disk, select “Property”

4 Click on “Details”

5 Select “NumberOfColumns” from “Property:”

6 The number of columns will be displayed underneath.

Note

If after rebooting, virtual disks are not attaching automatically, follow this guide to make them auto attach on reboot.