Author Posts

June 7, 2016 at 4:44 pm

I am in the process of creating a GUI tool for pulling remote server services to manage them (Start/Stop/Restart). But getting "cannot open service control manager on computer "server name" – is there any other way ?

June 7, 2016 at 5:16 pm

Can you view those same servers' remote services from the MMC?
Also can you share a snippet of your code?

June 7, 2016 at 10:48 pm

Default server name is localhost and even that is not working.

****CODE*****
$SvcsBtnConnectList_Click={
$varServerName = $SvcsTxtBoxServerNameList
try
{
$SvcsList = Get-service -ComputerName $varServerName | where { $_.DisplayName } | select -Property DisplayName
$ServicesStatusBar.Text = "Connected to $($varServerName) and List Loaded"
Load-Combobox -ComboBox $SvcsCmbBoxSelectService -Items $SvcsList
}
catch
{
$SvcsTxtBoxServerNameError.SetIconAlignment($EvtBtnConnect, 'MiddleLeft')
$SvcsTxtBoxServerNameError.SetError($EvtBtnConnect, $($_.Exception.Message))
$ServicesStatusBar.Text = "$($varServerName) : $($_.Exception.Message)"
}
}

June 7, 2016 at 11:36 pm

If I set $varServerName to 'localhost' and run this line:

Get-service -ComputerName $varServerName | where { $_.DisplayName } | select -Property DisplayName

...it works fine. If you just do that one line too, does it work?

I'm assuming that's the line that's tripping you up. Have you tried using the F9 breakpoint feature in ISE to step through your function?

June 8, 2016 at 12:00 am

In PS ISE, Yes it works. When we do via GUI tool i am building, throws error.

June 8, 2016 at 12:20 am

Complete shot in the dark here, but should this line be?...

$varServerName = $SvcsTxtBoxServerNameList.Text

June 8, 2016 at 3:23 am

Hi,

Somehow this is still fails for remote computer, I tried two below variations. This failing even in PS ISE

Get-service -ComputerName vdaldc01v | where { $_.DisplayName } | select -Property DisplayName
Error:
Get-service : Cannot open Service Control Manager on computer 'vdaldc01v'. This operation might require other privileges.
At line:1 char:1
+ Get-service -ComputerName vdaldc01v | where { $_.DisplayName } | select -Propert ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Service], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.GetServiceCommand

***************************************************************
Get-WmiObject -Class WIN32_service -ComputerName vdaldc01v
Error :
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:1 char:1
+ Get-WmiObject -Class WIN32_service -ComputerName vdaldc01v
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

1. Running with Domain admin privileges in my test lab
2. I saw few posts for similar issue, which suggest enable RPC/DCOM manually or Read permissions. For WinRM is disabled in our PRD
enviroment. So, want to check is there any real alternative to gather remote services without any modification.

Thanks
Kris

June 8, 2016 at 6:28 am

Hello
Have you tried Invoke-Command?

Invoke-Command -ComputerName "pc" -ScriptBlock  { Get-Service bits | Stop-Service -Force}

Edit:
Just saw WinRM is disabled in Prod, so it's not an alternative for you.

  • This reply was modified 2 years, 3 months ago by  Mystic pl.

June 8, 2016 at 1:41 pm

Do your remote machines require credentials? You should really post your psf in the sapien forums.

$services = (Get-WmiObject -Class WIN32_service -ComputerName " -Credential $cred).displayname
Load-ComboBox $combobox1 -Items $services

June 8, 2016 at 1:52 pm

#------------------------------------------------------------------------
# Source File Information (DO NOT MODIFY)
# Source ID: 7480120c-0d76-4c46-b0b7-4b89203b9b91

#------------------------------------------------------------------------


#----------------------------------------------
#region Application Functions
#----------------------------------------------

#endregion Application Functions

#----------------------------------------------
# Generated Form Function
#----------------------------------------------
function Call-services_psf {

	#----------------------------------------------
	#region Import the Assemblies
	#----------------------------------------------
	[void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
	[void][reflection.assembly]::Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
	[void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
	[void][reflection.assembly]::Load('System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
	[void][reflection.assembly]::Load('System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
	#endregion Import Assemblies

	#----------------------------------------------
	#region Generated Form Objects
	#----------------------------------------------
	[System.Windows.Forms.Application]::EnableVisualStyles()
	$form1 = New-Object 'System.Windows.Forms.Form'
	$textbox1 = New-Object 'System.Windows.Forms.TextBox'
	$buttonConnect = New-Object 'System.Windows.Forms.Button'
	$combobox1 = New-Object 'System.Windows.Forms.ComboBox'
	$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
	#endregion Generated Form Objects

	#----------------------------------------------
	# User Generated Script
	#----------------------------------------------
	
	$form1_Load = {
		
		$script:cred = Get-Credential
		
	}
	
	#region Control Helper Functions
	function Load-ComboBox 
	{
	
		Param (
			[ValidateNotNull()]
			[Parameter(Mandatory=$true)]
			[System.Windows.Forms.ComboBox]$ComboBox,
			[ValidateNotNull()]
			[Parameter(Mandatory=$true)]
			$Items,
		    [Parameter(Mandatory=$false)]
			[string]$DisplayMember,
			[switch]$Append
		)
		
		if(-not $Append)
		{
			$ComboBox.Items.Clear()	
		}
		
		if($Items -is [Object[]])
		{
			$ComboBox.Items.AddRange($Items)
		}
		elseif ($Items -is [Array])
		{
			$ComboBox.BeginUpdate()
			foreach($obj in $Items)
			{
				$ComboBox.Items.Add($obj)	
			}
			$ComboBox.EndUpdate()
		}
		else
		{
			$ComboBox.Items.Add($Items)	
		}
	
		$ComboBox.DisplayMember = $DisplayMember	
	}
	#endregion
	
	$buttonConnect_Click={
		
		$services = (Get-WmiObject -Class WIN32_service -ComputerName $textbox1.text -Credential $cred).displayname
		Load-ComboBox $combobox1 -Items $services
		$combobox1.DroppedDown = $true
	}
	
	# --End User Generated Script--
	#----------------------------------------------
	#region Generated Events
	#----------------------------------------------
	
	$Form_StateCorrection_Load=
	{
		#Correct the initial state of the form to prevent the .Net maximized form issue
		$form1.WindowState = $InitialFormWindowState
	}
	
	$Form_Cleanup_FormClosed=
	{
		#Remove all event handlers from the controls
		try
		{
			$buttonConnect.remove_Click($buttonConnect_Click)
			$form1.remove_Load($form1_Load)
			$form1.remove_Load($Form_StateCorrection_Load)
			$form1.remove_FormClosed($Form_Cleanup_FormClosed)
		}
		catch [Exception]
		{ }
	}
	#endregion Generated Events

	#----------------------------------------------
	#region Generated Form Code
	#----------------------------------------------
	$form1.SuspendLayout()
	#
	# form1
	#
	$form1.Controls.Add($textbox1)
	$form1.Controls.Add($buttonConnect)
	$form1.Controls.Add($combobox1)
	$form1.ClientSize = '343, 123'
	$form1.Name = 'form1'
	$form1.Text = 'Form'
	$form1.add_Load($form1_Load)
	#
	# textbox1
	#
	$textbox1.Location = '13, 29'
	$textbox1.Name = 'textbox1'
	$textbox1.Size = '132, 20'
	$textbox1.TabIndex = 2
	#
	# buttonConnect
	#
	$buttonConnect.Location = '166, 27'
	$buttonConnect.Name = 'buttonConnect'
	$buttonConnect.Size = '75, 23'
	$buttonConnect.TabIndex = 1
	$buttonConnect.Text = 'Connect'
	$buttonConnect.UseVisualStyleBackColor = $True
	$buttonConnect.add_Click($buttonConnect_Click)
	#
	# combobox1
	#
	$combobox1.FormattingEnabled = $True
	$combobox1.Location = '12, 75'
	$combobox1.Name = 'combobox1'
	$combobox1.Size = '314, 21'
	$combobox1.TabIndex = 0
	$form1.ResumeLayout()
	#endregion Generated Form Code

	#----------------------------------------------

	#Save the initial state of the form
	$InitialFormWindowState = $form1.WindowState
	#Init the OnLoad event to correct the initial state of the form
	$form1.add_Load($Form_StateCorrection_Load)
	#Clean up the control events
	$form1.add_FormClosed($Form_Cleanup_FormClosed)
	#Show the Form
	return $form1.ShowDialog()

} #End Function

#Call the form
Call-services_psf | Out-Null