i need a script that delete a multiple folder, when windows services was stopped. I writed this scrit:
[Array] $Services = 'LAS_LMB','LAS_LWS','LAS_CORE';
$las_path = "D:"
$tomcat_path = @('tomcat_core', 'tomcat_lmb', 'tomcat_web')
$log_folder = "$las_path\tomcat_*\logs"
$temp_folder = "$las-path\temp\*"
$localhost_folder = "$las_path$tomcat_path\work\Catalina\localhost"
# loop through each service, if its stopped, delete some folders
foreach($ServiceName in $Services)
{
$arrService = Get-Service -Name $ServiceName
if ($arrService.Status -eq 'Stopped')
{
Start-Sleep -s 5
Remove-Item $localhost_folder, $temp_folder -Force -Recurse -Verbose
Get-ChildItem -Path $log_folder -Recurse -include * | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-7)} | Remove-Item -Verbose
if ($arrService.Status -eq 'Running')
{
Write-Host "To delete Logs, Temporary Datas etc. must all serveices be stopped. Please start script Stopservices.ps1 first"
}
}
}
When i started the script, the skript check that service is stopped, but only one. I need when all of services are stoped, to delete the folders. For example 1. service -and 2.service -and 3.service. I don't know how to use this funktion: By start the script must to ask that write a name a service. For example: $Dienste = Read-Host "Please enter the Services" I write las1, las2, las3 and this values must be enter in:
[Array] $Services = $Dienste in this format
[Array] $Services = 'las1','las2','las3';
Thx a lot.
-splitoperator. - zett42"$las-path\temp\*"<<< is apparently wrong. i think you need an underscore where you have a hyphen. - Lee_Dailey