Tuesday, January 29, 2013

Powershell Quick Start



Get-Alias- complete list of available aliases

Get-Command - that returns a list of all the PowerShell cmdlets available to you

Format-List : is a cmdlet that takes information passed to it and then outputs that information in list view (that is, property values are displayed on separate lines rather than as columns in a table).
Eg:PS C:\scripts> Get-Command | Format-List

Format-Table : cmdlet can take pretty much any information and display it as a table rather than a list.

set-location c:\Windows

Get-ChildItem C:\Scripts –recurse

Set-ExecutionPolicy RemoteSigned
To run scripts from within Windows PowerShell you will need to change your security settings; by default, PowerShell only runs scripts signed by a trusted authority.

Get-Process
To get information about the properties and methods of an object retrieve an instance of that object and then “pipe” the object to the Get-Member cmdlet. For example, this command returns the properties and methods available when working with processes:  eg Get-Process | Get-Member

Get-Process 
To work with or display specified properties of a collection, pipe the returned results to the Select-Object cmdlet:
Eg Get-Process | Select-Object Name, Company


Where-Object {$_.Length -gt 200KB} | Sort-Object Length
To filter and sort objects . Sort-Object should typically appear on the right-hand side of a pipeline.
Eg1:
Get-ChildItem C:\Scripts | Where-Object {$_.Length -gt 200KB} | Sort-Object Length
eg2: Get-Service | Sort-Object Status | Format-Table
eg:3: $a = (Get-Process | Sort-Object ID)
 
You have a variable $a that contains a collection of data. You can sort that data, and sidestep the pipeline altogether, by using a command like this: eg: Sort-Object -inputobject $a



Some more must read for quick start

1)Running powershell
http://technet.microsoft.com/en-us/library/ee176949.aspx
 
2)Getting started with powershell
http://technet.microsoft.com/en-us/library/ee177003.aspx

and other links under those section of above links.


More references:




1) Windows PowerShell Quick Reference

http://www.microsoft.com/en-us/download/details.aspx?id=7097


2) Learn powershell
   http://blog.endjin.com/2012/03/an-omega-geeks-guide-to-learning-powershell/

3) Windows PowerShell Graphical Help File

Some issues and Solution
1)Issue unable to load snapin
Sol : some snapins are registered for 64 bit
in that use try powershell.exe at  C:\Windows\SysWOW64\WindowsPowerShell\v1.0 –
& some might work only for 32 bit then try powershell at C:\Windows\System32\WindowsPowerShell\v1.0)






Wednesday, January 23, 2013

Export grid to excel Asp.net


Good reference
http://mattberseth.com/blog/2007/04/export_gridview_to_excel_1.html 

Tuesday, January 22, 2013

Programming SCCM , Active directory using .Net



Some tools which help this development

1.The WMI Code Creator tool allows you to generate VBScript, C#, and VB .NET code that uses WMI to  complete a management task such as querying for management data, executing a method from a WMI class, or receiving event notifications using WMI.
 download at  http://www.microsoft.com/en-us/download/details.aspx?id=8572


2. webemtest



Refresh Package Source Distribution points using C#


Below is the code to update Refresh Package source distribution points using C# 


 public static string RefreshPackageDPs(string pkgID)
        {
 
            string result = null;
            List<string> dpstatusinfo = new List<string>();
            try
            {

//code to connect to SCCM
               ManagementScope scope;
ConnectionOptions connOptions = new ConnectionOptions()
                                   {
                                       Username = userName,
                                       Password = userPassword,
                                       Impersonation = ImpersonationLevel.Impersonate //Identify- recommended level for WMI Calls
                                       ,
                                   };//Timeout= TimeSpan.MaxValue
                    scope = new ManagementScope(wmiNameSpace, connOptions);
 scope.Connect();

//Code to Refresh the DP's
                ObjectQuery query = new ObjectQuery("SELECT *  FROM SMS_DistributionPoint WHERE PackageID='" + pkgID + "'");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
 
 
                foreach (ManagementObject queryObj in searcher.Get())
                {   
                    queryObj.SetPropertyValue("RefreshNow", true);
                    queryObj.Put();
                }
 
                result= "All DP's refresh started successfully!";
            }
            catch (ManagementException e)
            {
                result = "An error occurred while refresh package DP's.";

            }
            return result;
        }

Leave me a comment is you need any more info 

Difference between Update Dp's and Refresh Dp's.
Refer - > http://technet.microsoft.com/en-us/library/bb892806.aspx

Thursday, January 10, 2013

Get Username for logged in user Asp.net

The below is when using Windows Authentication using ASp.net

In ASP.NET, please use User.Identity.Name to get the logon user. User.Identity.Name might be empty if Anonymous Authentication is enabled in IIS.
http://msdn2.microsoft.com/en-us/library/system.web.httpcontext.user.aspx
Here is the logical to check if the identity is available.

VB.NET
' Gets the name if authenticated.
If User.Identity.IsAuthenticated Then
    Label1.Text = User.Identity.Name
Else
    Label1.Text = "No user identity available."
End If

C#
' Gets the name if authenticated.
if (User.Identity.IsAuthenticated)
    Label1.Text = User.Identity.Name;
else
    Label1.Text = "No user identity available.";


Environment.UserName is the running thread identity. If you have enabled Impersonation as Mark said, you can find out the returning result will be different. However this requires ASP.NET Impersionation. If you don't need ASP.NET Impersonation and dealing with the thread identity, you can ignore Environment.UserName if and just use User.Identity.Name.

Alternate ways to get username are are
  1. this
.Context.Request.LogonUserIdentity.Name
  • Request.LogonUserIdentity.Name
  • ref: http://forums.asp.net/t/1179997.aspx/1/10


    Asp.net 4 on IIs7


    1. how-to-install-internet-information-services-iis-7-on-windows-7

    ref: http://hrushikeshzadgaonkar.wordpress.com/2010/05/28/how-to-install-internet-information-services-iis-7-on-windows-7/

    2.How to add ASP.NET 4.0 as Application Pool on IIS 7, Windows 7

    http://stackoverflow.com/questions/4890245/how-to-add-asp-net-4-0-as-application-pool-on-iis-7-windows-7

    Monday, January 7, 2013

    Everything SQL Server Compact: SQL Server Compact Private Deployment tweaks

    Method 1:
    this worked for me
    build commands dint work in this




    MEthod 2: dint work dont know why!

    Everything SQL Server Compact: SQL Server Compact Private Deployment tweaks: As a follow up to my previous post about Private Deployment (the concept that you can simply include the SQL Server Compact DLL files with ...

    for SQLCE 3.5 the code to use is
     <bindingRedirect oldVersion="3.5.8080.0" newVersion="3.5.1.0" />


    Sunday, January 6, 2013

    Asp.net 4.0 & HTML 5



    1) Asp.net 4.0 with Visual Studio 2010 is compatible with HTML 5. You can download the Visual Studio Service pack 1 Beta From Here
    for Html 5 and CSS3 intellisense http://www.microsoft.com/en-us/download/details.aspx?id=23691

    2)http://blog.reybango.com/2010/09/21/how-to-create-html5-website-and-page-templates-for-visual-studio-2010/

    Devops links

      Build Versioning in Azure DevOps Pipelines