我正在寻找使用 powershell 来查看 ftp 文件夹中是否有特定文件。更具体地说,大约有 15 个不同的文件夹需要检查特定文件名。关于我将如何做到这一点的任何想法?
问问题
3268 次
2 回答
2
这里有一个 PowerShell ftp 模块。
于 2012-05-01T17:38:11.200 回答
0
$DEBUG = 1
# Machines
$MachineNames = @("machine1","machine2" )
$MachineIPs = @("192.168.1.1","192.168.1.2" )
# Websites
$WebsiteNames = @("website1","website2" )
$WebsiteURLs = @("http://yahoo.com","http://google.com" )
#====== check websites
$i = 0;
foreach ($WebsiteURL in $WebsiteURLs){
# First we create the request.
$HTTP_Request = [System.Net.WebRequest]::Create($WebsiteURL)
# We then get a response from the site.
$HTTP_Response = $HTTP_Request.GetResponse()
# We then get the HTTP code as an integer.
$HTTP_Status = [int]$HTTP_Response.StatusCode
#$HTTP_Response
If ($HTTP_Status -eq 200) {
if ($DEBUG -eq 1) {Write-Host "== " $WebsiteNames[$i] " is OK!" }
}
Else {
if ($DEBUG -eq 1) {Write-Host "==Error: "$WebsiteNames[$i] " may be down!" }
SendEmails $WebsiteNames[$i]
}
# Finally, we clean up the http request by closing it.
$HTTP_Response.Close()
Clear-Variable HTTP_Response
$i = $i + 1
}
#====== check IP
$i = 0;
foreach ($MachineIP in $MachineIPs){
$isValidIP = Test-Connection $MachineIP -Count 1 -Quiet
if ($DEBUG -eq 1) {
$hostn = [System.Net.Dns]::GetHostEntry($MachineIP).HostName
New-Object -TypeName PSObject -Property @{'Host'=$hostn;'IP'=$MachineIP}
}
if (-not($isValidIP)) {
if ($DEBUG -eq 1) {Write-Host "==Error: " $MachineNames[$i] " ("$MachineIPs[$i]") may be down!" }
SendEmails $MachineNames[$i]
}
$i = $i + 1
}
于 2014-07-17T22:01:25.200 回答