Hello,
I have the following script where I want to ask the user to select the folder they want the script to process the instructions from. I've added a function for Select-Folder as follows:
function Select-Folder($message='Select a folder', $path = 0) {
$object = New-Object -comObject Shell.Application
$folder = $object.BrowseForFolder(0, $message, 0, $path)
if ($folder -ne $null) {
$folder.self.Path
}
}
Select-Folder 'Select the folder where the move scripts reside'
$files=Get-ChildItem $folder -Filter "*.txt"
foreach ($file in $files){
$outFileName=[IO.Path]::GetFileNameWithoutExtension($file.Name) + "_StartVMs.txt"
Get-Content $file.FullName | foreach{
Add-Content $folder\$outFileName "Start-ClusterResource ""$($_.Split('"')[1])"""
}
}Issue #1:
The .txt files I am creating live in the same location as where this script lives. What I've found is the path I choose in the browseforfolder box that pops up is ignored and the files are converted in the location where the script lives.
Issue #2:
How do I get the Cancel button to work so the script will exit if the user selects Cancel?
Any help you can provide would be greatly appreciated.
Thank you.