About Me

My photo
HANUMANGARH, RAJASTHAN, India

Thursday, 19 November 2020

Tuesday, 10 November 2020

Export all users with groups and nested groups

 #Get all recursive groups a user belongs.

Function Get-ADUserNestedGroups


{

    Param

    (

        [string]$DistinguishedName,

        [array]$Groups = @()

    )

 

    #Get the AD object, and get group membership.

    $ADObject = Get-ADObject -Filter "DistinguishedName -eq '$DistinguishedName'" -Properties memberOf, DistinguishedName;

    

    #If object exists.

    If($ADObject)

    {

        #Enummurate through each of the groups.

        Foreach($GroupDistinguishedName in $ADObject.memberOf)

        {

            #Get member of groups from the enummerated group.

            $CurrentGroup = Get-ADObject -Filter "DistinguishedName -eq '$GroupDistinguishedName'" -Properties memberOf, DistinguishedName;

       

            #Check if the group is already in the array.

            If(($Groups | Where-Object {$_.DistinguishedName -eq $GroupDistinguishedName}).Count -eq 0)

            {

                #Add group to array.

                $Groups +=  $CurrentGroup;

 

                #Get recursive groups.      

                $Groups = Get-ADUserNestedGroups -DistinguishedName $GroupDistinguishedName -Groups $Groups;

            }

        }

    }

 

    #Return groups.

    Return $Groups;

}

 

#The user to check.

#$User = "o981729";

 

#Get all groups.

$Groups = Get-ADUserNestedGroups -DistinguishedName (Get-ADUser -Filter * ).DistinguishedName;

 

#Output all groups.

$Groups | Select-Object Name | Sort-Object -Property Name; 


Friday, 6 November 2020

Install Software Remotely, Get Software Inventory

 <#

.SYNOPSIS

Install software remotely in a group of computers and retry the installation in case of error.

Thursday, 23 July 2020

Get Multiple NSLOOKUP status in powershell

$servers = get-content C:\Users\sunil\Desktop\allservers.txt
foreach ($Server in $Servers)
{

Wednesday, 22 July 2020

How to know running vcentre us appliance or windows server.

Use below two command in powershell to determine running on Appliance or Window 

$server = Connect-VIServer -Server 192.168.x.x

$Server.ExtensionData.Content.about

It will tell in OS Type, if it is Linux-64, yes it definitely appliance. If not, yes Window 👍

Tuesday, 21 July 2020

Fetch Disk information with size and host informatuon in csv file

The code is:   #Get the server list
$servers = Get-Content D:\server1.txt
#Run the commands for each server in the list
$infoColl = @()

Tuesday, 14 July 2020

Get Vcentre Install State

Get the vmdk size via script..


Add-PSSnapin VMware.VimAutomation.Core

Set-PowerCLIConfiguration -InvalidCertificateAction ignore -Confirm:$False

 

#Connect to the VCenter server

 

Extract Disk Info from Remote host

 # Define the remote hostname or IP address $remoteHost = Get-Content "C:\temp\RemoteServer.txt" # Define the output CSV file path...