New Question
0

Confirmation pop-up when executing Format-Partition [CloudBase-Init 1.1.6, Windows Server 2019]

asked 2025-01-14 07:35:41 +0200

aenagy gravatar image

I have a CloudBase-Init that includes the following line of PowerShell:

Get-Disk | Where-Object PartitionStyle -Eq "RAW" | Initialize-Disk -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -NewFileSystemLabel "DATA" -FileSystem NTFS -Force

During deployment autologon logs in and I see the following pop-up:

Title: Microsoft Windows
Body:
You need to format the disk in drive E: before you can use it.
Do you want to format it?
[Format disk] [Cancel]

When installing CloudBase-Init I specified that it should run as system. In the same code block as above I output whoami /all to a text file and can confirm that the username is nt authority\system. If I run the above PowerShell after deployment as local Admin I don't get any pop-up or prompts -- it just executes.

How do I fix this?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2025-01-15 05:21:56 +0200

aenagy gravatar image

I posted this question thinking that had encountered a permission or elevated privilege problem. It seems that this is natural behaviour for 'Format-Volume'. The following code snippet is based on a solution from StackOverflow and does not generate the pop-up. This code has been modified to format multiple additional disks.

[char]$highestDriveLetterInUse = ( ( Get-Volume ).DriveLetter | Sort-Object -Descending )[0]
[char]$nextDriveLetter = [int]$highestDriveLetterInUse + 1
[int]$dataDiskCount = 1
$rawDiskList = Get-Disk | Where-Object PartitionStyle -eq "RAW"
$rawDiskList | Format-Table -AutoSize
foreach( $rawDisk in $rawDiskList ){
  # https://stackoverflow.com/a/42622812/8469997
  Initialize-Disk -Number $rawDisk.Number -PartitionStyle MBR -confirm:$false
  if ( 1 -eq $rawDiskList.Length ){ $fileSystemLabel = "Data" } else { $fileSystemLabel = "Data_${dataDiskCount}" }
  New-Partition -DiskNumber $rawDisk.Number -UseMaximumSize -IsActive | Format-Volume -FileSystem NTFS -NewFileSystemLabel $fileSystemLabel -confirm:$False  
  Set-Partition -DiskNumber $rawDisk.Number -PartitionNumber 1 -NewDriveLetter $nextDriveLetter
  [char]$nextDriveLetter = [int]$nextDriveLetter + 1
}

Formatting a disk using PowerShell without prompting for confirmation https://stackoverflow.com/a/42622812/...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2025-01-14 07:35:41 +0200

Seen: 21 times

Last updated: 12 hours ago