Advertisement
Guest User

Untitled

a guest
May 6th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. $VmmServerName = "VMM01"
  2. $SQLserver = "VMMDB"
  3. $SQLDatabase = "IploggingDB"
  4. $SQLuser = "MyUser"
  5. $SQLPassword = "SecretPWD"
  6.  
  7.  
  8. # Import VMM module.
  9. Import-Module virtualmachinemanager
  10.  
  11. # Connect to VMM server.
  12. Get-SCVMMServer -ComputerName $VmmServerName -ForOnBehalfOf
  13.  
  14. $Operation = "Create"
  15. $date = get-date
  16. $Date = '{0:s}' -f $date
  17. $Name = "Manual"
  18.  
  19. ### MsSQL CONNECTION
  20. $Connection = New-Object System.Data.SQLClient.SQLConnection
  21. $Connection.ConnectionString = "Server = '$SQLServer';database='$SQLDatabase'; User ID = '$SQLuser'; `
  22. Password = '$SQLPassword';trusted_connection=true; Integrated Security=false"
  23. $Connection.Open()
  24. $Command = New-Object System.Data.SQLClient.SQLCommand
  25. $Command.Connection = $Connection
  26. ###
  27.  
  28. $VMnetworks = Get-SCVMNetwork
  29.  
  30. foreach ($VMnetwork in $VMnetworks) {
  31.  
  32. $owner = $VMnetwork.Owner
  33.  
  34. if ($owner) {
  35.  
  36. $Gateways = Get-SCVMNetworkGateway -VMNetwork $VMnetwork
  37.  
  38. foreach ($Gateway in $Gateways) {
  39.  
  40. $IPs = ((Get-SCNATConnection -VMNetworkGateway $Gateway).Rules | ? ExternalPort -eq 0).Name
  41.  
  42. foreach ($IP in $IPs) {
  43.  
  44. $Command.CommandText = "INSERT INTO iplog (Owner, Operation, IP, Date, Name) `
  45. VALUES ('{0}','{1}','{2}','{3}','{4}')" `
  46. -f $Owner, $Operation, $IP, $Date, $Name
  47.  
  48. $Command.ExecuteNonQuery() | out-null
  49.  
  50. }
  51.  
  52. }
  53.  
  54. }
  55.  
  56. }
  57.  
  58. $Connection.Close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement