Sample code for ToolMaking in MOL

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 5 months ago.

  • Author
    Posts
  • #5559

    by etolleson at 2013-02-16 11:39:05

    I have downloaded the sample codes a few times and each time the zip file did not contain anything in the folders "PowerShell Studio – Ch23-24-25 – Out-GridView" and "PowerShell Studio – Ch25 Final" not sure why. I have tried IE9, firefox and chrome also made sure my virus protection was disabled. Is there a way a I can get these code samples?

    by DonJ at 2013-02-17 05:58:10

    Yup. I'm out of the country and don't have access to the files right now, but I'll post when I get hold of them – it'll be close to the end of the month.

    by etolleson at 2013-02-17 06:54:36

    Ok I will look for them then, Thanks Don

    by JeffH at 2013-02-17 07:26:23

    I double checked the Zip file from the MoreLunches site. Yes there are empty folders in the zip file, but I don't think there are actually any other than Listing 23.1 which does appear to be missing. There are no code listings in Chapter 24 and 25. And the zip file has Chapter 25 Script Complete.ps1.

    by JeffH at 2013-02-17 07:30:50

    Here is Listing 23.1


    Function Get-ServiceData {
    [cmdletbinding()]
    Param(
    [parameter(Position=0,Mandatory=$True,HelpMessage="Enter a computername")]
    [ValidateNotNullorEmpty()]
    [string]$Computername,
    [Parameter(Position=1)]
    [ValidateSet("Running","Stopped","All","%")]
    [string]$Filter="All"
    )

    Try {
    Write-Verbose "Getting $filter services from $computername"
    if ($Filter -eq "All") {
    $filter='%'
    Write-Verbose "Using WMI filter: state Like '$Filter'"
    }
    $services=Get-WmiObject -Class Win32_Service -ComputerName $Computername -filter "State Like '$Filter'"
    #write selected results to the pipeline
    $services | Select Name,Displayname,State,StartMode,StartName
    }
    Catch {
    Write-Warning "Failed to get services from $Computername. $_.Exception.Message"
    }

    } #end function

    by etolleson at 2013-02-18 07:40:35

    Thanks Jeff,

You must be logged in to reply to this topic.