A Woops–Creating Partition and Format disk using PowerShell does not update the $ share

While moving over to PowerShell one of the tasks is to stop using DISKPART.exe and switch into PowerShell, easy, there are all the commands for it, well it was not easy it turns out. Everything seems to work like expected, but we got an error installing Windows Deployment Services on that disk after it was partitioned and formatted. After digging into Process Monitor for a while we can see that WDS is trying to create folders over the network, in other words it is accessing the hidden disk share E$, which is not possible since that disk is not shared directly. It is marked to be shared but the Server service needs to be restarted. So here is a working script that will create the partition, format the disk AND make sure it is shared correctly to be used

$Disk = Get-Disk -Number 1
Set-Disk -InputObject $Disk -IsOffline $false
Initialize-Disk -InputObject $Disk
New-Partition $Disk.Number -UseMaximumSize -DriveLetter E
Format-Volume -DriveLetter E -FileSystem NTFS -Confirm:$false
Restart-Service Server

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.