July 2018
Beginner
552 pages
13h 18m
English
Let's examine the first dictionary, PSDefaultParameterValues, in the following code sample:
# The automatic variable is great to set defaults$labFolder = mkdir .\StagingDirectory -Force$PSDefaultParameterValues = @{ '*:Path' = $labFolder.FullName # Extremely generic. Set all Path parameters for all Cmdlets 'New-Item:ItemType' = 'File'}# Notice how all cmdlets use Path# New-Item uses ItemType File nowNew-Item -Name someFileGet-ChildItemTest-PathJoin-Path -ChildPath SomePathGet-ItemNew-FileCatalog -CatalogFilePath here.cat# Cmdlets can still override defaultsAdd-Content -Path (Join-Path -ChildPath someFile) -Value 'Some data'# Clear the defaults or remove single keys$PSDefaultParameterValues.Remove('*:Path')$PSDefaultParameterValues.Clear() ...Read now
Unlock full access