SlideShare a Scribd company logo
1
LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT
TABLE OF CONTENTS
LAB 2
WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS
CREATING AND MANAGING ACTIVE DIRECTORY OBJECTS
CONFIGURING NETWORK SETTINGS ON WINDOWS SERVER
CREATING A WEB SITE
SELECTING, SORTING, AND DISPLAYING DATA
FILTERING OBJECTS AND ENUMERATING OBJECTS
DESCRIPTION
Because objects play such a central role in Windows PowerShell, there are several
native commands designed to work with arbitrary object types. The most important
one is the Get-Member command.
The simplest technique for analyzing the objects that a command returns is to pipe
the output of that command to the Get-Member cmdlet. The Get-
Member cmdlet shows you the formal name of the object type and a complete
listing of its members. The number of elements that are returned can sometimes
be overwhelming. For example, a process object can have over 100 members.
To see all the members of a Process object and page the output so you can view
all of it, type:
Get-Process | Get-Member | Out-Host -Paging
We can make this long list of information more usable by filtering for elements we
want to see. The Get-Member command lets you list only members that are
properties. There are several forms of properties. The cmdlet displays properties of
any type if we set the Get-Member MemberType parameter to the
value Properties. The resulting list is still very long, but a bit more manageable:
PS> Get-Process | Get-Member -MemberType Properties
Using Select-Object cmdlets
You can also use the Select-object cmdlet to create objects with custom properties
2
LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT
Select-Object @{n='firstname';e={'Alexa'}},@{n='Google';e={'Google'}} -
InputObject ''
OR
'' | Select-Object @{n='firstname';e={'Alexa'}},@{n='lastname';e={'Google'}}
Using New-Object and Add-Member
This is longer way to create PowerShell objects, first you instantiate class: PSObjectthen
you use Add-Member cmdlet to add member properties to the object. You can also add
methods using this method.
$obj = New-Object -TypeName psobject
$obj | Add-Member -MemberType NoteProperty -Name firstname -Value 'Alexa'
$obj | Add-Member -MemberType NoteProperty -Name lastname -Value 'Google'
$obj
# add a method to an object
$obj | Add-Member -MemberType ScriptMethod -Name "GetName" -Value
{$this.firstname +' '+$this.lastname}
Using New-Object and hashtables
PowerShell also allows you to create hashtables and assign it as property to New-Object
PSObject cmdlet.
# Using New-Object and hashtables
$properties = @{
firstname = 'Alexa'
lastname = 'Google'
}
$o = New-Object psobject -Property $properties; $o
New-Object
3
LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT
Creates an instance of a Microsoft .NET Framework or COM object.
New-Object
[-TypeName] <String>
[[-ArgumentList] <Object[]>]
[-Property <IDictionary>]
[<CommonParameters>]
New-Object
[-ComObject] <String>
[-Strict]
[-Property <IDictionary>]
[<CommonParameters>]
Example 1: Create a System.Version object
This example creates a System.Version object using the "1.2.3.4" string as the
constructor.
You can specify either the type of a .NET Framework class or a ProgID of a COM object.
By default, you type the fully qualified name of a .NET Framework class and the cmdlet
returns a reference to an instance of that class. To create an instance of a COM object, use
the ComObject parameter and specify the ProgID of the object as its value.
New-Object -TypeName System.Version -ArgumentList "1.2.3.4"
Major Minor Build Revision
----- ----- ----- --------
1 2 3 4
Example 2: Create an Internet Explorer COM object
This example creates two instances of the COM object that represents the Internet
Explorer application. The first instance uses the Property parameter hash table to
call the Navigate2 method and set the Visible property of the object to $True to
make the application visible. The second instance gets the same results with
individual commands.
$IE1 = New-Object -COMObject InternetExplorer.Application -Property
@{Navigate2="www.microsoft.com"; Visible = $True}
Example 3: Use the Strict parameter to generate a non-terminating error
4
LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT
This example demonstrates that adding the Strict parameter causes the New-
Object cmdlet to generate a non-terminating error when the COM object uses an
interop assembly.
$A = New-Object -COMObject Word.Application -Strict -Property @{Visible =
$True}
Example 4: Create a COM object to manage Windows desktop
This example shows how to create and use a COM object to manage your Windows
desktop.
The first command uses the ComObject parameter of the New-Object cmdlet to
create a COM object with the Shell.Application ProgID. It stores the resulting
object in the $ObjShell variable. The second command pipes the $ObjShell variable
to the Get-Member cmdlet, which displays the properties and methods of the COM
object. Among the methods is the ToggleDesktop method. The third command
calls the ToggleDesktop method of the object to minimize the open windows on
your desktop.
$Objshell = New-Object -COMObject "Shell.Application"
$objshell | Get-Member
$objshell.ToggleDesktop()
Example 5: Pass multiple arguments to a constructor
This example shows how to create an object with a constructor that takes multiple
parameters. The parameters must be put in an array when
using ArgumentList parameter.
$array = @('One', 'Two', 'Three')
$parameters = @{
TypeName = 'System.Collections.Generic.HashSet[string]'
ArgumentList = ([string[]]$array,
[System.StringComparer]::OrdinalIgnoreCase)
}
$set = New-Object @parameters
5
LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT
PowerShell Snap-in: Creating Websites
Introduction
The IIS PowerShell namespace consists of items like Web-Sites, Apps, Virtual
Directories and Application Pools. Creating new namespace items and managing
them is very easy using the built-in PowerShell cmdlets.
Creating Web-Sites
If you are familiar with PowerShell you know that the New-Item cmdlet is used to
create new items in the various PowerShell namespaces. The command New-Item
c:TestDirectory creates a new filesystem directory for example (most people use
the MD or MKDIR alias for New-Item however). New-Item is also used to create new
Web-Sites within the IIS PowerShell namespace.
The goal of this code eventually will be go get all other web pages within a folder
and create hyperlinks to file with the name of the files. This code mostly works but
puts all elements of the array on both links. I need help to separate them links to
1 per file (per element of array until all created)
New-Item web.htm -Type file -force // Create a new web page
Add-Content -Path web.htm -Value '<HTML>' // Put default opening html tag in file
$pages = @('web1.htm', 'web2.htm') //Create an array to contain web hyperlinks to create
foreach($page in $pages)
{
Add-Content -Path web.htm -Value "<a href=$page> $page</a><br />"
}
Add-Content -Path web.htm -Value '</HTML>' //Close the html file tag
Order Your Output by Easily Sorting Objects in PowerShell
Much of the time, there is no guarantee to the order in which Windows
PowerShell returns objects. This tutorial explains how to fix that issue.
Anyway, after the user group meeting, when we were all standing around,
one of the attendees came up to me and asked me in what order Windows
PowerShell returns information. The answer is that there is no guarantee of
6
LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT
return order in most cases. The secret sauce is to use the built-in sorting
mechanism from Windows PowerShell itself. In the image that follows, the
results from the Get-Process cmdlet appear to sort on
the ProcessName property.
One could make a good argument that the processes should sort on the
process ID (PID) or on the amount of CPU time consumed, or on the amount
of memory utilized. In fact, it is entirely possible that for each property
supplied by the Process object, someone has a good argument for sorting
on that particular property. Luckily, custom sorting is easy to accomplish in
Windows PowerShell. To sort returned objects in Windows PowerShell, pipe
the output from one cmdlet to the Sort-Object cmdlet. This technique is
shown here where the Sort-Object cmdlet sorts the Process objects that
are returned by the Get-Process cmdlet.
Get-Process | Sort-Object id
The command to sort the Process objects on the ID property and the
output associated with that command are shown in the image that follows.
Reversing the sort order
By default, the Sort-Object cmdlet performs an ascending sort—the
numbers range from small to large. To perform a descending sort requires
utilizing the Descending switch.
Note: There is no Ascending switch for the Sort-Object cmdlet because
that is the default behavior.
To arrange the output from the Get-Process cmdlet such that
the Process objects appear from largest process ID to the smallest (the
smallest PID is always 0—the Idle process), choose the ID property to sort
on, and use the Descending switch as shown here:
Get-Process | Sort-Object id –Descending
The command to perform a descending sort of processes based on the
process ID.
7
LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT
When you use the Sort-Object cmdlet to sort output, keep in mind that the
first position argument is the property or properties upon which to sort.
Because Property is the default means that using the name Property in the
command is optional. Therefore, the following commands are equivalent:
Get-Process | Sort-Object id –Descending
Get-Process | Sort-Object -property id –Descending
In addition to using the default first position for the Property argument,
the Sort-Object cmdlet is aliased by sort. By using gps as an alias for
the Get-Process cmdlet, sort as an alias for Sort-Object, and a partial
parameter of des for Descending, the syntax of the command is very short.
This short version of the command is shown here.
gps | sort id –des
Sorting multiple properties at once
The Property parameter of the Sort-Object cmdlet accepts an array (more
than one) of properties upon which to sort. This means that I can sort on the
process name, and then sort on the working set of memory that is utilized
by each process (for example). When supplying multiple property names, the
first property sorts, then the second property sorts.
The resulting output may not always meet expectations, and therefore, may
require a bit of experimentation. For example, the command that follows
sorts the process names in a descending order. When that sort completes,
the command does an additional sort on the WorkingSet (ws is the alias)
property. However, this second sort is only useful when there happen to be
multiple processes with the same name (such as the svchost process). The
command that is shown here is an example of sorting on multiple properties.
Get-Process | Sort-Object -Property name, ws –Descending
When the name and ws properties reverse order in the command, the
resulting output is not very useful because the only sorting of
the name property happens when multiple processes have an identical
8
LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT
working set of memory. The command that is shown here reverses the order
of the WorkingSet and the process name properties.
Get-Process | Sort-Object -Property ws, name –Descending
Sorting and returning unique items
At times, I might want to see how many different processes are running on
a system. To do this, I can filter duplicate process names by using
the Unique switch. To count the number of unique processes that are
running on a system, I pipe the results from the Sort-Object cmdlet to
the Measure-Object cmdlet. This command is shown here.
Get-Process | Sort-Object -Property name -Descending -Unique | measure-
object
To obtain a baseline that enables me to determine the number of duplicate
processes, I drop the Unique switch. This command is shown here.
Get-Process | Sort-Object -Property name -Descending | measure-object
Performing a case sensitive sort
One last thing to discuss when sorting items is the CaseSensitive switch.
When used, the CaseSensitive switch sorts lowercase letters first, then
uppercase. The following commands illustrate this.
$a = “Alpha”,”alpha”,”bravo”,”Bravo”,”Charlie”,”charlie”,”delta”,”Delta”
$a | Sort-Object –CaseSensitive
Use the PowerShell Group-Object Cmdlet to Display Data
How to use the Windows PowerShell Group-Object cmdlet to organize
data?
One cmdlet that allows this analysis is the Group-Object cmdlet. In its most
basic form, the Group-Object cmdlet accepts a property from objects in a
9
LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT
pipeline, and it gathers up groups that match that property and displays the
results. For example, to check on the status of services on a system, pipe the
results from the Get-Service cmdlet to the Group-Object cmdlet and use
the Status property. The command is shown here.
Get-Service | Group-Object -Property status
In the Group field of the output from the Group-Object cmdlet, the objects
that are grouped appear. The output indicates that each grouped object is
an instance of a ServiceController object. This output is a bit distracting.
In situations, where the grouping is simple, the Group output might actually
be useful. (Group is an alias for Group-Object).
PS C:Windowssystem32> 1,2,3,2,1,4 | group
If the grouping information does not add any value, omit it by using
the NoElement switched parameter. The revised command to display the
status of services and the associated output are shown in the image that
follows.
PS C:Windowssystem32> Get-Service | group status -NoElement
Here are the steps for using the Group-Object cmdlet to return a hash table
of information:
1. Pipe the objects to the Group-Object cmdlet.
2. Use the AsHashTable switched parameter and the AsString switched
parameter.
3. Store the resulting hash table in a variable.
An example of using these steps is shown in the code that follows.
$hash = Get-Service | group status -AsHashTable –AsString
After it is created, view the hash table by displaying the content that is stored
in the variable. This technique is shown here.
10
LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT
PS C:> $hash
At this point, the output does not appear to be more interesting than a
simple grouping. But, the real power appears when accessing the key
properties (those stored under the Name column). To access the objects
stored in each of the key values, use dotted notation, as shown here.
$hash.running
I can index into the collection by using square brackets and selecting a
specific index number. This technique is shown here.
PS C:> $hash.running[5]
If I am interested in a particular running service, I can pipe the results to
the Where-Object cmdlet (the question mark is an alias for Where-Object).
This technique is shown here.
PS C:> $hash.running | ? {$_.name -match “bfe”}
In addition to being able to group directly by a property, such as running
services, it is also possible to group based on a script block. The script block
becomes sort of a where clause. To find the number of services that are
running, and support a stop command, use the Group-Object cmdlet and a
script block. This command is shown here.
PS C:> Get-Service | group {$_.status -eq “running” -AND $_.canstop}
References:
1. https://serverfault.com/questions/683942/use-powershell-to-create-a-web-page-from-an-array
2. https://devblogs.microsoft.com/scripting/use-the-powershell-group-object-cmdlet-to-display-data/
3. https://docs.microsoft.com/en-us/powershell/module/nettcpip/set-netipaddress?view=win10-ps
4. https://devblogs.microsoft.com/scripting/order-your-output-by-easily-sorting-objects-in-
powershell/

More Related Content

What's hot (20)

Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
Iram Ramrajkar
 
JavaScript
JavaScriptJavaScript
JavaScript
Sunil OS
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play Framework
Knoldus Inc.
 
Nativescript angular
Nativescript angularNativescript angular
Nativescript angular
Christoffer Noring
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
Christoffer Noring
 
Angular 2 Component Communication - Talk by Rob McDiarmid
Angular 2 Component Communication - Talk by Rob McDiarmidAngular 2 Component Communication - Talk by Rob McDiarmid
Angular 2 Component Communication - Talk by Rob McDiarmid
Amrita Chopra
 
Group111
Group111Group111
Group111
Shahriar Robbani
 
Power Shell and Sharepoint 2013
Power Shell and Sharepoint 2013Power Shell and Sharepoint 2013
Power Shell and Sharepoint 2013
Mohan Arumugam
 
PowerShell Fundamentals
PowerShell FundamentalsPowerShell Fundamentals
PowerShell Fundamentals
mozdzen
 
Compress and decompress
Compress and decompressCompress and decompress
Compress and decompress
Son Nguyen
 
Graphql, REST and Apollo
Graphql, REST and ApolloGraphql, REST and Apollo
Graphql, REST and Apollo
Christoffer Noring
 
Caching & validating
Caching & validatingCaching & validating
Caching & validating
Son Nguyen
 
Тарас Олексин - Sculpt! Your! Tests!
Тарас Олексин  - Sculpt! Your! Tests!Тарас Олексин  - Sculpt! Your! Tests!
Тарас Олексин - Sculpt! Your! Tests!
DataArt
 
QB Into the Box 2018
QB Into the Box 2018QB Into the Box 2018
QB Into the Box 2018
Ortus Solutions, Corp
 
Core Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug HuntCore Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug Hunt
CodeOps Technologies LLP
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
Siarhei Barysiuk
 
Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0
Oscar Renalias
 
Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010
Binh Nguyen
 
performancetestingjmeter-121109061704-phpapp02 (1)
performancetestingjmeter-121109061704-phpapp02 (1)performancetestingjmeter-121109061704-phpapp02 (1)
performancetestingjmeter-121109061704-phpapp02 (1)
QA Programmer
 
Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)
BoneyGawande
 
JavaScript
JavaScriptJavaScript
JavaScript
Sunil OS
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play Framework
Knoldus Inc.
 
Angular 2 Component Communication - Talk by Rob McDiarmid
Angular 2 Component Communication - Talk by Rob McDiarmidAngular 2 Component Communication - Talk by Rob McDiarmid
Angular 2 Component Communication - Talk by Rob McDiarmid
Amrita Chopra
 
Power Shell and Sharepoint 2013
Power Shell and Sharepoint 2013Power Shell and Sharepoint 2013
Power Shell and Sharepoint 2013
Mohan Arumugam
 
PowerShell Fundamentals
PowerShell FundamentalsPowerShell Fundamentals
PowerShell Fundamentals
mozdzen
 
Compress and decompress
Compress and decompressCompress and decompress
Compress and decompress
Son Nguyen
 
Caching & validating
Caching & validatingCaching & validating
Caching & validating
Son Nguyen
 
Тарас Олексин - Sculpt! Your! Tests!
Тарас Олексин  - Sculpt! Your! Tests!Тарас Олексин  - Sculpt! Your! Tests!
Тарас Олексин - Sculpt! Your! Tests!
DataArt
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
Siarhei Barysiuk
 
Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0
Oscar Renalias
 
Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010Introduction to windows power shell in sharepoint 2010
Introduction to windows power shell in sharepoint 2010
Binh Nguyen
 
performancetestingjmeter-121109061704-phpapp02 (1)
performancetestingjmeter-121109061704-phpapp02 (1)performancetestingjmeter-121109061704-phpapp02 (1)
performancetestingjmeter-121109061704-phpapp02 (1)
QA Programmer
 
Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)
BoneyGawande
 

Similar to WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE (20)

PowerShell-1
PowerShell-1PowerShell-1
PowerShell-1
Saravanan G
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
Thomas Lee
 
Everything you need to know about PowerShell
Everything you need to know about PowerShellEverything you need to know about PowerShell
Everything you need to know about PowerShell
Shane Hoey
 
05 objects for the admin
05 objects for the admin05 objects for the admin
05 objects for the admin
Shubham Atkare
 
An a z index of windows power shell commandss
An a z index of windows power shell commandssAn a z index of windows power shell commandss
An a z index of windows power shell commandss
Ben Pope
 
Power Shell for System Admins - By Kaustubh
Power Shell for System Admins - By KaustubhPower Shell for System Admins - By Kaustubh
Power Shell for System Admins - By Kaustubh
Kaustubh Kumar
 
PowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdfPowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdf
outcast96
 
2016 spice world_london_breakout
2016 spice world_london_breakout2016 spice world_london_breakout
2016 spice world_london_breakout
Thomas Lee
 
The Power of PowerShell: Advanced
The Power of PowerShell: Advanced The Power of PowerShell: Advanced
The Power of PowerShell: Advanced
Microsoft TechNet - Belgium and Luxembourg
 
SVCC 5 introduction to powershell
SVCC 5 introduction to powershellSVCC 5 introduction to powershell
SVCC 5 introduction to powershell
qawarrior
 
No-script PowerShell v2
No-script PowerShell v2No-script PowerShell v2
No-script PowerShell v2
Concentrated Technology
 
Powershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubPowershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge Club
Essam Salah
 
Manage your infrastructure with PowerShell
Manage your infrastructure with PowerShellManage your infrastructure with PowerShell
Manage your infrastructure with PowerShell
Jaap Brasser
 
PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)
Concentrated Technology
 
Powershell For Developers
Powershell For DevelopersPowershell For Developers
Powershell For Developers
Ido Flatow
 
Introduction to powershell
Introduction to powershellIntroduction to powershell
Introduction to powershell
Salaudeen Rajack
 
Sql Server & PowerShell
Sql Server & PowerShellSql Server & PowerShell
Sql Server & PowerShell
Aaron Shilo
 
Powershell for Log Analysis and Data Crunching
 Powershell for Log Analysis and Data Crunching Powershell for Log Analysis and Data Crunching
Powershell for Log Analysis and Data Crunching
Michelle D'israeli
 
Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)
Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)
Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)
Michael Blumenthal (Microsoft MVP)
 
2015 spice world_london_breakout
2015 spice world_london_breakout2015 spice world_london_breakout
2015 spice world_london_breakout
Thomas Lee
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
Thomas Lee
 
Everything you need to know about PowerShell
Everything you need to know about PowerShellEverything you need to know about PowerShell
Everything you need to know about PowerShell
Shane Hoey
 
05 objects for the admin
05 objects for the admin05 objects for the admin
05 objects for the admin
Shubham Atkare
 
An a z index of windows power shell commandss
An a z index of windows power shell commandssAn a z index of windows power shell commandss
An a z index of windows power shell commandss
Ben Pope
 
Power Shell for System Admins - By Kaustubh
Power Shell for System Admins - By KaustubhPower Shell for System Admins - By Kaustubh
Power Shell for System Admins - By Kaustubh
Kaustubh Kumar
 
PowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdfPowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdf
outcast96
 
2016 spice world_london_breakout
2016 spice world_london_breakout2016 spice world_london_breakout
2016 spice world_london_breakout
Thomas Lee
 
SVCC 5 introduction to powershell
SVCC 5 introduction to powershellSVCC 5 introduction to powershell
SVCC 5 introduction to powershell
qawarrior
 
Powershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubPowershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge Club
Essam Salah
 
Manage your infrastructure with PowerShell
Manage your infrastructure with PowerShellManage your infrastructure with PowerShell
Manage your infrastructure with PowerShell
Jaap Brasser
 
PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)
Concentrated Technology
 
Powershell For Developers
Powershell For DevelopersPowershell For Developers
Powershell For Developers
Ido Flatow
 
Introduction to powershell
Introduction to powershellIntroduction to powershell
Introduction to powershell
Salaudeen Rajack
 
Sql Server & PowerShell
Sql Server & PowerShellSql Server & PowerShell
Sql Server & PowerShell
Aaron Shilo
 
Powershell for Log Analysis and Data Crunching
 Powershell for Log Analysis and Data Crunching Powershell for Log Analysis and Data Crunching
Powershell for Log Analysis and Data Crunching
Michelle D'israeli
 
Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)
Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)
Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)
Michael Blumenthal (Microsoft MVP)
 
2015 spice world_london_breakout
2015 spice world_london_breakout2015 spice world_london_breakout
2015 spice world_london_breakout
Thomas Lee
 
Ad

More from Hitesh Mohapatra (20)

Introduction to Edge and Fog Computing.pdf
Introduction to Edge and Fog Computing.pdfIntroduction to Edge and Fog Computing.pdf
Introduction to Edge and Fog Computing.pdf
Hitesh Mohapatra
 
Amazon Web Services (AWS) : Fundamentals
Amazon Web Services (AWS) : FundamentalsAmazon Web Services (AWS) : Fundamentals
Amazon Web Services (AWS) : Fundamentals
Hitesh Mohapatra
 
Resource Cluster and Multi-Device Broker.pdf
Resource Cluster and Multi-Device Broker.pdfResource Cluster and Multi-Device Broker.pdf
Resource Cluster and Multi-Device Broker.pdf
Hitesh Mohapatra
 
Failover System in Cloud Computing System
Failover System in Cloud Computing SystemFailover System in Cloud Computing System
Failover System in Cloud Computing System
Hitesh Mohapatra
 
Resource Replication & Automated Scaling Listener
Resource Replication & Automated Scaling ListenerResource Replication & Automated Scaling Listener
Resource Replication & Automated Scaling Listener
Hitesh Mohapatra
 
Storage Device & Usage Monitor in Cloud Computing.pdf
Storage Device & Usage Monitor in Cloud Computing.pdfStorage Device & Usage Monitor in Cloud Computing.pdf
Storage Device & Usage Monitor in Cloud Computing.pdf
Hitesh Mohapatra
 
Networking in Cloud Computing Environment
Networking in Cloud Computing EnvironmentNetworking in Cloud Computing Environment
Networking in Cloud Computing Environment
Hitesh Mohapatra
 
Uniform-Cost Search Algorithm in the AI Environment
Uniform-Cost Search Algorithm in the AI EnvironmentUniform-Cost Search Algorithm in the AI Environment
Uniform-Cost Search Algorithm in the AI Environment
Hitesh Mohapatra
 
Logical Network Perimeter in Cloud Computing
Logical Network Perimeter in Cloud ComputingLogical Network Perimeter in Cloud Computing
Logical Network Perimeter in Cloud Computing
Hitesh Mohapatra
 
Software Product Quality - Part 1 Presentation
Software Product Quality - Part 1 PresentationSoftware Product Quality - Part 1 Presentation
Software Product Quality - Part 1 Presentation
Hitesh Mohapatra
 
Multitenancy in cloud computing architecture
Multitenancy in cloud computing architectureMultitenancy in cloud computing architecture
Multitenancy in cloud computing architecture
Hitesh Mohapatra
 
Server Consolidation in Cloud Computing Environment
Server Consolidation in Cloud Computing EnvironmentServer Consolidation in Cloud Computing Environment
Server Consolidation in Cloud Computing Environment
Hitesh Mohapatra
 
Web Services / Technology in Cloud Computing
Web Services / Technology in Cloud ComputingWeb Services / Technology in Cloud Computing
Web Services / Technology in Cloud Computing
Hitesh Mohapatra
 
Resource replication in cloud computing.
Resource replication in cloud computing.Resource replication in cloud computing.
Resource replication in cloud computing.
Hitesh Mohapatra
 
Software Measurement and Metrics (Quantified Attribute)
Software Measurement and Metrics (Quantified Attribute)Software Measurement and Metrics (Quantified Attribute)
Software Measurement and Metrics (Quantified Attribute)
Hitesh Mohapatra
 
Software project management is an art and discipline of planning and supervis...
Software project management is an art and discipline of planning and supervis...Software project management is an art and discipline of planning and supervis...
Software project management is an art and discipline of planning and supervis...
Hitesh Mohapatra
 
Software project management is an art and discipline of planning and supervis...
Software project management is an art and discipline of planning and supervis...Software project management is an art and discipline of planning and supervis...
Software project management is an art and discipline of planning and supervis...
Hitesh Mohapatra
 
The life cycle of a virtual machine (VM) provisioning process
The life cycle of a virtual machine (VM) provisioning processThe life cycle of a virtual machine (VM) provisioning process
The life cycle of a virtual machine (VM) provisioning process
Hitesh Mohapatra
 
BUSINESS CONSIDERATIONS FOR CLOUD COMPUTING
BUSINESS CONSIDERATIONS FOR CLOUD COMPUTINGBUSINESS CONSIDERATIONS FOR CLOUD COMPUTING
BUSINESS CONSIDERATIONS FOR CLOUD COMPUTING
Hitesh Mohapatra
 
Traditional Data Center vs. Virtualization – Differences and Benefits
Traditional Data Center vs. Virtualization – Differences and BenefitsTraditional Data Center vs. Virtualization – Differences and Benefits
Traditional Data Center vs. Virtualization – Differences and Benefits
Hitesh Mohapatra
 
Introduction to Edge and Fog Computing.pdf
Introduction to Edge and Fog Computing.pdfIntroduction to Edge and Fog Computing.pdf
Introduction to Edge and Fog Computing.pdf
Hitesh Mohapatra
 
Amazon Web Services (AWS) : Fundamentals
Amazon Web Services (AWS) : FundamentalsAmazon Web Services (AWS) : Fundamentals
Amazon Web Services (AWS) : Fundamentals
Hitesh Mohapatra
 
Resource Cluster and Multi-Device Broker.pdf
Resource Cluster and Multi-Device Broker.pdfResource Cluster and Multi-Device Broker.pdf
Resource Cluster and Multi-Device Broker.pdf
Hitesh Mohapatra
 
Failover System in Cloud Computing System
Failover System in Cloud Computing SystemFailover System in Cloud Computing System
Failover System in Cloud Computing System
Hitesh Mohapatra
 
Resource Replication & Automated Scaling Listener
Resource Replication & Automated Scaling ListenerResource Replication & Automated Scaling Listener
Resource Replication & Automated Scaling Listener
Hitesh Mohapatra
 
Storage Device & Usage Monitor in Cloud Computing.pdf
Storage Device & Usage Monitor in Cloud Computing.pdfStorage Device & Usage Monitor in Cloud Computing.pdf
Storage Device & Usage Monitor in Cloud Computing.pdf
Hitesh Mohapatra
 
Networking in Cloud Computing Environment
Networking in Cloud Computing EnvironmentNetworking in Cloud Computing Environment
Networking in Cloud Computing Environment
Hitesh Mohapatra
 
Uniform-Cost Search Algorithm in the AI Environment
Uniform-Cost Search Algorithm in the AI EnvironmentUniform-Cost Search Algorithm in the AI Environment
Uniform-Cost Search Algorithm in the AI Environment
Hitesh Mohapatra
 
Logical Network Perimeter in Cloud Computing
Logical Network Perimeter in Cloud ComputingLogical Network Perimeter in Cloud Computing
Logical Network Perimeter in Cloud Computing
Hitesh Mohapatra
 
Software Product Quality - Part 1 Presentation
Software Product Quality - Part 1 PresentationSoftware Product Quality - Part 1 Presentation
Software Product Quality - Part 1 Presentation
Hitesh Mohapatra
 
Multitenancy in cloud computing architecture
Multitenancy in cloud computing architectureMultitenancy in cloud computing architecture
Multitenancy in cloud computing architecture
Hitesh Mohapatra
 
Server Consolidation in Cloud Computing Environment
Server Consolidation in Cloud Computing EnvironmentServer Consolidation in Cloud Computing Environment
Server Consolidation in Cloud Computing Environment
Hitesh Mohapatra
 
Web Services / Technology in Cloud Computing
Web Services / Technology in Cloud ComputingWeb Services / Technology in Cloud Computing
Web Services / Technology in Cloud Computing
Hitesh Mohapatra
 
Resource replication in cloud computing.
Resource replication in cloud computing.Resource replication in cloud computing.
Resource replication in cloud computing.
Hitesh Mohapatra
 
Software Measurement and Metrics (Quantified Attribute)
Software Measurement and Metrics (Quantified Attribute)Software Measurement and Metrics (Quantified Attribute)
Software Measurement and Metrics (Quantified Attribute)
Hitesh Mohapatra
 
Software project management is an art and discipline of planning and supervis...
Software project management is an art and discipline of planning and supervis...Software project management is an art and discipline of planning and supervis...
Software project management is an art and discipline of planning and supervis...
Hitesh Mohapatra
 
Software project management is an art and discipline of planning and supervis...
Software project management is an art and discipline of planning and supervis...Software project management is an art and discipline of planning and supervis...
Software project management is an art and discipline of planning and supervis...
Hitesh Mohapatra
 
The life cycle of a virtual machine (VM) provisioning process
The life cycle of a virtual machine (VM) provisioning processThe life cycle of a virtual machine (VM) provisioning process
The life cycle of a virtual machine (VM) provisioning process
Hitesh Mohapatra
 
BUSINESS CONSIDERATIONS FOR CLOUD COMPUTING
BUSINESS CONSIDERATIONS FOR CLOUD COMPUTINGBUSINESS CONSIDERATIONS FOR CLOUD COMPUTING
BUSINESS CONSIDERATIONS FOR CLOUD COMPUTING
Hitesh Mohapatra
 
Traditional Data Center vs. Virtualization – Differences and Benefits
Traditional Data Center vs. Virtualization – Differences and BenefitsTraditional Data Center vs. Virtualization – Differences and Benefits
Traditional Data Center vs. Virtualization – Differences and Benefits
Hitesh Mohapatra
 
Ad

Recently uploaded (20)

All about the Snail Power Catalog Product 2025
All about the Snail Power Catalog  Product 2025All about the Snail Power Catalog  Product 2025
All about the Snail Power Catalog Product 2025
kstgroupvn
 
[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)
[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)
[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)
하이플럭스 / HIFLUX Co., Ltd.
 
Highway Engineering - Pavement materials
Highway Engineering - Pavement materialsHighway Engineering - Pavement materials
Highway Engineering - Pavement materials
AmrutaBhosale9
 
Webinar On Steel Melting IIF of steel for rdso
Webinar  On Steel  Melting IIF of steel for rdsoWebinar  On Steel  Melting IIF of steel for rdso
Webinar On Steel Melting IIF of steel for rdso
KapilParyani3
 
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdfKevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Medicoz Clinic
 
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her IndustryTesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia
 
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.pptfy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
sukarnoamin
 
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDINGMODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
ManiMaran230751
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos10
 
Air Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdfAir Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
RishabhGupta578788
 
Structural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptxStructural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptx
gunjalsachin
 
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
IRJET Journal
 
ISO 5011 Air Filter Catalogues .pdf
ISO 5011 Air Filter Catalogues      .pdfISO 5011 Air Filter Catalogues      .pdf
ISO 5011 Air Filter Catalogues .pdf
FILTRATION ENGINEERING & CUNSULTANT
 
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Mohamed905031
 
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
ManiMaran230751
 
ISO 4548-7 Filter Vibration Fatigue Test Rig Catalogue.pdf
ISO 4548-7 Filter Vibration Fatigue Test Rig Catalogue.pdfISO 4548-7 Filter Vibration Fatigue Test Rig Catalogue.pdf
ISO 4548-7 Filter Vibration Fatigue Test Rig Catalogue.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
sebastianku31
 
All about the Snail Power Catalog Product 2025
All about the Snail Power Catalog  Product 2025All about the Snail Power Catalog  Product 2025
All about the Snail Power Catalog Product 2025
kstgroupvn
 
Highway Engineering - Pavement materials
Highway Engineering - Pavement materialsHighway Engineering - Pavement materials
Highway Engineering - Pavement materials
AmrutaBhosale9
 
Webinar On Steel Melting IIF of steel for rdso
Webinar  On Steel  Melting IIF of steel for rdsoWebinar  On Steel  Melting IIF of steel for rdso
Webinar On Steel Melting IIF of steel for rdso
KapilParyani3
 
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdfKevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Medicoz Clinic
 
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her IndustryTesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia - A Leader In Her Industry
Tesia Dobrydnia
 
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.pptfy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
sukarnoamin
 
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDINGMODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
ManiMaran230751
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos10
 
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
RishabhGupta578788
 
Structural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptxStructural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptx
gunjalsachin
 
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
IRJET Journal
 
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Mohamed905031
 
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
ManiMaran230751
 
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
sebastianku31
 

WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS : PowerShell ISE

  • 1. 1 LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT TABLE OF CONTENTS LAB 2 WINDOWS ADMINISTRATION AND WORKING WITH OBJECTS CREATING AND MANAGING ACTIVE DIRECTORY OBJECTS CONFIGURING NETWORK SETTINGS ON WINDOWS SERVER CREATING A WEB SITE SELECTING, SORTING, AND DISPLAYING DATA FILTERING OBJECTS AND ENUMERATING OBJECTS DESCRIPTION Because objects play such a central role in Windows PowerShell, there are several native commands designed to work with arbitrary object types. The most important one is the Get-Member command. The simplest technique for analyzing the objects that a command returns is to pipe the output of that command to the Get-Member cmdlet. The Get- Member cmdlet shows you the formal name of the object type and a complete listing of its members. The number of elements that are returned can sometimes be overwhelming. For example, a process object can have over 100 members. To see all the members of a Process object and page the output so you can view all of it, type: Get-Process | Get-Member | Out-Host -Paging We can make this long list of information more usable by filtering for elements we want to see. The Get-Member command lets you list only members that are properties. There are several forms of properties. The cmdlet displays properties of any type if we set the Get-Member MemberType parameter to the value Properties. The resulting list is still very long, but a bit more manageable: PS> Get-Process | Get-Member -MemberType Properties Using Select-Object cmdlets You can also use the Select-object cmdlet to create objects with custom properties
  • 2. 2 LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT Select-Object @{n='firstname';e={'Alexa'}},@{n='Google';e={'Google'}} - InputObject '' OR '' | Select-Object @{n='firstname';e={'Alexa'}},@{n='lastname';e={'Google'}} Using New-Object and Add-Member This is longer way to create PowerShell objects, first you instantiate class: PSObjectthen you use Add-Member cmdlet to add member properties to the object. You can also add methods using this method. $obj = New-Object -TypeName psobject $obj | Add-Member -MemberType NoteProperty -Name firstname -Value 'Alexa' $obj | Add-Member -MemberType NoteProperty -Name lastname -Value 'Google' $obj # add a method to an object $obj | Add-Member -MemberType ScriptMethod -Name "GetName" -Value {$this.firstname +' '+$this.lastname} Using New-Object and hashtables PowerShell also allows you to create hashtables and assign it as property to New-Object PSObject cmdlet. # Using New-Object and hashtables $properties = @{ firstname = 'Alexa' lastname = 'Google' } $o = New-Object psobject -Property $properties; $o New-Object
  • 3. 3 LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT Creates an instance of a Microsoft .NET Framework or COM object. New-Object [-TypeName] <String> [[-ArgumentList] <Object[]>] [-Property <IDictionary>] [<CommonParameters>] New-Object [-ComObject] <String> [-Strict] [-Property <IDictionary>] [<CommonParameters>] Example 1: Create a System.Version object This example creates a System.Version object using the "1.2.3.4" string as the constructor. You can specify either the type of a .NET Framework class or a ProgID of a COM object. By default, you type the fully qualified name of a .NET Framework class and the cmdlet returns a reference to an instance of that class. To create an instance of a COM object, use the ComObject parameter and specify the ProgID of the object as its value. New-Object -TypeName System.Version -ArgumentList "1.2.3.4" Major Minor Build Revision ----- ----- ----- -------- 1 2 3 4 Example 2: Create an Internet Explorer COM object This example creates two instances of the COM object that represents the Internet Explorer application. The first instance uses the Property parameter hash table to call the Navigate2 method and set the Visible property of the object to $True to make the application visible. The second instance gets the same results with individual commands. $IE1 = New-Object -COMObject InternetExplorer.Application -Property @{Navigate2="www.microsoft.com"; Visible = $True} Example 3: Use the Strict parameter to generate a non-terminating error
  • 4. 4 LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT This example demonstrates that adding the Strict parameter causes the New- Object cmdlet to generate a non-terminating error when the COM object uses an interop assembly. $A = New-Object -COMObject Word.Application -Strict -Property @{Visible = $True} Example 4: Create a COM object to manage Windows desktop This example shows how to create and use a COM object to manage your Windows desktop. The first command uses the ComObject parameter of the New-Object cmdlet to create a COM object with the Shell.Application ProgID. It stores the resulting object in the $ObjShell variable. The second command pipes the $ObjShell variable to the Get-Member cmdlet, which displays the properties and methods of the COM object. Among the methods is the ToggleDesktop method. The third command calls the ToggleDesktop method of the object to minimize the open windows on your desktop. $Objshell = New-Object -COMObject "Shell.Application" $objshell | Get-Member $objshell.ToggleDesktop() Example 5: Pass multiple arguments to a constructor This example shows how to create an object with a constructor that takes multiple parameters. The parameters must be put in an array when using ArgumentList parameter. $array = @('One', 'Two', 'Three') $parameters = @{ TypeName = 'System.Collections.Generic.HashSet[string]' ArgumentList = ([string[]]$array, [System.StringComparer]::OrdinalIgnoreCase) } $set = New-Object @parameters
  • 5. 5 LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT PowerShell Snap-in: Creating Websites Introduction The IIS PowerShell namespace consists of items like Web-Sites, Apps, Virtual Directories and Application Pools. Creating new namespace items and managing them is very easy using the built-in PowerShell cmdlets. Creating Web-Sites If you are familiar with PowerShell you know that the New-Item cmdlet is used to create new items in the various PowerShell namespaces. The command New-Item c:TestDirectory creates a new filesystem directory for example (most people use the MD or MKDIR alias for New-Item however). New-Item is also used to create new Web-Sites within the IIS PowerShell namespace. The goal of this code eventually will be go get all other web pages within a folder and create hyperlinks to file with the name of the files. This code mostly works but puts all elements of the array on both links. I need help to separate them links to 1 per file (per element of array until all created) New-Item web.htm -Type file -force // Create a new web page Add-Content -Path web.htm -Value '<HTML>' // Put default opening html tag in file $pages = @('web1.htm', 'web2.htm') //Create an array to contain web hyperlinks to create foreach($page in $pages) { Add-Content -Path web.htm -Value "<a href=$page> $page</a><br />" } Add-Content -Path web.htm -Value '</HTML>' //Close the html file tag Order Your Output by Easily Sorting Objects in PowerShell Much of the time, there is no guarantee to the order in which Windows PowerShell returns objects. This tutorial explains how to fix that issue. Anyway, after the user group meeting, when we were all standing around, one of the attendees came up to me and asked me in what order Windows PowerShell returns information. The answer is that there is no guarantee of
  • 6. 6 LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT return order in most cases. The secret sauce is to use the built-in sorting mechanism from Windows PowerShell itself. In the image that follows, the results from the Get-Process cmdlet appear to sort on the ProcessName property. One could make a good argument that the processes should sort on the process ID (PID) or on the amount of CPU time consumed, or on the amount of memory utilized. In fact, it is entirely possible that for each property supplied by the Process object, someone has a good argument for sorting on that particular property. Luckily, custom sorting is easy to accomplish in Windows PowerShell. To sort returned objects in Windows PowerShell, pipe the output from one cmdlet to the Sort-Object cmdlet. This technique is shown here where the Sort-Object cmdlet sorts the Process objects that are returned by the Get-Process cmdlet. Get-Process | Sort-Object id The command to sort the Process objects on the ID property and the output associated with that command are shown in the image that follows. Reversing the sort order By default, the Sort-Object cmdlet performs an ascending sort—the numbers range from small to large. To perform a descending sort requires utilizing the Descending switch. Note: There is no Ascending switch for the Sort-Object cmdlet because that is the default behavior. To arrange the output from the Get-Process cmdlet such that the Process objects appear from largest process ID to the smallest (the smallest PID is always 0—the Idle process), choose the ID property to sort on, and use the Descending switch as shown here: Get-Process | Sort-Object id –Descending The command to perform a descending sort of processes based on the process ID.
  • 7. 7 LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT When you use the Sort-Object cmdlet to sort output, keep in mind that the first position argument is the property or properties upon which to sort. Because Property is the default means that using the name Property in the command is optional. Therefore, the following commands are equivalent: Get-Process | Sort-Object id –Descending Get-Process | Sort-Object -property id –Descending In addition to using the default first position for the Property argument, the Sort-Object cmdlet is aliased by sort. By using gps as an alias for the Get-Process cmdlet, sort as an alias for Sort-Object, and a partial parameter of des for Descending, the syntax of the command is very short. This short version of the command is shown here. gps | sort id –des Sorting multiple properties at once The Property parameter of the Sort-Object cmdlet accepts an array (more than one) of properties upon which to sort. This means that I can sort on the process name, and then sort on the working set of memory that is utilized by each process (for example). When supplying multiple property names, the first property sorts, then the second property sorts. The resulting output may not always meet expectations, and therefore, may require a bit of experimentation. For example, the command that follows sorts the process names in a descending order. When that sort completes, the command does an additional sort on the WorkingSet (ws is the alias) property. However, this second sort is only useful when there happen to be multiple processes with the same name (such as the svchost process). The command that is shown here is an example of sorting on multiple properties. Get-Process | Sort-Object -Property name, ws –Descending When the name and ws properties reverse order in the command, the resulting output is not very useful because the only sorting of the name property happens when multiple processes have an identical
  • 8. 8 LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT working set of memory. The command that is shown here reverses the order of the WorkingSet and the process name properties. Get-Process | Sort-Object -Property ws, name –Descending Sorting and returning unique items At times, I might want to see how many different processes are running on a system. To do this, I can filter duplicate process names by using the Unique switch. To count the number of unique processes that are running on a system, I pipe the results from the Sort-Object cmdlet to the Measure-Object cmdlet. This command is shown here. Get-Process | Sort-Object -Property name -Descending -Unique | measure- object To obtain a baseline that enables me to determine the number of duplicate processes, I drop the Unique switch. This command is shown here. Get-Process | Sort-Object -Property name -Descending | measure-object Performing a case sensitive sort One last thing to discuss when sorting items is the CaseSensitive switch. When used, the CaseSensitive switch sorts lowercase letters first, then uppercase. The following commands illustrate this. $a = “Alpha”,”alpha”,”bravo”,”Bravo”,”Charlie”,”charlie”,”delta”,”Delta” $a | Sort-Object –CaseSensitive Use the PowerShell Group-Object Cmdlet to Display Data How to use the Windows PowerShell Group-Object cmdlet to organize data? One cmdlet that allows this analysis is the Group-Object cmdlet. In its most basic form, the Group-Object cmdlet accepts a property from objects in a
  • 9. 9 LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT pipeline, and it gathers up groups that match that property and displays the results. For example, to check on the status of services on a system, pipe the results from the Get-Service cmdlet to the Group-Object cmdlet and use the Status property. The command is shown here. Get-Service | Group-Object -Property status In the Group field of the output from the Group-Object cmdlet, the objects that are grouped appear. The output indicates that each grouped object is an instance of a ServiceController object. This output is a bit distracting. In situations, where the grouping is simple, the Group output might actually be useful. (Group is an alias for Group-Object). PS C:Windowssystem32> 1,2,3,2,1,4 | group If the grouping information does not add any value, omit it by using the NoElement switched parameter. The revised command to display the status of services and the associated output are shown in the image that follows. PS C:Windowssystem32> Get-Service | group status -NoElement Here are the steps for using the Group-Object cmdlet to return a hash table of information: 1. Pipe the objects to the Group-Object cmdlet. 2. Use the AsHashTable switched parameter and the AsString switched parameter. 3. Store the resulting hash table in a variable. An example of using these steps is shown in the code that follows. $hash = Get-Service | group status -AsHashTable –AsString After it is created, view the hash table by displaying the content that is stored in the variable. This technique is shown here.
  • 10. 10 LAB 2 // Hitesh Mohapatra // ACM // MCA // SCT PS C:> $hash At this point, the output does not appear to be more interesting than a simple grouping. But, the real power appears when accessing the key properties (those stored under the Name column). To access the objects stored in each of the key values, use dotted notation, as shown here. $hash.running I can index into the collection by using square brackets and selecting a specific index number. This technique is shown here. PS C:> $hash.running[5] If I am interested in a particular running service, I can pipe the results to the Where-Object cmdlet (the question mark is an alias for Where-Object). This technique is shown here. PS C:> $hash.running | ? {$_.name -match “bfe”} In addition to being able to group directly by a property, such as running services, it is also possible to group based on a script block. The script block becomes sort of a where clause. To find the number of services that are running, and support a stop command, use the Group-Object cmdlet and a script block. This command is shown here. PS C:> Get-Service | group {$_.status -eq “running” -AND $_.canstop} References: 1. https://serverfault.com/questions/683942/use-powershell-to-create-a-web-page-from-an-array 2. https://devblogs.microsoft.com/scripting/use-the-powershell-group-object-cmdlet-to-display-data/ 3. https://docs.microsoft.com/en-us/powershell/module/nettcpip/set-netipaddress?view=win10-ps 4. https://devblogs.microsoft.com/scripting/order-your-output-by-easily-sorting-objects-in- powershell/