Sie sind auf Seite 1von 16

Questions and Answers

Automation and Configuration Management


Questions for 2 marks:
Qs Sub Final
1. Explain what is the function of $input variable?

The $input variable enables a function to access data coming from the pipeline.

2. What is the code to find the name of the installed application on the current computer?

Get-WmiObject-Class Win32_Product- ComputerName . l Format-wide-column1

3. Explain how you can rename a variable?

To rename a variable,
Rename-Item- Path Env: MyVariable –NewName MyRenamedVar

4. Mention what is the command that can be used to get all child folders in a specific folder?

To get all child folders in a specific folder, you have to use parameter recurse in the code.
Get-ChildItem C:\Scripts –recurse

5. Explain what is the use of Array in PowerShell?

The use of Array in PowerShell is to run a script against remote computers. In order to create
an array, you have to create a variable and assign the array. Arrays are represented by
“@”symbol, they are represented as hashtable but not followed by curly braces.

For example, $arrmachine = @ ( “machine1” , “machine2” , “machine3”)

6. Mention what is the command that can be used to get all child folders in a specific folder?

To get all child folders in a specific folder, you have to use parameter recurse in the code.
Get-ChildItem C:\Scripts –recurse

7. What is the use of hash table in PowerShell?

A hash table is also referred as dictionary. It is an array that allows you to store data in a “key-
value” pair association. The “key” and “value” can be of any data and length. To declare a hash
table you have to use @ followed by curly braces.

8. Explain what PowerShell Scripting is?

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA


PowerShell file contains a series of PowerShell commands with each command appearing on a
separate line. To use a text file as a PowerShell script, its filename should have.PS1 extension.
To run a script you need

Type the commands in a text editor


Save the file with .ps1 extension
Execute the file in PowerShell

9. What is the function of Get-Service Status in PowerShell?

The cmdlets of windows enable you to filter the window services. PowerShell can list which
services are ‘Running’ and which are ‘Stopped’ by scripting with windows.

10. What are the uses of PowerShell Array?

PowerShell Array is used to run scripts on remote computers. To create PowerShell Array, users
will need to create variable, as well as they will have to assign the PowerShell Array. PowerShell
Arrays are expressed with a “@” symbol, and illustrated as hash table.
For instance, it would be like -
$arrmachine = @ (“machine1”, “machine2”, “machine3”)

11. Explain the hash table functions in PowerShell?

PowerShell’s hash table can be referred as a dictionary. Basically, it is a series that


enables users in storing data with a pair association known as “key-value”. Here, both
“keys”, as well as “value”, might comprise of any length and data. In order to declare
hash table users will have to apply @ in front of curly braces.

12. Define the key features of PowerShell?

The prime characteristics of Microsoft PowerShell can be summed up as follows -


• PowerShell is a scripting environment
• PowerShell commands are customizable
• The programming language isn’t text-based. It’s object-based.

13. Define Microsoft PowerShell?

Microsoft PowerShell is a command-line shell and scripting language built on .NET. It


helps system admins and power-users to quickly manage OS. (Windows, MacOS and
Linux) and processes.

14. What is a PowerShell loop? Explain its types.

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA


When repetitive tasks are automated using PowerShell, it is called PowerShell Loop.
The types of loop that PowerShell supports are as follows:
• for loop
Execute a sequence of statements multiple times and abbreviates the code that
manages the loop variable.
• forEach loop
Enhanced for loop. This is mainly used to traverse collection of elements
including arrays.
• while loop
Repeats a statement or group of statements while a given condition is true. It
tests the condition before executing the loop body.
• do...while loop
Like a while statement, except that it tests the condition at the end of the loop
body.

15. Differentiate between cmdlet and command.

Cmdlets are way different from commands in other command-shell


environments in the following manners –
• Cmdlets are .NET Framework class objects; and not just stand-alone
executables.
• Cmdlets can be easily constructed from as few as a dozen lines of code.
• Parsing, error presentation, and output formatting are not handled by
cmdlets. It is done by the Windows PowerShell runtime.
• Cmdlets process works on objects not on text stream and objects can be
passed as output for pipelining.
• Cmdlets are record-based as they process a single object at a time.

16. What are PowerShell objects and how are they created?

Variables:
PowerShell variables are named objects. As PowerShell works with objects, these
variables are used to work with objects.
Creating Variables:
Variable name should start with $ and can contain alphanumeric characters and
underscore in their names. A variable can be created by typing a valid variable name.
Example:
Type the following command in PowerShell ISE Console. Assuming you are in D:\test
folder.
$location = Get-Location

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA


Here we've created a variable $location and assigned it the output of Get-Location
cmdlet. It now contains the current location.
Using variable:
Type the following command in PowerShell ISE Console.
$location
Output
You can see following output in PowerShell console.
Path
----
D:\test

17. Explain PowerShell conditions. What are the different types of PowerShell
conditions?

PowerShell conditions:
Decision making structures have one or more conditions to be evaluated or
tested by the program, along with a statement or statements that are to be
executed if the condition is determined to be true, and optionally, other
statements to be executed if the condition is determined to be false.
Types of PowerShell conditions:
• if statement
An if statement consists of a Boolean expression followed by one or
more statements.
• if...else statement
An if statement can be followed by an optional else statement, which
executes when the Boolean expression is false.
• nested if statement
You can use one if or elseif statement inside another if or elseif
statement(s).
• switch statement
A switch statement allows a variable to be tested for equality against a
list of values.

18. What is alias and how to create them?

PowerShell alias:
PowerShell alias is another name for the cmdlet or for any command element.
Creating alias:
Use New-Alias cmdlet to create a alias. In the below example, we've created an
alias help for Get-Help cmdlet.
New-Alias -Name help -Value Get-Help

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA


19. What do you understand by get-command in PowerShell?
The Get-Command cmdlet gets all commands that are installed on the
computer, including cmdlets, aliases, functions, filters, scripts, and applications.
Get-Command gets the commands from PowerShell modules and commands
that were imported from other sessions.
For example, if anyone is searching cmdlet between E and K, then:
get-command [ E–K] *

20. What is CIM and how it is different from WMI in PowerShell?

In PowerShell, CMI stands for Common Information Model which is used for describing
the structure of the behavior of the resources (Storage, software components,
network, etc.).
While WMI is an abbreviated form of Windows Management Instrumentation which is
used for the management of devices and network with the help of Windows
computing systems.

21. What is alias and how to create them?

PowerShell alias:
PowerShell alias is another name for the cmdlet or for any command element.
Creating alias:
Use New-Alias cmdlet to create a alias. In the below example, we've created an
alias help for Get-Help cmdlet.
New-Alias -Name help -Value Get-Help

22. What do you understand by get-command in PowerShell?

The Get-Command cmdlet gets all commands that are installed on the computer,
including cmdlets, aliases, functions, filters, scripts, and applications. Get-Command
gets the commands from PowerShell modules and commands that were imported
from other sessions.
For example, if anyone is searching cmdlet between E and K, then:
get-command [ E–K] *

23. What are the uses of PowerShell Array?

PowerShell Array is used to run scripts on remote computers. To create PowerShell


Array, users will need to create variable, as well as they will have to assign the

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA


PowerShell Array. PowerShell Arrays are expressed with a “@” symbol, and illustrated
as hash table.
For instance, it would be like -
$arrmachine = @ (“machine1”, “machine2”, “machine3”)

24. explain the hash table functions in PowerShell?

PowerShell’s hash table can be referred as a dictionary. Basically, it is a series that


enables users in storing data with a pair association known as “key-value”. Here, both
“keys”, as well as “value”, might comprise of any length and data. In order to declare
hash table users will have to apply @ in front of curly braces.

25. Define the key features of PowerShell?

The prime characteristics of Microsoft PowerShell can be summed up as follows -


• PowerShell is a scripting environment
• PowerShell commands are customizable
• The programming language isn’t text-based. It’s object-based.

Questions for 5 marks:


1. a What do you think is Microsoft PowerShell? And
Ans: Microsoft PowerShell is a command-line shell and scripting language built on .NET. It helps
system admins and power-users to quickly manage OS. (Windows, MacOS and Linux) and
processes.
b Define the key features of PowerShell?
Ans: The prime characteristics of Microsoft PowerShell can be summed up as follows -
PowerShell is a scripting environment
PowerShell commands are customizable
The programming language isn’t text-based. It’s object-based.

2. a What makes up the variables in PowerShell?


Ans: Variables contain objects, integers, and strings.
b In PowerShell, what according to you is the implication of brackets?
Ans: We use () Parentheses Brackets in compulsory arguments.
We use {} Braces Brackets for blocked statements
We do not normally use [] Square Brackets. These brackets specify optional items.

3. a What is your understanding of cmdlet?


Ans: Cmdlet are commands scripted in languages such as PowerShell VB or C#.
b Are you aware of PowerShell Loop?
Ans: When repetitive tasks are automated using PowerShell, it is called PowerShell Loop.

4. a Can PowerShell scripts be created for the deployment of SharePoint components?

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA


Ans: If the web part is created employing VS2010, SharePoint components can be deployed with
the help of ctrl+f5. Features of web part can be activated through PowerShell script.
b What is your idea about comparison operators in PowerShell?
Ans: Comparison operators in PowerShell compare values. Comparison operators can be
classified into four types - Match, Equality, Replace, and Containment. To declare variables, –eq
comparison is used. Similarly, lt is used for ‘less than’, -gt for ‘greater than’, and ‘not equal’ is
denoted by –ne.

5. a What is the use of the PowerShell pipeline?


Ans: When we have to join two statements, we use the PowerShell pipeline. In this case, one
statement’s output emerges as the second statement’s input.
b What do you understand by get-command in PowerShell?
Ans: PowerShell’s get-command is applied to fetch cmdlets. For instance, if anyone is searching
cmdlet between E and K, then the get-command would look like -get-command [ E–K] *

6. a Can you explain how network drive is mapped in PowerShell?


Ans: For mapping network drive, the following PowerShell commands have to be executed
# PowerShell Map Network Drive

b Do you know the methods to ‘Select’ in PowerShell?


Ans: The simplest way is WQL (WMI Query Language) statement. This technique uses the ‘-
query’ in order to introduce ‘Select * from’.
Select-String is the next method to ‘Select’ in PowerShell. In this scenario, matching pattern,
phrase, and word is checked by the cmdlet.
The last way is through Select-Object.

7. a What is PowerShell’s Get-Service Status function?


Ans: The functions of Get-Service Status enable filtering of window services. PowerShell lists
the services that are ‘Running’, also, the services that are ‘Stopped’ through scripting.
b Since you mentioned scripting, define what Scripting in PowerShell is?
Ans: PowerShell files contain an array of commands, where each command appears in separate
lines. When using text file, the filename will have the .PS1 extension. PowerShell script can be
run by -
Typing commands in text editor, saving file with the .ps1 extension, Executing the file

8. a Can you explain the hash table functions in PowerShell?


Ans: PowerShell’s hash table can be referred as a dictionary. Basically, it is a series that enables
users in storing data with a pair association known as “key-value”. Here, both “keys”, as well as
“value”, might comprise of any length and data. In order to declare hash table users will have to
apply @ in front of curly braces.
b Can you explain the uses of PowerShell Array?
Ans: PowerShell Array is used to run scripts on remote computers. To create PowerShell Array,
users will need to create variable, as well as they will have to assign the PowerShell Array.
PowerShell Arrays are expressed with a “@” symbol, and illustrated as hash table.

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA


For instance, it would be like –

9. a Define what commands to use in order to get child folders into a specified folder?
Ans: We will have to apply parameter recurse to get child folders into a specified folder. It will
be - Get-ChildItem C: Scripts –recurse
b Can you explain the ways to convert the object to HTML?
Ans: In order to convert the object to HTML, we will have to execute –
Get-Process l Sort-object – property CPU –descending l convert to – HTML l Out-file
“process.html”

10. a Can you define how you will assign a different name to a variable?
Ans: A variable can be renamed by using – Rename-Item- Path Env: MyVariable –NewName
MyRenamedVar
b Are you aware of $input variable? What are its functions?
Ans: $input variable activates a function that enables pipeline data access.

a Can you illustrate the code used to locate names of installed applications on a current
computer?
Ans: We will have to employ the following code - Get-WmiObject-Class Win32_Product
- ComputerName. l Format-wide-column1
b Q22) How do you think you will find that sql services in PowerShell are in one server?
Ans: We can do this in two ways –

11. a What according to you is an efficient way to locate all sql services in one server?
Ans: In this case also, we can do it in two ways –

b Are you aware of the class that can enable us to identify if mc is 64 bit or 32 bits?
win32_computersystem. We can use this as follows –

12. a What is your idea about Variable Interpolation?


Ans: When a variable is added to double-quoted strings, then PowerShell changes the name of
that variable through its value. Typically, this feature in PowerShell is known as variable
interpolation.
B Explain what is PowerShell Loop?

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA


Automating repetitive task with the help of PowerShell loop is known as PowerShell
Loop. Through PowerShell, you can execute For each loop, While loop and Do While loop.

13. a Explain can you create PowerShell scripts for deploying components in SharePoint?

If you have created a web part using VS 2010 then, you can deploy it using cntrl+f5. However,
to activate the web part feature you can write a PowerShell script (.ps1) and execute it after
deployment
B Explain about the PowerShell’s comparison operators?

Comparison Operators compares value in PowerShell. Four types of comparison operators are
used equality, match, containment and replace. In PowerShell, one of the key comparison
operators is –eq that is used instead of “=” sign for declaring variables. Likewise, there are other
operators like –ne for “not equal” , -gt ( greater than ) or –lt (less than).

14. a Explain what is PowerShell pipeline is used for?

PowerShell pipeline is used for joining two statements such that the output of one statement
becomes the input of the second.
b Explain what is PowerShell get-command?

Get command in PowerShell is used to fetch other cmdlets, for example you are looking for
cmdlet between letter L and R then your PowerShell get-command will be like

# PowerShell Get – Command Range


Clear-Host
Get-Command [ L–R] *

15. Explain how you can find in PowerShell that all the sql services are on one server?

There are two ways to do this


get-wmiobject win32_service l where-object {$_name-like “*sql*”}
get-service sql*
Questions for 5 marks:
1. Write the brief history about PowerShell.

Let See Version Wise History of PowerShell:


•PowerShell version 1 supported the local administration of Windows Server 2003
•PowerShell 2.0 was integrated with Windows 7 and Windows Server 2008 R2. This version
supports for remoting and enhances the capabilities of PowerShell like transactions, background
jobs, events, debugging, etc.
•PowerShell 3.0 was released as an internal part of the Windows management framework. It
was installed on Windows 8 and Windows Server 2012. You can add and scheduled jobs, session
connectivity, automatic module loading, etc.
•PowerShell 4.0 was shipped with Windows 8.1 and Windows Server 2012 R2. In this version
added support for desired state configuration, enhanced debugging, network diagnostics.

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA


•PowerShell 5.0 was released as internal part of Windows management framework 5. The
feature offers in this version are remote debugging, class definitions, .NET enumerations, etc.

2. What are the features of PowerShell which make it differ from DOS and powerful?
PowerShell Remoting: PowerShell allows scripts and cmdlets to be invoked on a remote
machine.

Background Jobs: It helps you to invoked script or pipeline asynchronously. You can run your
jobs either on the local machine or multiple remotely operated machines.

Transactions: Enable cmdlet and allows developers to perform

Evening: This command helps you to listen, forwarding, and acting on management and
system events.

Network File Transfer: PowerShell offers native support for prioritized, asynchronous,
throttled, transfer of files between machines using the Background Intelligent Transfer Service
(BITS) technology.

3. Explain what is the significance of brackets in PowerShell?

Parenthesis Brackets (): Curved parenthesis style brackets are used for compulsory
arguments.

Braces Brackets {}: Curly brackets are employed in blocked statements

Square Brackets []: They define optional items, and they are not frequently used

4. Mention what are the three ways that PowerShell uses to ‘Select’?

• The most common way is in a WMI Query Language (WQL) statement. In this technique
Wmiobject uses ‘-query’ to introduce a classic ‘Select * from’ a phrase
• The second context for ‘Select’ in PowerShell is Select-String. This cmdlet checks for a
word, phrase or any pattern match
• Another way is Select Object

5. How to select a specific object with some certain condition?

Use the Where-Object cmdlet to select items in a list (or command output) that match
a condition you provide. The Where-Object cmdlet has the standard aliases where and?
To list all running processes that have “search” in their name, use the -like operator to
compare against the process’s Name property:

Get-Process | Where-Object { $_.Name -like "*Search*" }

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA


To list all processes not responding, test the Responding property:

Get-Process | Where-Object { -not $_.Responding }

To list all stopped services, use the -eq operator to compare against the service’s Status
property:

Get-Service | Where-Object { $_.Status -eq "Stopped" }

For simple comparisons on properties, you can omit the script block syntax and use the
comparison parameters of Where-Object directly:

Get-Process | Where-Object Name -like "*Search*"

6. How to easily access items in a list by a property name?

Use the Group-Object cmdlet (which has the standard alias group) with the -AsHash and -
AsString parameters. This creates a hashtable with the selected property (or expression) used
as keys in that hashtable:

PS > $h = dir | group -AsHash -AsString Length


PS > $h

Name Value
---- -----
746 {ReplaceTest.ps1}
499 {Format-String.ps1}
20494 {test.dll}

PS > $h["499"]
Directory: C:\temp

Mode LastWriteTime Length Name


---- ------------- ------ ----
-a--- 10/18/2009 9:57 PM 499 Format-String.ps1

7. Explain CIM and state it connection types.

Common Information Model (CIM) is an industry standard defined by DMTF


(Distributed Management Task Force).
It is a new technology based on open and cross platform standards. It also enables
remote ad-hoc connections.
The CIM has common information repository which can be queried and manipulated
for the management task.
There are three types of connections possible under CIM:
• Connection to local computer by using DCOM.
• Connection to remote computer by using WS-WAN.

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA


• Connection to remote computer (Session based) by using both DCOM
and WA-LAN.

8. Discuss about Active Directory Management (ADM).

AD Manager Plus is one simple, hassle-free web-based solution for all Active Directory
Management challenges, safe with secure authentication and performs all actions with
just mouse clicks.
This Active Directory management tool allows administrators to design templates to
manage all Active Directory account creation and modification processes. In order to
use these Windows PowerShell scripts, you must import the module for interacting
with AD — the Active Directory Module for Microsoft Windows PowerShell.

9. What do you mean by transaction in PowerShell registry keys? Explain.

When working in the registry, you might sometimes want to chain a set of related
changes and be sure that they all get applied as a single unit. These are goals known as
atomicity and consistency.
To support this type of management task, Windows PowerShell supports a change
management strategy known as transactions.
When you start a transaction, any commands in that transaction are virtual and don’t
actually apply to the system until you complete the transaction.
Within the context of the transaction, though, each participating command sees the
system as though the state really had changed.
Once you complete a transaction, changes are applied as a single unit.

10. Write a shirt note on registry keys.

The registry plays a central role in system administration. It is also generally hard to
manage. Though command line tools exists, it is still difficult to manage the registry.
This problem is somehow tackled by windows PowerShell by exposing windows
registry as a navigation tool. Windows PowerShell lets you navigate the Windows
Registry in exactly the same way that you navigate the filesystem, certificate drives,
and other navigation-based providers.

11. How to enable remoting on a single local machine?

The inbuilt Windows Remote Management (WinRM) enables network connections for
windows PS to experience the remote access.

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA


This service explicitly needs to get active in the earlier version of windows, whereas it
is already included in windows 7 and windows server 2008 R2.
This function can be activated simply by calling “Enable-PS”.
Remote enabling connects remote desktop through WMI (Windows Management
Instrumentation).
To enable this, a method “Create()” needs to be invoked in Windows 32.
It is a de-facto management protocol which can be configured form windows registry.
For successful connection, the properties of registry must be set to 1
The command “Enable-PsRemoting” can be used.

12. What is PS Provider? How to Install and remove the providers?

The data that a provider exposes appears in a drive, and you access the data in a path
like you would on a hard disk drive. Windows PowerShell includes a set of built-in providers
that you can use to access the different types of data stores. One among them is PSProvider.
Installing and removing providers:
• Providers are typically installed via Windows PowerShell modules.
• Importing the module loads the provider into your session.
• You cannot uninstall the built-in providers.
• You can uninstall providers loaded by other modules.
• You can unload a provider from the current session.
• You can do this by using the Remove-Module cmdlet.
• This cmdlet does not uninstall the provider, but it makes the provider
unavailable in the session.

13. Write a short note on Windows PowerShell remoting.

Windows PowerShell remoting provides a method to transmit any command to a


remote computer for local execution.
In version one, local administration was essentially the limit of where PowerShell
applied its unique perspective. It supported interaction with traditional remoting m
focus of their collaboration. Starting with standard interactive remoting, PowerShell
lets you easily connect to a remote system and work with it one to one.

14. What do you mean by Microsoft PowerShell providers? Explain.

Windows PowerShell providers are Microsoft .NET Framework-based programs that


make the data in a specialized data store available in Windows PowerShell so that you
can view and manage it. The data that a provider exposes appears in a drive, and you

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA


access the data in a path like you would on a hard disk drive. You can use any of the
built-in cmdlets that the provider supports to manage the data in the provider drive.

15. What is CIM and how it is different from WMI in PowerShell?

In PowerShell, CMI stands for Common Information Model which is used for describing
the structure of the behavior of the resources (Storage, software components,
network, etc.).
While WMI is an abbreviated form of Windows Management Instrumentation which is
used for the management of devices and network with the help of Windows
computing systems.

16. Explain Execution Policies and types of Execution Policy?

There are 6 types of execution policies in PowerShell. These are:


• Restricted: This is the default type. Under this, PowerShell will not run any
script including PowerShell profiles too.
• RemoteSigned: PowerShell will only run any script that is created locally. Any
script that has been coming from the Internet should be digitally signed with a
signing certificate code and is trusted by the computer.
• AllSigned: PowerShell will only run any script that has been digitally signed
using a trusted code signing certificate.
• Unrestricted: PowerShell will run any script. If the script comes from an
untrusted source, users are prompted once to execute it.
• Bypass: This policy will run any script without any question or prompt.
• Undefined: There is no execution policy set for this in the current scope.

17. What are PowerShell objects and how are they created?

Variables:
PowerShell variables are named objects. As PowerShell works with objects, these variables are
used to work with objects.
Creating Variables:
Variable name should start with $ and can contain alphanumeric characters and underscore in
their names. A variable can be created by typing a valid variable name.
Example:
Type the following command in PowerShell ISE Console. Assuming you are in D:\test folder.
$location = Get-Location
Here we've created a variable $location and assigned it the output of Get-Location cmdlet. It
now contains the current location.
Using variable:
Type the following command in PowerShell ISE Console.

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA


$location
Output
You can see following output in PowerShell console.
Path
----
D:\test

18. Explain PowerShell conditions. What are the different types of PowerShell conditions?

PowerShell conditions:
Decision making structures have one or more conditions to be evaluated or tested by the
program, along with a statement or statements that are to be executed if the condition is
determined to be true, and optionally, other statements to be executed if the condition is
determined to be false.
Types of PowerShell conditions:
• if statement
An if statement consists of a Boolean expression followed by one or more statements.
• if...else statement
An if statement can be followed by an optional else statement, which executes when the
Boolean expression is false.
• nested if statement
You can use one if or elseif statement inside another if or elseif statement(s).
• switch statement
A switch statement allows a variable to be tested for equality against a list of values.

19. Differentiate between cmdlet and command.

Cmdlets are way different from commands in other command-shell environments in


the following manners –
• Cmdlets are .NET Framework class objects; and not just stand-alone executables.
• Cmdlets can be easily constructed from as few as a dozen lines of code.
• Parsing, error presentation, and output formatting are not handled by cmdlets. It is
done by the Windows PowerShell runtime.
• Cmdlets process works on objects not on text stream and objects can be passed as
output for pipelining.
• Cmdlets are record-based as they process a single object at a time.

20. What is a PowerShell loop? Explain its types.

When repetitive tasks are automated using PowerShell, it is called PowerShell Loop.
The types of loop that PowerShell supports are as follows:
• for loop

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA


Execute a sequence of statements multiple times and abbreviates the code that
manages the loop variable.
• forEach loop
Enhanced for loop. This is mainly used to traverse collection of elements
including arrays.
• while loop
Repeats a statement or group of statements while a given condition is true. It
tests the condition before executing the loop body.
• do...while loop
Like a while statement, except that it tests the condition at the end of the loop
body.

Explain Execution Policies and types of Execution Policy?

There are 6 types of execution policies in PowerShell. These are:


• Restricted: This is the default type. Under this, PowerShell will not run any
script including PowerShell profiles too.
• RemoteSigned: PowerShell will only run any script that is created locally. Any
script that has been coming from the Internet should be digitally signed with a
signing certificate code and is trusted by the computer.
• AllSigned: PowerShell will only run any script that has been digitally signed
using a trusted code signing certificate.
• Unrestricted: PowerShell will run any script. If the script comes from an
untrusted source, users are prompted once to execute it.
• Bypass: This policy will run any script without any question or prompt.
• Undefined: There is no execution policy set for this in the current scope.

Prepared By: Hitesh Mohapatra, Associate Professor, Dept. Of MCA

Das könnte Ihnen auch gefallen