Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9167145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:19:07+00:00 2026-06-17T15:19:07+00:00

I need to tell that iI’m programming in Powershell for quiet short time and

  • 0

I need to tell that iI’m programming in Powershell for quiet short time and there is some basic that I do not handle well for the moment.

So what I’m trying to do is to pre-enter data into a XML file to use those data and populate $var into powershell then use those var to change Active Directory Attribute. For the change AD attribute i’m good, but the automation process by calling XML file to fill my var is simply not working at all. I think i’m not using the got method and that’s why i’m asking for help.

Here’s my XML file (where I have only two Site declared)

<Location>
  <Site> 
    <City>Alma</City> 
    <Street>333 Pont Champlain Street</Street> 
    <POBox></POBox>
    <State>Ontario</State> 
    <Zip>G1Q 1Q9</Zip>
    <Country>CA</Country>
    <OfficePhone>+1 555-555-2211</OfficePhone>
   </Site> 

  <Site> 
    <City>Dolbeau</City> 
    <Street>2525 Avenue du Pinpont</Street> 
    <POBox></POBox>
    <State>Quebec</State> 
    <Zip>G2Q 2Q9</Zip>
    <Country>CA</Country>
    <OfficePhone>+1 555-555-3000</OfficePhone>        
  </Site>
</Location>

I want to use a var name $Destination to “-match” location.site.city. If the $destination match city, then fill the var

$Newcity = location.site.city
$NewStreet = location.site.street
$NewState = location.site.state

etc, etc

Here’s the part of script I did but I can’t get the result that I want.

$var1 = ""
$Street = ""
$Destination = "Alma"

[xml]$SiteAttribute = Get-Content SitesAttributes.xml

foreach( $City in $SiteAttribute.location.Site){
    $var1 = $site.city    
    If ($var1 -match $Destination){
       $NewStreet = $Site.Street
       $NewCity = $Site.city
       $NewPoBox = $site.POBox
       $NewState = $site.State
       $Newzip = $Site.zip
       $NewCountry = $Site.country
       $NewPhone = $Site.OfficePhone
       } 
}

Then I would use those var to change my AD attribute with an other Powershell command

##Normal AD module come with W2k8
Import-Module ActiveDirectory

Set-ADUser $username -server $dc -StreetAddress $NewStreet -City $NewCity -State $NewState -PostalCode $NewZip -OfficePhone $NewPhone  -Country $NewCountry

But all my try faild, cause I think my Foreach statement followed by my If statement is not adequate for the process I want to do. Any advice ?

Thanks
John

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:19:08+00:00Added an answer on June 17, 2026 at 3:19 pm

    Try this:

    $var1 = ""
    $Street = ""
    $Destination = "Alma"
    [xml]$SiteAttribute = Get-Content SitesAttributes.xml
    
    foreach( $Site in $SiteAttribute.location.Site){ #this line in your code has issue
        $var1 = $Site.city    
        If ($var1 -match $Destination){
           $NewStreet = $Site.Street
           $NewCity = $Site.city
           $NewPoBox = $site.POBox
           $NewState = $site.State
           $Newzip = $Site.zip
           $NewCountry = $Site.country
           $NewPhone = $Site.OfficePhone
           } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SOLVED! This works, I need to tell the compiler that T implements IEquatable of
I need to tell chronic that the format of date is day-month-year is that
Given a path, in Mac OS X, is there a way to tell that
please tell that can we consume .net web services in php or not. if
please tell that can we consume .net web services in php or not. if
This one should be easy... Do I need to explicitly tell PHP that I
I have some functions that I am calling and they take some time (milliseconds),
I need to tell you that i'm very new to jquery and still learning,
I need to be able to tell if a link (URL) points to an
Can anyone tell me what is the need of Serialization of objects in Java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.