diskLayout fix on VM (windows)
This commit is contained in:
parent
1dd4028123
commit
1ed7115168
@ -1001,74 +1001,69 @@ function diskLayout(callback) {
|
|||||||
if (_windows) {
|
if (_windows) {
|
||||||
try {
|
try {
|
||||||
util.wmic('diskdrive get /value').then((stdout, error) => {
|
util.wmic('diskdrive get /value').then((stdout, error) => {
|
||||||
if (!error) {
|
let devices = stdout.toString().split(/\n\s*\n/);
|
||||||
let devices = stdout.toString().split(/\n\s*\n/);
|
devices.forEach(function (device) {
|
||||||
devices.forEach(function (device) {
|
let lines = device.split('\r\n');
|
||||||
let lines = device.split('\r\n');
|
const size = util.getValue(lines, 'Size', '=').trim();
|
||||||
const size = util.getValue(lines, 'Size', '=').trim();
|
const status = util.getValue(lines, 'Status', '=').trim().toLowerCase();
|
||||||
const status = util.getValue(lines, 'Status', '=').trim().toLowerCase();
|
if (size) {
|
||||||
if (size) {
|
result.push({
|
||||||
result.push({
|
device: '',
|
||||||
device: '',
|
type: device.indexOf('SSD') > -1 ? 'SSD' : 'HD', // just a starting point ... better: MSFT_PhysicalDisk - Media Type ... see below
|
||||||
type: device.indexOf('SSD') > -1 ? 'SSD' : 'HD', // just a starting point ... better: MSFT_PhysicalDisk - Media Type ... see below
|
name: util.getValue(lines, 'Caption', '='),
|
||||||
name: util.getValue(lines, 'Caption', '='),
|
vendor: util.getValue(lines, 'Manufacturer', '='),
|
||||||
vendor: util.getValue(lines, 'Manufacturer', '='),
|
size: parseInt(size),
|
||||||
size: parseInt(size),
|
bytesPerSector: parseInt(util.getValue(lines, 'BytesPerSector', '=')),
|
||||||
bytesPerSector: parseInt(util.getValue(lines, 'BytesPerSector', '=')),
|
totalCylinders: parseInt(util.getValue(lines, 'TotalCylinders', '=')),
|
||||||
totalCylinders: parseInt(util.getValue(lines, 'TotalCylinders', '=')),
|
totalHeads: parseInt(util.getValue(lines, 'TotalHeads', '=')),
|
||||||
totalHeads: parseInt(util.getValue(lines, 'TotalHeads', '=')),
|
totalSectors: parseInt(util.getValue(lines, 'TotalSectors', '=')),
|
||||||
totalSectors: parseInt(util.getValue(lines, 'TotalSectors', '=')),
|
totalTracks: parseInt(util.getValue(lines, 'TotalTracks', '=')),
|
||||||
totalTracks: parseInt(util.getValue(lines, 'TotalTracks', '=')),
|
tracksPerCylinder: parseInt(util.getValue(lines, 'TracksPerCylinder', '=')),
|
||||||
tracksPerCylinder: parseInt(util.getValue(lines, 'TracksPerCylinder', '=')),
|
sectorsPerTrack: parseInt(util.getValue(lines, 'SectorsPerTrack', '=')),
|
||||||
sectorsPerTrack: parseInt(util.getValue(lines, 'SectorsPerTrack', '=')),
|
firmwareRevision: util.getValue(lines, 'FirmwareRevision', '=').trim(),
|
||||||
firmwareRevision: util.getValue(lines, 'FirmwareRevision', '=').trim(),
|
serialNum: util.getValue(lines, 'SerialNumber', '=').trim(),
|
||||||
serialNum: util.getValue(lines, 'SerialNumber', '=').trim(),
|
interfaceType: util.getValue(lines, 'InterfaceType', '=').trim(),
|
||||||
interfaceType: util.getValue(lines, 'InterfaceType', '=').trim(),
|
smartStatus: (status === 'ok' ? 'Ok' : (status === 'degraded' ? 'Degraded' : (status === 'pred fail' ? 'Predicted Failure' : 'Unknown')))
|
||||||
smartStatus: (status === 'ok' ? 'Ok' : (status === 'degraded' ? 'Degraded' : (status === 'pred fail' ? 'Predicted Failure' : 'Unknown')))
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
util.powerShell('Get-PhysicalDisk | Format-List')
|
|
||||||
.then(data => {
|
|
||||||
let devices = data.split(/\n\s*\n/);
|
|
||||||
devices.forEach(function (device) {
|
|
||||||
let lines = device.split('\r\n');
|
|
||||||
const serialNum = util.getValue(lines, 'SerialNumber', ':').trim();
|
|
||||||
const name = util.getValue(lines, 'FriendlyName', ':').trim();
|
|
||||||
const size = util.getValue(lines, 'Size', ':').trim();
|
|
||||||
const interfaceType = util.getValue(lines, 'BusType', ':').trim();
|
|
||||||
let mediaType = util.getValue(lines, 'MediaType', ':').trim();
|
|
||||||
if (mediaType === '3' || mediaType === 'HDD') { mediaType = 'HD'; }
|
|
||||||
if (mediaType === '4') { mediaType = 'SSD'; }
|
|
||||||
if (mediaType === '5') { mediaType = 'SCM'; }
|
|
||||||
if (size) {
|
|
||||||
let i = util.findObjectByKey(result, 'serialNum', serialNum);
|
|
||||||
if (i === -1) {
|
|
||||||
i = util.findObjectByKey(result, 'name', name);
|
|
||||||
}
|
|
||||||
if (i != -1) {
|
|
||||||
result[i].type = mediaType;
|
|
||||||
result[i].interfaceType = interfaceType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (callback) {
|
|
||||||
callback(result);
|
|
||||||
}
|
|
||||||
resolve(result);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
if (callback) {
|
|
||||||
callback(result);
|
|
||||||
}
|
|
||||||
resolve(result);
|
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
if (callback) {
|
|
||||||
callback(result);
|
|
||||||
}
|
}
|
||||||
resolve(result);
|
});
|
||||||
}
|
util.powerShell('Get-PhysicalDisk | Format-List')
|
||||||
|
.then(data => {
|
||||||
|
let devices = data.split(/\n\s*\n/);
|
||||||
|
devices.forEach(function (device) {
|
||||||
|
let lines = device.split('\r\n');
|
||||||
|
const serialNum = util.getValue(lines, 'SerialNumber', ':').trim();
|
||||||
|
const name = util.getValue(lines, 'FriendlyName', ':').trim().replace('Msft ', 'Microsoft');
|
||||||
|
const size = util.getValue(lines, 'Size', ':').trim();
|
||||||
|
const model = util.getValue(lines, 'Model', ':').trim();
|
||||||
|
const interfaceType = util.getValue(lines, 'BusType', ':').trim();
|
||||||
|
let mediaType = util.getValue(lines, 'MediaType', ':').trim();
|
||||||
|
if (mediaType === '3' || mediaType === 'HDD') { mediaType = 'HD'; }
|
||||||
|
if (mediaType === '4') { mediaType = 'SSD'; }
|
||||||
|
if (mediaType === '5') { mediaType = 'SCM'; }
|
||||||
|
if (mediaType === 'Unspecified' && model.toLowerCase().indexOf('virtual') > -1) { mediaType = 'Virtual'; }
|
||||||
|
if (size) {
|
||||||
|
let i = util.findObjectByKey(result, 'serialNum', serialNum);
|
||||||
|
if (i === -1 || serialNum === '') {
|
||||||
|
i = util.findObjectByKey(result, 'name', name);
|
||||||
|
}
|
||||||
|
if (i != -1) {
|
||||||
|
result[i].type = mediaType;
|
||||||
|
result[i].interfaceType = interfaceType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (callback) {
|
||||||
|
callback(result);
|
||||||
|
}
|
||||||
|
resolve(result);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
if (callback) {
|
||||||
|
callback(result);
|
||||||
|
}
|
||||||
|
resolve(result);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user