Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Return value Read-Host in a function

$
0
0

Hi everyone,

Reason:

I receive .tif files from users but usually not in the correct format. Because of that I need to rename about 30 files every day. It requires to be in a bit of a strange format as they are automatically imported into another system. In about six months this will all be automated but until then I don't feel like doing it all manually.

Issue:

I want to use a function as I would have the same code four times in this script. When I use the Do {rev... -eq 2} straight in the code it works. I have no idea how to return a read-host value from a function. After googling and testing a few things I cannot get it to work and I do not receive any error messages.

Does it have something to do with the scope of the function or something like that? Can anyone help me out? Maybe it is something small that I'm missing.

Code:

FunctionRead-Revision

{

 

 

 

Do {$revision=Read-host"Revision"} while ($revision-notmatch"^\d{2}"-and$revision.name.length -eq2)

 

 

 

return $revision

 

 

 

Write-Host $revision

}

 

#Get all .tif files.

$List

 

 

=get-childitem$Directory|where {$_.extension -eq".tif"}

ForEach ($tiffilein$list)

{

 

 

#When format is 1234567.tif

 

 

 

 

If($tiffile.name.length -eq11)

{

 

 

If($tiffile.name.substring(7,4) -eq".tif")

{

 

 

$number=$tiffile.name.substring(0,7)

 

 

 

 

Write-Host"Only number"

 

 

 

 

Invoke-Item$tiffile

 

 

 

 

Set-Focus

 

 

 

 

Read-Revision

 

 

 

 

Read-Sheet

 

 

 

 

Read-Format

 

 

 

 

Rename-Item$tiffile"$number-$revision-sht$sheet-$format.tif"

 

 

 }

}

}

Format Sample:

9999999-03-sht01-A0.tif

9999998-01-sht01-A1.tif

9999998-01-sht02-A3.tif


Viewing all articles
Browse latest Browse all 6937

Trending Articles