提供池、虚拟磁盘和共享
provide pool, virtual disc and shares
我开始自学 PowerShell。在其中一本书(Windows Server 2012 R2,实施和维护)中,我得到了必须创建脚本的任务,该脚本将在 运行 之后创建存储池、虚拟磁盘和新共享新创建的 vdisc。
根据书本说明,我已经这样做了:
New-StoragePool -FriendlyName "Pool" -StorageSubSystemFriendlyName (Get-StorageSubSystem).FriendlyName -PhysicalDisk (Get-PhysicalDisk | where CanPool -eq True) -ProvisingTypeDefault Thin -ResiliencySettingNameDefault Mirror
New-VirtualDisk -FriendlyName "vDisk1" -StoragePoolFriendlyName "Pool" -Size 5TB
New-VirtualDisk -FriendlyName "vDisk2" -StoragePoolFriendlyName "Pool" -Size 10TB
New Partition -DiskNumber(Get-Disk | where BusType -eq Spaces).Number -UseMaximumSize -AssignDriveLetter | Format-Volume -FileSystem NTFS -Confirm:$false
现在我想通过New-Item
功能为新创建的虚拟磁盘创建共享文件夹。问题是我不确定如何为多个磁盘创建路径,而且 New Partition
中的参数 -AssignDriveLetter
会自动创建驱动器号。因此,我不知道驱动器号。结果我不知道如何在 New-Item
.
中设置变量 Path
我建议一个通用的方法:
在配置池和磁盘时使用变量,这样您就可以在接下来的步骤中重用它们,并且将引用您创建的特定对象:
$NewPartitions = New-Partition -DiskNumber(Get-Disk | where BusType -eq Spaces).Number -UseMaximumSize -AssignDriveLetter | Format-Volume -FileSystem NTFS -Confirm:$false
$NewPartitions
变量将包含新分区的数组及其驱动器号,您可以使用 foreach
循环迭代,每次执行 New-Item
:
$NewFolders = foreach ($DriveLetter in ($NewPartitions.DriveLetter))
{
New-Item -Type Directory -Path ($DriveLetter+":\share")
}
这将在每个驱动器上生成一个名为 "share" 的文件夹,您可能希望使用相同的策略将其传递给 New-SmbShare
cmdlet。 $NewFolders.FullName
包含您新创建的文件夹的完整路径。
我开始自学 PowerShell。在其中一本书(Windows Server 2012 R2,实施和维护)中,我得到了必须创建脚本的任务,该脚本将在 运行 之后创建存储池、虚拟磁盘和新共享新创建的 vdisc。
根据书本说明,我已经这样做了:
New-StoragePool -FriendlyName "Pool" -StorageSubSystemFriendlyName (Get-StorageSubSystem).FriendlyName -PhysicalDisk (Get-PhysicalDisk | where CanPool -eq True) -ProvisingTypeDefault Thin -ResiliencySettingNameDefault Mirror
New-VirtualDisk -FriendlyName "vDisk1" -StoragePoolFriendlyName "Pool" -Size 5TB
New-VirtualDisk -FriendlyName "vDisk2" -StoragePoolFriendlyName "Pool" -Size 10TB
New Partition -DiskNumber(Get-Disk | where BusType -eq Spaces).Number -UseMaximumSize -AssignDriveLetter | Format-Volume -FileSystem NTFS -Confirm:$false
现在我想通过New-Item
功能为新创建的虚拟磁盘创建共享文件夹。问题是我不确定如何为多个磁盘创建路径,而且 New Partition
中的参数 -AssignDriveLetter
会自动创建驱动器号。因此,我不知道驱动器号。结果我不知道如何在 New-Item
.
Path
我建议一个通用的方法: 在配置池和磁盘时使用变量,这样您就可以在接下来的步骤中重用它们,并且将引用您创建的特定对象:
$NewPartitions = New-Partition -DiskNumber(Get-Disk | where BusType -eq Spaces).Number -UseMaximumSize -AssignDriveLetter | Format-Volume -FileSystem NTFS -Confirm:$false
$NewPartitions
变量将包含新分区的数组及其驱动器号,您可以使用 foreach
循环迭代,每次执行 New-Item
:
$NewFolders = foreach ($DriveLetter in ($NewPartitions.DriveLetter))
{
New-Item -Type Directory -Path ($DriveLetter+":\share")
}
这将在每个驱动器上生成一个名为 "share" 的文件夹,您可能希望使用相同的策略将其传递给 New-SmbShare
cmdlet。 $NewFolders.FullName
包含您新创建的文件夹的完整路径。