I am researching using SQLPS module; PowerShell version 3.0. When running Get-SqlInstance, I consistently get the following error.
PS 11/16/2015 08:34:29> $cred = Get-Credential
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
PS 11/16/2015 08:44:28> $instance = Get-SqlInstance -MachineName SM1208 -Credential $cred
Get-SqlInstance : The operation failed on target server 'SM1208'. Verify that the target server is accessible and that the SQL Server
Cloud Adapter service is running.
At line:1 char:13
+ $instance = Get-SqlInstance -MachineName SM1208 -Credential $cred
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (SM1208:String) [Get-SqlInstance], SqlPowerShellRemoteOperationFailedException
+ FullyQualifiedErrorId : RemoteOperationFailedError,Microsoft.SqlServer.Management.PowerShell.IaaS.GetSqlInstanceCommand
I have tried this using localhost, the IP, and a different server that also hosts SQL Server instances. Also used the -Name to specify the instance name. Same error each time. SQL Server instance is running on the hosts.
PS 11/16/2015 08:44:55> Get-ExecutionPolicy
RemoteSigned
Any ideas? Thanks
From the error, and confirmed by OP, it seems a needed service on the target host is missing:
Verify that (...) SQL Server Cloud Adapter service is running.
Try:
Get-Item SQLSERVER:\SQL\machinename\instancename
Related
Goal: Secure Powershell Remoting to Communicate from Docker Container (Windows Server Core) to Host Machine (Windows 10).
I am trying to communicate from Docker Container to Hostmachine to run Powershell commands. PS Remoting looked promising. I did a little POC and It works simply using HTTP. I just pass in the Credentials and everything seems to work fine. However, I am having hard time securing the PS Remoting using SSL.
I followed this article to secure the PS Remoting.
Like below
$password = ConvertTo-SecureString "passwordstring" -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ("username string", $password)
Enter-PSSession -ComputerName "ComputerName" -UseSSL -Credential $Cred
Expected: Powershell Remoting to Work -UsingSSL
Actual:
Enter-PSSession : Connecting to remote server DESKTOP-T773322.mshome.net failed with the following error message : Access is denied.
For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:1
+ Enter-PSSession -ComputerName DESKTOP-T773322.mshome.net -UseSSL -Cre ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (DESKTOP-T773322.mshome.net:String) [Enter-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
I am able to get the -UseSSL working from a VM to my Local Machine. but not Docker Container to Host Machine.
Things I tried:
Turn off all Windows Firewalls.
Ping works both ways (From Container to Host and Vice versa).
Ran Set-PSSessionConfiguration -ShowSecurityDescriptorUI -Name Microsoft.PowerShell to verify if the User has enough permissions to Remote Connect.
Restart Machine.
Added the Container Machine to trusted Hosts.
Changed Trusted Hosts Value to *(all).
Note: The end goal here is to communicate from Docker Container to Local Host Machine. So, It can run Powershell Commands/Batch Files on the Host machine (Securely - Using SSL). I have not found an alternative other than PS Remoting. Please suggest me if there is another better way to do this.
I'm writing a series of automation scripts that will allow our developers to stand up a simple development environment in Azure. This environment has 3 primary properties:
There is a client machine (Windows 10) where dev tools like their IDE and code will live.
There is a server machine (Windows Server 2016) where that their scripts will target.
Both of these machines live in the same domain, and 1 Domain Admin user is available for use.
I have steps 1 and 2 scripted out, but 3 is currently a mess. Since the script is designed to work from the Developer's local workstation, I need to have the script remote in to the Windows Server and run a few commands to set up the Domain Controller.
Here is my code currently:
Invoke-Command -ComputerName "$RGName-$VMPurpose" -ScriptBlock
{
$ADFeature = Install-WindowsFeature AD-Domain-Services
If ($ADFeature.Success -eq $true)
{
Import-Module ADDSDeployment
Install-ADDSForest -CreateDnsDelegation:$false -DatabasePath
"C:\Windows\NTDS" -DomainMode "Win2016R2" -DomainName "$project.com" -
DomainNetbiosName "$project" -ForestMode "Win2016R2" -InstallDns:$true -
LogPath "C:\Windows\NTDS" -NoRebootOnCompletion $false -sysvolpath
"C:\Windows\SYSVOL" -force $true
$domUserPassword = ConvertTo-SecureString "Th1s is a bad password" -
AsPlainText -Force
New-ADUser -Name "$VMPurpose-DomAdm" -AccountPassword
$domUserPassword
Add-ADGroupMember -Name "Administrators" -Member {Get-ADUser
"$VMPurpose-DomAdm"}
}
} -Credential $Cred
When I attempt to run this I get an error showing that WinRM cannot connect, specifically this error:
[Foo] Connecting to remote server Foo failed with the following error
message : WinRM cannot process the request. The following error with
errorcode 0x80090311
occurred while using Kerberos authentication: There are currently no logon
servers available to service the logon request.
Possible causes are:
-The user name or password specified are invalid.
-Kerberos is used when no authentication method and no user name are
specified.
-Kerberos accepts domain user names, but not local user names.
-The Service Principal Name (SPN) for the remote computer name and port
does not exist.
-The client and remote computers are in different domains and there is no
trust between the two domains.
After checking for the above issues, try the following:
-Check the Event Viewer for events related to authentication.
-Change the authentication method; add the destination computer to the
WinRM TrustedHosts configuration setting or use HTTPS transport.
Note that computers in the TrustedHosts list might not be authenticated.
-For more information about WinRM configuration, run the following
command: winrm help config. For more information, see the
about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (Foo:String) [],
PSRemotingTransportException
+ FullyQualifiedErrorId : AuthenticationFailed,PSSessionStateBroken
I added the target machine (Foo) to the TrustedHosts configuration setting in WinRM (I actually added the IP address to make sure that there wasn't any DNS problem happening), and then I get this error:
[Foo's IP] Connecting to remote server <Foo's IP> failed with the following
error message : WinRM cannot complete the operation. Verify that the
specified computer name is valid, that the
computer is accessible over the network, and that a firewall exception for
the WinRM service is enabled and allows access from this computer. By
default, the WinRM firewall exception for public
profiles limits access to remote computers within the same local subnet. For
more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (Foo's Ip[:String) [],
PSRemotingTransportException
+ FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionStateBroken
Any thoughts here? Am what I trying simply not ever going to work via Powershell?
According to your error message, we can use this PowerShell script to invoke command to Azure:
$username = 'jason'
$pass = ConvertTo-SecureString -string 'password' -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $pass
$s = New-PSSession -ConnectionUri 'http://23.99.82.2:5985' -Credential $cred -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)
Invoke-Command -Session $s -ScriptBlock {Get-Process PowerShell}
PowerShell result like this:
More information about invoke command, please refer to this answer.
I'm trying to connect to amazon windows instance using powershell. I'm following the steps from the below link:
Execute powershell script remotely on Amazon EC2 instance from my local computer
http://barakme.tumblr.com/post/89748667258/windows-remote-execution-with-powershell-and-winrm
http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/connecting_to_windows_instance.html
I cannot make this to work. I'm new Amazon CLI, I've been struggling for the past few days to connect to my windows instance which is already running.
I keep getting the same error each time. Am I missing out something?
enable-psremoting -force
set-item wsman:\localhost\Client\TrustedHosts -value "*" -force
$password = convertto-securestring -asplaintext -force -string "MY_PASSWORD_GOES_HEREr"
$credential = new-object -typename system.management.automation.pscredential -argumentlist "MY_USERNAME", $pa
ssword
$session = new-pssession x.x.x.x -credential $credential
new-pssession : [x.x.x.x] Connecting to remote server x.x.x.x failed with the following error message : WinRM
cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over
the network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By
default, the WinRM firewall exception for public profiles limits access to remote computers within the same local
subnet. For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:12
+ $session = new-pssession x.x.x.x -credential $credential
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin
gTransportException
+ FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionOpenFailed
I am trying to run my DSC configuration against a remote machine and end up with the following error
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' =
SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' =
root/Microsoft/Windows/DesiredStateConfiguration'.
The WinRM client cannot process the request. If the authentication scheme is different from Kerberos, or if the client
computer is not joined to a domain, then HTTPS transport must be used or the destination machine must be added to the
TrustedHosts configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts
list might not be authenticated. You can get more information about that by running the following command: winrm help
config.
+ CategoryInfo : NotEnabled: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : HRESULT 0x803380e4
+ PSComputerName : vishtest.timmons.com
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.169 seconds
The server has the WinRM service running and configured for running over HTTPS. The client machine can connect to the remote machine successfully with the Enter-PSSession command.
Enter-PSSession -computerName vishtest.timmons.com -credential $credential -UseSSL
Any ideas on what I could be missing here?
Just figured it out with some help from some tweeps. I had to create a CimSession with the -UseSSL flag and pass that session to the Start-DscConfiguration command. The Start-DscConfiguration by itself does not have the -UseSSL option. Did not need any DSC service on the target to push configuration.
Try running this command :
Enable-PSRemoting -Force
This always works for me when I face that error!
I am having problems connecting to a remote server using PowerShell where the remote machine uses a non-default port number. The setup is as follows: I have a virtual host server with several virtual machines. All of these virtual machines have the same IP address but are accessed with a different port, for example:
a.b.c.d:3000
a.b.c.d:3001
etc
So, the PowerShell script I have so far is:
$password = ConvertTo-SecureString "<MyPassword>" -AsPlainText -Force
$cred= New-Object System.Management.Automation.PSCredential ("<Domain\UserName>", $password)
Enter-PSSession -ComputerName <IPAddress> -Port <PortNumber> -Credential $cred
The bits inside the "<>" are specific to the individual machines. When running this script I get the following error:
Enter-PSSession : Connecting to remote server failed
with the following error message : The client cannot connect to the
destination specified in the request. Verify that the service on the
destination is running and is accepting requests. Consult the logs and
documentation for the WS- Management service running on the
destination, most commonly IIS or WinRM. If the destination is the
WinRM service, run the following command o n the destination to
analyze and configure the WinRM service: "winrm quickconfig". For more
information, see the about_Remote_Troubleshooting H elp topic. At
C:\PowerShell\Test7.ps1:25 char:16
+ Enter-PSSession <<<< -ComputerName -Port -Credential $cred
+ CategoryInfo : InvalidArgument: (:String) [Enter-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
Another variant I tried is as follows:
$password = ConvertTo-SecureString "<MyPassword>" -AsPlainText -Force
$cred= New-Object System.Management.Automation.PSCredential ("<Domain\UserName>", $password)
$powershell_uri = "http://<IPAddress>:<PortNumber>"
Enter-PSSession -ConnectionUri $powershell_uri -Credential $cred
but this gave the following error:
Enter-PSSession : Connecting to remote server failed with the
following error message : The client cannot connect to the destination
specified in the request. Verify that the service on the destination
is running and is accepting requests. Consult the logs and
documentation for the WS- Management service running on the
destination, most commonly IIS or WinRM. If the destination is the
WinRM service, run the following command o n the destination to
analyze and configure the WinRM service: "winrm quickconfig". For more
information, see the about_Remote_Troubleshooting H elp topic. At
C:\PowerShell\Test7.ps1:21 char:16
+ Enter-PSSession <<<< -ConnectionUri $powershell_uri -Credential $cred # -ComputerName -Port -Credential
$cred
+ CategoryInfo : InvalidArgument: (http://:/:Uri) [Enter-PSSession],
PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
I have set the TrustedHosts on my local machine (winrm set winrm/config/client #{TrustedHosts=""}) and on the remote machine I have run the "winrm quickconfig" command. On the remote machine I have also run the "winrm create winrm/config/listener?Address=*+Transport=HTTP #{Port=""}" command.
Any assistance on how I can establish a connection within PowerShell to these machines would be greatly appreciated.
On the remote computer:
In: Control Panel\Network and Internet\Network and Sharing CenterMake sure the remote computer is not in the public location, but set it to work or private
Start PowerShell in administrator mode and enter the command:
Enable-PSRemoting
exit
Goto Control Panel -> System and Security ->Windows Firewall and click advanced Settings
Add the ip-range of your managing computer to windows remote management(http-In) both in the private and in the domain inbound rules.
On the managing computer:
Start PowerShell in administrator mode and enter the command:
Set-Item WSMan:\localhost\Client\TrustedHosts -Concatenate remotecomputer.domain.suffix -Force
using your complete remote computer's network path.
This adds the remote computer network name to your trusted hosts.
That should do the trick.