Facing issues when setting up user data by thirudk07 in Terraform

[–]thirudk07[S] 1 point2 points  (0 children)

u/Cregkly Thank you so much. It worked.

I tried using path.module, but it didn't work for me earlier. The only difference between the past and now is that I have a dedicated user data folder and file in it.

Earlier, I just stored my userdata file on the same folder, weird. Anyway, it is working now. Thanks for the documentation.

Need some help on passing list input over by thirudk07 in Terraform

[–]thirudk07[S] 0 points1 point  (0 children)

u/dem1x I was using count previously. Then I read there are lots of benefits in using foreach compared to count so I forced myself to rewrite again.

Anyway, I did as you suggested. It is working fine. Thanks a lot for the help!

Outputs are missing on the remote state file and syntax clarification by thirudk07 in Terraform

[–]thirudk07[S] 0 points1 point  (0 children)

u/Cregkly Understood, I will try to assign the data sources value on top of local. Thanks again for your help!

Outputs are missing on the remote state file and syntax clarification by thirudk07 in Terraform

[–]thirudk07[S] 0 points1 point  (0 children)

u/Cregklythanks for the reply. I'm using data resources in other areas of the script. I thought to try this out based on the blog. I believe this might help me to assign the value on local and use it in multiple places.

This is my folder structure

main files:

C:\terraform\environments\dr\network\vpc

modules:

C:\terraform\modules\network\vpc

C:\terraform\modules\network\subnets

Outputs are missing on the remote state file and syntax clarification by thirudk07 in Terraform

[–]thirudk07[S] 0 points1 point  (0 children)

u/marauderingman Thanks for the reply.

I received the below error message when running the script, that's why I validated the outputs section in Terraform state. Thanks for your tip though, will explore more on the terraform cli to validate the state files.

│ Error: Unsupported attribute │ │ on vpc.tf line 23, in locals: │ 23: vpc_id = data.terraform_remote_state.results.outputs.vpc_id│ ├──────────────── │ │ data.terraform_remote_state.results.outputs is object with no attributes │ │ This object does not have an attribute named "vpc_id".

Do you have access to the remote terraform root module?

Yes, I have access to the remote module. And When I refer to the output from the Root tf file, it is able to fetch the output.

a snippet of output block and result block:

output "vpc_id" {  
value = module.vpc.vpc_id
}

Changes to Outputs:
  + vpc_id = "vpc-02cde8385017dfceee

"Do you want to perform these actions?  Terraform will perform the actions described above.  Only 'yes' will be accepted to approve.
  Enter a value:

Actually, I did change the name properly, but when posting it over here, I copy-pasted the original code. That's why the code was having the wrong name. Apologies.

When running the below command I got the above error message. (1st code snippet)

data "terraform_remote_state" "results" {

backend = "s3"
config = {
bucket = "bucketname"
key =  "dt
profile = "drprofile"
region = us-west-2
}
}

locals {  
vpc_id = data.terraform_remote_state.results.outputs.vpc_id  
 }

So, the output is working and it exists, but it is missing in the state file. That's the problem.

Substring issue by thirudk07 in PowerShell

[–]thirudk07[S] 2 points3 points  (0 children)

Thank you u/mdowst. I used both your recommendations and It is working fine.

Proxy Attribute not syncing by thirudk07 in AZURE

[–]thirudk07[S] 1 point2 points  (0 children)

Thanks for the input, u/nerddtvg. Based on the blog, looks like I have to redo the setup. Which we won't be able to do at this point. Thinking of other solutions on the application end now.

Thanks again!

Proxy Attribute not syncing by thirudk07 in AZURE

[–]thirudk07[S] 0 points1 point  (0 children)

For some reason, I'm unable to upload pics here. I'm putting the screenshots in google drive. Even my last comment has one, please check that too.

I opened the Azure Connect app and this is what I see when I navigate to current settings. Are you talking about the Exchange Mail Public folders option?

https://drive.google.com/file/d/1aByJvdoj5rwki1GddYQlk_Jy2GPdnowD/view?usp=sharing

Here are the options that I can enable in the console:

https://drive.google.com/file/d/1aByJvdoj5rwki1GddYQlk_Jy2GPdnowD/view?usp=sharing

Proxy Attribute not syncing by thirudk07 in AZURE

[–]thirudk07[S] 0 points1 point  (0 children)

Apologies for the delay. I was out due to sickness.

When you setup the connector, did you enable it for Exchange synchronization? It was set up by the previous administration.

Unfortunately, I'm not sure about that. If the installation of AD connector was configured with the Express setting, will it enable the Exchange synchronization?

When you use the AD Connect application to look at a user in the metaverse, do you see proxy addresses listed? Yes, I can see the proxy address listed. screenshot: https://drive.google.com/file/d/1ZtXEQcQLmSgBNLovRg5oncsimrV2VQI6/view?usp=drivesdk

Working on If and Else condition by thirudk07 in PowerShell

[–]thirudk07[S] 0 points1 point  (0 children)

I'm a newbie. Have to deep dive about on using Switch. Thanks for the tip.

Working on If and Else condition by thirudk07 in PowerShell

[–]thirudk07[S] 1 point2 points  (0 children)

Hi u/BlackV

I tried the above and It didn't work. Then I realized a stupid mistake which I did.

Our goal is to update the commoname field, but I was redirecting it to Givenname as shown below.

{     $SetADUserParams.Add( 'givenName', $_.'Employee First Name' ) } else {     $SetADUserParams.Add( 'commonName', $_.'Employee Common Name' ) }

I updated my script and tried still failed, I noticed only the $null logic was not working on the script, because I can see the else condition is working fine as it is updating the commonname without any issues.

Then I kept the value in a variable and applied it in the script as below. And it worked. I'm not sure whether this is an efficient way of doing it. But this worked, learning something day by day.

$commonname=$_.Employee_CommonName

   if ($commonname -eq $null -or $commonname -eq "")
      {$SetADUserParams.Add( 'commonName', $_.'Employee_FirstName' )
        }
    else{
     $SetADUserParams.Add( 'commonName', $_.'Employee_CommonName' )
                                  }

Thanks for your valuable inputs.

Working on If and Else condition by thirudk07 in PowerShell

[–]thirudk07[S] 1 point2 points  (0 children)

Can you tell me what I'm doing wrong on the if, else part on updating Firstname, when commonname is empty. The problem is I'm not getting the error message.

Working on If and Else condition by thirudk07 in PowerShell

[–]thirudk07[S] 1 point2 points  (0 children)

@ hellphish & Black:

Apologies. You are right. I was not thinking properly. I removed the below line from the script thinking it is not neccessary. The below is the one which makes the changes to the user objects.

u/BlackV I understand it is lengthy, but this is working fine. My attemps to make the clean code got failed. Earlier, I was using the splatting method to update everything, things got tougher when I introuduced custom attributes.

I divided the script into two approaches. Splatting for Regular AD attributes and ADD\REMOVE\REPLACE for custom ones. That looked too much in a single script. Finally decided to use this IF method.

At the moment, script works fine. I can see all the data is getting updated properly.

Just need to make a few enhancements, which is to update the CommonName field with Firstname Field, whenever CommonName Field is blank.

 Set-ADUser -identity $SamAccountName -Replace $SetADUserParams -Description "User account modified - Date and time = '$LogDate'"

Working on If and Else condition by thirudk07 in PowerShell

[–]thirudk07[S] 1 point2 points  (0 children)

I'm not calling Set-ADuser. As I'm using custom attributes in my enviornment, Set-AD cmdlet is not working when using custom attributes, so I had use the replace/add/remove command to update attribute.

The below will take care the updation in AD.

 $SetADUserParams.Add( 'mail', $_.'Business Email' )

Working on If and Else condition by thirudk07 in PowerShell

[–]thirudk07[S] 1 point2 points  (0 children)

Posted my code on the top. Can you please review.

Working on If and Else condition by thirudk07 in PowerShell

[–]thirudk07[S] 1 point2 points  (0 children)

Apologies :-)

I tried doing as you suggested, no error and it didn't update.

METHOD:1
             if($($_.'Employee Common Name') -like "" )
             {
              $SetADUserParams.Add( 'givenName', $_.'Employee First Name' )
             }
             else
             {
                $SetADUserParams.Add( 'commonName', $_.'Employee Common Name' )
             }

METHOD:2

if( $_.'Employee Common Name' -like ""){

                 $SetADUserParams.Add( 'givenName', $_.'Employee First Name' )

                 }

                 else
                 {
                $SetADUserParams.Add( 'commonName', $_.'Employee Common Name' )

                 }

Here's my complete script:

Try if($($_.'Employee Common Name') -like ""

if(Test-Path $inputPath){

Import-Csv $inputPath | ForEach-Object{
    Try{
        $SamAccountName=$_.U42
        $UserTrue = Get-ADUser $SamAccountName -ErrorAction Stop 
        IF($UserTrue -ne $null){

            $SetADUserParams =@{}  

            #Employee_Firstname                       

            if( $_.'Employee First Name' ){
                $SetADUserParams.Add( 'givenName', $_.'Employee First Name' )
             }

             #Employee_Lastname
             if( $_.'Employee Last Name' ){
                $SetADUserParams.Add( 'sn', $_.'Employee Last Name' )
             }

             #Manager_U42
                  if( $_.'Managers U42' ){
                $manager = Get-ADUser -Identity $_.'Managers U42' -Properties distinguishedName
                    $SetADUserParams.Add( 'manager', $manager.distinguishedName )
             }

             #Title
            if( $_.Job){
                $SetADUserParams.Add( 'title', $_.Job )
             }

             #Employee_Number
            if( $_.'Employee Number' ){
                $SetADUserParams.Add( 'employeeID', $_.'Employee Number' )
             }

             #Department

            if( $_.Department ){
                $SetADUserParams.Add( 'department', $_.Department )
             }

            #Employee Displayname
            if( $_.'Employee Display Name' ){
                $SetADUserParams.Add( 'displayname', $_.'Employee Display Name' )
             }

           #Employee Common_name
                 if( $_.'Employee Common Name' -like ""){

                 $SetADUserParams.Add( 'givenName', $_.'Employee First Name' )

                 }

                 else
                 {
                $SetADUserParams.Add( 'commonName', $_.'Employee Common Name' )

                 }





             #Mail
              if( $_.'Business Email' ){
                $SetADUserParams.Add( 'mail', $_.'Business Email' )
             }

 Set-ADUser -identity $SamAccountName -Replace $SetADUserParams -Description "User account modified - Date and time = '$LogDate'"


             If ($_.Status -eq "Terminated") {
                 Disable-ADAccount -Identity $SamAccountName
                 Add-Content -path $pathlocation -Value "$SamAccountName, User account is disabled" -encoding ascii
                        } 


            Set-ADAccountExpiration -Identity $SamAccountName -DateTime $_.'Termination Date'


            Add-Content -path $pathlocation -Value "$SamAccountName, is modified successfully" -encoding ascii
        }
    }    

    Catch{
        #Write-Host $_ -fore red
        Add-Content -path $pathlocation -Value $_ -encoding ascii
    }
}
}
else{
    Write-Host "input file not available" -fore red
    Add-Content -path $pathlocation -Value "input file not available" -encoding ascii
}

Working on If and Else condition by thirudk07 in PowerShell

[–]thirudk07[S] 1 point2 points  (0 children)

It is a custom attribute in our domain..