Skip to content

Instantly share code, notes, and snippets.

@mczerniawski
Created December 21, 2018 14:23
Show Gist options
  • Save mczerniawski/b3ef3c684d83f78013890169d2d41b23 to your computer and use it in GitHub Desktop.
Save mczerniawski/b3ef3c684d83f78013890169d2d41b23 to your computer and use it in GitHub Desktop.
#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