Вот алгоритм, который я бы использовал для выполнения этой задачи:
Теперь у вас есть шесть случайных чисел с суммой в нужном диапазоне. Возможно, вам просто нужно добавить или вычесть 1 к одному из значений в случае, если при округлении сумма вышла за пределы диапазона. Вы можете выбрать одно из случайных чисел для настройки.
'Create a random number generator.
Dim rng As New Random
'Create a random number in the desired range for the final sum.
Dim sum = rng.Next(120, 235 + 1)
'Generate six proportional values as fractions of 1.0.
Dim proportions = Enumerable.Range(1, 6).Select(Function(n) rng.NextDouble()).ToArray()
'Get the sum of all the proportional values.
Dim proportionsSum = proportions.Sum()
'Normalise the proportional values so that they sum to 1.0
proportions = Array.ConvertAll(proportions, Function(r) r / proportionsSum)
'Break the final sum up into the specified proportions.
Dim numbers = Array.ConvertAll(proportions, Function(r) CInt(Math.Round(r * sum)))
'Adjust as required if rounding has pushed the sum below the minimum value.
Do While numbers.Sum() < 120
'Get a random element index.
Dim index = rng.Next(0, numbers.Length)
'Increment the element at that index.
numbers(index) = numbers(index) + 1
Loop
'Adjust as required if rounding has pushed the sum above the maximum value.
Do While numbers.Sum() > 235
'Get a random element index.
Dim index = rng.Next(0, numbers.Length)
'Decrement the element at that index.
numbers(index) = numbers(index) - 1
Loop
'The numbers array now contains six random values with a sum in the range 120 to 235.
Используйте платформу.NET:
PS H:\> $x = new-object system.io.driveinfo("h:\")
PS H:\> $x.drivetype
Network
Попытка WMI:
Get-WMI -query "Select ProviderName From Win32_LogicalDisk Where DeviceID='H:'"
Немного более компактная вариация на принятый ответ:
[System.IO.DriveInfo]("C")
Альтернативный способ использовать WMI:
get-wmiobject Win32_LogicalDisk | ? {$_.deviceid -eq "s:"} | % {$_.providername}
Получите все сетевые диски с:
get-wmiobject Win32_LogicalDisk | ? {$_.drivetype -eq 4} | % {$_.providername}
Возьмите это шаг вперед как показано ниже:
([System.IO.DriveInfo]("C")).Drivetype
Обратите внимание, что это только работает на локальная система. Используйте WMI для удаленных компьютеров.
Самый надежный путь состоит в том, чтобы использовать WMI
get-wmiobject win32_volume | ? { $_.DriveType -eq 4 } | % { get-psdrive $_.DriveLetter[0] }
DriveType является перечислимым остроумием hthe после значений
0 - Неизвестный 1 - никакой корневой каталог 2 - съемный диск 3 - локальный диск 4 - сетевой диск 5 - компакт-диск 6 - псевдодиск
Вот ссылка на сообщение в блоге, которое я сделал на предмете