{"id":76384,"date":"2024-11-25T01:58:22","date_gmt":"2024-11-25T01:58:22","guid":{"rendered":"http:\/\/bangla.sitestree.com\/?p=76384"},"modified":"2024-12-04T03:47:41","modified_gmt":"2024-12-04T03:47:41","slug":"misc-on-power-shell-script","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=76384","title":{"rendered":"Misc. on Power Shell Script"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Misc. on Power Shell Script<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to read data from users?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Read-Host<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to write\/print output data\/text to the user:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Write-Output<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to Check if a file exists?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Test-Path $filePath<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to append data to a file?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Add-Content -Path $filePath -Value &#8220;x: $x, y: $y&#8221;<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to create a file?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>New-Item -Path $filePath -ItemType File -Force<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to write content to a file?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Set-Content -Path $filePath -Value &#8220;x: $name, y: $age&#8221;<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to get a list of all files in a directory<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>$files = Get-ChildItem -Path $dirPath<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to find the size of a file?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>$file.Length<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to append content to a file?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>$content | Out-File -FilePath $outputFile -Append <\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to Create a file and write content to it?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>$content | Out-File -FilePath $outputFile<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Misc. on Power Shell Script How to read data from users? Read-Host How to write\/print output data\/text to the user: Write-Output How to Check if a file exists? Test-Path $filePath How to append data to a file? Add-Content -Path $filePath -Value &#8220;x: $x, y: $y&#8221; How to create a file? New-Item -Path $filePath -ItemType File &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=76384\">Continue reading<\/a><\/p>\n","protected":false},"author":1,"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":[1968,1,1345],"tags":[],"class_list":["post-76384","post","type-post","status-publish","format-standard","hentry","category-operating-systems","category-root","category----operating-systems","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":69884,"url":"http:\/\/bangla.sitestree.com\/?p=69884","url_meta":{"origin":76384,"position":0},"title":"Razor, Web-page Model, Web-Application Development in C# #19","author":"Author-Check- Article-or-Video","date":"August 21, 2021","format":false,"excerpt":"Razor, Web-page Model, Web-Application Development in C# Razor: a markup syntax to add server side code into ASP.net pages Razor example: Current time is @DateTime.Now Razor Code Syntax Single statement block @{ var message = \"Hello World\"; } Inline expression or variable The message: @message Multi-statement block @{ var greeting\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":70285,"url":"http:\/\/bangla.sitestree.com\/?p=70285","url_meta":{"origin":76384,"position":1},"title":"Razor, Web-page Model, Web-Application Development in C# #.Net Web Applications","author":"Author-Check- Article-or-Video","date":"August 31, 2021","format":false,"excerpt":"Brought from: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=1320&title=Razor,%20Web-page%20Model,%20Web-Application%20Development%20in%20C# (written long back) Razor, Web-page Model, Web-Application Development in C# Razor:a markup syntax to add server side code into ASP.net pages Razor example: Current time is @DateTime.Now Razor Code Syntax Single statement block @{ var message = \"Hello World\"; } Inline expression or variable The message: @message\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78793,"url":"http:\/\/bangla.sitestree.com\/?p=78793","url_meta":{"origin":76384,"position":2},"title":"Write-Error","author":"Sayed","date":"July 13, 2026","format":false,"excerpt":"Write-Error in PowerShell Write-Error writes an error message to PowerShell\u2019s error stream. By default, it creates a non-terminating error. That means PowerShell displays the error, but usually continues with the next command. Write-Error \"The file could not be found.\" Write-Output \"The script continued.\" Typical result: Write-Error: The file could not\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":78791,"url":"http:\/\/bangla.sitestree.com\/?p=78791","url_meta":{"origin":76384,"position":3},"title":"Terminating error vs non-terminating error","author":"Sayed","date":"July 13, 2026","format":false,"excerpt":"Terminating error vs non-terminating error in PowerShell Non-terminating error A non-terminating error reports a problem but allows PowerShell to continue running the remaining commands. Example: Get-Content -Path \".\\MissingFile.txt\" Write-Output \"The script continued.\" Possible output: Get-Content : Cannot find path '.\\MissingFile.txt' because it does not exist. The script continued. The file-reading\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":78663,"url":"http:\/\/bangla.sitestree.com\/?p=78663","url_meta":{"origin":76384,"position":4},"title":"write-output vs write-host","author":"Sayed","date":"May 24, 2026","format":false,"excerpt":"Write-Output vs Write-Host in PowerShell FeatureWrite-OutputWrite-HostSends data to pipeline\u2705 Yes\u274c NoCan be stored in variable\u2705 Yes\u274c Usually noCan be redirected to file\u2705 Yes\u274c Not normally usefulUsed for script output\u2705 Recommended\u26a0\ufe0f Mainly for display messagesSupports formatting\/colorLimited\u2705 Good for colors 1. Write-Output Write-Output sends data to the PowerShell pipeline. Write-Output \"Hello PowerShell\"\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":17008,"url":"http:\/\/bangla.sitestree.com\/?p=17008","url_meta":{"origin":76384,"position":5},"title":"Python: Ecommerce: Part \u2014 7: Partition a Data File (with product information) into Multiple Files.","author":"Sayed","date":"April 19, 2020","format":false,"excerpt":"In previous steps, we created a product data file to be uploaded to Magento 2 (from supplier data). However, there is a limit, how big a file can be uploaded to Magento 2 for product data import. Hence, this code will divide the data file into multiple files. This data\u2026","rel":"","context":"In &quot;Build Ecommerce Software&quot;","block_context":{"text":"Build Ecommerce Software","link":"http:\/\/bangla.sitestree.com\/?cat=1912"},"img":{"alt_text":"8112223 Canada Inc. (Justetc)","src":"https:\/\/miro.medium.com\/fit\/c\/80\/80\/0*P_esmjKoJnHlNjFX","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/76384","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\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=76384"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/76384\/revisions"}],"predecessor-version":[{"id":76385,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/76384\/revisions\/76385"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=76384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=76384"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=76384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}