Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'winrm'
- module YP
- module DevOps
- class Ypwinrm
- @winrm_connector
- attr_reader :pdcserver
- def initialize(username, password)
- @pdcserver = "172.27.12.130"
- opts = {
- endpoint: "http://#{pdcserver}:5985/wsman",
- user: username,
- password: password
- }
- @winrm_connector = WinRM::Connection.new(opts)
- end
- def remove_dns(servername)
- unless servername.downcase.include?("*")
- @winrm_connector.shell(:powershell) do |shell|
- output = shell.run("Remove-DnsServerResourceRecord -ZoneName 'itops.ad.ypg.com' -Name '#{servername}' -RRType 'A' -Force") do |stdout, stderr|
- STDOUT.print stdout
- STDERR.print stderr
- end
- puts "The script exited with exit code #{output.exitcode}"
- end
- else
- raise "Cannot use wildcard with delete functions!"
- end
- end
- def remove_computer_acc(servername)
- unless servername.downcase.include?("*")
- @winrm_connector.shell(:powershell) do |shell|
- output = shell.run("Remove-ADComputer -Identity '#{servername}' -Confirm:$False") do |stdout, stderr|
- STDOUT.print stdout
- STDERR.print stderr
- end
- puts "The script exited with exit code #{output.exitcode}"
- end
- else
- raise "Cannot use wildcard with delete functions!"
- end
- end
- def get_computer_acc(servername)
- @winrm_connector.shell(:powershell) do |shell|
- output = shell.run("Get-ADComputer -Identity '#{servername}' -Properties *") do |stdout, stderr|
- STDOUT.print stdout
- STDERR.print stderr
- end
- puts "The script exited with exit code #{output.exitcode}"
- end
- end
- def get_dns(servername)
- @winrm_connector.shell(:powershell) do |shell|
- output = shell.run("Get-DnsServerResourceRecord -ZoneName 'itops.ad.ypg.com' -Name '#{servername}' -RRType 'A'") do |stdout, stderr|
- STDOUT.print stdout
- STDERR.print stderr
- end
- puts "The script exited with exit code #{output.exitcode}"
- end
- end
- def powershell_command(command)
- unless servername.downcase.include?("*")
- @winrm_connector.shell(:powershell) do |shell|
- output = shell.run(command) do |stdout, stderr|
- STDOUT.print stdout
- STDERR.print stderr
- end
- puts "The script exited with exit code #{output.exitcode}"
- end
- else
- raise "Cannot use wildcard with powershell function!"
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement