update
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
<# Scheduled Task metadata
|
||||
General
|
||||
Get IPs for PA
|
||||
run as ndgov\!itdvcenterppa
|
||||
run whether user is logged on or not
|
||||
Triggers
|
||||
Daily, 11am
|
||||
Daily, 11pm
|
||||
Actions
|
||||
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -file "C:\itdscript\GetIPs.ps1"
|
||||
Settings
|
||||
allow task to be run on demand
|
||||
stop the task if it runs longer than 1 hour -eq $true
|
||||
if the running task does not end when requested, force it to stop
|
||||
#>
|
||||
|
||||
|
||||
Start-Transcript C:\ITDSCRIPT\Logs\GetIPs.txt -Append
|
||||
#Add-PSSnapin VMware.VimAutomation.Core
|
||||
Set-PowerCLIConfiguration -DefaultVIServerMode multiple -Scope Session -Confirm:$false
|
||||
|
||||
#Connect
|
||||
Connect-VIServer itdvmvc1.nd.gov, itdvmvc2.nd.gov
|
||||
|
||||
|
||||
##Windows
|
||||
|
||||
|
||||
#Output File
|
||||
$OutFileWin = "c:\inetpub\wwwroot\Win.txt"
|
||||
$Date = Get-Date -UFormat "%Y%m%d%H%M%S"
|
||||
Get-Item -Path $OutFileWin | Copy-Item -Destination "D:\Backup\Win\$Date-Win.txt"
|
||||
Remove-Item $OutFileWin
|
||||
Start-Sleep -Seconds 5
|
||||
|
||||
|
||||
#Get Powered On VM's
|
||||
$vmwin = get-VM | Where-Object { $_.PowerState -eq "PoweredOn" `
|
||||
-and ($_.GuestID -eq "windows7Guest" `
|
||||
-or $_.GuestID -eq "windows7_64Guest" `
|
||||
-or $_.GuestID -eq "windows7Server64Guest" `
|
||||
-or $_.GuestID -eq "windows8_64Guest" `
|
||||
-or $_.GuestID -eq "windows8Server64Guest" `
|
||||
-or $_.GuestID -eq "windows9Server64Guest" `
|
||||
-or $_.GuestID -eq "winLonghorn64Guest" `
|
||||
-or $_.GuestID -eq "winLonghornGuest" `
|
||||
-or $_.GuestID -eq "winNetStandardGuest" `
|
||||
-or $_.GuestID -eq "winNetEnterpriseGuest" `
|
||||
-or $_.GuestID -eq "windows9_64Guest" `
|
||||
-or $_.GuestID -eq "windows2019srv_64Guest" `
|
||||
-or $_.GuestID -eq "windows2019srvNext_64Guest") }
|
||||
$vmviewwin = $vmwin | Get-View
|
||||
|
||||
$Outputwin = ""
|
||||
|
||||
#Loop through VM's, NIC's, and IP addresses.
|
||||
Foreach ($v in $vmviewwin) {
|
||||
Foreach ($nic in $v.Guest.Net) {
|
||||
Foreach ($IP in $nic.IPAddress) {
|
||||
If ($IP -notlike "fe80*" -and $IP -notlike "192.168.*" -and $IP -notlike "172.16*") {
|
||||
$OutputWin += $IP + "`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#If ($Outputwin -ne "") {$OutputWin | Out-File $OutFileWin -Encoding utf8 -NoNewline}
|
||||
If ($Outputwin -ne "") { $OutputWin | Out-File $OutFileWin -Encoding ASCII -NoNewline }
|
||||
|
||||
|
||||
|
||||
##Linux
|
||||
|
||||
#Output File
|
||||
$OutFileLin = "c:\inetpub\wwwroot\Lin.txt"
|
||||
$Date = Get-Date -UFormat "%Y%m%d%H%M%S"
|
||||
Get-Item -Path $OutFileLin | Copy-Item -Destination "D:\Backup\Lin\$Date-Lin.txt"
|
||||
Remove-Item $OutFileLin
|
||||
Start-Sleep -Seconds 5
|
||||
|
||||
#Get Powered On VM's
|
||||
$vmLin = get-VM | Where-Object { $_.PowerState -eq "PoweredOn" `
|
||||
-and ($_.GuestID -eq "centos6_64Guest" `
|
||||
-or $_.GuestID -eq "centos64Guest" `
|
||||
-or $_.GuestID -eq "centos7_64Guest" `
|
||||
-or $_.GuestID -eq "oracleLinux64Guest" `
|
||||
-or $_.GuestID -eq "oracleLinux7_64Guest" `
|
||||
-or $_.GuestID -eq "rhel4Guest" `
|
||||
-or $_.GuestID -eq "rhel5Guest" `
|
||||
-or $_.GuestID -eq "rhel5_64Guest" `
|
||||
-or $_.GuestID -eq "rhel6Guest" `
|
||||
-or $_.GuestID -eq "rhel6_64Guest" `
|
||||
-or $_.GuestID -eq "rhel7_64Guest" `
|
||||
-or $_.GuestID -eq "sles11_64Guest" `
|
||||
-or $_.GuestID -eq "sles12_64Guest" `
|
||||
-or $_.GuestID -eq "ubuntu64Guest") }
|
||||
$vmviewlin = $vmLin | Get-View
|
||||
|
||||
$OutputLin = ""
|
||||
|
||||
#Loop through VM's, NIC's, and IP addresses.
|
||||
Foreach ($v in $vmviewlin) {
|
||||
Foreach ($nic in $v.Guest.Net) {
|
||||
Foreach ($IP in $nic.IPAddress) {
|
||||
If ($IP -notlike "fe80*" -and $IP -notlike "192.168.*" -and $IP -notlike "172.16*") {
|
||||
$OutputLin += $IP + "`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#If ($OutputLin -ne "") {$OutputLin | Out-File $OutFileLin -Encoding utf8 -NoNewline}
|
||||
If ($OutputLin -ne "") { $OutputLin | Out-File $OutFileLin -Encoding ASCII -NoNewline }
|
||||
|
||||
|
||||
Stop-Transcript
|
||||
@@ -0,0 +1,149 @@
|
||||
<# Scheduled Task metadata
|
||||
General
|
||||
Get IPs for PA - Azure
|
||||
run as ndgov\svcitdazurescript
|
||||
run whether user is logged on or not
|
||||
Triggers
|
||||
Daily, 2pm - repeat every 1 hour indefinitely
|
||||
Actions
|
||||
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -file "C:\itdscript\GetIPsAzure.ps1"
|
||||
Settings
|
||||
allow task to be run on demand
|
||||
stop the task if it runs longer than 1 hour -eq $true
|
||||
if the running task does not end when requested, force it to stop
|
||||
#>
|
||||
|
||||
|
||||
Start-Transcript C:\itdscript\Logs\GetIPsAzureB.txt -Append
|
||||
$VerbosePerfrence = "Continue"
|
||||
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$OutputPath = "C:\inetpub\wwwroot"
|
||||
|
||||
$WindowsIPs = ""
|
||||
$LinuxIPs = ""
|
||||
$OutFileWin = $OutputPath + "\AzureWin.txt"
|
||||
$OutFileLin = $OutputPath + "\AzureLin.txt"
|
||||
Remove-Item $OutFileWin
|
||||
Remove-Item $OutFileLin
|
||||
|
||||
|
||||
$username="svcitdazurescript@nd.gov"
|
||||
$usernameg="svcitdazurescript@ndstate.onmicrosoft.com"
|
||||
#Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File C:\Users\svcitdazurescript\AppData\Local\Microsoft\sac.bat
|
||||
$password=Get-Content C:\Users\svcitdazurescript\AppData\Local\Microsoft\sac.bat | ConvertTo-SecureString
|
||||
$passwordg=Get-Content C:\Users\svcitdazurescript\AppData\Local\Microsoft\sacg.bat | ConvertTo-SecureString
|
||||
$AdminCred=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$password
|
||||
$AdminCredg=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $usernameg,$passwordg
|
||||
|
||||
Login-AzureRMAccount -Credential $AdminCred -Environment AzureCloud -Verbose
|
||||
|
||||
$Subscriptions = Get-AzureRMSubscription | Where-Object {$_.Name -ne "sandbox"}
|
||||
foreach($subscription in $subscriptions)
|
||||
{
|
||||
Set-AzureRMContext -SubscriptionObject $subscription
|
||||
$WindowsVMs = Get-AzureRMVM | Where-Object {$_.StorageProfile.osdisk.ostype -match "Windows"}
|
||||
$LinuxVMs = Get-AzureRMVM | Where-Object {$_.StorageProfile.osdisk.ostype -match "Linux" -and $_.StorageProfile.ImageReference.Publisher -ne "infoblox" -and $_.StorageProfile.ImageReference.Publisher -ne "paloaltonetworks" -and $_.StorageProfile.ImageReference.Publisher -ne "juniper-networks"}
|
||||
$nics = Get-AzureRMNetworkInterface | Where-Object {$_.VirtualMachine -NE $null}
|
||||
|
||||
foreach($vm in $WindowsVMs)
|
||||
{
|
||||
$vmnicinterfaces = $vm.Networkprofile.NetworkInterfaces.id
|
||||
foreach($vmnicinterface in $vmnicinterfaces)
|
||||
{
|
||||
$nic = $nics | Where-Object {$_.Id -eq $vmnicinterface}
|
||||
$privateip = $nic.IpConfigurations | Select PrivateIPAddress
|
||||
|
||||
If($privateip.count -gt 1)
|
||||
{
|
||||
foreach($private in $privateip)
|
||||
{
|
||||
$WindowsIPs += $private.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
elseIf($privateip.privateIPAddress -ne $null)
|
||||
{
|
||||
$WindowsIPs += $privateip.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($vm in $LinuxVMs)
|
||||
{
|
||||
$vmnicinterfaces = $vm.Networkprofile.NetworkInterfaces.id
|
||||
foreach($vmnicinterface in $vmnicinterfaces)
|
||||
{
|
||||
$nic = $nics | Where-Object {$_.Id -eq $vmnicinterface}
|
||||
$privateip = $nic.IpConfigurations | Select PrivateIPAddress
|
||||
|
||||
If($privateip.count -gt 1)
|
||||
{
|
||||
foreach($private in $privateip)
|
||||
{
|
||||
$LinuxIPs += $private.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
elseif($privateip.privateIPAddress -ne $null)
|
||||
{
|
||||
$LinuxIps += $privateip.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Login-AzureRMAccount -EnvironmentName AzureUSGovernment -Credential $AdminCredg
|
||||
|
||||
$Subscriptions = Get-AzureRMSubscription | Where-Object {$_.Name -ne "sandbox"}
|
||||
foreach($subscription in $subscriptions)
|
||||
{
|
||||
Set-AzureRMContext -SubscriptionObject $subscription
|
||||
$WindowsVMs = Get-AzureRMVM | Where-Object {$_.StorageProfile.osdisk.ostype -match "Windows"}
|
||||
$LinuxVMs = Get-AzureRMVM | Where-Object {$_.StorageProfile.osdisk.ostype -match "Linux" -and $_.StorageProfile.ImageReference.Publisher -ne "infoblox" -and $_.StorageProfile.ImageReference.Publisher -ne "paloaltonetworks" -and $_.StorageProfile.ImageReference.Publisher -ne "juniper-networks"}
|
||||
$nics = Get-AzureRMNetworkInterface | Where-Object {$_.VirtualMachine -NE $null}
|
||||
|
||||
foreach($vm in $WindowsVMs)
|
||||
{
|
||||
$vmnicinterfaces = $vm.Networkprofile.NetworkInterfaces.id
|
||||
foreach($vmnicinterface in $vmnicinterfaces)
|
||||
{
|
||||
$nic = $nics | Where-Object {$_.Id -eq $vmnicinterface}
|
||||
$privateip = $nic.IpConfigurations | Select PrivateIPAddress
|
||||
If($privateip.count -gt 1)
|
||||
{
|
||||
foreach($private in $privateip)
|
||||
{
|
||||
$WindowsIPs += $private.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
elseIf($privateip.privateIPAddress -ne $null)
|
||||
{
|
||||
$WindowsIPs += $privateip.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($vm in $LinuxVMs)
|
||||
{
|
||||
$vmnicinterfaces = $vm.Networkprofile.NetworkInterfaces.id
|
||||
foreach($vmnicinterface in $vmnicinterfaces)
|
||||
{
|
||||
$nic = $nics | Where-Object {$_.Id -eq $vmnicinterface}
|
||||
$privateip = $nic.IpConfigurations | Select PrivateIPAddress
|
||||
|
||||
If($privateip.count -gt 1)
|
||||
{
|
||||
foreach($private in $privateip)
|
||||
{
|
||||
$LinuxIPs += $private.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
elseif($privateip.privateIPAddress -ne $null)
|
||||
{
|
||||
$LinuxIps += $privateip.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
If ($WindowsIPs -ne "" -and $WindowsIPs.Length -gt 150) {$WindowsIPs | Out-File $OutFileWin -Encoding ASCII -NoNewline -Force}
|
||||
If ($LinuxIPs -ne ""-and $LinuxIPs.Length -gt 150) {$LinuxIPs | Out-File $OutFileLin -Encoding ASCII -NoNewline -Force}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
<# Scheduled Task metadata
|
||||
General
|
||||
Get IPs for PA - Azure Backup
|
||||
run as ndgov\svcitdazurescript
|
||||
run whether user is logged on or not
|
||||
Triggers
|
||||
Daily, 4:12pm - repeat every 1 hour indefinitely
|
||||
Actions
|
||||
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -file "C:\itdscript\GetIPsAzureBackup.ps1"
|
||||
Settings
|
||||
allow task to be run on demand
|
||||
stop the task if it runs longer than 1 hour -eq $true
|
||||
if the running task does not end when requested, force it to stop
|
||||
#>
|
||||
|
||||
start-transcript D:\zm.log -force
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$OutputPath = "C:\inetpub\wwwroot"
|
||||
$OutputBackupPath = "C:\inetpub\wwwroot\AzureBak\"
|
||||
$CurrentDateTime = Get-Date -UFormat "%Y%m%d%H%M%S"
|
||||
|
||||
|
||||
$BackupIPs = ""
|
||||
$OutFileBak = $OutputPath + "\AzureBak.txt"
|
||||
$OutFileBakBackup = $OutputBackupPath + "\AzureBak-$CurrentDateTime.txt"
|
||||
|
||||
Remove-Item $OutFileBak
|
||||
|
||||
|
||||
$username="svcitdazurescript@nd.gov"
|
||||
$usernameg="svcitdazurescript@ndstate.onmicrosoft.com"
|
||||
#Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File C:\Users\svcitdazurescript\AppData\Local\Microsoft\sac.bat
|
||||
$password=Get-Content C:\Users\svcitdazurescript\AppData\Local\Microsoft\sac.bat | ConvertTo-SecureString
|
||||
$passwordg=Get-Content C:\Users\svcitdazurescript\AppData\Local\Microsoft\sacg.bat | ConvertTo-SecureString
|
||||
$AdminCred=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$password
|
||||
$AdminCredg=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $usernameg,$passwordg
|
||||
|
||||
Login-AzureRMAccount -Credential $AdminCred -Environment AzureCloud
|
||||
|
||||
$Subscriptions = Get-AzureRMSubscription | Where-Object {$_.Name -ne "sandbox"}
|
||||
foreach($subscription in $subscriptions)
|
||||
{
|
||||
Set-AzureRMContext -SubscriptionObject $subscription
|
||||
$BackupVMs = Get-AzureRMVM | Where-Object {$_.Tags["Backup"] -match "OS-BackupEnabled"}
|
||||
$nics = Get-AzureRMNetworkInterface | Where-Object {$_.VirtualMachine -NE $null}
|
||||
|
||||
foreach($vm in $BackupVMs)
|
||||
{
|
||||
$vmnicinterfaces = $vm.Networkprofile.NetworkInterfaces.id
|
||||
foreach($vmnicinterface in $vmnicinterfaces)
|
||||
{
|
||||
$nic = $nics | Where-Object {$_.Id -eq $vmnicinterface}
|
||||
$privateip = $nic.IpConfigurations | Select PrivateIPAddress
|
||||
|
||||
If($privateip.count -gt 1)
|
||||
{
|
||||
foreach($private in $privateip)
|
||||
{
|
||||
$BackupIPs += $private.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
elseIf($privateip.privateIPAddress -ne $null)
|
||||
{
|
||||
$BackupIPs += $privateip.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Login-AzureRMAccount -EnvironmentName AzureUSGovernment -Credential $AdminCredg
|
||||
|
||||
$Subscriptions = Get-AzureRMSubscription | Where-Object {$_.Name -ne "sandbox"}
|
||||
foreach($subscription in $subscriptions)
|
||||
{
|
||||
Set-AzureRMContext -SubscriptionObject $subscription
|
||||
$BackupVMs = Get-AzureRMVM | Where-Object {$_.Tags["Backup"] -match "OS-BackupEnabled"}
|
||||
$nics = Get-AzureRMNetworkInterface | Where-Object {$_.VirtualMachine -NE $null}
|
||||
|
||||
foreach($vm in $BackupVMs)
|
||||
{
|
||||
$vmnicinterfaces = $vm.Networkprofile.NetworkInterfaces.id
|
||||
foreach($vmnicinterface in $vmnicinterfaces)
|
||||
{
|
||||
$nic = $nics | Where-Object {$_.Id -eq $vmnicinterface}
|
||||
$privateip = $nic.IpConfigurations | Select PrivateIPAddress
|
||||
If($privateip.count -gt 1)
|
||||
{
|
||||
foreach($private in $privateip)
|
||||
{
|
||||
$BackupIPs += $private.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
elseIf($privateip.privateIPAddress -ne $null)
|
||||
{
|
||||
$BackupIPs += $privateip.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
If ($BackupIPs -ne "") {
|
||||
$BackupIPs | Out-File $OutFileBak -Encoding ASCII -NoNewline -Force
|
||||
$BackupUPs | Out-File $OutFileBakBackup -Encoding ascii -NoNewline -Force
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<# Scheduled Task metadata
|
||||
General
|
||||
Get IPs for PA - Azure Backup
|
||||
run as ndgov\!itdvcenterscript
|
||||
run whether user is logged on or not
|
||||
Triggers
|
||||
Daily, 11:30am - repeat every 1 hour indefinitely
|
||||
Actions
|
||||
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -file "C:\itdscript\GetIPsMonitor.ps1"
|
||||
Settings
|
||||
allow task to be run on demand
|
||||
stop the task if it runs longer than 1 hour -eq $true
|
||||
if the running task does not end when requested, force it to stop
|
||||
#>
|
||||
|
||||
|
||||
#cdfelchle 7/12/16
|
||||
|
||||
#Files to Monitor
|
||||
$FileCheckWin = "c:\inetpub\wwwroot\win.txt"
|
||||
$FileCheckLin = "c:\inetpub\wwwroot\lin.txt"
|
||||
$FileCheckBak = "c:\inetpub\wwwroot\AzureBak.txt"
|
||||
$FileCheckWinAz = "c:\inetpub\wwwroot\Azurewin.txt"
|
||||
$FileCheckLinAz = "c:\inetpub\wwwroot\Azurelin.txt"
|
||||
|
||||
#E-mail Initialization and Construction
|
||||
$emailSubject = "VMware-PA Integration Failure"
|
||||
$emailRelay = "apprelay2.nd.gov"
|
||||
$emailBody =
|
||||
"Scripting Server Error Report (ITDVMVCP1SCRIPT)
|
||||
------------------------------------------
|
||||
"
|
||||
$emailRecipients = "itdvctremailalerts@nd.gov"
|
||||
$emailSender = "itdvmvcp1script@nd.gov"
|
||||
|
||||
#File Presence Check
|
||||
$WindowsPresent = Test-Path $FileCheckWin
|
||||
$LinuxPresent = Test-Path $FileCheckLin
|
||||
$AzureWindowsPresent = Test-Path $FileCheckWinAz
|
||||
$AzureLinuxPresent = Test-Path $FileCheckLinAz
|
||||
$AzureBakPresent = Test-Path $FileCheckBak
|
||||
|
||||
|
||||
#Flag to send e-mail
|
||||
$SendEmail = $False
|
||||
|
||||
|
||||
#File Presence Check
|
||||
If ($WindowsPresent -eq $False){
|
||||
$SendEmail = $True
|
||||
$emailBody += $FileCheckWin + " --- Missing File`n"
|
||||
}
|
||||
|
||||
If ($LinuxPresent -eq $False){
|
||||
$SendEmail = $True
|
||||
$emailBody += $FileCheckLin + " --- Missing File`n"
|
||||
}
|
||||
|
||||
If ($AzureWindowsPresent -eq $False){
|
||||
$SendEmail = $True
|
||||
$emailBody += $FileCheckWinAz + " --- Missing File`n"
|
||||
}
|
||||
|
||||
If ($AzureLinuxPresent -eq $False){
|
||||
$SendEmail = $True
|
||||
$emailBody += $FileCheckLinAz + " --- Missing File`n"
|
||||
}
|
||||
|
||||
If ($AzureBakPresent -eq $False){
|
||||
$SendEmail = $True
|
||||
$emailBody += $FileCheckBak + " --- Missing File`n"
|
||||
}
|
||||
|
||||
|
||||
#File Size Check
|
||||
If ($WindowsPresent -eq $True -and (Get-Item $FileCheckWin).length -lt 1000){
|
||||
$SendEmail = $True
|
||||
$emailBody += "$FileCheckWin --- File size is less than 1kb`n"
|
||||
}
|
||||
|
||||
If ($LinuxPresent -eq $True -and (Get-Item $FileCheckLin).length -lt 1000){
|
||||
$SendEmail = $True
|
||||
$emailBody += "$FileCheckLin --- File size is less than 1kb`n"
|
||||
}
|
||||
|
||||
If ($AzureWindowsPresent -eq $True -and (Get-Item $FileCheckWinAz).length -lt 100){
|
||||
$SendEmail = $True
|
||||
$emailBody += "$FileCheckWinAz --- File size is less than 1kb`n"
|
||||
}
|
||||
|
||||
If ($AzureLinuxPresent -eq $True -and (Get-Item $FileCheckLinAz).length -lt 100){
|
||||
$SendEmail = $True
|
||||
$emailBody += "$FileCheckLinAz --- File size is less than 1kb`n"
|
||||
}
|
||||
|
||||
If ($AzureBakPresent -eq $True -and (Get-Item $FileCheckBak).length -lt 10){
|
||||
$SendEmail = $True
|
||||
$emailBody += "$FileCheckBak --- File size is less than 10 bytes`n"
|
||||
}
|
||||
|
||||
|
||||
|
||||
#File Age Check
|
||||
$CurrentTime = Get-Date
|
||||
|
||||
If ($WindowsPresent -eq $True -and (Get-Item $FileCheckWin).LastWriteTime -lt $CurrentTime.AddHours(-13)){
|
||||
$SendEmail = $True
|
||||
$emailBody += "$FileCheckWin --- File is older than 12 hours`n"
|
||||
}
|
||||
|
||||
If ($LinuxPresent -eq $True -and (Get-Item $FileCheckLin).LastWriteTime -lt $CurrentTime.AddHours(-13)){
|
||||
$SendEmail = $True
|
||||
$emailBody += "$FileCheckLin --- File is older than 12 hours`n"
|
||||
}
|
||||
|
||||
If ($AzureWindowsPresent -eq $True -and (Get-Item $FileCheckWinAz).LastWriteTime -lt $CurrentTime.AddHours(-13)){
|
||||
$SendEmail = $True
|
||||
$emailBody += "$FileCheckWinAz --- File is older than 12 hours`n"
|
||||
}
|
||||
|
||||
If ($AzureLinuxPresent -eq $True -and (Get-Item $FileCheckLinAz).LastWriteTime -lt $CurrentTime.AddHours(-13)){
|
||||
$SendEmail = $True
|
||||
$emailBody += "$FileCheckLinAz --- File is older than 12 hours`n"
|
||||
}
|
||||
|
||||
If ($AzureBakPresent -eq $True -and (Get-Item $FileCheckBak).LastWriteTime -lt $CurrentTime.AddHours(-13)){
|
||||
$SendEmail = $True
|
||||
$emailBody += "$FileCheckBak --- File is older than 12 hours`n"
|
||||
}
|
||||
|
||||
|
||||
If ($SendEmail -eq $True){
|
||||
Send-MailMessage -To $emailRecipients -From $emailSender -Subject $emailSubject -Body $emailBody -SmtpServer $emailRelay
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<# Scheduled Task metadata
|
||||
General
|
||||
Old-VMware Billing
|
||||
run as ndgov\!itdvcenterscript (required for SQL Database access)
|
||||
run whether user is logged on or not
|
||||
Triggers
|
||||
Daily, 5am
|
||||
Actions
|
||||
old-C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -file "C:\itdscript\vmconfig.ps1"
|
||||
|
||||
Settings
|
||||
allow task to be run on demand
|
||||
stop the task if it runs longer than 1 hour -eq $true
|
||||
if the running task does not end when requested, force it to stop
|
||||
#>
|
||||
|
||||
|
||||
Start-Transcript C:\ITDSCRIPT\Logs\VMConfig.txt
|
||||
Add-PSSnapin VMware.VimAutomation.Core
|
||||
Set-PowerCLIConfiguration -DefaultVIServerMode multiple -Scope Session -Confirm:$false
|
||||
Connect-VIServer -Server itdvmvcp1.nd.gov,itdvmvcp2.nd.gov,itdvmvc1.nd.gov,itdvmvc2.nd.gov
|
||||
#Connect-VIServer -Server itdvmvcp2.nd.gov
|
||||
|
||||
|
||||
###########################
|
||||
## Functions #
|
||||
###########################
|
||||
|
||||
###
|
||||
### Override Invoke-SQLCmd cmdlet in order to display proper error Handling.
|
||||
###
|
||||
function Invoke-SQLCmd ([string] $ServerInstance, [string] $Database, [String] $Query)
|
||||
{
|
||||
Try
|
||||
{
|
||||
$conn = new-object system.data.SqlClient.SqlConnection("Data Source=$ServerInstance;Integrated Security=TRUE;Initial Catalog=$Database");
|
||||
$ds = new-object "System.Data.DataSet" "dsChildSites"
|
||||
|
||||
$da = new-object "System.Data.SqlClient.SqlDataAdapter" ($Query, $conn)
|
||||
$fillcnt = $da.Fill($ds)
|
||||
$conn.Close()
|
||||
|
||||
$dtChild = new-object "System.Data.DataTable" "dsChildSites"
|
||||
$dtChild = $ds.Tables[0]
|
||||
$dtChild | FOREACH-OBJECT -process {
|
||||
$_
|
||||
}
|
||||
}
|
||||
Catch
|
||||
{
|
||||
write-output $Query
|
||||
Throw $_
|
||||
}
|
||||
}
|
||||
|
||||
#$Servers = Get-VM | Where-Object {$_.PowerState -like 'PoweredOn'} | Select Name, NumCPU, @{label="MemoryMB"; expression={$_.MemoryGB * 1024}}, @{label="HardDiskSizeGB"; expression={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum * 1024}}, VMHost | Sort-Object Name
|
||||
$Servers = Get-VM | Where-Object {($_ | Get-Harddisk).count -ne 0} | Select Name, NumCPU, @{label="MemoryMB"; expression={$_.MemoryGB * 1024}}, @{label="HardDiskSizeGB"; expression={(Get-HardDisk -VM $_ | Measure-Object -Sum CapacityGB).Sum * 1024}}, VMHost | Sort-Object Name
|
||||
|
||||
|
||||
$SQLServer = "ITDSQL16P1\SQL16P1"
|
||||
$DB = "ITD-SRS-Billing"
|
||||
|
||||
$Connection = New-Object System.Data.SQLClient.SQLConnection
|
||||
$Connection.ConnectionString = "server='$SQLServer';database='$DB';Integrated Security=TRUE;"
|
||||
$Connection.Open()
|
||||
$Command = New-Object System.Data.SQLClient.SQLCommand
|
||||
$Command.Connection = $Connection
|
||||
|
||||
$Date = "'" + (Get-Date).ToString('yyyy/MM/dd') + "'"
|
||||
|
||||
$sql = "delete from [VMware_VCenter_VMs] where snapshotdate = $Date;"
|
||||
Invoke-SQLCmd -ServerInstance $SQLServer -Database $DB -Query $sql
|
||||
|
||||
foreach($Server in $Servers) {
|
||||
$ServerName = "'" + $Server.Name + "'"
|
||||
$ServerMemoryMB = $Server.MemoryMB
|
||||
$ServerNumCPU = $Server.NumCPU
|
||||
$ServerHardDiskSizeGB = $Server.HardDiskSizeGB
|
||||
$ServerHost = "'" + $Server.VMHost + "'"
|
||||
$sql ="INSERT INTO [VMware_VCenter_VMs] (ServerName, SnapshotDate, VMName, Memory_MB, Num_VCPU, Disk_MB, ESXHostName) Values ('None', $Date, $ServerName, $ServerMemoryMB, $ServerNumCPU, $ServerHardDiskSizeGB, $ServerHost);"
|
||||
Invoke-SQLCmd -ServerInstance $SQLServer -Database $DB -Query $sql
|
||||
|
||||
}
|
||||
|
||||
$Connection.Close()
|
||||
Stop-Transcript
|
||||
|
||||
Reference in New Issue
Block a user