-
Notifications
You must be signed in to change notification settings - Fork 1
Parameter Specification Priority and How to
The scripts have 3way for parameter specification.
- Specify in Param section of the script
- In execution, specify with arguments
- Use common config file (above version 3.0)
[Use Common config file] has the highest priority of the specification. And [Specify in Param section of the script] has the lowest.
You can specify in Param section of the script with text editor.
FileMaintenance.ps1
---snip---
Param(
---snip---
[Boolean]$Log2File = $TRUE ,
[Switch]$NoLog2File ,
[String]$LogPath = 'D:\log\log.txt',
You can specify with argument when execute the script.
PS D:\FileMaintenace> .\FileMaintenance.ps1 -TargetFolder .\TEST -Log2File $TRUE -LogPath 'D:\log\log.txt'
Write a common config file with text editor.
CommonConfig.ps1
---snip---
[Boolean]$Log2File = $TRUE ,
[String]$LogPath = 'D:\log\log.txt',
---snip---
Specify common config file path in Param section of the script. You can specify the file path in only relative file format. Can not specify in absolute or UNC path format.
FileMaintenance.ps1
---snip---
Param(
---snip---
[String]$CommonConfigPath = '.\CommonConfig.ps1' , #MUST specify with relative path format
---snip---
or Specify common config file path with arguments in executing the scripts.
PS D:\FileMaintenace> .\FileMaintenance.ps1 -TargetFolder .\TEST -CommonFilePath '.\CommonConfig.ps1'
If you want to cancel the specification of the common config file temporarily when you specified in the Param section, you specify the path of common config file path with Null or empty.
PS D:\FileMaintenace> .\FileMaintenance.ps1 -TargetFolder .\TEST -CommonFilePath '' -Log2File $FALSE