I have a simple function which takes 2 arguments.
When I call the function like this, it throw the error. I am sure I am doing a mistake the way I am passing parameters.
PS D:\scripts> .\Validate-QRM-HPC.ps1 AWDWQRMHEAD01 D:\FHLBScripts\log\Log-QRM-HPC-Validation.txt
Validate-HPC : Cannot bind argument to parameter ‘aQRMHeadNodeName’ because it is an empty string.
At D:\scripts\Validate-QRM-HPC.ps1:87 char:15
- Validate-HPC $aQRMHeadNodeName $logfile
-
~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidData: (
[Validate-HPC], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Validate-HPC
Add-PSSnapIn Microsoft.HPC
Import-Module AWSPowerShell
- CategoryInfo : InvalidData: (
Write-Log Function makes it easy to write messages to a log file that is parseable and based on a standard log format
Function Write-Log {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]
$Message,
[Parameter(Mandatory=$False)]
[ValidateSet("INFO","WARN","ERROR","FATAL","DEBUG")]
[String]
$Level = "INFO",
[Parameter(Mandatory=$False)]
[string]
$logfile
)
$Stamp = (Get-Date).toString("yyyy/MM/dd HH:mm:ss:fff")
$Line = $Stamp + "," + $Level + "," + '"' + $Message + '"'
If($logfile) {
Add-Content $logfile -Value $Line
}
Else {
Write-Output $Line # used when a logfile name is not passed to Write-Log, Write to the Standard Output, the console.
}
}
Function Validate-HPC {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string] $aQRMHeadNodeName,
[Parameter(Mandatory=$True)]
[string]
$logfile
)
try{
$logMsg = "Validating HPC Cluster " + $aQRMHeadNodeName
Write-Log $logMsg "INFO" $logfile
$aclusterOutput = Get-HpcClusterOverview -Scheduler $aQRMHeadNodeName -Verbose
$logMsg = -join ( "HPC Cluster Validation Completed ", "ClusterName: ", $aclusterOutput.ClusterName, " Total Node Count: ", $aclusterOutput.TotalNodeCount , " Total Ready Nodes: ", $aclusterOutput.ReadyNodeCount)
Write-Log $logMsg "INFO" $logfile
}
Catch{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
$logMsg = "Exception Message: HPC Host name supplied is : " +$aQRMHeadNodeName + $_.Exception + " with Failed Item: " + $FailedItem
Write-Log $logMsg "FATAL" $logfile
}
}
Validate-HPC $aQRMHeadNodeName $logfile