# Checking on correct usage

**URL:** <https://forums.powershell.org/t/checking-on-correct-usage/5801>\
**Category:** PowerShell Help\
**Created:** [February 16, 2016, 8:04pm UTC](https://forums.powershell.org/t/checking-on-correct-usage/5801 "2016-02-16T20:04:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![graham-beer1](https://avatars.discourse-cdn.com/v4/letter/g/958977/32.png) [@graham-beer1](https://forums.powershell.org/u/graham-beer1)\
**Post date:** [February 16, 2016, 8:04pm UTC](https://forums.powershell.org/t/checking-on-correct-usage/5801/1 "2016-02-16T20:04:05Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [February 18, 2016, 5:03am UTC](https://forums.powershell.org/t/checking-on-correct-usage/5801/2 "2016-02-18T05:03:09Z")

</div>

Nothing wrong with that.

---

<div class="post-metadata">

**Author:** ![graham-beer](https://avatars.discourse-cdn.com/v4/letter/g/49beb7/32.png) [@graham-beer](https://forums.powershell.org/u/graham-beer)\
**Post date:** [February 18, 2016, 5:18am UTC](https://forums.powershell.org/t/checking-on-correct-usage/5801/3 "2016-02-18T05:18:23Z")

</div>

Thanks Don. 😌

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:42pm UTC](https://forums.powershell.org/t/checking-on-correct-usage/5801/4 "2024-05-16T20:42:52Z")

</div>


