I am using PowerShell and BMC Control-M for automation, I have created a PowerShell script to create a folder:
$directoryname= "D:\sysdba"
$DoesFolderExist = Test-Path $directoryname
$null = if (!$DoesFolderExist){MKDIR "$directoryname"}
$directoryname= "D:\temp"
$DoesFolderExist = Test-Path $directoryname
$null = if (!$DoesFolderExist){MKDIR "$directoryname"}
I am using below command to create folder on host server:
<commands>
<command>\\Path\SPUpgrade\Create_Folder.ps1</command>
</commands>
But it is creating a file instead of folder:
Any idea why? I am confused as why not creating folder and why file
Using mkdir
from Powershell is not encouraged since mkdir
is an external utility and not an internal Powershell command. Instead, use New-Item -ItemType directory
to achieve what you want:
$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"
}
And you can do the same for "D:\temp".