Can you restart SQL Server Reporting Services using Powershell?

Hi!

I’m new to powershell but trying to learn. I need to restart a named instance of SSRS on a server. The instance is called POCSSRS

This is my code:

Get-Service -Computer $ssrs.machinename -Name “POCSSRS” | Restart-Service;

But I get the error:

Get-Service : Cannot validate argument on parameter ‘ComputerName’. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

 

Any idea what Im doing wrong?

Thanks,

Zoe

 

It looks like the property “machinename” on the $SSRS object is null or empty. If you output $SSRS.MachineName, is the value a string?

If you look at $SSRS, are there any other properties that might be useful?

Hi @Zoe79,

In your command, the parameter name is not -Computer, its -ComputerName.

Usually named SSRS instances are created with the service name as ‘ReportServer$InstanceName’.

so in your case, you can use the command below…

[pre]

Get-Service -ComputerName $ssrs.machinename -Name ‘ReportServer$POCSSRS’ | Restart-Service;

[/pre]

Thank you.

@Kiran

Powershell will actually work on portion parameter names as long as it’s non-ambiguous. For instance, you have Get-WMIObject that has -ComputerName and -Class, we can’t use -C because that it is ambiguous, but if you add a letter it will work:

gwmi -co . -cl Win32_OperatingSystem

Powershell is built for admins so it is not strict and does a lot of automatic look ups. -Co is basically a wildcard search -Co* that resolves to -ComputerName. For instance, Powershell also does things like automatic Module import if you call a command and it’s not available. It’s all about making things simple.

[quote quote=186799]@kiran

Powershell will actually work on portion parameter names as long as it’s non-ambiguous. For instance, you have Get-WMIObject that has -ComputerName and -Class, we can’t use -C because that it is ambiguous, but if you add a letter it will work:

<textarea class="ace_text-input" style="opacity: 0; height: 17.6471px; width: 7.19608px; left: 45px; top: 0px;" spellcheck="false" wrap="off"></textarea>
1
2
gwmi -co . -cl Win32_OperatingSystem
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Powershell is built for admins so it is not strict and does a lot of automatic look ups. -Co is basically a wildcard search -Co* that resolves to -ComputerName. For instance, Powershell also does things like automatic Module import if you call a command and it's not available. It's all about making things simple.

[/quote]
Okay, it’s something new to me. Noted.

Thank you.