{"id":78795,"date":"2026-07-13T14:10:50","date_gmt":"2026-07-13T14:10:50","guid":{"rendered":"http:\/\/bangla.sitestree.com\/?p=78795"},"modified":"2026-07-13T14:10:51","modified_gmt":"2026-07-13T14:10:51","slug":"validatenotnullorempty","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=78795","title":{"rendered":"ValidateNotNullOrEmpty"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><code>[ValidateNotNullOrEmpty()]<\/code> is a PowerShell parameter-validation attribute.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It rejects values that are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>$null<\/code><\/li>\n\n\n\n<li>An empty string: <code>\"\"<\/code><\/li>\n\n\n\n<li>An empty collection<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function Show-ComputerName {\n    param(\n        &#91;Parameter(Mandatory)]\n        &#91;ValidateNotNullOrEmpty()]\n        &#91;string]$ComputerName\n    )\n\n    Write-Output \"Computer name: $ComputerName\"\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Valid call:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Show-ComputerName -ComputerName \"PC01\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Computer name: PC01\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Invalid empty value:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Show-ComputerName -ComputerName \"\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Invalid null value:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$name = $null\nShow-ComputerName -ComputerName $name\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Why combine it with <code>Mandatory<\/code>?<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Parameter(Mandatory)]\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">requires the parameter to be supplied.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;ValidateNotNullOrEmpty()]\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">requires the supplied value to contain something.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">They are commonly used together:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>param(\n    &#91;Parameter(Mandatory)]\n    &#91;ValidateNotNullOrEmpty()]\n    &#91;string]$Path\n)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Array example<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>function Test-Servers {\n    param(\n        &#91;Parameter(Mandatory)]\n        &#91;ValidateNotNullOrEmpty()]\n        &#91;string&#91;]]$ComputerName\n    )\n\n    foreach ($computer in $ComputerName) {\n        Write-Output \"Testing $computer\"\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Call:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Test-Servers -ComputerName \"PC01\", \"PC02\"\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Important limitation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A string containing only spaces is not technically empty:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Show-ComputerName -ComputerName \"   \"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To reject whitespace too, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;ValidateScript({\n    -not &#91;string]::IsNullOrWhiteSpace($_)\n})]\n&#91;string]$ComputerName\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A simple definition:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><code>[ValidateNotNullOrEmpty()]<\/code> ensures that a parameter value is not null, blank, or an empty collection.<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>[ValidateNotNullOrEmpty()] is a PowerShell parameter-validation attribute. It rejects values that are: Example: Valid call: Output: Invalid empty value: Invalid null value: Why combine it with Mandatory? requires the parameter to be supplied. requires the supplied value to contain something. They are commonly used together: Array example Call: Important limitation A string containing only spaces is &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=78795\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1981],"tags":[],"class_list":["post-78795","post","type-post","status-publish","format-standard","hentry","category-power-shell","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":78719,"url":"http:\/\/bangla.sitestree.com\/?p=78719","url_meta":{"origin":78795,"position":0},"title":"CmdletBinding","author":"Sayed","date":"June 27, 2026","format":false,"excerpt":"Ref: AI Tools\/ChatGPT [CmdletBinding()] turns a normal PowerShell function into an advanced function. That means the function behaves more like a real PowerShell cmdlet. Basic example Normal function: function Install-Office { param( [string]$Version ) Write-Host \"Installing Office $Version\" } Advanced function: function Install-Office { [CmdletBinding()] param( [string]$Version ) Write-Host \"Installing\u2026","rel":"","context":"In &quot;Power Shell&quot;","block_context":{"text":"Power Shell","link":"http:\/\/bangla.sitestree.com\/?cat=1981"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10156,"url":"http:\/\/bangla.sitestree.com\/?p=10156","url_meta":{"origin":78795,"position":1},"title":"ServletUtilities.java Utility class that simplifies the output of the DOCTYPE and HEAD in servlets, among other things. Used by most remaining servlets in the chapter.","author":"","date":"August 15, 2015","format":false,"excerpt":"ServletUtilities.java\u00a0 Utility class that simplifies the output of the DOCTYPE and HEAD\u00a0 in servlets, among other things. Used by most remaining servlets in the chapter. package cwp; import javax.servlet.*; import javax.servlet.http.*; \/** Some simple time savers. Note that most are static methods. \u00a0* \u00a0 \u00a0*\u00a0 Taken from Core Web Programming\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10164,"url":"http:\/\/bangla.sitestree.com\/?p=10164","url_meta":{"origin":78795,"position":2},"title":"ServletUtilities.java Utility class that, among other things, contains the static filter method that replaces special HTML characters with their HTML character entities.","author":"","date":"August 17, 2015","format":false,"excerpt":"ServletUtilities.java\u00a0 Utility class that, among other things, contains the static filter\u00a0 method that replaces special HTML characters with their HTML character entities. package cwp; import javax.servlet.*; import javax.servlet.http.*; \/** Some simple time savers. Note that most are static methods. \u00a0* \u00a0 \u00a0*\u00a0 Taken from Core Web Programming Java 2 Edition\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10158,"url":"http:\/\/bangla.sitestree.com\/?p=10158","url_meta":{"origin":78795,"position":3},"title":"SimplerHelloWWW.java Servlet that uses ServletUtilities to simplify the generation of the DOCTYPE and HEAD part of the servlet.","author":"","date":"August 15, 2015","format":false,"excerpt":"SimplerHelloWWW.java\u00a0 Servlet that uses ServletUtilities\u00a0 to simplify the generation of the DOCTYPE and HEAD part of the servlet. package cwp; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; \/** Simple servlet that generates HTML. This variation of \u00a0*\u00a0 HelloWWW uses the ServletUtilities utility class \u00a0*\u00a0 to generate the DOCTYPE, HEAD, and TITLE.\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7544,"url":"http:\/\/bangla.sitestree.com\/?p=7544","url_meta":{"origin":78795,"position":4},"title":"\u0986\u099c \u0986\u09ae\u09bf \u0986\u09aa\u09a8\u09be\u09a6\u09c7\u09b0 \u099c\u09be\u09a8\u09be\u09ac\u09cb \u099c\u09be\u09ad\u09be \u0985\u09ac\u099c\u09c7\u0995\u09cd\u099f \u0995\u09bf\u09ad\u09be\u09ac\u09c7 Thread \u09a4\u09c8\u09b0\u09bf \u0995\u09b0\u09be \u09b9\u09df \u098f\u09ac\u0982 \u098f\u09b0 \u09ac\u09cd\u09af\u09ac\u09b9\u09be\u09b0\u0964","author":"Author-Check- Article-or-Video","date":"March 27, 2015","format":false,"excerpt":"\u09ac\u09b2\u09be \u099a\u09b2\u09c7 \u09aa\u09cd\u09b0\u09af\u09c1\u0995\u09cd\u09a4\u09bf \u099b\u09be\u09dc\u09be \u0986\u09ae\u09be\u09a6\u09c7\u09b0 \u099c\u09c0\u09ac\u09a8 \u0985\u099a\u09b2\u0964 \u0986\u09b0 \u098f\u0995\u099f\u09bf \u0986\u09a7\u09c1\u09a8\u09bf\u0995 \u09ab\u09bf\u099a\u09be\u09b0 \u09ab\u09cb\u09a8 \u09b9\u09b2 \u09a4\u09be\u09b0 \u098f\u0995\u099f\u09bf \u0989\u09a6\u09be\u09b9\u09b0\u09a8\u0964 \u0986\u09b0 \u09ab\u09bf\u099a\u09be\u09b0 \u09b8\u09ae\u09c3\u09a6\u09cd\u09a7 \u09ab\u09cb\u09a8 \u09a8\u09bf\u09df\u09c7 \u0986\u09b2\u09cb\u099a\u09a8\u09be \u0995\u09b0\u09a4\u09c7 \u0997\u09c7\u09b2\u09c7 \u09af\u09c7 \u09ac\u09bf\u09b7\u09df\u099f\u09bf \u09b8\u09be\u09ae\u09a8\u09c7 \u0986\u09b8\u09c7 \u09a4\u09be \u09b9\u09b2 \u0985\u09cd\u09af\u09be\u09aa\u09b2\u09bf\u0995\u09c7\u09b6\u09a8 \u0985\u09a5\u09ac\u09be \u099c\u09be\u09ad\u09be\u0964 \u00a0 \u0986\u09b0 \u09b6\u09c1\u09a7\u09c1 \u099c\u09be\u09ad\u09be \u09b8\u09ae\u09aa\u09b0\u09cd\u0995\u09c7 \u09ac\u09b2\u09a4\u09c7 \u0997\u09c7\u09b2\u09c7 \u0995\u09bf\u099b\u09c1 \u0996\u09c1\u099f\u09bf\u09a8\u09be\u099f\u09bf \u09ac\u09bf\u09b7\u09df \u0986\u09b8\u09c7 \u09a4\u09be \u09b9\u09b2 \u0995\u09bf\u09ad\u09be\u09ac\u09c7 \u098f\u0987 \u098f\u0987 \u0985\u09cd\u09af\u09be\u09aa\u09b2\u09bf\u0995\u09c7\u09b8\u09a8\u2026","rel":"","context":"In &quot;\u099c\u09be\u09ad\u09be&quot;","block_context":{"text":"\u099c\u09be\u09ad\u09be","link":"http:\/\/bangla.sitestree.com\/?cat=266"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26521,"url":"http:\/\/bangla.sitestree.com\/?p=26521","url_meta":{"origin":78795,"position":5},"title":"ServletUtilities.java  Utility class that simplifies the output of the DOCTYPE and HEAD  in servlets, among other things. Used by most remaining servlets in the chapter. #Programming Code Examples #Java\/J2EE\/J2ME #Servlet","author":"Author-Check- Article-or-Video","date":"April 27, 2021","format":false,"excerpt":"ServletUtilities.java Utility class that simplifies the output of the DOCTYPE and HEAD in servlets, among other things. Used by most remaining servlets in the chapter. package cwp; import javax.servlet.*; import javax.servlet.http.*; \/** Some simple time savers. Note that most are static methods. * * Taken from Core Web Programming Java\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/78795","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=78795"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/78795\/revisions"}],"predecessor-version":[{"id":78796,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/78795\/revisions\/78796"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=78795"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=78795"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=78795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}