无法在刚刚在 DSC 脚本中创建的分区上创建文件夹

Cannot create a folder on the partition that was just created within a DSC script

我正在尝试使用 DSC 格式化驱动器并在新格式化的驱动器上创建特定的文件夹结构。

在我创建分区、格式化磁盘并为其分配驱动器盘符后,我正在尝试使用新磁盘路径创建文件夹,但是我收到 Cannot find drive. A drive with the name 'K' does not exist 类型的错误New-Item打电话。此代码是在 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 脚本 "rediscover" 成为允许 运行 New-Item 的新卷?

我尝试过的(没有成功):

P.S。我知道 xStorage DSC 模块,但不幸的是,由于限制(与问题无关)我无法使用它。

在尝试 Whosebug 五分钟后找到答案。添加以下命令将强制 PowerShell 刷新缓存并获取丢失的驱动器。

$null = Get-PSDrive