Wednesday, August 21, 2019

Python : IndentationError: expected an indented block

Initial learning of Python in IDLE, while executing While or For Loop examples like below, you will end up with "IndentationError: expected an indented block".

Example Error:

>>> z = ['a','b','c','d','e']
>>> i = 0
>>> while i < len(z):
... print(i, z[i])
  File "<stdin>", line 2
    print(i, z[i])
        ^
IndentationError: expected an indented block

>>> z = ['a','b','c','d','e']
>>> for i in range(0, len(z)):
... print(i, z[i])
  File "<stdin>", line 2
    print(i, z[i])
        ^
IndentationError: expected an indented block


Solved Example :

>>> z = ['a','b','c','d','e']
>>> i = 0
>>> while i < len(z):
...    print(i, z[i])
...    i += 1
...
0 a
1 b
2 c
3 d
4 e

>>> z = ['a','b','c','d','e']
>>> for i in range(0, len(z)):
...     print(i, z[i])
...
0 a
1 b
2 c
3 d
4 e

Solution :

 Should use Minimum 2 spaces or 4 Spaces on highlighted area in examples.
 

Friday, August 31, 2018

Managed Service Account Creation on Windows server 2012 R2



In AD DS, MSA’s will stored under CN=Managed Service Accounts, DC=<domain>, DC=<com>

Example: CN=Managed Service Accounts, DC=Contoso, DC=com


1)      Open the PowerShell console with administrator privileges

2)      To create service account,
New-ADServiceAccount –Name <MSA_Name> –DNSHostname <DNS name of Domain_Controller>
Example in my LAB -
New-ADServiceAccount –Name ADCSFSSVC –DNSHostname DC1.Contoso.Com

While Exexuting above Command , will get an error on first time.

New-ADServiceAccount : Key does not exist
At line:1 char:1
+ New-ADServiceAccount -Name ADCSFSSVC -DNSHostName dc1;

To create the KDS root key in my test environment for immediate effectiveness

Add-KdsRootKey –EffectiveTime ((get-date).addhours(-10));

In Production we need to use below command and need to wait until replication successful with Other DC’s.
Add-KdsRootKey –EffectiveImmediately

Now Below command will run successfully.

3)      New-ADServiceAccount –Name ADCSFSSVC –DNSHostname DC1.Contoso.Com

Need to associate it with the computer object

4)      Add-ADComputerServiceAccount –identity <Host_Computer_Name> -ServiceAccount <MSA_Name>

In my LAB Environment, I associate it with computer ADCSFS

5)      Add-ADComputerServiceAccount –identity ADCSFS -ServiceAccount ADCSFSSVC

Then need to install the MSA in hostcomputer of ADCSFS, where service Account going to configure

If Server is Non-Domain Controller, Need to follow below steps

  • .       Open the PowerShell console with administrator privileges
  • .       Run the Import-Module ServerManager cmdlet
  • .       Add-WindowsFeature RSAT-AD-PowerShell cmdlet to install the Active Directory module for Windows PowerShell.
  • .       Close and re-open PowerShell console with administrator privileges
  • .       Import-Module ActiveDirectory cmdlet


6)      Set-ADServiceAccount -Identity ServiceManager -PrincipalsAllowedToRetrieveManagedPassword ADCSFS$;
7)      Install-ADServiceAccount -Identity ADCSFSSVC;

Post that, Managed Service Account visible on AD.