Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Adding an IF statment?

$
0
0

I have the following (functioning) script, which applies a FSRM quota template to a user wihtin the specified group.

I receive an error if the quota exists - how do I stop this behavior? (IF statement?)

If quota? dir? exists -exit? skip? --not sure about the command. I only want it to apply if it does NOT exist.



$group = [adsi]"LDAP://CN=<blank>"
$groupSearcher = New-Object DirectoryServices.DirectorySearcher($group)
$groupSearcher.PageSize = 1000
$results = $groupSearcher.FindOne()
#$results.properties.item("member")

$members = $results.properties.item("member")

foreach ($member in $members) {

    $user = [adsi]"LDAP://$($member)"
    $userSearcher = New-Object DirectoryServices.DirectorySearcher($user)
    $userSearcher.PageSize = 1
    $results = $userSearcher.FindOne()
    $sAMAccountNames = $sAMAccountNames + $results.properties.item("sAMAccountName")
}

foreach ($sAMAccountName in $sAMAccountNames) {
    Write-Host "Quotas being modified for $($sAMAccountName)"
    New-FsrmQuota -Path "E:\Users\$($sAMAccountName)" -Template:"UserSQ"
}


Viewing all articles
Browse latest Browse all 15028

Trending Articles



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