Powershell scriping excercise Nr.1

Added:
1. File extension filtered file-counter.
2. System-info display script (OS, CPU, RAM).
3. File listing script.
4. Filtered file renaming script by pattern.
5. Start of to-do-text-file for next commit.
This commit is contained in:
serialexperiments0815 2025-10-14 19:21:00 +02:00
commit 361e384195
5 changed files with 48 additions and 0 deletions

View file

@ -0,0 +1,7 @@
# Call 'Get-ChildItem' cmdlet method to retrieve filesystem objects.
# './' specifies current directory.
# '-Recurse' instructs iterations through subdirectories.
# '-File' returns results for files only, no directories.
# '-Filter' returns results for specified string pattern.
Get-ChildItem -Path "./" -Recurse -File -Filter *.ps1

View file

@ -0,0 +1,4 @@
# Calling 'Get-ComputerInfo' method to return all computer information.
Get-ComputerInfo |
# Calling 'Select-Object' method to filter results through '-Property' parameters.
Select-Object -Property WindowsProductName, OSDisplayVersion, CsProcessors, OsTotalVisibleMemorySize

View file

@ -0,0 +1,18 @@
# Call 'Get-ChildItem' cmdlet method to retrieve filesystem objects.
# './' specifies current directory.
# '-Recurse' instructs iterations through subdirectories.
# '-File' returns results for files only, no directories.
Get-ChildItem -Path './' -Recurse -File |
# Call 'Select-Object' cmdlet method to return specified properties.
# '-Property FullName' returns full String path for each object.
# '-Property LastWriteTime' returns DateTime for last modification.
Select-Object -Property FullName, LastWriteTime |
# Call 'Export-Csv' cmdlet method to convert outputs into CSV file.
# '-Path './folderFiles.csv'' returns output of file in current directory.
# '-NoTypeInformation' supresses #TYPE metadata line.
Export-Csv -Path './folderFiles.csv' -NoTypeInformation

View file

@ -0,0 +1,19 @@
# Calling 'Get-ChildItem' method for return of items in Folder.
# "./" In current directory.
# "-Filter *.PNG" Of the type PNG.
Get-ChildItem "./" -Filter *.PNG |
# Calling 'ForEach-Object' loop method for iterating through returned files.
ForEach-Object {
# Declaring and defining $newName variable.
# Consisting of "{0}/$_.BaseName/Original Name" "_" "{1:D4}/$i/4-digit-counter" "{2}/$_.Extension/original extension"
$newName = "{0}_{1:D4}{2}" -f $_.BaseName, $i, $_.Extension
# Calling 'Rename-Item" method returns updated filename.
Rename-Item $_.FullName -NewName $newName
# Increment counter.
$i++
}