Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Problems with my colon

$
0
0

Thought that title would get some extra attention. Here's what I'm trying to do in my attempt to make a small script into an advanced one, with organized and separate functions and validation; all that good stuff. I want to be able to share it out to a few users of the product as well.

I have a folder structure, wfx32\user, that would be present on every install of the product. What can change is the drive letter. My first function, called Get-File, does nothing more than ask for the drive letter and then get the list of files in that drive letter's folder structure. I want to have the validation check to see if a colon was added to the back end of the drive letter, and if it wasn't, add it automatically and go on to the next part. The validation works, in as much as it detects if it has a colon and if it doesn't it will output to the screen a message that it doesn't, but it doesn't append the colon to be used later in the join-path.

Any ideas?

disclaimer: several puppies were killed during the creation of this script. Those lines will be removed after getting it to work.

Function Get-File{ Param( [parameter(mandatory=$true)] [ValidateScript({ If($_.EndsWith(":")) {Write-Host "drive letter good"} Else{Write-Host $_" is the drive letter";Write-host "drive letter no good";$ProfileDrive=$_ + ":"} $true})] [String]$ProfileDrive ) $ProfileDrive $ProfileFolder = Join-Path -Path $ProfileDrive -ChildPath "wfx32\user" $ProfileFolder } Get-File


Viewing all articles
Browse latest Browse all 15370

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>