I am having some issues getting command to work with posh-ssh and Cisco gear.
Commands are pretty simple;
New-SSHSession -ComputerName 10.10.101.240 -Port 22
Will connect fine, and will give me an ID.
I then try
Invoke-SSHCommand -SessionId 0 -Command "show version"
but I always get
Exception calling "EndExecute" with "1" argument(s): "An established connection was aborted by the server."
At C:\Program Files\WindowsPowerShell\Modules\Posh-SSH\2.0.2\Posh-SSH.psm1:266 char:25
+ $Output = $_.cmd.EndExecute($_.Async)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SshConnectionException
I have tried different hosts and different PCs.
I can, however, use $sshsession.write() and $sshsession.read() and I can talk to the switch fine.
Can anyone point out what I am doing wrong here?
Related
I'm trying to speed up how soon SCCM recognises a device on the domain and starts the process of installing applications.
I have the below in powershell
$CCMInstallerPath = "\\ServerFQDN\SMS_MAN\Client\ccmsetup.exe"
$args = "/mp:MPServer", "/LOGON", "/UsePKICert", "SMSSLP=SMSSLPServer", "SMSSITECODE=MAN"
& $CCMInstallerPath $args
I get the below error:
Program 'ccmsetup.exe' failed to run: Access is deniedAt line:1 char:5
+ & $CCMInstallerPath $args
+ ~~~~~~~~~~~~~~~~~~~~~~~~~.
At line:1 char:5
+ & $CCMInstallerPath $args
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [], ApplicationFailedException
+ FullyQualifiedErrorId : NativeCommandFailed
I have read and execute access to this file, both by group and directly by name
I have also tried:
Start-Process -FilePath \\ServerFQDN\SMS_MAN\Client\ccmsetup.exe -ArgumentList "/mp:MPServer", "/logon SMSSITECODE-MAN", "/UsePKICert"
and get the error
Start-Process : This command cannot be run due to the error: Access is denied.
At line:1 char:5
+ Start-Process -FilePath \\ServerFQDN\SMS_MAN\Client\c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
ServerFQDN is a replacement for one of our NM servers
I can fully connect to the folder and run the exe manually
I am running elevated powershell
Issue was caused by incorrect share permissions found in effective access.
Permission was granted to run the file but effective access was showing differences
Powershell Errors: "Session operation has timed out" At C:\SpDrive\Moodle\Provision-MoodleLMS.ps1:108 char:2
+ Invoke-SSHCommand -ComputerName $serName -Command "$temp" -q
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-SSHCommand], MethodInvocationException
+ FullyQualifiedErrorId : SshOperationTimeoutException,Invoke-SSHCommand
Is there any way to increase the session timeout for Invoke-SSHCommand ?
According to this GitHub issue, the developer has added a -Timeout parameter to address this in version 1.7.
Unfortunately, I cannot find this in the release notes, and all I manage to install on my own computer is version 1.6, which does not have that parameter :-/.
you can use "New-SSHSession" Like the following, and you can modify "ConnectionTimeout" as you want.
New-SSHSession -ComputerName $ComputerName -Credential $Credentials -ConnectionTimeout 5000
I am trying to get a registry value from a remote machine but everything I have tried did not work.
Both machines are running windows 7 x64, they are on the same domain, firewall off, powershell 4.0
when I run :
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", "APPS-EUAUTO1")
$key = $reg.OpenSubkey('SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion')
Write-Host $key.GetValue('InstallDate')
i get
Exception calling "OpenRemoteBaseKey" with "2" argument(s): "The network path was not found.
"
At C:\Users\User\Desktop\test.ps1:1 char:1
+ $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", "APPS-EU ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : IOException
I know nothing of .Net and I have only played with PowerShell for the last month.
I have also tried the module PSRemoteRegistry and when I am using Get-RegValue I get the same error message (I think it is using the same thing)
Assuming you can ping APPS-EUAUTO1(and it resolves to correct IP) and firewall is off.. make sure Remote Registry service is running on your APPS-EUAUTO1
I'm working on a script to deploy vendor software to a large environment. The first step is to stop the services in question. The script executes fine in our test environment, but I'm not an admin in the production environment so I'm convinced it's a permissions issue. I can't get admin rights to the prod environment so I need to try to find out anything that I may need to set to grant permissions to stop services remotely. I'm issuing the following command to stop services:
Stop-Service -InputObject $(Get-Service -Computer $destination.Server -Name ("moca."+$destEnv))
When I run the script I get:
Cannot find any service with service name 'moca.WMSPRD'.
+ CategoryInfo : ObjectNotFound: (moca.WMSPRD:String) [Get-Service], ServiceCommandException
+ FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand
Cannot validate argument on parameter 'InputObject'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
+ CategoryInfo : InvalidData: (:) [Stop-Service], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StopServiceCommand
The service definitely exists and if I rdp into the target box and issue the stop-service command locally it will execute. So there is something preventing me from stopping the service remotely. Any ideas?
Edit:
A coworker suggested using WMI so tried replacing the Stop-Service line with:
(Get-WmiObject -computer $destination.Server Win32_Service -Filter ("Name='moca."+$destEnv+"'")).InvokeMethod("StopService",$null)
and I get:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
+ CategoryInfo : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
If you know the exact service name you can try this
(Get-WmiObject -computerName $_.name Win32_Service -Filter "Name='moca'").StopService()
Here im assuming that the service name is moca
Is DCOM working on the remote computer? I know how to do it with remote powershell, which uses wsman:
invoke-command comp001 { stop-service adobearmservice }
Im trying to change the windows update settings in a remote server using powershell, but when i run the below commands it gives me an error.
PS C:\Windows\system32> Enter-PSSession opalisbinary
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings = (New-Object -com "Microsoft.Update.AutoUpdate").Settings
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings.NotificationLevel=2
Property 'NotificationLevel' cannot be found on this object; make sure it exists and is settable.
At line:1 char:14
+ $AUSettings. <<<< NotificationLevel=2
+ CategoryInfo : InvalidOperation: (NotificationLevel:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings.IncludeRecommendedUpdates=$true
Property 'IncludeRecommendedUpdates' cannot be found on this object; make sure it exists and is settable.
At line:1 char:14
+ $AUSettings. <<<< IncludeRecommendedUpdates=$true
+ CategoryInfo : InvalidOperation: (IncludeRecommendedUpdates:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
[opalisbinary]: PS C:\Users\superv\Documents> $AUSettings.Save()
You cannot call a method on a null-valued expression.
At line:1 char:18
+ $AUSettings.Save <<<< ()
+ CategoryInfo : InvalidOperation: (Save:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Although when i run it locally on the server it works fine...
Could anyone please help me.
Does it work when you connect via Remote desktop and run the commands? It also depends on the bittnes. I don't know the Microsoft.Update.AutoUpdate, so I'm just guessing, but - is it available for x64 version of PowerShell? In other words if you run it locally in x64 version and x86, do you see the errors?
I am sorry, I could not find a real answer. What I found is this link which states that remote PS sessions can be used with SCCM 2012, but they could not with SCCM 2007.
This does not help you, but it seems that not all COM objects are compatible with remote PS sessions.