Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

PowerShell - The FALSE Half of an IF Statement

$
0
0

After beating my head against my desk for the last four hours (have mercy on me, it's Monday), it finally dawned on me to try this as a script and it works. However, when I'm writing, I generally just take my code and copy-and-paste into a PS window, and there's where I was having a problem. The ELSE part of the IF statement would just display as text, even if the IF was actually FALSE. Just wondering if anyone can explain why.

Powershell
if(test-path$objUser.HomeDirectory){Write-Host"$($objUser.HomeDirectory) already exists. Setting permissions..."-ForegroundColorRed}# else{#NEW-ITEM –path $objuser.HomeDirectory -type directory -forceWrite-Host"$($objUser.HomeDirectory) not there. Creating folder and setting permissions..."-ForegroundColorRed}
The part that really gets me is that I only ran into this because I couldn't...

Viewing all articles
Browse latest Browse all 15370

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>