【发布时间】:2018-01-23 21:17:40
【问题描述】:
我正在尝试使用 DSC 格式化驱动器并在新格式化的驱动器上创建特定的文件夹结构。
在我创建分区、格式化磁盘并给它一个驱动器号之后,我正在尝试使用新的磁盘路径创建一个文件夹,但是我在 New-Item 调用时收到了 Cannot find drive. A drive with the name 'K' does not exist 类型的错误.此代码是在Script DSC 中执行的示例:
$someDiskNumber = 3 # for the sake of testing
Initialize-Disk -Number $someDiskNumber -PartitionStyle GPT -PassThru
$partition = New-Partition -DiskNumber $someDiskNumber -UseMaximumSize -DriveLetter 'K'
Format-Volume -Partition $partition -FileSystem NTFS -AllocationUnitSize 65536 -NewFileSystemLabel "san-root" -Confirm:$False
New-Item -Path "K:\Test" -ItemType Directory -Force -ErrorAction Stop
如何让 DSC 脚本“重新发现”新卷以允许为它运行 New-Item?
我尝试过的(没有成功):
- 在
Format-Volume调用之后运行Update-Disk -DiskNumber $someDiskNumber - 在
Format-Volume调用之后运行Update-HostStorageCache - 在
Format-Volume调用之后添加一个while循环以等待Test-Path "K:\"返回True(它永远循环)
附:我知道xStorage DSC 模块,但不幸的是,由于限制(与问题无关),我无法使用它。
【问题讨论】:
-
是
xStorage做你想做的但你不能使用它,你仍然可以查看它的源代码来确定它如何做你想做的。你试过吗? -
@briantist 我不确定
xStorage是否符合我的要求。我遇到的问题不是创建挂载点(xStorage所做的),它是最后一行(New-Item),它不属于xStorage。
标签: powershell dsc