So i have a script I've written to pull down scope information from DHCP. It works fine drawing the information into the PowerShell window. I can pipe Out-GridView or Export-ToCSV to the process, but I was trying to find a way that when someone use's these functions, they can choose either of those by using a parameter in the function.
Example: Get-ScopeByDescription -Description "Site" -Property "Hostname" -ToCSV or -ToGridView
Function Get-ScopeByDescription
{
[cmdletBinding()]
Param
(
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[String] $Description,
[Parameter(ValueFromPipelineByPropertyName)]
[ValidateSet('IPAddress','Hostname','ClientID']
[String] $Property = 'Hostname'
###This is where I'm looking to add functionality of Export-ToCSV and Out-GridView as a Parameter.
)
Begin
{
Write-Warning "This process will take a minute. Ctrl+C to cancel."
}
Process
{
$ScopeDesc = Get-DhcpServerv4Scope -ComputerName DHCPsvr |
Where-Object -Property Description -Like *"$Description"*
$ScopeDesc | Get-DhcpServerv4Lease -ComputerName DHCPsvr -AllLeases |
Select IPAddress, Hostname, ClientID, LeaseExpiryTime, AddressState, ScopeID |
Sort-Object -Property $Property
}
This script is meant to pull down the DHCP scope from the server by description, which is an easier to find/remember parameter for the persons using this to remember.