LucD escreveu:
The .psc1 file is what is called a PSConsoleFile, it is used to load PSSnapins.
The powershell.exe command has multiple options (you can do powershell.exe /? to see them).
If your script is stored in a .ps1 file, you can use the File parameter to run it.
Dear LucD
Great !! The Parameter -File works
Now im ant to test the script line per line
My script is that bellow. but im have another problem
See bellow the blue lines
When im insert the while apears two arrows >> in the lef side
and im cannot exit of this to continue insert anothers lines of the script
how im can do ?? is normal ????
$tgtEsxName = "ESXI HOST" #ESXI Host you want to clone to
$tgtDatastoreName = "DATASTORE" #Datastore you want to clone to
$Vc = "mcb-vcenter" #Name of Vcenter Server
$vcUser = "USER" # Username for VCENTER
$vcPass = "PASSWORD"# Password for VCENTER
#set up email
$emailSMTP = "IP.IP.IP.IP" #Ip address of SMTP server
$emailfrom = "CLONING@YOURDOMAIN.COM" #From Email
$emailRCpt = "ADMINS@YOURDOMAIN.COM" #Recipient email
$smtp = New-Object Net.Mail.SmtpClient -arg $emailSMTP
# add snapin for VMware
add-pssnapin VMware.VimAutomation.Core
Connect-VIServer -Server $vc -User $vcUser -Password $vcPass # log into server
# import CSV File
$importFrom = "CSV"
$vmPath = "C:\CLONES\CLONES.CSV" #path of CSV
$vmList = Import-csv $vmPath # Retrieve the CSV file
$Lines = Get-Content $vmPath | Measure-Object #count the lines
#count line ins CSV file
$Total = $Lines.Count - 1
#initiate Counters
$i = 0
$ttl = 1
#start loop
While ($ttl -le $Total) {
# set date format
$date = Get-Date -Format "MM/dd/yyyy HH:mm"
Function doDate() {
$now = Get-Date -Format "ddd MMM yyyy HH:mm:ss"
Write-Host -NoNewline "`n$now | "}
$VM = Get-VM $vmList[$i].Name
$fromVMname = $vm
$newvmname = "$fromVmname $date"
Write-Host "Creating clone of $VM ($ttl of $Total)"
#Command to clone VM
New-VM -Name ($newvmname) -VM ($fromvmname) -Datastore ($tgtDatastoreName) -VMHost ($tgtEsxName) -location ("Remote_clones")
$test = Get-Vm -name $newvmname
#if statement for if Vm is not found
if (!$test){
#vm not found
#else Statement used if the VM is found
else{
$path = "C:\CLONES\$vm.txt"#path of log file REPLACE EVERYTHING BEFORE\$VM.TXT
$deleteVM = Get-Content $path #pull line from log file
Remove-VM $deleteVM -deletepermanently -confirm:$false #remove old clone
Clear-Content $path #Delete content of log file
$newvmname | Out-File $path #put name of new server in log file
}
$i++
$ttl++
}