Hello All,
i have a simple script that reads a .txt file with IPs of servers and create a folder structure on each of the servers. The problem is that it does not create folders on servers, only on local server where script is ran.
Here what i have:
$servers = Get-Content -Path "C:\servers.txt"
$servers
foreach ($server in $servers)
{
$rootdir = "C:\"
try {
foreach ($folder in @("Year", "Month", "day")){
if(-not(test-path -path (join-path $rootdir $folder))){
New-Item -Path (Join-Path $rootdir $folder) -Type Directory `
-ErrorAction stop
}
}
}
catch
{
$ErrorMessage = $_.Exception.Message
Write-Warning ($ErrorMessage)
}
md -Path "$rootdir\Month\ws"
md -Path "$rootdir\Month\sql"
md -Path "$rootdir\day\PDF\backup","$rootdir\day\PDF\deleted"
md -Path "$rootdir\day\JPG\backup","$rootdir\day\JPG\deleted"
$FolderPath = "C:\Month"
$ShareName = "Month"
$Type = 0
#create share
$objWMI = [wmiClass] 'Win32_share'
$objWMI.create($FolderPath, $ShareName, $Type)
}
Any help would be appreciated.