У меня проблема в том, что скрипт выполнялся правильно на одном сервере (2016 / PS5.1), но не на другом (2008 / PS2). Путь должен быть в порядке, потому что он уже работает. Я вполне уверен, что это проблема версии PS, однако у меня нет достаточного опыта или знаний, чтобы понять это ...
Ошибка:
sshd.exe is not present in script path
Bei C:\Admin\LANAgentTransfer\OpenSSH-Win64\install-sshd.ps1:14 Zeichen:10
+ throw <<<< "sshd.exe is not present in script path"
+ CategoryInfo : OperationStopped: (sshd.exe is not present in script path:String) [], RuntimeException
+ FullyQualifiedErrorId : sshd.exe is not present in script path
Соответствующий install-sshd.ps1:
# @manojampalam - authored initial script
# @friism - Fixed issue with invalid SDDL on Set-Acl
# @manojampalam - removed ntrights.exe dependency
# @bingbing8 - removed secedit.exe dependency
$scriptpath = $MyInvocation.MyCommand.Path
$scriptdir = Split-Path $scriptpath
$sshdpath = Join-Path $scriptdir "sshd.exe"
$sshagentpath = Join-Path $scriptdir "ssh-agent.exe"
$etwman = Join-Path $scriptdir "openssh-events.man"
if (-not (Test-Path $sshdpath)) {
throw "sshd.exe is not present in script path"
}
СКРИПТ:
Set-ExecutionPolicy RemoteSigned -Force
Set Variables
$credentials = New-Object System.Net.NetworkCredential("XY", "XY")
$url = "ftp://XY/OpenSSH-Win64/OpenSSH-Win64/"
$localPath = "C:\XY\XY\OpenSSH-Win64"
function DownloadFtpDirectory($url, $credentials, $localPath)
{
$listRequest = [Net.WebRequest]::Create($url)
$listRequest.Method = [System.Net.WebRequestMethods+Ftp]::ListDirectoryDetails
$listRequest.Credentials = $credentials
$lines = New-Object System.Collections.ArrayList
$listResponse = $listRequest.GetResponse()
$listStream = $listResponse.GetResponseStream()
$listReader = New-Object System.IO.StreamReader($listStream)
while (!$listReader.EndOfStream)
{
$line = $listReader.ReadLine()
$lines.Add($line) | Out-Null
}
$listReader.Dispose()
$listStream.Dispose()
$listResponse.Dispose()
foreach ($line in $lines)
{
$tokens = $line.Split(" ", 9, [StringSplitOptions]::RemoveEmptyEntries)
$name = $tokens[8]
$permissions = $tokens[0]
$localFilePath = Join-Path $localPath $name
$fileUrl = ($url + $name)
if ($permissions[0] -eq 'd')
{
if (!(Test-Path $localFilePath -PathType container))
{
Write-Host "Creating directory $localFilePath"
New-Item $localFilePath -Type directory | Out-Null
}
DownloadFtpDirectory ($fileUrl + "/") $credentials $localFilePath
}
else
{
Write-Host "Downloading $fileUrl to $localFilePath"
$downloadRequest = [Net.WebRequest]::Create($fileUrl)
$downloadRequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile
$downloadRequest.Credentials = $credentials
$downloadResponse = $downloadRequest.GetResponse()
$sourceStream = $downloadResponse.GetResponseStream()
$targetStream = [System.IO.File]::Create($localFilePath)
$buffer = New-Object byte[] 10240
while (($read = $sourceStream.Read($buffer, 0, $buffer.Length)) -gt 0)
{
$targetStream.Write($buffer, 0, $read);
}
$targetStream.Dispose()
$sourceStream.Dispose()
$downloadResponse.Dispose()
}
}
}
IF (Test-Path C:\XY\XY\OpenSSH-Win64) {
ECHO "FOLDER ALREADY EXISTS"
}
else{
#Function to Download all Files from a Directory
md "C:\XY\XY\OpenSSH-Win64"
}
IF (Test-Path C:\XY\XY\OpenSSH-Win64\scp.exe) {
ECHO "FILES ALREADY EXIST"
}
else {
DownloadFtpDirectory $url $credentials "C:\XY\XY\OpenSSH-Win64"
}
#Install SSH via integrated ps1
C:\XY\XY\OpenSSH-Win64\install-sshd.ps1
#Set Service to start automatic and start service
Set-Service -Name sshd -StartupType Automatic
Start-Service -Name sshd
ECHO "SCRIPT SUCCESFUL"
Set-ExecutionPolicy Default -Force
СОДЕРЖАНИЕ ПАПКИ:
Я открыт для критики!