I just want to create a new directory named with a date an hour. And I want to copy something from another directory to new created directory. Like a back-up operation.
Well I'm new learner about powershell. I've tried to read all docs from microsoft. But I clearly don't understand what am I missing?
So my script is like this without a function block and it's working:
     if (Test-Path -Path "$pathBackup\$finalDate") {
       Remove-Item $pathBackup\$finalDate -Recurse -Force         
    }
 New-Item -Path $pathBackup -Name $finalDate -ItemType Directory
 [string]$backupDirectory = "$pathApplication\*"
 [string]$backupDestination = "$pathBackup$backupDate"
 Copy-item -Force -Recurse -Verbose $backupDirectory -Destination $backupDestination
But When I try this steps in a function block. For a modular struct. Because I want to use this function with different parameters. So my function is like this: and it's not working.
function createDir ($pathName, $folderName){ 
 if ((Test-Path -Path "$path$folderName")) {
     Remove-Item "$path$folderName" -Recurse -Force
 }
New-Item -ItemType Directory -Path $pathName -Name $folderName 
[string]$backupSource = "$pathApplication\*"
[string]$backupDestination = "$pathName$folderName"
Copy-item -Force -Recurse -Verbose $backupSource -Destination $backupDestination
 }
I think the ps reads my variables as a System.Object but I should use String. But I don't know how to do
I'm calling the function like this:
  createDir($pathBackup, $finalDate)
And Powershell doesn't recognize pathBackup and finalDate variables. Instead of this ps creates a folder which is named System.Object[] in location of powershell scripts path.
 
    
