iNNOKENTIY21
Silver Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
Код: 1 class MountedDiskImage { 2 # Файл образа диска 3 [Parameter(Mandatory)] 4 [ValidateNotNullOrEmpty()] 5 [Alias("FullName")] 6 [IO.FileInfo] 7 $Path 8 9 [Parameter(Mandatory)] 10 [ValidateNotNullOrEmpty()] 11 [Microsoft.Management.Infrastructure.CimInstance] 12 $Image 13 14 [Parameter(Mandatory)] 15 [ValidateNotNullOrEmpty()] 16 [char] 17 $DriveLetter 18 19 MountedDiskImage() { } 20 21 MountedDiskImage($Path) { 22 $this.Path = $Path 23 $this.Image = $this.GetImage() 24 25 if (-not ($this.Image.Attached)) { 26 $this.Mount() 27 } 28 29 $this.GetDriveLetter() 30 } 31 32 hidden [Microsoft.Management.Infrastructure.CimInstance] GetImage() { 33 return Get-DiskImage -ImagePath $this.Path 34 } 35 36 hidden [void] GetDriveLetter() { 37 switch ($this.Image.StorageType) { 38 1 { $this.GetDriveLetterISO() } 39 2 { $this.GetDriveLetterVHD() } 40 3 { $this.GetDriveLetterVHD() } 41 Default { throw "Неизвестный тип хранения образа диска" } 42 } 43 } 44 45 hidden [void] Mount() { 46 $this.Image = Mount-DiskImage -ImagePath $this.Path 47 } 48 49 hidden [void] GetDriveLetterISO() { 50 $this.DriveLetter = ($this.Image | Get-Volume).DriveLetter 51 } 52 53 hidden [void] GetDriveLetterVHD() { 54 $this.DriveLetter = ( 55 $this.Image | Get-Disk | Get-Partition | Get-Volume 56 ).DriveLetter 57 } 58 } |
|