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

Filling in webpage info from text file

$
0
0

My text file has these fields:

Name, OfficePhone, WebPage

Tester, 502-555-5555, www.contoso.com

My code looks like this:

add-PSSnapin quest.activeroles.admanagement -erroraction silentlyContinue

Import-Csv C:\userList.txt | ForEach {

    $ErrorActionPreference = 'SilentlyContinue'
    $user = Get-ADUser $_.UserName -Properties OfficePhone
    $user2 = Get-ADUser $_.UserName -Properties WebPage
    $ErrorActionPreference = 'Continue'

    If ($user) {

        If (!($user.OfficePhone)) { Set-ADUser -Identity $_.UserName -OfficePhone $_.OfficePhone }
        Remove-Variable user

    }

    If ($user2) {

        If (!($user.WebPage)) { Set-ADUser -Identity $_.UserName -WebPage $_.WebPage }
        Remove-Variable user

    }
}

The first if statement works and sets my AD objects Telephone number field (on the general tab) correctly.

But the webpage will not set, I've also tried replacing the text file with wWWHomePage and the code with wWWHomePage but I get the same result. It won't fill in that field. Why is that?

Another part to this is, if there is an easier way to edit everyone in our domains web page with www.contoso.com that would work too instead of adding it in to this script.

Any help is appreciated. Thanks!


Viewing all articles
Browse latest Browse all 15028

Trending Articles



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