Pages

Tuesday, December 22, 2015

Error "Object reference not set to an instance of an object"

Error "Object reference not set to an instance of an object" while installing some roles or features on Windows Server 2012


Sometimes when we have a Microsoft update (KB3000850) installed on Windows Server 2012 some feature/role installation fails with error "Object reference not set to an instance of an object". Upon doing some research it turns out to be a BUG which has been mentioned on the Microsoft Article https://support.microsoft.com/en-us/kb/3062960 there is a hotfix available for this as well but I was having difficulties to get the hotfix downloaded hence I downloaded it by an alternate method and posting the alternate link here for so that it can be used by some one in need.

Install the hotfix below and the problem should be resolved.

Please note that installation of .net 3.5 feature requires sources files from Microsoft Windows 2012 ISO to be supplied as part of it x:\Sources\sxs x: is the drive letter of DVD installer image.

Installing this hotfix may need Reboot in some cases where there are some configuration changes pending on target server.



 

Friday, December 18, 2015

Allow more than 2 Concurrent RDP sessions on Windows Server 2012

To Enable more than two Concurrent RDP sessions on a Windows 2012 Server here are the steps to be followed.

   Windows Server 2012 does not have the GUI snapin available to specify the licensing server, number of concurrent sessions to be allowed and type of licensing (Per Device /Per User). So to specify these settings one need to do it either via GPO or via Registry after installing Remote Desktop Session Host Role.

(#)Install RD-Licensing Server along with RD Licensing Diagnoser:

 # Powershell method:
    install-windowsfeature RDS-RD-Server,RSAT-RDS-Licensing-Diagnosis-UI
 # GUI (Add Roles /Features) method:
    Server Manager > Add Roles > Remote Desktop Services > Remote Desktop Session Host

(#)Reboot machine for the installed roles to come into effect.
 

(#)Specify Licensing server configuration Details:

 # Registry method:
  Reg Path - HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Terminal  Services
    REG_DWORD - "MaxInstanceCount" Value = Number of sessions to be allowed
    REG_SZ - "LicenseServers"    Value = LicenseServer.domain.com
    REG_DWORD - "LicensingMode" Value = 2 (PerDevice); 4 (Per User)


 # Group Policy method

 (1) Computer Configuration>Administrative Templates>Windows Components>Remote Desktop Services>Remote Desktop Session Host>Connections>Limit Number of Connections.
   

 (2) Computer Configuration>Administrative Templates>Windows Components>Remote Desktop Services>Remote Desktop Session Host>Licensing>Use the specified Remote Desktop license servers.
   
 (3) Computer Configuration>Administrative Templates>Windows Components>Remote Desktop Services>Remote Desktop Session Host>Set the Remote Desktop licensing mode.

(#)Open Administrative Tools > Remote Desktop Services > RD Licensing Diagnoser
 

(#)Scroll down and click on the Licensing server being shown below.
 

(#)Click Provide Credentials from the Right hand actions pane.
 

(#)Once credentials are validated it should be green with licensing status showing there.

Wednesday, August 5, 2015

List of users from Remote Computers

Here is a Powershell script which will list all the local users from remote computers and output them in a csv file.

####################################################################################################
#Read List of servers from a Text file and fetch all local users from the servers mentioned in it. #
#List of local users from servers is exported in CSV file at the same location.                    #
#Written by Prakash Kumar 12:58 PM 8/5/2015                                                        #
####################################################################################################

get-content "Servers.txt" | foreach-object {
    $Comp = $_
    if (test-connection -computername $Comp -count 1 -quiet)
        {
            ([ADSI]"WinNT://$comp").Children | ?{$_.SchemaClassName -eq 'user'} | %{
                $groups = $_.Groups() | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
                $_ | Select @{n='Server';e={$comp}},
                @{n='UserName';e={$_.Name}},
                @{n='Active';e={if($_.PasswordAge -like 0){$false} else{$true}}},
                @{n='PasswordExpired';e={if($_.PasswordExpired){$true} else{$false}}},
                @{n='PasswordLastSet';e={(get-date).AddDays(-[math]::Round($_.PasswordAge[0]/86400,0))}},
                @{n='PasswordAgeDays';e={[math]::Round($_.PasswordAge[0]/86400,0)}},
                @{n='LastLogin';e={$_.LastLogin}},
                @{n='Groups';e={$groups -join ';'}},
                @{n='Description';e={$_.Description}}
             }
        } Else {Write-Warning "Server '$Comp' is Unreachable hence Could not fetch data"}
     }|Export-Csv -NoTypeInformation LocalUsers.csv


Copy the Code above and save it as GetlocalUsers.PS1,  Create a file named Servers.txt and save both files at the same location.

Execute above PowerShell script to fetch the list of users from remote computers.
 

Monday, April 20, 2015

Disable Slow mouse movement in Windows 2012

Whenever we are working on a rdp session on Windows 2012 it seems that we are working on a dialup connection even if connected with a good link.

To get rid of slow connection all you need to do is disable Pointer Shadow from Mouse control panel, Follow the steps below:

From control panel open Mouse applet and go too the Pointers Tab, Uncheck Enable pointer Shadow from the bottom and hit Apply.

Alternatively you can open command prompt and type
  • Start main.cpl ,1  (It will open the mouse control panel applet and with pointers tab active)
  • Press Alt key and E,  (It will uncheck the Enable Pointer shadow Checkbox)
  • Press Alt key and A, (It will apply the changes)
  • Press Esc key and the applet disappears (YOu already applied the changes :) )

Move the cursor and feel the difference :)

List all users in domain with Membership to each AD Group.

To list all the users from a domain with whatever groups they are member of, Use the below script (Remember it needs Quest PowerShell for Active Directory installed on the server where it is being run from) :

get-qaduser * | foreach-object {
$User = $_
(get-QADuser $user).memberof | Get-Qadgroup | select @{n="UserSAMID";e={$User}},Name,SAMAccountname,DisplayName,Type,canonicalname
} | export-csv Users_Memberof.csv -notypeinformation


This will generate a CSV file which will have user's Samid in the first column and Group name (direct membership) in the second column with other group attributes in subsequent columns.

get-qaduser * | foreach-object {
$User = $_
(get-QADuser $user).allmemberof | Get-Qadgroup | select @{n="UserSAMID";e={$User}},Name,SAMAccountname,DisplayName,Type,canonicalname
} | export-csv Users_Memberof.csv -notypeinformation



This will generate a CSV file which will have user's Samid in the first column and Group name (indirect nested group membership) in the second column with other group attributes in subsequent columns.

Wednesday, February 4, 2015

Get Member of Local Administrators Group on remote Windows machines and Export to CSV

Create a text file named servers.txt and put all servers in the file (one server at one line)
Copy and paste the below code (in Blue) in a text file and  save it as LocalAdmins.Ps1. Put both Servers.txt and LocalAdmins.PS1 at the same location and execute the Script from Powershell console as .\LocalAdmins.Ps1



#Read Server Names from the list Servers.txt
Get-Content "Servers.txt" |foreach-object {
$Content = $_
# Loop only executed when ping is successful
if (test-connection -computername $Content -count 1 -quiet)
{
#Fetching details from servers
([ADSI]"WinNT://$_/Administrators").Members() | Select-Object `
@{n='Computername';e={ $Content }},
@{n='User/Group Name';e={ $_.GetType().InvokeMember('Name', 'GetProperty', $Null, $_, $Null) }},
@{n='ADSPath';e={ $_.GetType().InvokeMember('ADSPath', 'GetProperty', $Null, $_, $Null) }},
@{n='Type';e={ $_.GetType().InvokeMember('class', 'GetProperty', $Null, $_, $Null) }}
}}| export-csv Local_Admins.csv –notypeinformation



Wait for the script to finis and a CSV file will be ready once it is done.

Fetch IP Address, Subnet Mask, Default Gateway, Plateform, Hardware Vendor from Multiple computers adn export in CSV

Fetch Networking Information from remote Windows Computers

Create a text file named servers.txt and put all servers in the file (one server at one line)
Copy and paste the below code (in Blue) in a text file and  save it as IP_Details.PS1 and and put both servers.txt and IP_Details.ps1 at the same location.

Execute the script from powershell console as .\IP_Details.ps1


(Get-Content .\Servers.txt)| ForEach {
$SrvName = $_

        If (Test-Connection -ComputerName $SRVName -Count 1 -Quiet) {

            $csp = Get-WmiObject Win32_ComputerSystemproduct -Computername $SrvName
            $cs = Get-WmiObject Win32_ComputerSystem -ComputerName $SRVName
              $Nic = Get-WmiObject -computername $SRVName -Class win32_networkadapterconfiguration -Filter ipenabled='true'|select DHCPEnabled,IPAddress,IPSubnet,DefaultIPGateway
            $props = @{
                ComputerName = $SRVName
                Domain = $cs.Domain
        IPAdd = $NIC.IpAddress
        Subnet = $NIC.IPSubnet
        Gateway = $Nic.DefaultiPGateway
        Platform = $Csp.Name
        Vendor = $CSp.Vendor
            }
            New-Object PsObject -Property $props
        } Else {
            Write-Warning "$SRVName cannot be reached, skipping."
        }
    } | Sort ComputerName |
            Select ComputerName,Platform,Vendor,Domain,@{N='IPAddress';E={[string]::join(".",($_.IPAdd))}},@{N='SubnetMask';E={[string]::join(".",($_.subnet))}},@{N='DefaultGateway';E={[string]::join(".",($_.Gateway))}} |
    Export-csv -notypeinformation ComputerDetails.csv


Wait for the script to finish and a csv file will be ready with all the information at the same location where script is located.

HBA Information from Remote Windows Machines

Create a text file named servers.txt and put all servers in the file (one server at one line)

Copy and paste the below code (in Blue) in a text file and  save it as HBAInfo.Ps1 and put both servers.txt and HBAInfo.ps1 at the same location.

Execute the script from powershell console as .\HBAInfo.ps1


Get-Content .\Servers.txt | ForEach-object {

$SrvName = $_

# Loop only executed when ping is successful
if (test-connection -computername $SRVName -count 1 -quiet)
{
Get-WmiObject -computername $SRVName -class MSFC_FCAdapterHBAAttributes -namespace "root\WMI" |select __SERVER,@{Name='Node WWN';Expression={(($_.NodeWWN | % {"{0:x2}" -f $_}) -join ":").ToUpper()}},Active,DriverName,HBAStatus,MAnufacturer,NumberofPorts
}Else { Write-Warning "$SRVName cannot be reached, skipping."

}} |export-Csv -NoTypeInformation hbaDetails.csv



Wait for the script to finish and a csv file will be ready with all the information at the same location where script is located.

Find RDP Port number specified on a Remote Windows machine via Powershell


# Script to know the RDP port numbers used on remote servers

clear-host
Write-host **************************************************************************
Write-host -foregroundcolor Yellow This script can be used to know the RDP port number specified on a server:
Write-host **************************************************************************
$servername = Read-host    "Enter ServerName to know its RDP port number"
$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $ServerName)
$RegKey= $Reg.OpenSubKey("system\\currentcontrolset\\control\\terminal server\\winstations\\rdp-tcp")
$PortNumber = $RegKey.GetValue("PortNumber")
write-host
write-host ===========================================
Write-Host -ForegroundColor Green RDP Port Number for $servername is $PortNumber
write-host ===========================================


Save above code (in blue) as get-rdpport.ps1 and execute it from Powershell window.
It will prompt for Server name and once supplied it will read the registry value and return RDP port number specified in there.