PowerShell – directories creation script

[deklarations]--------------------------
#source
$departments=Get-Content '\\hostname\scripts\departments.txt'
#logs
$successLog='\\hostname\logs\groups-done.LOG'
$errorLog='\\hostname\logs\groups-error.LOG'
$unreachableLog='\\hostname\logs\groups-unreachable.LOG'
$reportLog='\\hostname\logs\groups-report.txt'
#params
$header=''
$sharepath='\\hostname'

$groupName
#-------------[functions]--------------------------
foreach($department in $departments) {
    $dirPath= $sharePath + "\orders\" + $department + "\"
        
    if(-not (Get-Item $dirPath -ErrorAction SilentlyContinue)) {
        New-Item $dirPath -ItemType Directory
        Write-host "Directory: $dirPath CREATED." -foreground 'green'
        $dirPath >> $successLog
    } else {
        Write-host "Directory '$($dirPath)' already exist" -foreground 'red'
        $dirPath >> $errorLog
    }
}
#-------------krolaki.eu--------------------------

Leave a Reply

Your email address will not be published. Required fields are marked *