Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
74 lines (56 sloc) 2.2 KB
Configuration Diskinitialization
{
Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
Script Initialize_Disk
{
SetScript =
{
# Start logging the actions
Start-Transcript -Path C:\Temp\Diskinitlog.txt -Append -Force
# Move CD-ROM drive to Z:
"Moving CD-ROM drive to Z:.."
Get-WmiObject -Class Win32_volume -Filter 'DriveType=5' | Select-Object -First 1 | Set-WmiInstance -Arguments @{DriveLetter='Z:'}
# Set the parameters
$disks = Get-Disk | Where-Object partitionstyle -eq 'raw' | Sort-Object number
$letters = 69..89 | ForEach-Object { [char]$_ }
$count = 0
$label = "Data"
"Formatting disks.."
foreach ($disk in $disks) {
$driveLetter = $letters[$count].ToString()
$disk |
Initialize-Disk -PartitionStyle MBR -PassThru |
New-Partition -UseMaximumSize -DriveLetter $driveLetter |
Format-Volume -FileSystem NTFS -NewFileSystemLabel "$label.$count" -Confirm:$false -Force
"$label.$count"
$count++
}
Stop-Transcript
}
TestScript =
{
try
{
Write-Verbose "Testing if any Raw disks are left"
# $Validate = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg' -ErrorAction SilentlyContinue
$Validate = Get-Disk | Where-Object partitionstyle -eq 'raw'
}
catch
{
$ErrorMessage = $_.Exception.Message
$ErrorMessage
}
If (!($Validate -eq $null))
{
Write-Verbose "Disks are not initialized"
return $False
}
Else
{
Write-Verbose "Disks are initialized"
Return $True
}
}
GetScript = { @{ Result = Get-Disk | Where-Object partitionstyle -eq 'raw' } }
}
}
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.