Powershell
2023-20-11
Submitted by: Sushan Bhadel
Submitted to: Arbind Sir
1. How do you change the current location to a
specific drive in PowerShell?
Ans: To change the current location of PowerShell the command is set-
location c:/
2. Write a PowerShell command to list all files in the
current directory.
Ans: The powershell command to list all files in the current
directory command is get-childitem
3. What is the purpose of the Clear-Host cmdlet in
PowerShell?
Ans: The purpose of the Clear-Host cmdlet is to clear all console.
4. Using Get-Content, how would you display the
contents of a file named "example.txt"?
Ans: To display the contents of a file named "example.txt” the
command is Get-content ‘./example.txt’
5. Provide three examples of aliases and their
corresponding full cmdlet names. Why might
aliases be useful in PowerShell?
Ans: The three example of aliases and their corresponding
full cmdlet name are :
o Get-Alias - Gets all the aliases in the current session.
• New-Alias - Creates a new alias.
• Set-Alias - Creates or changes an alias.
It makes it easier to ensure your professional and personal
life remain separate.
6. Explain how you can run an external command, like
"Ping" or "Calc," from within the PowerShell
console.
Ans: In powershell we can run an external command like ping or
calc through Invoke-expression -command “ping example.com”
7. What information does the ipconfig /all command
provide, and in what scenarios might it be useful?
Ans: The ipconfig /all command displays detailed information
about all adapters. Such as:
• LAN info
• Wireless info
• VPN
• Lease expiration date
• DHCP server address
It might be useful in following scenarios:
• Accessing the internet
If you can't access the internet, you can use ipconfig to set your IP address.
• Changing your IP address
You can use ipconfig to change your IP address.
• Diagnosing network issues
You can use ipconfig to renew or release DHCP leases, flush DNS caches, and troubleshoot
other network issues.
8. Write a PowerShell command to retrieve
information about all services on your computer,
including the service name, display name, and
status.
Ans: To retrieve information about all services on your computer
including the service name, display name, and status just type get-
service in powershell.
9. What is the purpose of the Update-Help -Force
command in PowerShell?
Ans: The purpose of the Update-Help -Force command in
powershell is to update the latest version of powershell.
10. How would you use the Get-Help cmdlet to find
general information about all available cmdlets?
Ans: To get help for a PowerShell cmdlet, type Get-Help followed by
the cmdlet name, such as: Get-Help Get-Process . Conceptual help
articles in PowerShell begin with about, such as
about_Comparison_Operators. To see all about articles, type Get-Help
about* .
11. List two examples of approved verbs used in
PowerShell cmdlet naming.
Ans: Two examples of approved verbs used in Powershell cmdlet
naming include:
• Reset
• Search
12. How can you view the current directory path in
PowerShell?
Ans: To view the current directory path in PowerShell the
command is get-location.
13. Write a command to copy a file named
"report.doc" from the current directory to the
"Backup" directory.
Ans: The command to copy a file named “report.doc” from the
current directory to the “Backup” directory the command is Copy-
Item -Path .\report.doc -Destination .\Backup\
14. Explain the significance of the -Force
parameter in the Remove-Item cmdlet.
Ans: The significance of the -Force parameter in the Remove-Item
cmdlet is to remove items that can't otherwise be changed, such as
hidden or read-only files or read-only aliases or variables. The
cmdlet can't remove constant aliases or variables.
15. Using Get-Help, find detailed information
about the Copy-Item cmdlet, including syntax and
examples.
Ans: You can use the Get-Help cmdlet in PowerShell to find detailed
information about the Copy-Item cmdlet.
This command will display detailed information about the Copy-
Item cmdlet, including its syntax, parameters, and examples.
16. How can you open the online help
documentation for a specific cmdlet, for example,
Get-Service?
Ans: To open the online help documentation for a specific cmdlet
we can use command get-help get-service -online.
17. Provide an example of a scenario where using
an alias in PowerShell might be beneficial.
Ans: An example of a scenario where using an alias in powershell
might be beneficial
Scenario:
Let's say you frequently need to retrieve information about running
processes using the Get-Process cmdlet. Typing out the full cmdlet
each time can be cumbersome. In this case, you can create an alias to
simplify the command.
without using alias
Get-process
Using alias
gal -name exploder
By using the alias, you can significantly reduce the amount of typing
required to perform the same task. This is particularly beneficial
when you are working interactively in the PowerShell console and
want to streamline your commands.
18. Write a PowerShell command to display all
aliases starting with the letter "G."
Ans: The command to display all aliases starting with
the letter "G” is get-alias -name G*.
19. Explain the difference between Get-Service and
Get-Process in terms of their functionality.
Ans: Difference between Get-Process and Get-service
Get-Process: This cmdlet is used to retrieve information about
processes that are currently running on a computer. A process is an
instance of a computer program that is being executed. It represents
the execution of a software program in memory.
Get-Service: This cmdlet is used to retrieve information about
services on a computer. Services are background processes that can
be automatically started when the system boots, and they perform
various tasks such as running applications, managing hardware
components, or providing network services.
20. How would you use the Get-Content cmdlet to
display only the first 10 lines of a text file named
"log.txt"?
Ans: We can use the Get-content cmdlet to display only the first 10
line of a text file named “log.txt” the command we can use Get-
Content -Path "log.txt" | Select-Object -First 10.