PowerShell Scripting Tutorials
|
|||
SN
|
Purpose
|
Cmdlets / Command
|
Description
|
Show
version
|
$PSVersionTable
|
Show
PowerShell Version
|
|
Update
package
|
Get-Help
Add-AppPackage
|
Update
packages
|
|
Update
package
|
Get-HotFix
|
Get-HotFix
and to install a hot fix as follows
|
|
Update package
|
Get-HotFix -id kb2741530
|
Update kb2741530
|
|
Create
folder
|
New-Item
-Path 'D:\temp\Test Folder' -ItemType Directory
|
Create a folder in D:\Temp\ with name
"Test Folder"
|
|
Create
file
|
New-Item
-Path 'D:\temp\Test Folder\Test File.txt' -ItemType File
|
Create
a file in D:\Temp\Test Folder with name "Test File.txt"
|
|
Copy
folder
|
Copy-Item
'D:\temp\Test Folder' 'D:\temp\Test Folder1'
|
Copy
a folder D:\Temp\Test Folder as D:\Temp\Test Folder1
|
|
Copy
folder
|
Copy-Item
'D:\temp\Test Folder' -Destination 'D:\temp\Test Folder1'
|
Copy
a folder recursively D:\Temp\Test Folder to D:\Temp\Test Folder1
|
|
Copy
file
|
Copy-Item
'D:\temp\Test Folder\Test File.txt' 'D:\temp\Test Folder1\Test File1.txt'
|
Copy
a file D:\Temp\Test Folder\Test File.txt to D:\Temp\Test Folder1
|
|
Copy
file
|
Copy-Item
-Filter *.txt -Path 'D:\temp\Test Folder' -Recurse -Destination 'D:\temp\Test
Folder1'
|
Copy all text file recursively D:\Temp\Test
Folder to D:\Temp\Test Folder1
|
|
Delete
folder
|
Remove-Item
'D:\temp\Test Folder1'
|
Delete
a folder D:\Temp\Test Folder1
|
|
Delete
folder
|
Remove-Item
'D:\temp\Test Folder' -Recurse
|
Remove
the folder D:\Temp\Test Folder1 recursively. In first example, PowerShell
confirms if directory is not empty. In this case, it will simply delete the
item.
|
|
Delete
file
|
Remove-Item
'D:\temp\Test Folder\test.txt'
|
Delete
a file D:\Temp\Test Folder\Test.txt
|
|
Delete
file
|
Remove-Item
'D:\temp\Test Folder' -Recurse
|
Remove
the folder D:\Temp\Test Folder recursively deleting its all files. In first
example, PowerShell confirms if directory is not empty. In this case, it will
simply delete the item.
|
|
Rename
folder
|
Rename-Item
D:\temp\Test D:\temp\Test1
|
Rename
a folder D:\Temp\Test to D:\Temp\Test1
|
|
Rename
file
|
Rename-Item
D:\temp\Test\test.txt test1.txt
|
Rename
a folder D:\Temp\Test\test.txt to test1.txt
|
|
Retrieving
Item
|
Get-Content
D:\temp\Test\test.txt
|
Read
a file D:\Temp\Test\Test.txt
|
|
Retrieving
Item Length/size
|
(Get-Content
D:\temp\test\test.txt).length
|
Read
the size of the content of the file read.
|
|
Check
Folder Existence
|
Test-Path
D:\temp\test
Output : Test-Path D:\temp\test True |
We're
having a folder test in D:\temp directory
|
|
Check
Folder Existence
|
Test-Path
D:\temp\test2
Output : Test-Path D:\temp\test2 False |
We're
not having a folder named test2 in D:\temp directory
|
|
Check
File Existence
|
Test-Path
D:\temp\test\test.txt
Output : Test-Path D:\temp\test\test.txt True |
We're
having a file test.txt in D:\temp\test directory
|
|
Check
File Existence
|
Test-Path
D:\temp\test\test2.txt
Output : Test-Path D:\temp\test\test2.txt False |
We're
not having a file named test2.txt in D:\temp\test directory
|
|
Get
System Date
|
Get-Date
Output : Get-Date Saturday, May 05, 2018 9:58:06 AM |
we're
using Get-Date to get current date
|
|
Get-Date
-DisplayHint Date
Output : Get-Date -DisplayHint Date Wednesday, April 04, 2018 |
we're
using -DisplayHint to print only Date.
|
||
Set
system date
|
set-date
-Date (Get-Date).AddDays(1)
Output : Sunday, May 06, 2018 9:59:16 AM |
we're
using Set-Date to add one more day to current date
|
|
Set
system date (Revert)
|
set-date
-Date (Get-Date).AddDays(-1)
Output : Saturday, May 05, 2018 10:00:37 AM |
Now
revert back to substract added day to current date.
|
|
Get-Date
-DisplayHint Time
Output : 10:04:18 AM |
we're
using -DisplayHint to print only Time.
|
||
Set
System Time
|
>
$timeToAdd = New-TimeSpan -Minutes 60
> set-date -adjust $timeToAdd Output : Saturday, May 05, 2018 11:05:16 AM |
we're
using Set-Date to adjust to 60 minutes.
|
|
Set
System Time
|
>
$timeToAdd = New-TimeSpan -Minutes -60
> set-date -adjust $timeToAdd Output : Saturday, May 05, 2018 10:08:54 AM |
Now
revert back to substract added time to current date.
|
Welcome to my Posts on Information Technology. Contact here, for any trouble with your computer Email to: masudrana2003@gmail.com. Disclaimer: Opinions expressed here are personal and cannot in any way be associated or reflects those of my employer. In addition, my thoughts and opinions change from time to time I consider this a necessary consequence of having an open mind.
Friday, May 15, 2020
PowerShell Scripting Tutorials
Subscribe to:
Post Comments (Atom)
Describe BIOS and UEFI
BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing har...
-
How to Free Up Hard Disk Space on Windows 10 menu to make the process easier. From here, you can see how much space has been used on your ...
-
On Windows 32-bit for 32-bit Office 2016 / 365 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\16.0\ClickToRun\REGISTRY\MACHINE\Software\M...
-
How to change directory in CMD on Windows 10 via Command line If you are new to Windows Command prompt then you might be looking for ways ...
No comments:
Post a Comment