public async Task <IVolume> GetVolume() { Log.Debug("Getting volume of {Partition}", this); var results = await PowerShellMixin.ExecuteCommand("Get-Volume", ("Partition", await this.GetPsPartition())); var result = results.FirstOrDefault()?.ImmediateBaseObject; if (result == null) { return(null); } var driveLetter = (char?)result.GetPropertyValue("DriveLetter"); var vol = new Volume(this) { Size = new ByteSize(Convert.ToUInt64(result.GetPropertyValue("Size"))), Label = (string)result.GetPropertyValue("FileSystemLabel"), Root = driveLetter != null?PathExtensions.GetRootPath(driveLetter.Value) : null, FileSystemFormat = FileSystemFormat.FromString((string)result.GetPropertyValue("FileSystem")), }; Log.Debug("Obtained {Volume}", vol); return(vol); }
public async Task RemoveDriveLetter() { var part = await this.GetPsPartition(); await PowerShellMixin.ExecuteCommand("Remove-PartitionAccessPath", ("InputObject", part), ("AccessPath", Root) ); }
public async Task Format(FileSystemFormat fileSystemFormat, string label) { var part = await this.Partition.GetPsPartition(); await PowerShellMixin.ExecuteCommand("Format-Volume", ("Partition", part), ("Force", null), ("Confirm", false), ("FileSystem", fileSystemFormat.Moniker), ("NewFileSystemLabel", label) ); }
public async Task <char> AssignDriveLetter() { var part = await this.GetPsPartition(); var letter = GetFreeDriveLetter(); await PowerShellMixin.ExecuteCommand("Set-Partition", ("InputObject", part), ("NewDriveLetter", letter) ); Root = PathExtensions.GetRootPath(letter); return(letter); }
public async Task Resize(ByteSize size) { if (size.MegaBytes < 0) { throw new InvalidOperationException($"The partition size cannot be negative: {size}"); } var sizeBytes = (ulong)size.Bytes; Log.Verbose("Resizing partition {Partition} to {Size}", this, size); var psPart = await this.GetPsPartition(); await PowerShellMixin.ExecuteCommand("Resize-Partition", ("InputObject", psPart), ("Size", sizeBytes)); }
public async Task SetGptType(GptType gptType) { Log.Verbose("Setting new GPT partition type {Type} to {Partition}", gptType, this); if (Equals(GptType, gptType)) { return; } var part = await this.GetPsPartition(); await PowerShellMixin.ExecuteCommand("Set-Partition", ("InputObject", part), ("GptType", $"{{{gptType.Guid}}}") ); await Disk.Refresh(); Log.Verbose("New GPT type set correctly", gptType, this); }
public async Task Remove() { var part = await this.GetPsPartition(); await PowerShellMixin.ExecuteCommand("Remove-Partition", ("InputObject", part), ("Confirm", false)); }
public async Task ToggleOnline(bool isOnline) { await PowerShellMixin.ExecuteCommand("Set-Disk", ("Number", Number), ("IsOffline", !isOnline)); }