Difference between revisions of "Useful PowerShell Commands"

From rbachwiki
Jump to navigation Jump to search
Line 20: Line 20:
<h3>Rename Files using csv list / excel file (exported to CSV)</h3>
<h3>Rename Files using csv list / excel file (exported to CSV)</h3>
<p>If you execute the script in the same directory as the files, you don't have to add the full path, but if it's in a different directory the the full path is needed</p>
<p>If you execute the script in the same directory as the files, you don't have to add the full path, but if it's in a different directory the the full path is needed</p>
<p>You can start with an excel file, but when you export the excel file to CSV you have to add the "Path" and the "NewName" to the top of the CSV exported file </p>
<p>You can start with an excel file. Header has to be <span class="high"> Path</span> and <span class="high">NewName </span></p>
<p class="subhead">Path refers to the Old Filename and NewName is the New Filename </p>
<p>The reason why we add the <span class="high">Path,</span> and <span class="high">NewName </span> is because the <span class="high">Rename-Item</span> function accepts a Path string and a NewName string</p>
<p>The reason why we add the <span class="high">Path,</span> and <span class="high">NewName </span> is because the <span class="high">Rename-Item</span> function accepts a Path string and a NewName string</p>



Revision as of 17:24, 18 October 2024

Get-ComputerInfo

Accessing the properties of a command

Get-Computerinfo -Properties csusername
Get-Computerinfo -Properties csusername | Get-Member
Get-ComputerInfo | Format-List OsType,osName,csusername

Write output to the screen, like Echo

Write-Output "Hello World" 

Read Text file

Get-Content filename.txt
Rename-Computer
Restart-Computer
Get-Date
Get-TimeZone

Update Windows From PowerShell

Import csv file The pipe it to another function

import-csv .\filename.csv | 

Rename Files using csv list / excel file (exported to CSV)

If you execute the script in the same directory as the files, you don't have to add the full path, but if it's in a different directory the the full path is needed

You can start with an excel file. Header has to be Path and NewName

Path refers to the Old Filename and NewName is the New Filename

The reason why we add the Path, and NewName is because the Rename-Item function accepts a Path string and a NewName string

import-csv ./rename.csv | rename-item

The CSV File

Path,NewName
dog.jpg,222-dog.jpg
rat.jpg,333-rat.jpg
cat.jpg,111-cat.jpg


Home - Category