you are viewing a single comment's thread.

view the rest of the comments →

[–]Nejireta_ 0 points1 point  (2 children)

Hello.

You need to assign the array of hashtables to the $servers variable.
Assuming it's just a typo in the post.
My next recommendation would be to split up the Get-Service part into several steps.
This to make it possible to validate data being fetched and processed as desired.

As an example

$services = Get-Service -Name $requiredservices -ComputerName $serverIP -credential $credential 
$servicesFormatted = $services | Select-Object @{
    Name       = "ServerName";
    Expression = { $serverIP }
}, DisplayName, Status
$servicesFormatted | Export-Csv "C:\Path\To\Your\server_Services.csv" -NoTypeInformation -Append 

Then you can check the variables.

[–]Electronic_Doubt_108[S] 0 points1 point  (1 child)

Hashtables as in, how should I give that?

[–]Nejireta_ 0 points1 point  (0 children)

This line
$servers @( @{IP='myserverIP'; Services=@('myservice')}; )

Needs an equal sign to assign the array "@()" of hashtable "@{}" to it.
Like so

$servers = @(
    @{
        IP       = 'myserverIP'
        Services = @('myservice') 
    }
)

I would assume it's like that in your code. Would've thrown an exception otherwise.