Tuesday 2 December 2014

PowerShell .NET OBJECT



I believe powershell V5 will close the gap between ITPRO and Developers and this is a chance to jump into the bus of Developers if we miss it some how.

Let see Method or Function overloading.

What is Function Overloading, Same name of the function and with multiple parameters.

Here the name of the class is Test and we have two function with the same name ADD but the number of parameter is different, that is what function overloading from the eye of ITPRO.
















Constructor A constructor initializes an Object when it is created, It has the same name as its class and similar to method ,However constructor have no explicit return type.



Thursday 20 November 2014

Desired State configuration

Desired State configuration.




A simple scenario what felt me to understand it, A lots need to cover and learn, but thought sharing it will be worth for the beginner like me. I am just in love with DSC.  Making sense Ahha :)

Execution happen in three steps, Make the configuration, Call it and Make it so (pointer to MOF)

 - Install PowerShell Version 4.0 and enable PowerShell Remoting.

A common problem on laptops is that the initial PowerShell Remoting configuration will fail because the system is connected to a public network.








Step 1.

Enable-PSRemoting -SkipNetworkProfileCheck -Force

Step 2. Make the configuration
#=====================================

Configuration MyFirstDSC
{


    Node 'Anirban-PC'
    {
        Service VM
        {
            Name = 'VMwareHostd'
            State = 'Running'
            StartupType = 'Automatic'
         

        }
    }
}

MyFirstDSC

#=================================================
Step 3 Execute the Powershell and it will create the Folder MyFirstDSC having the MOF


Step 4 Make it So.



Saturday 15 November 2014

Error-Handling Session in PSBUG

Thanks Ravi Sir for the DSC book and Deepak for giving the opportunity to speak in the group meet and Audience who come and join us today.


Error-Handling in PSBUG meet.


Sunday 5 October 2014

Sync Error Series - An object with DN "CN=" already exists in management agent

Note : This series is for the Beginner and trouble shooting the Error With Sync Engine, Based on Test Lab, Highly advice do not do Full Sync of the Management Agent. Errors are Fun, Debug It...!!

The Management Agent Run and see the error message in the Stack information.

"Microsoft.MetadirectoryServices.ObjectAlreadyExistsException: An object with DN "CN=4,OU=FIMOU,DC=corp,DC=fim2010,DC=com" already exists in management agent "ADMATest".
   at Microsoft.MetadirectoryServices.Impl.ConnectorImpl.Commit()
   at Miis_Metaverse.MVExtensionObject.Microsoft.MetadirectoryServices.IMVSynchronization.Provision(MVEntry mventry)"



The error message arise because there is already an existing object with the same DN in provisioning connector space.















Step 1.  Search the user in metaverse and the object will not existing in MV as it fails during the provisioning, First challenge is to bring the Object in MV.

Step 2.  Disable the Provisioning Rule Extension ( Tool-Options)
             Unchecked the option Enable Provisioning Rule Extension.




















Step 3. Go to the connector space of the MA and commit preview, this will project the object in MV.

After Step 3,checked the option Enable Provisioning Rule Extension. See Step 2,
Step 4. See How to join connector Space Object to a MV object, the tech net link is below

Join a Connector Space Object to a Metaverse Object Link

 Go to Joiner Tab and Join the existing disconnect object to newly project object in MV.

This will fix the Error .. !! 




Saturday 20 September 2014

Create multiple instances of custom Powershell object

function Aka($x,$y)
{
 $hash = @{          
        Value1       = $x
        Value2       = $y
    }                  
                                   
   New-Object PSObject -Property $hash  
}

$Obj=@()
$Obj+=Aka 1 2
$Obj+=Aka 2 3
$Obj+=Aka 3 4


Sunday 14 September 2014

FIM : Group Membership Export GUI with Powershell

Powershell GUI to export the group membership from FIM portal, This will open up a PowerShell console window and simple GUI showing the input box for the name of group and Outbox for the membership of the group.In addition the membership of the group will export with name of the group in CSV in user profile.

To hide the powershell console window running at the background we can use PowerGUI to wrap it as an exe. 
Open the Script in PowerGUI Script Editor and then go to Tools > Compile Script.

Link for the code .... 

Monday 18 August 2014

Powershell GUI


My First experience with GUI in PowerShell, If you know how to manipulate the form you can make very powerful GUI apps for Help desk and for the team members. Lets see it how it works.

The version of PowerShell is 3.0.Add a .NET Framework type to a PowerShell session. If a .NET Framework class is added to your PowerShell session with Add-Type, those objects may then be instantiated (with New-Object ), just like any .NET Framework object. 

#=====================Begin of the Script===========

Add-Type -AssemblyName System.Windows.Forms

#Create function to add two numbers, You can create your own function.

function add ($objTextBox2,$objTextBox1)
{

$a1=[int]$objTextBox1
$a2=[int]$objTextBox2

$Get=$a1+$a2
$outputBox.text = "$Get" 

}


#System.Windows.Forms.Form will create a blank form, Lets create a object.

$Form = New-Object system.Windows.Forms.Form
$form.Size = New-Object Drawing.Size @(1000,10000)

############## Create Input BOX1

$objTextBox1 = New-Object System.Windows.Forms.TextBox
$objTextBox1.Location = New-Object System.Drawing.Size(10,40)
$objTextBox1.Size = New-Object System.Drawing.Size(260,20)
$Form.Controls.Add($objTextBox1)
########################### End of Input Box1

$objTextBox1.Text

############# Create Input BOX1

$objTextBox2 = New-Object System.Windows.Forms.TextBox
$objTextBox2.Location = New-Object System.Drawing.Size(10,4)
$objTextBox2.Size = New-Object System.Drawing.Size(260,2)
$Form.Controls.Add($objTextBox2)
########################### End of Input Box2
$objTextBox2.Text

############# Create OutBOX

$outputBox = New-Object System.Windows.Forms.RichTextBox 
$outputBox.Location = New-Object System.Drawing.Size(10,150) 
$outputBox.Size = New-Object System.Drawing.Size(565,200) 
$outputBox.MultiLine = $True 

$outputBox.ScrollBars = "Vertical" 
$Form.Controls.Add($outputBox)

########################### End of Outbox

#################Create the ADD Button

$Button = New-Object System.Windows.Forms.Button 
$Button.Location = New-Object System.Drawing.Size(400,30) 
$Button.Size = New-Object System.Drawing.Size(110,80) 
$Button.Text = "ADD" 
$Button.Add_Click({add $objTextBox1.Text $objTextBox2.Text}) 
$Form.Controls.Add($Button) 

#####################End of Button

$drc = $form.ShowDialog()



#========================End==========================

The GUI will look like below


You can add back ground wallpaper in your GUI like below, Its all depend on you how you play with the blue shell.




Saturday 26 July 2014

PowerShell and C# - Custom Object

I am not a Big Fan of C# and was exploring the Blue shell today. Was alone in room, Roommate was not there  and was thinking can I copy a C# code from net and execute it in PowerShell and with luck was successfully execute it.PowerShell is faster to write, and deploy..!!


I have copy the code to find the factorial of a number from Web and then create a new object $kali


The Output 


I am done for today time to have some Beer..!!!

Sunday 6 July 2014

Distribution Group Management



Disclaimer: The purpose of this document to show how group management can be configure in FIM environment, all the test has been done in virtual basement lab environment. It is highly advice to test your architecture design in Test environment before deploying in Production environment. It carry no right and it implementer will be fully responsible for its own act without analyzing the risk impact. 

Monday 23 June 2014

FIM Error 1068 :the dependency service or group failed to start.


It is simple as the name suggests the dependency service is not started; You have to start all the dependency service first before you starting your FIMSynchronizationService.


Do not start any services by trial and error method process, as I tried to figured out what is wrong in my LAB.







 Know all of your dependency service password,If not take the help of SQL Admin to know the password of the SQL services
.
Find the service you can't start in services.msc, right click and open properties. Go to dependency and make sure all those are started. 99% of the time one of those services hasn't started.

Cheers.. !!!, I was able to start my FIMSynchronizationService.


Happy Troubleshooting and Good Night

Saturday 21 June 2014

PowerShell : How to sent mail using gmail SMTP

#---------------------------------------------------------------------------------------
$From = "Any.Singha@gmail.com"
$To = "Any.Singha@gmail.com"
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$Username = "Any.Singha@gmail.com"
$Password = "XXXX" # Give your password
$subject = "Welcome to Powershell Group Meet Bangalore"
$body = "Hi, All Welcome"

$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);

$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.Send($From, $To, $subject, $body);
#-----------------------------------------------------------------------------------

Sunday 15 June 2014

Adding Multiple user to Group in FIM portal

"YOU Can get what you want if you help enough other people to get what they Want".

The Powershell way of doing thing,Feel Free to Tweak it as per your need

Thursday 12 June 2014

__Powershell : Update Database.

When you working  as IT PRO you will not have all application installed in production servers and have some limitation in installing the application, Guess what will happen when you asked to  update 10000 or 2000 records in SQL database and you have to  update the correct value each time in table.I have spent couple of sleep less night in updating SQL table, So here is a power shell way of updating the  table. It will take 10 to 15 min to execute it and finish your work and landed home safely on time.

1. Save the input file in CSV (comma delimited)



2. Lets your  Select Query looks like

Select EmpNO,Name,Lastname,Department,Roles,Country from Employee

3.Import the CSV in  Blue Shell






4. Next Steps is the use of Pipe Line






5. Check your SQL txt in your profile and update the database.






I am done with my Blue Shell todays, Time to sleep.  Have a FUN Friday, Weekend is gona started soon Cheers

Saturday 7 June 2014

Unable to RUN ManagementAgent

I hit the Error message,Unable to RUN Management Agent.









To solve this you have to Refresh the Schema of the Management Agent with correct password

Friday 30 May 2014

System.Management.Automation : Powershell & C#

There are blogs mentioning how to add reference System.Management.Automation in your C# code, But all system are not properly configured. I found the DLL  System.Management.Automation  in C:\Windows\winsxs\msil_system.management.automation_

Just you stuck in finding your DLL this may be the folder you have to look in
C:\Windows\winsxs\msil_system.management.automation_

Reference Blog :
http://blogs.msdn.com/b/saveenr/archive/2010/03/08/how-to-create-a-powershell-2-0-module-and-cmdlet-with-visual-studio-2010-screencast-included.aspx
http://www.cibengineering.com/blog/system-management-automation/
http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C

Happy Weekend, I am done with my Learning Today.

Self-Improvement: The First Step – Write down your weaknesses.


Sunday 27 April 2014

Synchronization Rule

The strategy of group creation in AD can be defined in Sync Rule, It is very important to know how to customize the DN so the group can be sync to respective OU in AD.
FIM Administrator can customize the DN in Outbound Sync Rule, so the group can be create to respective OU in AD.

For example.

IIF(Eq(groupLocation,"Bangalore"),"CN="+mailNickname+",OU=Groups,OU=Bangalore,DC=XXX,DC=com",IIF(Eq(groupLocation,"Pune"),"CN="+ mailNickname +",OU=Groups,OU=Pune,DC=XXX,DC=com",Null())) àDN


Thursday 20 February 2014

@Cognizant Goodbye and Thank you - Till we meet Again !!

Thank you Cognizant,Today is my last day in CTS and take this opportunity to share the experience so far, First time have seen almost all the Microsoft technologies in one floor.
Guys without your help I would not have come so far. Anil and Vinit Thank you so much for all your help and advice whenever i looked upon and faced issues you were always there for me.
Sincere gratitude and thanks to my manager Mangal & Ghouse Sir.
Thanks Change Management team for all the change approved during my tenure, SD team for understanding the things more than me,YOU Rocks.
Special Thanks to first row Wintel for all your sweets - Exchange,Lync.
Thanks Networking team for your Kindness and sharing resources.
All the best to Bike Riders Gangs... We enjoyed lots and hopes the journey will remain continue.....

Best wishes to all your future endeavors and stay in touch.
Dont say WHY ME?
Just say TRY ME!!!!
Let life put you down a 100 times...
Just keep echoing to life, "I will be back"
When Life puts you in tough situations.

Thank You All...All the best FIM Team.


Regards,
Anirban Singha
================================================

Thursday 6 February 2014

Use PowerShell to Back Up Group Membership

What i found in one of the Change in Production FIM 2010 to fix something leads to break of group membership of the new user. Always advise to have group membership back up of your environment before implementing change that may break group membership of the user.Thank God Nothing was break for the existing user only then realize how important to keep the back up.

Steps: 
Take a Group Membership back up.

Back-Up Steps: 
Recover the Group Membership from back Up.

Create a backup folder where the entire user in AD will have their Group Membership having its own txt file with samaccountname, In case need to back up -the PowerShell can be point to the each txt to add back the group membership.

How to take Group Membership back-Up.

To search user with all the properties

Get-ADUSer -filter * -properties *

To select attribute we have to pipe it out

Get-ADUSer -filter * -properties * | Select name,samaccountname

OR

Get-ADUSer -filter * -properties * | %{
$x=$_.samaccountname
$x
}

The Output will show the attribute of the user, if you want to make further search you have to capture all the attribute in array.

Function FindGroupmember  {
   [CmdletBinding()]
   Param(
                 [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
                 [string[]] $value    
              )
Begin {}
Process{
     foreach($i in $value) {
      # Write-Host  "=== Finding Group Membership of $i========"
     Write-Output "=== Finding Group Membership of $i========"
     $y=Get-ADUSer -identity $i -properties * 
     $z=($y.memberof -split (",")  | Select-String -SimpleMatch "CN=") -replace "CN=",""
     $z  # To display the output.
     # The below is the path to backup in csv
     $z >>C:\Users\Administrator\Desktop\Backup.csv
     $z >>C:\Users\Administrator\Desktop\Test\$i.txt
                                          }
             }
End {}
 }
Import-Module ActiveDirectory
$a=@( ) # Dynamic array
Get-ADUSer -filter * -properties * | %{
$x=$_.samaccountname
$a+=$x
}
FindGroupmember  -value $a

I have intensely strike Write-Host cmdlet after reading  Jeffrey Snover's blog

I am closing this topic with the line . Make sure you know what you are doing before you start to make changes you do not understand

Sunday 26 January 2014

List of Users in Multiple Domain..

How to find user in multiple domain, PowerShell by default will point to parent domain and will not fetch the result in child domain.When u will get list of users containing both  parent and Child domain,PowerShell will not fetch the result for child domain.
The below is the Script which will point to both domain.



How to Use PowerShell to Find all Users Having no Manager in FIM Portal

Thursday 9 January 2014

Search Scopes in FIM 2010.

Search Scopes in FIM 2010.

What is the use - To display the attribute in the main UI of the portal.
Taking as example - The Users are not showing their EmployeeID details in the main UI of the portal.

Go to Administrator , Search Scopes, All Users, Results

In Attribute type EmployeeID.
IISRESET

ServiceNow onboarding Sailpoint