Monday, May 27, 2019

How to syncronize a Physical Folder on Another Location without Duplicating the files

The problem

I want to synchronize my F: drive with one drive without any loss of data or duplicating any files. My Username on the computer is jorte, and my onedrive is configured locally at: "C:\Users\jorte\OneDrive" How can I solve that?

The solution

The solution is to create a symbolic link between the two locations.

1. Open a CMD window as an administrator. and run,
Mklink /D "C:\Users\jorte\OneDrive\Ddrive" "F:"

This solution works for "Onedrive Personal" (white cloud) and also works for "Onedrive For business" and always remember that there are invalid file names that can be researched on the documentation


For more information you can check here Please consider to donate and thank you very much for reading this.

Friday, September 8, 2017

How to preserve the naming convention

The problem

[string]$VMName = 'VM-EURO-UK-01'
[int]$NumberOfVMs = 12
$VMPrefix = ($VMName -split '(?=\d)',2)[0]
[int]$VMSuffix = ($VMName -split '(?=\d)',2)[1]

for($i=0;$i -lt $NumberOfVMs;$i++)
{
    $VMName = $VMPrefix+$VMSuffix

    Write-Host "VM Name is $VMName"

    $VMSuffix = $VMSuffix + 1
}
How to preserve the naming convention in Powershell?

The solution

[string]$VMName = 'VM-EURO-UK-01'
[int]$NumberOfVMs = 12

$VMPrefix = ($VMName -split '(?=\d)',2)[0]

[int]$VMSuffix = ($VMName -split '(?=\d)',2)[1] 

for($i=0;$i -lt $NumberOfVMs;$i++)
{
    $str = if($VMSuffix -le 9){
        "0{0}" -f $VMSuffix
    }
    else{
       $VMSuffix
    }  
    $VMName = $VMPrefix+$str

    Write-Host "VM Name is $VMName"

    $VMSuffix+=1
}

Thursday, June 22, 2017

Configure to run a Powershell Script into task scheduler

The Requirement

To create a periodic action that reports in CSV the top 20 processes into a Folder in Desktop, every hour.


I have been doing a lot of Powershell Scripting in the last years. So I have to work with Task Scheduler a lot in recent days. I will show the configuration


    List of steps:
  1. Create your PowerShell script.
  2. I'll use an advanced PowerShell liner script for this tasks

         
    $start= Get-date
    $file = $start.Tostring("yyyyMMdd-hhmmss")
    Get-Process -IncludeUserName * | select @{l="Date";e={$($start)}},ProcessName,CPU,Id,StartTime,Username | Sort-Object CPU -Descending | select -First 10 | ConvertTo-Csv -NoTypeInformation  | Out-File ".\$file.csv"
    

    This script will get all the processes in the computer you run it, also it will add the 'Date' where you are doing the query, select some variables of interest, then sort descending using the "WorkingSet" property, select the first 20, convert the object to CSV, no type information about the class and finally the output would be the Output.CSV file. (In the same folder of running the script).

  3. Configure the Task

  4. Open task manager, by clicking the Windows icon, and typing "task scheduler"


    Once opened, create a Tasks by clicking the "Create Task" link in the "Actions section."

    At the start, you will be located in the "General" tab, on the next screen add a name and make sure that the checkbox "Run it with the highest privileges" is checked.
    Then move to the Triggers, here we configure that it should execute every hour. To do so we need to click the "New" Button and then set as shown in the next image, and then click ok.
    Now on the "Actions" Tab is the important one. we click on "new" on the program script add: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe (without quotes since there's no space in there)

    In arguments would be the path of the file, (if contain spaces add quotes): -file "C:\Users\j0rt3g4\Desktop\scripts\Startcoco.ps1"

    and in working directory make sure that you don't add any quotes so the path should never contain any blank space. (this will be the location of the reports): C:\Users\j0rt3g4\Desktop\scripts

    Finally, the settings should be seen like this:
    And in the final configuration tab is called "Settings" in here you just need to check that "allow the task to be run on demand" and "Do not Start a new instance" are checked and selected respectively.


  5. Make sure that is working or troubleshoot what you could have missed

  6. Enable all the history for all tasks

    Make sure that the "start in contains the file".
    Successful code is 0x000000.
    And it should be generating every single hour, in the "start in" path0 configured in the "Action" of the task.
    At the end in your "Start in" you should see something like this:

If you enjoy and worked for you, thank you so much for reading and please consider to donate.

Thursday, February 9, 2017

Error -2146893022 The target principal name is incorrect (AD Replication)

The History


I had a client today that reported the CEO's computer unabled to login agaist Active Directory, it had the message 'Trust Relationship was lost'. In this kind of issues the solution is just to take out the computer from the domain and re-join it. After removing the computer from the AD I was unable to join it again, because of a error: "Logon failure: the target account name is incorrect". After checking the replication in the domain controllers, i figure out this:
Basically the CHENSDC2 and CHENSDC had 54 days without talking to each other. IPV6 was disabled on the servers And checking replication of Active Directory:
And this guide us to the headache

The Headache


Basically the Repadmin gives an error "The Target principal Name is incorrect", so replication from "CHENSDC2" to "CHENSDC" works, but from "CHENSDC" to "CHENSDC2", doesn't.
I tried several solutions to make this work but none of those worked, so I'll try to be as clean as I can be in the solution.

The Solution


To fix this issue you just need to go to do the following:

    1. Determine the Primary Domain Controller (PDC) by doing this steps:

  1. Windows key + R (at the same time)
  2. Write cmd and then press enter. A console windows will open.
  3. netdom query fsmo
The output will be something like this, and determine the server that has the PDC role:
So our PDC is called CHENSDC2 in this example, and the problematic domain controller will be CHENSDC

    2. Stop Kerberos Key Distribution Center (KDC) service in CHENSDC (problematic server):

  1. Open the console (cmd) as the previous step, if you don't have it
  2. Use the command Net stop KDC

Pre step Download WS2003 Resource kit in the link: https://www.microsoft.com/en-us/download/details.aspx?id=17657" then install it. I did it in windows server 2008 R2 with nothing but a warning about versions, just ignore it and install the software.

    3. Purge Kerberos keys in the CHENDC (problematic server)

  1. Navigate to: C:\Program files (x86)\Windows Resource Kits\Tools and run "kerbtray.exe"
  2. You will get a Green bar Next to the time, like this
  3. Now just right click the green bar and select "Purge tickets"
  4. After this the server will be aware of the syncronization KDC from the PDC.

    4. Reset the Computer's Password in the Primary Domain Controller (PDC)

  1. In the PDC computer, we got this computer in the step 1. Open the console (cmd) as the previous step, if you don't have it
  2. netdom resetpwd /server:serverName /userd:DomainName\Administrator /passwordd:AdminPassword

    5. Start the service in the CHENSDC (problematic server)

  1. Finally in the PDC computer, we got this computer in the step 1. Open the console (cmd) as the previous step, if you don't have it
  2. Then run the command: net start kdc

    6. Start IPV6 on both servers

  1. IPv6 is used by servers to communicate to each other, so enabled it and run "ipconfig /registerdns" so they can talk to each other, specially in the consoles for Active directory

Sidenote: This is basically to improve communication between domain controllers specially for the consoles of AD (AD sites and services, AD Users and Computers, etc)

    7. Check replication again

  1. run repadmin /replsum
  2. repadmin /showrepl
  3. repadmin /showreps
And make sure that all is working good again.

Please consider to donate and thank you very much for reading this.

Friday, January 9, 2015

Mapping Servers Drives by using "Net use" with username and password DOS

Client Require that All drives from ServerA andS erverB to be mapped in ServerC

The client is implementing a new file server called ServerC, and he requires that all the drives from ServerA and ServerB to be visible in ServerC to do the migration of all the company data from SrvA and B to the serverC. Here's the scenario in image

I will make a table to assist me in the creation of the drives

Now I can comply the request by creating a script called: 'mapping.bat' in notepad or notepad++. As Follows:
NET USE * /D /Y REM
net use I: "\\172.30.2.6\C$" /user:"SERVERA\administrator" Pa$$w0rd$ /p:YES
net use J: "\\172.30.2.6\D$" /user:"SERVERA\administrator" Pa$$w0rd$ /p:YES
net use K: "\\172.30.2.6\F$" /user:"SERVERA\administrator" Pa$$w0rd$ /p:YES
net use L: "\\172.30.2.6\G$" /user:"SERVERA\administrator" Pa$$w0rd$ /p:YES
net use O: "\\172.30.2.7\C$" /user:"SERVERB\administrator" C0ntr3s3n4 /p:YES
net use P: "\\172.30.2.7\D$" /user:"SERVERB\administrator" C0ntr3s3n4 /p:YES
net use Q: "\\172.30.2.7\F$" /user:"SERVERB\administrator" C0ntr3s3n4 /p:YES
net use R: "\\172.30.2.7\G$" /user:"SERVERB\administrator" C0ntr3s3n4 /p:YES

Script Explanation

In line number 1, we just clean all the "network drives" that can be in use
NET USE * /D /Y REM

* : A comodin to says all drives.
/D : Short for /delete
/Y : Short for /yes (so the scripts doesn't require user's confirmation).

Note: If you have any map drives already mapped and you wouldn't wanna clear, then just comment (by adding REM at the start of the line) or delete this line.

In the following lines we do the mapping I will explain line 2:

net use I: \\172.30.2.6\C$ /user:SERVERA\administrator Pa$$w0rd$ /p:YES

Net Use: Command used to connect network drives.
I: Drive to map (it should not be on use by any other hard drive or DVD,BLUERAY or network drive).
"\\172.30.2.6\C$": Specified the IP of the computer and the resource C$, the "$" at the end means that you will need administrative privilegies.
/user:SERVERA\administrator this option specifies the local admin from that machine (it can be a domain\user as well).
Pa$$w0rd$ Specifies the password from the user
/p Specifies the persistent option

Please consider to donate and thank you very much for reading this.

Monday, January 5, 2015

How to easily add DNS Reverse using Azure Powershell

Instalation of Windows Azure Powershell

Here's the easiest way to install this is to follow the steps in:Microsoft Web Platform Installer and follow the wizard's steps. If for any issues you need a complete guide: Install and Configure Windows Powershell .

How to add the DNS Reverse into a VM

In windows Azure a VM is hosted by a "Cloud Server", we will need the "name" of that "cloud Server". And the DNS Reverse Resolution name (well format name ended by a dot). I think the easiest way is to modify line 1 and 2 from the folowwing powershell script:

/*Programmer: jortega added this*/
Made by MCSE Server Infrastructure and messaging jortega928@yahoo.com/j0rt3g4@j0rt3g4.com
https://www.j0rt3g4.com
$CloudService="jdotex"           #Change the service name of the VM
$ReverseName="mail.j0rt3g4.com." #Ended by a dot
Set-AzureService –ServiceName $CloudService –Description "Exchange Reverse DNS" –ReverseDnsFqdn $ReverseName
And this is the result of copy&paste into a windows azure powershell console:

In the following link are more information if you want to extend your knowledge: Announcing reverse DNS for azure cloud services

Here's the test

Up and running

Please consider to donate and thank you very much for reading this.