Templates/PowerShell.Template.Function.Get-Something.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
##From https://docs.microsoft.com/en-us/previous-versions/technet-magazine/hh360993(v=msdn.10)
Function Get-Something
{
<#
    .SYNOPSIS
        Describe the function here
 
    .DESCRIPTION
        Describe the function in more detail
 
    .EXAMPLE
        Give an example of how to use it
 
    .EXAMPLE
        Give another example of how to use it
 
    .PARAMETER ComputerName
        The Computer name to query. Just one.
 
    .PARAMETER LogName
        The name of a file to write failed Computer names to. Defaults to errors.txt.
 
    .INPUTS
        Input is from command line or called from a script.
 
    .OUTPUTS
        This will output the logfile.
 
    .NOTES
        Version: 0.1
        Author: Lars Panzerbj´┐Żrn
        Creation Date: 2020.05.12
        Purpose/Change: Initial script development
#>

    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory,
            ValueFromPipeline=$True,
            ValueFromPipelineByPropertyName=$True,
            HelpMessage='What Computer name would you like to target?')]
        [Alias('host')]
        [ValidateLength(3,30)]
        [string[]]$ComputerName,

        [string]$LogName='Errors.txt'
    )

    BEGIN
    {
        Write-Verbose "Beginning $($MyInvocation.Mycommand)"
        Write-Verbose "Deleting $LogName"
        Remove-Item $LogName -ErrorActionSilentlyContinue
    }

    PROCESS
    {
        Write-Verbose "Processing $($MyInvocation.Mycommand)"

        ForEach ($Computer in $ComputerName) {
            Write-Verbose "Processing $Computer"
            # use $Computer to target a single Computer

            # create a hashtable with your output info
            $Info = @{
                'info1'=$value1;
                'info2'=$value2;
                'info3'=$value3;
                'info4'=$value4
            }
            Write-Output (New-Object -Typename PSObject -Property $Info)
        }
    }
    END
    {
        Write-Verbose "Ending $($MyInvocation.Mycommand)"
    }
}