Showing posts with label Group-Object. Show all posts
Showing posts with label Group-Object. Show all posts

Tuesday, July 3, 2012

Powershell and Group Policy : "Find all Group Policy Objects in a domain environment using Powershell"

 

Hi,

As you know that yesterday we install "RSAT" tools and enable the "Group Policy" module for powershell. You can refer to this link about enable Group Policy Module.

After Enabling our "Group Policy Module" our first task is to list all Group Policies. Let See which cmdlet we can use.

Lets Start.

Make sure you have RSAT Tool Installed and Enabled the Group Policy in Optional Features (http://newdelhipowershellusergroup.blogspot.in/2012/07/enable-group-policy-powershell-module.html)

Import group Policy Module

Import-Module Grouppolicy

02-07-2012 20-08-30


One our Module is loaded,


we can use Get-Gpo -All


Our today's target is simple , it is to "list  all Group Policy Objects"


run Get-Gpo -All and after that we will get all of our group policies.


03-07-2012 11-31-14


That's all for now , now we know that to list all Group Policy Objects we need to run "Get-Gpo -All" cmdlet.


Thanks!


Aman Dhally


Buy-More-Twitter-Followers   4fb29548b6adc


tom_hit

Tuesday, January 10, 2012

Creating System Footprints using PowerShell

 

 

WMI can retrieve a lot more object instances than you might think. If you submit a parent class, Get-WmiObject returns all instances of all derived classes. That's why a simple line like the following can get you all hardware-related instances:

PS> Get-WmiObject -Class CIM_PhysicalElement | Group-Object -Property __Class

 

Count Name                                                       Group

----- ----                                                       -----

    1 Win32_OnBoardDevice                     {\\DEMO5\root\cimv2:Win32_OnBoardDevice.Tag=...

    1 Win32_PhysicalMemoryArray  {\\DEMO5\root\cimv2:Win32_PhysicalMemoryArra...

    3 Win32_PortConnector                     {\\DEMO5\root\cimv2:Win32_PortConnector.Tag=...

    1 Win32_BaseBoard                                {\\DEMO5\root\cimv2:Win32_BaseBoard.Tag="Bas...

    1 Win32_SystemSlot                             {\\DEMO5\root\cimv2:Win32_SystemSlot.Tag="Sy...

    2 Win32_PhysicalMemory                  {\\DEMO5\root\cimv2:Win32_PhysicalMemory.Tag...

    1 Win32_SystemEnclosure               {\\DEMO5\root\cimv2:Win32_SystemEnclosure.Ta...

    4 Win32_PhysicalMedia                    {\\DEMO5\root\cimv2:Win32_PhysicalMedia.Tag=...

You can turn this into a lookup tool. Here's how:

PS> $col1 = @{Name='Key'; Expression={ ($_.__Class.ToString() -split '_')[-1] }}

PS> $info = Get-WmiObject -Class CIM_PhysicalElement | Select-Object *, $col1 | Group-Object -Property Key -AsHashTable -AsString

Use it like this:

PS> $info

 

Name                                                Value

----                                                -----

SystemEnclosure                 {@{Tag=System Enclosure 0; Status=; Name=Syst...

OnBoardDevice                      {@{Status=; Description=HD-Audio; __GENUS=2; ...

PhysicalMemory                    {@{__GENUS=2; __CLASS=Win32_PhysicalMemory; _...

PhysicalMedia                      {@{__GENUS=2; __CLASS=Win32_PhysicalMedia; __...

SystemSlot                              {@{Status=Unknown; SlotDesignation=PCI Expres...

BaseBoard                                 {@{Status=OK; Name=Base Board; PoweredOn=True...

PortConnector                      {@{Status=; Name=Port Connector; ExternalRefe...

PhysicalMemoryArray      {@{Status=; Name=Physical Memory Array; Repla...

PS> $info.baseboard

(...)

PS> $info.OnboardDevice

(...)

PS> $info.PhysicalMemory

(...)

Monday, January 9, 2012

Finding Standard Parameter Names in PowerShell

 

PowerTip of the Day, from PowerShell.com:

 

In a previous tip, we suggested you to use standard parameter names for your own functions. To get a feeling for what the parameter names are that built-in cmdlets use, here is some code that creates a list of them:

PS> Get-Command -CommandType Cmdlet | Select-Object -ExpandProperty Parameters |  ForEach-Object { $_.Keys } | Group-Object -NoElement | Sort-Object Count, Name -Descending

(...)

   68 Force

   67 Name

   54 InputObject

   54 Credential

   52 Path

   44 PassThru

(...)

Friday, November 25, 2011

“Find how many types of files you have in you laptop” using Powershell.

 

Hi

Today i was searching for one PDF file on my laptop and then I just thinks “How Many PDF files do i have?”, i have no idea, one way to find is go to windows search and find all .PDF files? but “how can i find this with powershell”

we can

let try it ..

Cmdlet Used: Get-ChildItem,Group-Object, Sort-Object

Command: $files =  Get-ChildItem -Path C:\Users\aman.dhally\Documents –Recurse

In $files variable i am saving the result of Get-ChildItem -Path C:\Users\aman.dhally\Documents –Recurse  command , Get-ChildItem in equal as DIR command and we are using –Path switch parameter to give the path of the folder in which we want to search for files, –Recurse means including sub folders.

File

lets run $files variable and see what it has stored

It showing the files and folders located in my “Document” folder

File_2

let filer the results

$files | Group-Object -Property Extension | Sort-Object Count –Descending

now pipe the $files variable to Group-Object cmdlet and the grouping Property is Extensions because we want to group files by there extensions, now piped the command to Sort-Object and we are sorting the results by Count,

OoPs 751 .torrent files,, going to delete them . )

File_3 

Thanks

aman dhally