Closed rvani closed 3 months ago
You will need a shellstream since echo is part of a full shell and not a binary that would be invoked.
Sent from my iPhone
On Mar 6, 2020, at 6:18 PM, rvani notifications@github.com wrote:
$remotecommand = 'echo '+$sshuser_passwd+' | sudo -S sed /^server/d /etc/ntp.conf > /etc/m21.txt'
Try { $rootUser = $sshuser_username $PlainSafeModeAdministratorPassword = $sshuser_passwd $SecureSafeModeAdministratorPassword = ConvertTo-SecureString -String $PlainSafeModeAdministratorPassword -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential ($rootUser, $SecureSafeModeAdministratorPassword) New-SSHSession -computername $ip -credential $mycreds -AcceptKey | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null LogMessage "SSH Session to $($ip) created"
Invoke-SSHCommand -timeout 300 -sessionid 0 -command 'uname -a' | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
Invoke-SSHCommand -sessionid 0 -command $remotecommand -timeout 2 | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
Invoke-SSHCommand -sessionid 0 -command $remotecommand -timeout 2 | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
LogMessage "Command issued to" Remove-SSHSession -sessionid 0 | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null LogMessage "SSH Session Removed" } Catch { LogMessage "Unable to reimage VxRail using PTAB" Red catchWriter $_ }
OUTPUT :
[03-06-2020_01:53:22] Importing Posh-SSH Module
SessionId Host Connected
0 192.168.31.60 True
[03-06-2020_01:53:22] SSH Session to 192.168.31.60 createdHost : 192.168.31.60 Output : {} ExitStatus : 1
[03-06-2020_01:53:22] Command issued to True [03-06-2020_01:53:22] SSH Session Removed
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Thank you. But how to do that?
From: Carlos Perez notifications@github.com Reply to: darkoperator/Posh-SSH reply@reply.github.com Date: Saturday, 7 March 2020 at 3:56 AM To: darkoperator/Posh-SSH Posh-SSH@noreply.github.com Cc: Vani devaneedi nagabhushana reddy Reddy rvani@vmware.com, Author author@noreply.github.com Subject: Re: [darkoperator/Posh-SSH] Invoke-SSHCommand , unable to execute sed command on remote linux host using Invoke-SSHCommand. (#312)
You will need a shellstream since echo is part of a full shell and not a binary that would be invoked.
Sent from my iPhone
On Mar 6, 2020, at 6:18 PM, rvani notifications@github.com wrote:
$remotecommand = 'echo '+$sshuser_passwd+' | sudo -S sed /^server/d /etc/ntp.conf > /etc/m21.txt'
Try { $rootUser = $sshuser_username $PlainSafeModeAdministratorPassword = $sshuser_passwd $SecureSafeModeAdministratorPassword = ConvertTo-SecureString -String $PlainSafeModeAdministratorPassword -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential ($rootUser, $SecureSafeModeAdministratorPassword) New-SSHSession -computername $ip -credential $mycreds -AcceptKey | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null LogMessage "SSH Session to $($ip) created"
Invoke-SSHCommand -timeout 300 -sessionid 0 -command 'uname -a' | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
Invoke-SSHCommand -sessionid 0 -command $remotecommand -timeout 2 | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
Invoke-SSHCommand -sessionid 0 -command $remotecommand -timeout 2 | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
LogMessage "Command issued to" Remove-SSHSession -sessionid 0 | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null LogMessage "SSH Session Removed" } Catch { LogMessage "Unable to reimage VxRail using PTAB" Red catchWriter $_ }
OUTPUT :
[03-06-2020_01:53:22] Importing Posh-SSH Module
SessionId Host Connected
0 192.168.31.60 True [03-06-2020_01:53:22] SSH Session to 192.168.31.60 created
Host : 192.168.31.60 Output : {} ExitStatus : 1
[03-06-2020_01:53:22] Command issued to True [03-06-2020_01:53:22] SSH Session Removed
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdarkoperator%2FPosh-SSH%2Fissues%2F312%3Femail_source%3Dnotifications%26email_token%3DAOYGAUSSCH4ZA676ETX2GR3RGF2A3A5CNFSM4LDI6HR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEODBVPI%23issuecomment-595991229&data=02%7C01%7Crvani%40vmware.com%7Cb888b7b43ed546a1e00108d7c21d668c%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637191303842131272&sdata=twDFYkTQdMmO8EH%2B6sRPbs7FZpDDT2ngWq5Jwt%2FBdvM%3D&reserved=0, or unsubscribehttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAOYGAUVOYJCAW7DY5EUCD4DRGF2A3ANCNFSM4LDI6HRQ&data=02%7C01%7Crvani%40vmware.com%7Cb888b7b43ed546a1e00108d7c21d668c%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637191303842131272&sdata=hiQNf52B%2BP6DnDDRKKukpGL1n3f2pqNFSbYcZYv3gKM%3D&reserved=0.
https://github.com/darkoperator/Posh-SSH/blob/master/docs/New-SSHShellStream.md
https://blog.linoproject.net/powershell-managing-ubuntu-with-sudo-and-posh-ssh/
Sent from my iPhone
On Mar 6, 2020, at 6:30 PM, rvani notifications@github.com wrote:
Thank you. But how to do that?
From: Carlos Perez notifications@github.com Reply to: darkoperator/Posh-SSH reply@reply.github.com Date: Saturday, 7 March 2020 at 3:56 AM To: darkoperator/Posh-SSH Posh-SSH@noreply.github.com Cc: Vani devaneedi nagabhushana reddy Reddy rvani@vmware.com, Author author@noreply.github.com Subject: Re: [darkoperator/Posh-SSH] Invoke-SSHCommand , unable to execute sed command on remote linux host using Invoke-SSHCommand. (#312)
You will need a shellstream since echo is part of a full shell and not a binary that would be invoked.
Sent from my iPhone
On Mar 6, 2020, at 6:18 PM, rvani notifications@github.com wrote:
$remotecommand = 'echo '+$sshuser_passwd+' | sudo -S sed /^server/d /etc/ntp.conf > /etc/m21.txt'
Try { $rootUser = $sshuser_username $PlainSafeModeAdministratorPassword = $sshuser_passwd $SecureSafeModeAdministratorPassword = ConvertTo-SecureString -String $PlainSafeModeAdministratorPassword -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential ($rootUser, $SecureSafeModeAdministratorPassword) New-SSHSession -computername $ip -credential $mycreds -AcceptKey | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null LogMessage "SSH Session to $($ip) created"
Invoke-SSHCommand -timeout 300 -sessionid 0 -command 'uname -a' | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
Invoke-SSHCommand -sessionid 0 -command $remotecommand -timeout 2 | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
Invoke-SSHCommand -sessionid 0 -command $remotecommand -timeout 2 | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
LogMessage "Command issued to" Remove-SSHSession -sessionid 0 | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null LogMessage "SSH Session Removed" } Catch { LogMessage "Unable to reimage VxRail using PTAB" Red catchWriter $_ }
OUTPUT :
[03-06-2020_01:53:22] Importing Posh-SSH Module
SessionId Host Connected
0 192.168.31.60 True [03-06-2020_01:53:22] SSH Session to 192.168.31.60 created
Host : 192.168.31.60 Output : {} ExitStatus : 1
[03-06-2020_01:53:22] Command issued to True [03-06-2020_01:53:22] SSH Session Removed
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdarkoperator%2FPosh-SSH%2Fissues%2F312%3Femail_source%3Dnotifications%26email_token%3DAOYGAUSSCH4ZA676ETX2GR3RGF2A3A5CNFSM4LDI6HR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEODBVPI%23issuecomment-595991229&data=02%7C01%7Crvani%40vmware.com%7Cb888b7b43ed546a1e00108d7c21d668c%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637191303842131272&sdata=twDFYkTQdMmO8EH%2B6sRPbs7FZpDDT2ngWq5Jwt%2FBdvM%3D&reserved=0, or unsubscribehttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAOYGAUVOYJCAW7DY5EUCD4DRGF2A3ANCNFSM4LDI6HRQ&data=02%7C01%7Crvani%40vmware.com%7Cb888b7b43ed546a1e00108d7c21d668c%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637191303842131272&sdata=hiQNf52B%2BP6DnDDRKKukpGL1n3f2pqNFSbYcZYv3gKM%3D&reserved=0. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
Thank you but I still could not fix this issue –
================================ $rootUser = $sshuser_username $PlainSafeModeAdministratorPassword = $sshuser_passwd $SecureSafeModeAdministratorPassword = ConvertTo-SecureString -String $PlainSafeModeAdministratorPassword -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential ($rootUser, $SecureSafeModeAdministratorPassword) $oSessionSSH = New-SSHSession -ComputerName $ip -Credential $mycreds $stream = $oSessionSSH.Session.CreateShellStream("PS-SSH", 0, 0, 0, 0, 1000) $result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command "sudo su -" '$PlainSafeModeAdministratorPassword' -SecureAction 'uname -a' $sClearPassword if ($result -eq "False"){ $result = Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command "sudo su -" "$PlainSafeModeAdministratorPassword" -SecureAction 'uname -a' $sClearPassword }
$sReturn = $stream.Read() $stream.WriteLine("whoami") sleep -s 2 $sReturn = $stream.Read()
[cid:image001.png@01D5F43F.B5702400]
From: Carlos Perez notifications@github.com Reply to: darkoperator/Posh-SSH reply@reply.github.com Date: Saturday, 7 March 2020 at 4:10 AM To: darkoperator/Posh-SSH Posh-SSH@noreply.github.com Cc: Vani devaneedi nagabhushana reddy Reddy rvani@vmware.com, Author author@noreply.github.com Subject: Re: [darkoperator/Posh-SSH] Invoke-SSHCommand , unable to execute sed command on remote linux host using Invoke-SSHCommand. (#312)
https://github.com/darkoperator/Posh-SSH/blob/master/docs/New-SSHShellStream.md
https://blog.linoproject.net/powershell-managing-ubuntu-with-sudo-and-posh-ssh/
Sent from my iPhone
On Mar 6, 2020, at 6:30 PM, rvani notifications@github.com wrote:
Thank you. But how to do that?
From: Carlos Perez notifications@github.com Reply to: darkoperator/Posh-SSH reply@reply.github.com Date: Saturday, 7 March 2020 at 3:56 AM To: darkoperator/Posh-SSH Posh-SSH@noreply.github.com Cc: Vani devaneedi nagabhushana reddy Reddy rvani@vmware.com, Author author@noreply.github.com Subject: Re: [darkoperator/Posh-SSH] Invoke-SSHCommand , unable to execute sed command on remote linux host using Invoke-SSHCommand. (#312)
You will need a shellstream since echo is part of a full shell and not a binary that would be invoked.
Sent from my iPhone
On Mar 6, 2020, at 6:18 PM, rvani notifications@github.com wrote:
$remotecommand = 'echo '+$sshuser_passwd+' | sudo -S sed /^server/d /etc/ntp.conf > /etc/m21.txt'
Try { $rootUser = $sshuser_username $PlainSafeModeAdministratorPassword = $sshuser_passwd $SecureSafeModeAdministratorPassword = ConvertTo-SecureString -String $PlainSafeModeAdministratorPassword -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential ($rootUser, $SecureSafeModeAdministratorPassword) New-SSHSession -computername $ip -credential $mycreds -AcceptKey | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null LogMessage "SSH Session to $($ip) created"
Invoke-SSHCommand -timeout 300 -sessionid 0 -command 'uname -a' | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
Invoke-SSHCommand -sessionid 0 -command $remotecommand -timeout 2 | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
Invoke-SSHCommand -sessionid 0 -command $remotecommand -timeout 2 | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
LogMessage "Command issued to" Remove-SSHSession -sessionid 0 | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null LogMessage "SSH Session Removed" } Catch { LogMessage "Unable to reimage VxRail using PTAB" Red catchWriter $_ }
OUTPUT :
[03-06-2020_01:53:22] Importing Posh-SSH Module
SessionId Host Connected
0 192.168.31.60 True [03-06-2020_01:53:22] SSH Session to 192.168.31.60 created
Host : 192.168.31.60 Output : {} ExitStatus : 1
[03-06-2020_01:53:22] Command issued to True [03-06-2020_01:53:22] SSH Session Removed
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdarkoperator%2FPosh-SSH%2Fissues%2F312%3Femail_source%3Dnotifications%26email_token%3DAOYGAUSSCH4ZA676ETX2GR3RGF2A3A5CNFSM4LDI6HR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEODBVPI%23issuecomment-595991229&data=02%7C01%7Crvani%40vmware.com%7Cb888b7b43ed546a1e00108d7c21d668c%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637191303842131272&sdata=twDFYkTQdMmO8EH%2B6sRPbs7FZpDDT2ngWq5Jwt%2FBdvM%3D&reserved=0, or unsubscribehttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAOYGAUVOYJCAW7DY5EUCD4DRGF2A3ANCNFSM4LDI6HRQ&data=02%7C01%7Crvani%40vmware.com%7Cb888b7b43ed546a1e00108d7c21d668c%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637191303842131272&sdata=hiQNf52B%2BP6DnDDRKKukpGL1n3f2pqNFSbYcZYv3gKM%3D&reserved=0. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdarkoperator%2FPosh-SSH%2Fissues%2F312%3Femail_source%3Dnotifications%26email_token%3DAOYGAUX7CBFQY77SV5IHSX3RGF3T3A5CNFSM4LDI6HR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEODCS7Y%23issuecomment-595995007&data=02%7C01%7Crvani%40vmware.com%7C5d280de5102045c3de2408d7c21f4d14%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C637191312005349417&sdata=8eSswl%2F86ptYslClN1Cx6G05NHzBl7ipHWfbjUM026A%3D&reserved=0, or unsubscribehttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAOYGAUXY3EMAA37UMRUNYEDRGF3T3ANCNFSM4LDI6HRQ&data=02%7C01%7Crvani%40vmware.com%7C5d280de5102045c3de2408d7c21f4d14%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C637191312005359411&sdata=sWhJgQhC4br7LKdA%2BZXIHahNFCIOprZPEVrwvcv48pI%3D&reserved=0.
PS C:\Users\carlos\Documents\Posh-SSH\Release> New-SSHSession -ComputerName 192.168.1.213 -Credential carlos
SessionId Host Connected
--------- ---- ---------
0 192.168.1.213 True
PS C:\Users\carlos\Documents\Posh-SSH\Release> $stream = New-SSHShellStream -SessionId 0
PS C:\Users\carlos\Documents\Posh-SSH\Release> Invoke-SSHStreamExpectSecureAction -ShellStream $stream -Command 'sudo su -' -ExpectString '[sudo] password for carlos:' -SecureAction (ConvertTo-SecureString ‘Passw0rd1' -AsPlainText -Force)
True
PS C:\Users\carlos\Documents\Posh-SSH\Release> $stream.Read()
root@ubuntu:~#
I could resolve this issue - https://gitlab.eng.vmware.com/isbu-dev-tools/wsa/tree/master
Could not open the link
Sent from my iPhone
On Mar 11, 2020, at 12:28 PM, rvani notifications@github.com wrote:
I could resolve this issue - https://gitlab.eng.vmware.com/isbu-dev-tools/wsa/tree/master
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
From: Carlos Perez notifications@github.com Reply to: darkoperator/Posh-SSH reply@reply.github.com Date: Thursday, 12 March 2020 at 12:20 AM To: darkoperator/Posh-SSH Posh-SSH@noreply.github.com Cc: Vani devaneedi nagabhushana reddy Reddy rvani@vmware.com, Author author@noreply.github.com Subject: Re: [darkoperator/Posh-SSH] Invoke-SSHCommand , unable to execute sed command on remote linux host using Invoke-SSHCommand. (#312)
Could not open the link
Sent from my iPhone
On Mar 11, 2020, at 12:28 PM, rvani notifications@github.com wrote:
I could resolve this issue - https://gitlab.eng.vmware.com/isbu-dev-tools/wsa/tree/master
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdarkoperator%2FPosh-SSH%2Fissues%2F312%23issuecomment-597806762&data=02%7C01%7Crvani%40vmware.com%7Caeb0b6ae6dcc4f828e0608d7c5ed22b4%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637195494588273037&sdata=6TpaXk3pNGRGyHKktpOVQua3IGhx4Z8KNI4TwqAJoYE%3D&reserved=0, or unsubscribehttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAOYGAUV5KW4BSFFJLKJNXMDRG7MRDANCNFSM4LDI6HRQ&data=02%7C01%7Crvani%40vmware.com%7Caeb0b6ae6dcc4f828e0608d7c5ed22b4%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637195494588273037&sdata=fvY28%2FOBOGs5ogdmQoh142inihrDDP4ILc%2BP7iO6S9o%3D&reserved=0.
Unbale to send attachment. Please find the program pasted here –
.Created By: Vani Reddy
.Group: HCI BU
.Organization: VMware, Inc.
.Version: 1.0
.Date: 2020-03-09
==============================================================================================================
.CHANGE_LOG
- 1.x (Vani Reddy / 2020-03-09) - Initial script creation
- Deploy Single Instance of WORKSPACEONE Access Node
=================================================================================================================================================================================================================== .DESCRIPTION This script automates the deployment of single instance of WORKSPACEONE Access node
Function setupLogFile { $timeStamp = Get-Date -Format "MM-dd-yyyy_hh_mm_ss" $Global:logFile = $PSScriptRoot+'\logs\platformPrep-'+$timeStamp+'.log' $logFolder = $PSScriptRoot+'\logs' $logFolderExists = Test-Path $logFolder If (!$logFolderExists) { New-Item -ItemType Directory -Path $logFolder } New-Item -type File -path $logFile | Out-Null $logContent = '['+$timeStamp+'] Starting Log' Add-Content -path $logFile $logContent }
Function LogMessage { param( [Parameter(Mandatory=$true)] [String]$message, [Parameter(Mandatory=$false)] [String]$colour, [Parameter(Mandatory=$false)] [string]$skipnewline )
If (!$colour){
$colour = "green"
}
$timeStamp = Get-Date -Format "MM-dd-yyyy_hh:mm:ss"
Write-Host -NoNewline -ForegroundColor White " [$timestamp]"
If ($skipnewline)
{
Write-Host -NoNewline -ForegroundColor $colour " $message"
}
else
{
Write-Host -ForegroundColor $colour " $message"
}
$logContent = '['+$timeStamp+'] '+$message
Add-Content -path $logFile $logContent
}
Function catchWriter ($object) { $lineNumber = $object.InvocationInfo.ScriptLineNumber $lineText = $object.InvocationInfo.Line.trim() $errorMessage = $object.Exception.Message LogMessage "Error at Script Line $lineNumber" Red LogMessage "Relevant Command: $lineText" Red LogMessage "Error Message: $errorMessage" Red }
Function setConsoleParams { $ErrorActionPreference = "Stop"
If ($Env:OS = "Windows_NT")
{
$width = 180
$height = $((Get-Host).UI.RawUI.MaxWindowSize.Height-5)
$Console = $host.ui.rawui
$Buffer = $Console.BufferSize
$ConSize = $Console.WindowSize
# If the Buffer is wider than the new console setting, first reduce the buffer, then do the resize
If ($Buffer.Width -gt $Width ) {
$ConSize.Width = $Width
$Console.WindowSize = $ConSize
}
$Buffer.Width = $Width
$ConSize.Width = $Width
$Buffer.Height = 3000
$Console.BufferSize = $Buffer
$ConSize = $Console.WindowSize
$ConSize.Width = $Width
$ConSize.Height = $Height
$Console.WindowSize = $ConSize
$ConColour = $Console.BackgroundColor
$Console.BackgroundColor = "Black"
Clear-Host
}
Set-Item wsman:\localhost\client\trustedhosts * -Force
Clear-Host; Write-Host -Object " $utilityName ($utilityBuild)" -ForegroundColor yellow; Write-Host -Object ""
$OriginalPref = $ProgressPreference # Default is 'Continue'
$ProgressPreference = "SilentlyContinue"
{
LogMessage "Importing Posh-SSH Module"
Import-Module -Name Posh-SSH -warningaction silentlycontinue | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
}
Catch
{
LogMessage "POSH-SSH Module not found. Installing"
Install-PackageProvider NuGet -Force | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
Set-PSRepository PSGallery -InstallationPolicy Trusted | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
Install-Module -Name Posh-SSH -force | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
}
Try
{
LogMessage "Importing PowerCLI Module"
Import-Module -Name VMware.PowerCLI | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
}
Catch
{
LogMessage "PowerCLI Module not found. Installing. Note this is a large installer and may take several minutes to download and install "
Install-PackageProvider NuGet -Force | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
Set-PSRepository PSGallery -InstallationPolicy Trusted | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
Install-Module VMware.PowerCLI -confirm:$false | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
}
}
Function deployWSA { $WSAovfPath='C:\Users\mrvani\MMM\WSA\identity-manager-3.3.2.0-15504338_OVF10.ova' $VC="sfo01m01vc01.sfo01.rainpole.local" $VCUsername="administrator@vsphere.local" $VCPasswd="VMware123!" $WSAvmname="sfo01wsa01" $WSAvmnameFQDN="sfo01wsa01.sfo01.rainpole.local" $Datacenter="sfo01-m01-dc" $Cluster="sfo01-m01-mgmt01" $Datastore="sfo01-m01-vsan" $WSAvmFolder="sfo01-m01fd-wsa" $timezone="US/Pacific" $gateway="192.168.31.1" $domain="sfo01.rainpole.local" $rootDomain="rainpole.local" $searchpath="sfo01.rainpole.local, rainpole.local"
$dnsServer1="172.24.11.4"
$dnsServer2="172.24.11.5"
$WSAip="192.168.31.60"
$netmask="255.255.255.0"
$network="regionasegment"
$logFile="M:\BigNFS\MWORKSPACE\logfile.txt"
$ntpServer1="ntp.sfo01.rainpole.local"
$ntpServer2="ntp.lax01.rainpole.local"
If (Test-Path -Path $WSAovfPath)
{
LogMessage "Found WSAOVA: $WSAovfPath. Proceeding."
Try
{
LogMessage "Connecting to vCenter Server $($VC)"
Connect-VIServer $VC -user $VCUsername -Password $VCPasswd | Out-File $logFile -encoding ASCII -append
}
Catch
{
LogMessage "Unable to connect to vCenter Server $($VC)" Red
catchWriter $_
}
Try
{
LogMessage "Checking for Pre-Existing WSA deployment named $WSAvmname"
$WSAExists = Get-VM -Name $WSAvmname -ErrorAction SilentlyContinue
}
Catch
{
LogMessage "Failed to check for Pre-Existing $WSAvmname Node" Red
catchWriter $_
}
If ($WSAExists)
{
LogMessage "A virtual machine called $WSAvmname already exists on host" Yellow
}
else
{
LogMessage "No virtual machine named $WSAvmname found. Proceeding with deployment"
$command = '"C:\Program Files\VMware\VMware OVF Tool\ovftool.exe" --noSSLVerify --acceptAllEulas --allowAllExtraConfig --diskMode=thin --powerOn --name='+$WSAvmname+' --ipProtocol="IPv4" --ipAllocationPolicy="fixedAllocatedPolicy" --vmFolder='+$WSAvmFolder+' --net:"Network 1"='+$network+' --datastore='+$Datastore+' --X:injectOvfEnv --prop:vamitimezone='+$timezone+' --prop:vami.ip0.IdentityManager='+$WSAip+' --prop:vami.netmask0.IdentityManager='+$netmask+' --prop:vami.hostname='+$WSAvmnameFQDN+' --prop:vami.gateway.IdentityManager='+$gateway+' --prop:vami.domain.IdentityManager='+$domain+' --prop:vami.searchpath.IdentityManager='+$domain+' --prop:vami.DNS.IdentityManager='+$dnsServer1+' $WSAovfPath "vi://'+$VCUsername+':'+$VCpasswd+'@'+$VC+'/'+$Datacenter+'/host/'+$Cluster+'/"'
LogMessage "This will take at least 10-15 minutes and maybe significantly longer depending on the environment. Please be patient"
iex "& $command" | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
Try
{
$WSAExists = Get-VM -Name $WSAvmname -ErrorAction SilentlyContinue
}
Catch
{
catchWriter $_
}
If ($WSAExists)
{
$Timeout = 320 ## seconds
$CheckEvery = 1 ## second
try
{
## Start the timer
$timer = [Diagnostics.Stopwatch]::StartNew()
LogMessage "Checking the deployment status of WORKSPACEONE Access: $WSAvmnamee"
LogMessage "Waiting for $($WSAip) to become pingable." Yellow
While (-not (Test-Connection -ComputerName $WSAip -Quiet -Count 1))
{
## If the timer has waited greater than or equal to the timeout, throw an exception exiting the loop
If ($timer.Elapsed.TotalSeconds -ge $Timeout)
{
Throw "Timeout exceeded. Giving up on ping availability to $($WSAip)"
}
## Stop the loop every $CheckEvery seconds
Start-Sleep -Seconds $CheckEvery
}
}
catch
{
LogMessage "ERROR: Failed to get a response from $WSAvmname" Red
}
finally
{
## Stop the timer
$timer.Stop()
}
$test = iex "& $command" 2>&1 | Out-Null
LogMessage "Initial connection made, waiting for $($WSAvmnameFQDN) to boot up completely" Yellow
#Do{sleep 30; $test = iex "& $command"} Until($test -eq 'active')
sleep 325
LogMessage "Deployment of $WSAvmname using $WSAovfPath completed successfully"
Disconnect-viserver * -Force -Confirm:$false -WarningAction SilentlyContinue
}
else
{
LogMessage "WSA VM Failed to deploy. Please check for errors in $logFile" Red
}
}
}
else
{
LogMessage "The OVA/OVF file $WSAovfPath does not exist" Red
}
}
This is how I could successfully execute all ‘sed’ commands on remote linux host.
Thanks and Regards, Vani Reddy
From: Carlos Perez notifications@github.com Reply to: darkoperator/Posh-SSH reply@reply.github.com Date: Thursday, 12 March 2020 at 12:20 AM To: darkoperator/Posh-SSH Posh-SSH@noreply.github.com Cc: Vani devaneedi nagabhushana reddy Reddy rvani@vmware.com, Author author@noreply.github.com Subject: Re: [darkoperator/Posh-SSH] Invoke-SSHCommand , unable to execute sed command on remote linux host using Invoke-SSHCommand. (#312)
Could not open the link
Sent from my iPhone
On Mar 11, 2020, at 12:28 PM, rvani notifications@github.com wrote:
I could resolve this issue - https://gitlab.eng.vmware.com/isbu-dev-tools/wsa/tree/master
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdarkoperator%2FPosh-SSH%2Fissues%2F312%23issuecomment-597806762&data=02%7C01%7Crvani%40vmware.com%7Caeb0b6ae6dcc4f828e0608d7c5ed22b4%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637195494588273037&sdata=6TpaXk3pNGRGyHKktpOVQua3IGhx4Z8KNI4TwqAJoYE%3D&reserved=0, or unsubscribehttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAOYGAUV5KW4BSFFJLKJNXMDRG7MRDANCNFSM4LDI6HRQ&data=02%7C01%7Crvani%40vmware.com%7Caeb0b6ae6dcc4f828e0608d7c5ed22b4%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637195494588273037&sdata=fvY28%2FOBOGs5ogdmQoh142inihrDDP4ILc%2BP7iO6S9o%3D&reserved=0.
Can I close the issue?
Yes please. Thank you for the support provided.
From: Carlos Perez notifications@github.com Reply to: darkoperator/Posh-SSH reply@reply.github.com Date: Tuesday, 17 March 2020 at 12:59 AM To: darkoperator/Posh-SSH Posh-SSH@noreply.github.com Cc: Vani devaneedi nagabhushana reddy Reddy rvani@vmware.com, Author author@noreply.github.com Subject: Re: [darkoperator/Posh-SSH] Invoke-SSHCommand , unable to execute sed command on remote linux host using Invoke-SSHCommand. (#312)
Can I close the issue?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdarkoperator%2FPosh-SSH%2Fissues%2F312%23issuecomment-599720234&data=02%7C01%7Crvani%40vmware.com%7C554cfac1446543af10d108d7c9e04d41%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637199837516856209&sdata=V%2FCi39oD1bgulQ%2BRgOA%2BSVi68Ps7u1ldpqgwX1Xvr8c%3D&reserved=0, or unsubscribehttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAOYGAUQ2OFJNIKPSE5DH6KTRHZ4YJANCNFSM4LDI6HRQ&data=02%7C01%7Crvani%40vmware.com%7C554cfac1446543af10d108d7c9e04d41%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637199837516856209&sdata=yjKps1Wtl63LRzLR5V5LGeCN6pxSYNYHguAwn2Kqtjs%3D&reserved=0.
$remotecommand = 'echo '+$sshuser_passwd+' | sudo -S sed /^server/d /etc/ntp.conf > /etc/m21.txt'
Try { $rootUser = $sshuser_username $PlainSafeModeAdministratorPassword = $sshuser_passwd $SecureSafeModeAdministratorPassword = ConvertTo-SecureString -String $PlainSafeModeAdministratorPassword -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential ($rootUser, $SecureSafeModeAdministratorPassword) New-SSHSession -computername $ip -credential $mycreds -AcceptKey | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null LogMessage "SSH Session to $($ip) created"
Invoke-SSHCommand -timeout 300 -sessionid 0 -command 'uname -a' | Out-File $logFile -encoding ASCII -append #2>&1 | Out-Null
} Catch { LogMessage "Unable to reimage VxRail using PTAB" Red catchWriter $_ }
OUTPUT :
[03-06-2020_01:53:22] Importing Posh-SSH Module
SessionId Host Connected
[03-06-2020_01:53:22] SSH Session to 192.168.31.60 created
Host : 192.168.31.60 Output : {} ExitStatus : 1
[03-06-2020_01:53:22] Command issued to True [03-06-2020_01:53:22] SSH Session Removed