Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 232869

Running a powercli from powershell

$
0
0

The first script reads through a list of files and starts jobs using the second script...
the first echo works great and write the VM name to a file but I don't get any of the other echoes and it stops processing ...
I can run the second script by itself if I just pass a parameter to it and I will get all the echoes and the CSV file...
Any advice?
I start the first script (or the second one if I run it by itslef) this way:
C:\Windows\System32\WindowsPowerShell\v1.0>powershell.exe D:\Powercli\Scripts\Storage\test2.ps1

 

 

Two scripts: the calling script:
#Multithreads Jobs
"Killing existing jobs . . ."
Get-Job | Remove-Job -Force
"Done."

$vms = Get-Content D:\Powercli\Scripts\Storage\ImportVMs.txt
foreach ($vm in $vms){
   while ((Get-Job -State Running).length -ge 10)
   {
   Start-Sleep -seconds 3
   }
   Start-Job -ScriptBlock {& D:\Powercli\Scripts\Storage\WriteVMs.ps1 $using:vm } -Name $VM
   Start-Sleep -s 10
}

 

 

The called script - D:\Powercli\Scripts\Storage\WriteVMs.ps1
param(
   [string]$VM
   )

echo $vm >> "D:\Powercli\Scripts\Storage\args.txt"


#Load PowerCLI module in PowerShell
Add-PSSnapin VMware.VimAutomation.Core
Set-PowerCLIConfiguration -InvalidCertificateAction ignore -Confirm:$False

echo snapinloaded >> "D:\Powercli\Scripts\Storage\args.txt"

#Initialize
$vCenterHost = "server.test.com"
$user = "ID-Here"
$password = "PW-Here"


echo initialized >> "D:\Powercli\Scripts\Storage\args.txt"


#Connect to VCenter server
Connect-Viserver $vCenterHost -user $user -password $password

echo connected >> "D:\Powercli\Scripts\Storage\args.txt"

Get-VM -Name $VM | Export-Csv -NoTypeInformation -UseCulture -append -Path "D:\Powercli\Scripts\Storage\exported.csv"

echo gotVM >> "D:\Powercli\Scripts\Storage\args.txt"


Viewing all articles
Browse latest Browse all 232869

Trending Articles



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