troubleshooting Question

Reading a null value for TextBox.Text.

Avatar of ShannonCallahan
ShannonCallahan asked on
Powershell* Automation
2 Comments1 Solution52 ViewsLast Modified:
Hello!

I am trying to make a little automated program to make some changes to start services. I am using a button click event to run the following:

{
    
    #Define Variables
    $ComputerName = $WorkstationNameTextBox.Text
    $Credentials = $ServiceIDTextBox.Text
    $ServiceName = [ToString]$ServiceNameTextBox.Text

    #create session and set startup type
    $s = New-PSSession -ComputerName $ComputerName -Credential $Credentials
    Invoke-Command -Session $s -ScriptBlock {Set-Service -Name $ServiceName -StartupType Automatic

    #changing the Failure options
    sc.exe failure $ServiceName actions = restart/60000/restart/60000/restart/60000 reset= 86400;

    #Restart service
    Restart-Service -Name $ServiceName -Force -ErrorAction Stop}

I am getting an error with this script:

Cannot bind argument to parameter 'Name' because it is null.
    + CategoryInfo          : InvalidData: (:) [Set-Service], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SetServiceCommand
    + PSComputerName        : MyComputerName
 
Cannot bind argument to parameter 'Name' because it is null.
    + CategoryInfo          : InvalidData: (:) [Restart-Service], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RestartServiceCommand
    + PSComputerName        : MyComputerName

I am sure this is something small, but I cannot figure it out. Any Ideas as to why this is happening? And how to fix my issue.

Thank you!,
Shannon
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros