无法在刚刚在 DSC 脚本中创建的分区上创建文件夹 [英] Cannot create a folder on the partition that was just created within a DSC script

查看:53
本文介绍了无法在刚刚在 DSC 脚本中创建的分区上创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use DSC to format drives and create a certain folder structure on newly formatted drives.

在创建分区、格式化磁盘并为其指定驱动器号后,我正尝试使用新磁盘路径创建文件夹,但是我收到 找不到驱动器.名为K"的驱动器不存在 类型的 New-Item 调用错误.此代码是在 Script DSC 中执行的示例:

Right after I've created a partition, formatted a disk and gave it a drive letter I'm trying to create a folder using the new disk path however I'm receiving Cannot find drive. A drive with the name 'K' does not exist types of errors on New-Item call. This code is an example of one executed within a 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?

How do I make the DSC script "rediscover" the new volume to allow running New-Item for it?

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

What I have tried (no success):

  • Format-Volume 调用后运行 Update-Disk -DiskNumber $someDiskNumber
  • Format-Volume调用后运行Update-HostStorageCache
  • Format-Volume 调用之后添加一个 while 循环以等待 Test-Path "K:\" 返回 (它一直循环)
  • Running Update-Disk -DiskNumber $someDiskNumber after the Format-Volume call
  • Running Update-HostStorageCache after the Format-Volume call
  • Add a while loop after the Format-Volume call to wait for Test-Path "K:\" to return True (it looped forever)

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

P.S. I am aware of the xStorage DSC module but unfortunately I cannot use it due to limitations (irrelevant to the question).

推荐答案

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

Figured an answer five minutes after trying StackOverflow. Adding the command below will force PowerShell to refresh the cache and get the missing drives.

$null = Get-PSDrive

这篇关于无法在刚刚在 DSC 脚本中创建的分区上创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆