通过powershell/window在BMC中创建文件夹会创建文件而不是文件夹

通过powershell/window在BMC中创建文件夹会创建文件而不是文件夹,powershell,bmc,Powershell,Bmc,我正在使用Powershell和BMC实现自动化,我已创建Powershell脚本以创建文件夹: $directoryname= "D:\sysdba" $DoesFolderExist = Test-Path $directoryname $null = if (!$DoesFolderExist){MKDIR "$directoryname"} $directoryname= "D:\temp" $DoesFolderExist = Test-Path $directoryname

我正在使用Powershell和BMC实现自动化,我已创建Powershell脚本以创建文件夹:

$directoryname= "D:\sysdba" 
$DoesFolderExist = Test-Path $directoryname 
$null = if (!$DoesFolderExist){MKDIR "$directoryname"}

$directoryname= "D:\temp" 
$DoesFolderExist = Test-Path $directoryname 
$null = if (!$DoesFolderExist){MKDIR "$directoryname"}
我正在使用以下命令在主机服务器上创建文件夹:

<commands>
  <command>\\Path\SPUpgrade\Create_Folder.ps1</command>
</commands>

\\路径\SPUpgrade\Create_Folder.ps1
但它正在创建一个文件而不是文件夹:


知道为什么吗?我不明白为什么不创建文件夹,为什么不鼓励使用Powershell中的
mkdir
创建文件,因为
mkdir
是一个外部实用程序,而不是内部Powershell命令。相反,使用
newitem-ItemType目录
来实现您想要的:

$directoryname= "D:\sysdba" 
if(!(Test-Path -Path $directoryname )){
    New-Item -ItemType directory -Path $directoryname
    Write-Host "created a new folder"
}
else
{
  Write-Host "The folder is already exists"
}

您也可以对“D:\temp”执行同样的操作。

不知道为什么mkdir不再工作,但您可以尝试将其替换为:
new item-Path$directoryname-ItemType Directory
我无法用您的代码重现这种行为。您能否确认是您的脚本生成了
sysdba
文件,而不是同时运行的其他进程?您可以通过将路径从'D:\sysdba'更改为'D:\foo'来测试这一点,并查看是否会发生同样的情况。它可能是一个别名?请尝试md或此处提供的建议。我检查了新的itemtype目录。生成的是同一个文件,而不是folderi。我再次检查了生成的文件