0

This script is throwing a null exception and I am not certain why that is the case...

Function StopServices{    
    Param
    (
        $ServiceName,     
        $Remoteserver
    )
    write-host($Remoteserver)
    write-host($ServiceName)
    [System.ServiceProcess.ServiceController]$service = Get-Service -Name $ServiceName -ComputerName $Remoteserver
}

the write-host writes the variable. The Get-Service -ComputerName method throws this exception:

powershell cannot validate argument on parameter 'computername' the argument is null or empty

I am wondering what they are talking about, Neither is empty...

StopServices("DUMMY","VALUES")

Neither of those are empty. Why is it throwing that exception?

1 Answer 1

0

I can run it like this:

Function StopServices{
Param (

    $ServiceName,     
    $Remoteserver
)
write-host($ServiceName)
write-host($Remoteserver)
Get-Service -Name $ServiceName -ComputerName $Remoteserver }

StopServices $servicename $remoteserver

This will write the value of the vaiables and then run the get-service on it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .