Questions and Answers Automation and Configuration Management
Questions and Answers Automation and Configuration Management
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?
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
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.
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
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.
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.
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”)
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
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.
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
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.
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
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] *
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 –
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).
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
15. Explain how you can find in PowerShell that all the sql services are on one server?
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.
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.
Parenthesis Brackets (): Curved parenthesis style brackets are used for compulsory
arguments.
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
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:
To list all stopped services, use the -eq operator to compare against the service’s Status
property:
For simple comparisons on properties, you can omit the script block syntax and use the
comparison parameters of Where-Object directly:
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:
Name Value
---- -----
746 {ReplaceTest.ps1}
499 {Format-String.ps1}
20494 {test.dll}
PS > $h["499"]
Directory: C:\temp
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.
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.
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.
The inbuilt Windows Remote Management (WinRM) enables network connections for
windows PS to experience the remote access.
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.
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.
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.
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.
When repetitive tasks are automated using PowerShell, it is called PowerShell Loop.
The types of loop that PowerShell supports are as follows:
• for loop