Avatar of ShannonCallahan
ShannonCallahan

asked on 

Reading a null value for TextBox.Text.

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}

Open in new window


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
Powershell* Automation

Avatar of undefined
Last Comment
ShannonCallahan
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of ShannonCallahan
ShannonCallahan

ASKER

Sorry for the delayed response. Thank you very much!!!
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo