0

我正在使用 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>

但它正在创建一个文件而不是文件夹:

在此处输入图像描述

知道为什么吗?我很困惑为什么不创建文件夹以及为什么文件

4

1 回答 1

1

mkdir不鼓励从 Powershell使用,因为mkdir它是外部实用程序,而不是内部 Powershell 命令。相反,使用New-Item -ItemType directory来实现你想要的:

$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”做同样的事情。

于 2017-10-12T07:19:14.847 回答