Hi,
For the below block of script,
#Run get-ciminstance with query
Get-CimInstance @query |
Select-Object @{Name="Count";Expression={$Script:count;$Script:count++}},
AppName,Machinename,
@{Name="StatusOfApplication";Expression={$AppStatusTypeTable["$($PSItem.AppStatusType)"]}} |
where {$PSItem.StatusOfApplication -eq "$status"} -OutVariable Countcheck
I’ve added an outvariable so i can run a small count check at the end and display a message if the result comes back with less than 0,
if([int]($countcheck).count-le 0){write-host -foreground Cyan "No Data found with the Status of `"$status"" "}
Just want to know, am i doing best practice ? It works fine, but am i using the best usage of code for what i’m after ?
Full script below.
Many thanks.
Function Get-DeploymentStatus {
[CmdletBinding()]
Param
(
#Set application name
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string]$AppName,
[string]$Collection,
[ValidateSet("Success","InProgress","RequirementsNotMet","Unknown","error")]
[String]$Status
)
Begin {
#Set query for 'Get-Ciminstance' search
$query = @{
Namespace = 'root\SMS\site_AAC'
ClassName = 'SMS_AppDeploymentAssetDetails'
Filter = "AppName like '$AppName' and CollectionName like '$Collection'"
}
#Set counter for 'count' column in select statement
$script:count = 1
#Application Status table
$AppStatusTypeTable = DATA {ConvertFrom-StringData @'
1 = Success
2 = InProgress
3 = RequirementsNotMet
4 = Unknown
5 = Error
'@}
}#End Begin
process {
#Run get-ciminstance with query
Get-CimInstance @query |
Select-Object @{Name="Count";Expression={$Script:count;$Script:count++}},
AppName,Machinename,
@{Name="StatusOfApplication";Expression={$AppStatusTypeTable["$($PSItem.AppStatusType)"]}} |
where {$PSItem.StatusOfApplication -eq "$status"} -OutVariable Countcheck
#If 0 count display a message
if([int]($countcheck).count-le 0){write-host -foreground Cyan "No Data found with the Status of `"$status"" "}
}#End Process
}#End of Function