Settings service back

Welcome Forums General PowerShell Q&A Settings service back

This topic contains 2 replies, has 2 voices, and was last updated by

5 years, 7 months ago.

  • Author
  • #10838

    Topics: 14
    Replies: 12
    Points: 0
    Rank: Member

    I have a script that perform an inventory of services and saves the info to a csv file (see portion below). Later, I wish to refresh the machine with the startup type of each service as it existed in my inventory. This is my new script. The problem is that I keep getting:
    cmdlet Set-Service at command pipeline position 1
    Supply values for the following parameters:

    as the output in the window. What needs to be changed in order for the script to go thru.

    Here is the new script,
    $Path="$env:userprofile\My Documents\Serverinfo\Services\zxxp73zrcs1-ServicesInventory.csv"
    #Take only two important columns from the CSV file and rename the columns
    $Temp=Import-CSV $Path|Select @{Name="ServiceName";Expression={$}},@{Name="startuptype";Expression={$_.startmode}}
    #Now, populate the hash
    foreach ($row in $Temp) {$ServiceHashTable[$row.ServiceName]=$row.startuptype}
    #Gather the inventory and state of services running now on the system
    $Services=Get-Service -ComputerName "zxxp73zrcs1"
    #Reset each startuptype to what was previously set in CSV file
    foreach ($service in $Services) {
    if ($ServiceHashTable.ContainsKey($ {
    Set-Service -ComputerName "zxxp73zrcs1" -startuptype $ServiceHashTable.Get_Item($
    } #end if statement
    } #end foreach statement

    The CSV file from the old script looks like,
    systemname name displayname startmode state
    ZXXP73ZRCS1 AdobeFlashPlayerUpdateSvc Adobe Flash Player Update Service Manual Stopped
    ZXXP73ZRCS1 Alerter Alerter Disabled Stopped
    ZXXP73ZRCS1 ALG Application Layer Gateway Service Manual Stopped
    ZXXP73ZRCS1 AppMgmt Application Management Manual Stopped
    ZXXP73ZRCS1 aspnet_state ASP.NET State Service Manual Stopped

  • #10841

    Topics: 1
    Replies: 1
    Points: 0
    Rank: Member

    Why Use the extra hash Table ?
    Import-CSV is already coverting it to a psobject.

    By the way the solution to your problem is that Set-Service Expects the Service Name as mandatory Parameter.
    Set-Service -Name $ -ComputerName “zxxp73zrcs1″ -startuptype $ServiceHashTable.Get_Item($
    This should fix it.

  • #10847

    Topics: 14
    Replies: 12
    Points: 0
    Rank: Member

    Your suggestion did the trick, thank you.

    The $Temp was needed as an intermediary. When I tried to import the info directly to $ServiceHashTable, I no longer had the methods associated with a hash.
    See the following,
    PS C:\documents and settings\usf48555\My Documents\scripts> $temp|gm

    TypeName: Selected.System.Management.Automation.PSCustomObject

    Name MemberType Definition
    —- ———- ———-
    Equals Method bool Equals(System.Object obj)
    GetHashCode Method int GetHashCode()
    GetType Method type GetType()
    ToString Method string ToString()
    ServiceName NoteProperty System.String ServiceName=gupdate
    startuptype NoteProperty System.String startuptype=Automatic

    PS C:\documents and settings\usf48555\My Documents\scripts> $ServiceHashTable|gm

    TypeName: System.Collections.Hashtable

    Name MemberType Definition
    —- ———- ———-
    Add Method System.Void Add(System.Object key, System...
    Clear Method System.Void Clear()
    Clone Method System.Object Clone()
    Contains Method bool Contains(System.Object key)
    ContainsKey Method bool ContainsKey(System.Object key)
    ContainsValue Method bool ContainsValue(System.Object value)
    CopyTo Method System.Void CopyTo(array array, int array...
    Equals Method bool Equals(System.Object obj)
    GetEnumerator Method System.Collections.IDictionaryEnumerator ...
    GetHashCode Method int GetHashCode()
    GetObjectData Method System.Void GetObjectData(System.Runtime....
    GetType Method type GetType()
    OnDeserialization Method System.Void OnDeserialization(System.Obje...
    Remove Method System.Void Remove(System.Object key)
    ToString Method string ToString()
    Item ParameterizedProperty System.Object Item(System.Object key) {ge...
    Count Property System.Int32 Count {get;}
    IsFixedSize Property System.Boolean IsFixedSize {get;}
    IsReadOnly Property System.Boolean IsReadOnly {get;}
    IsSynchronized Property System.Boolean IsSynchronized {get;}
    Keys Property System.Collections.ICollection Keys {get;}
    SyncRoot Property System.Object SyncRoot {get;}
    Values Property System.Collections.ICollection Values {get;}

The topic ‘Settings service back’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort