Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Assistace with asking user from my script which location to pick up the file

$
0
0

Hello,

I have a process whereby we daily create a file in two different (server) locations.  It's a list of all VM's in each of our two Hyper-V clusters.  I have a script that will read this file and split it out by host (where each cluster has 5 hosts). 

#********************************************************************************************************
# Split Function to read Move_ClusterGroup_script.txt file and create files of 20 records by Host name.
# Update Line 25 if you want to change the number of records that are put into the output file.
#********************************************************************************************************

#Begin
Set-Location '.\'
$HostName = Read-Host 'Please provide a Hyper-v Host'

Function Split-File{

    Process {
        Remove-Item .\$($_)* -Force #remove existing files
        $currentfile=Get-Content ".\Move_ClusterGroup_script.txt" | Select-String -Pattern $_
        $filecounter=1
        #if($currentfile){
        For($i=0;$i -le @($currentfile).Count;$i++){
            $currentfile[$i] | Add-Content ".\$($_)_$($filecounter).txt"
            If(!(($i+1)%25)){$filecounter++}
            }
        #}
    }
}

$HostName | Split-File

As you can see the file looks in the same location that it resides for a Move_ClusterGroup_script.txt file

My script asks the user to provide a hostname.  I would like to add this to script to ask another question, where to find the Move_ClusterGroup_script.txt file.  I'm thinking I'll ask the user to provide the Cluster Name and depending upon the name requested, the script will know which location to go and get the Move_ClusterGroup_script.txt file.

I know I can add another line like:

$ClusterName = Read-Host 'Please provide a Cluster Name'

But once a valid cluster name has been given, how do I within Powershell use the answer given to provide the correct path to the file?

Thank you.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



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