Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#optional
#$Creds = Get-Credential #Credki do VM - moga byc domenowe lub lokalne
$NewVMDiskProps = @{
VMProps = @{
ComputerName = 'HyperV'
VMName = 'VMName1'
}
VHDProps = @(
@{
VHDSize = 100GB
VHDType = 'Dynamic'
NewFileSystemLabel = 'Data'
FileSystem = 'NTFS'
},
@{
VHDSize = 150GB
VHDType = 'Dynamic'
NewFileSystemLabel = 'Data1'
FileSystem = 'NTFS'
}
)
OSName = 'OSName1'
}
foreach ($disk in $NewVMDiskProps.VHDProps) {
$addDiskProps = $NewVMDiskProps.VMProps
$addDiskProps.VHDSize = $disk.VHDSize
$addDiskProps.VHDType = $disk.VHDType
if($creds) {
$addDiskProps.Credential = $creds
}
Add-AHVMDisk @addDiskProps -Verbose
$formatDriveProps = @{
ComputerName = $NewVMDiskProps.OSName
NewFileSystemLabel = $disk.NewFileSystemLabel
FileSystem = $disk.FileSystem
}
if($creds) {
$formatDriveProps.Credential = $creds
}
Format-RemoteDrive @formatDriveProps -Verbose
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment