shutdown.exe /r /t 5 /f /m \\SERVER1
shutdown.exe /r /t 5 /f /m \\SERVER2
shutdown.exe /r /t 5 /f /m \\SERVER3
shutdown.exe /r /t 5 /f /m \\SERVER4
shutdown.exe /r /t 5 /f /m \\SERVER5
Category Archives: Scripts
Server Reboot Batch File
SCOM 2012 R2 Close All Alerts Script
This script will close all alerts in the console.
$RMS = “RMSNAME”
Add-PSSnapin “Microsoft.EnterpriseManagement.OperationsManager.Client”
Set-Location “OperationsManagerMonitoring::”
New-ManagementGroupConnection -ConnectionString:$RMS
Set-Location $RMS
$alerts = get-alert |where-object {$_.ResolutionState -eq 0}
foreach($alert in $alerts)
{
resolve-alert -comment “Resolving Alert” -Alert $alert
}
SCOM 2012 Reminder Alerts – PowerShell Script to Update Alert Resolution
I use this to regenerate reminder alerts for certain alerts. This script will trigger for alerts with “Disk” in the name.
$MS = “yourRMS.yourCO.com”
$connect = New-SCOMManagementGroupConnection –ComputerName $MS
Get-SCOMAlert -criteria ‘ResolutionState = “0” AND Severity = “2”‘ |
Where-Object {$_.Name -like “*disk*” -and $_.IsMonitorAlert -eq $true} |
Set-SCOMAlert -ResolutionState 0 |
out-null
PowerShell Script Close All SCOM Alerts 2007R2
DOWNLOAD: http://www.scomgod.com/wp-content/uploads/2014/06/CloseAlerts.zip
$RMS = “YOUR-RMS-NAME”
Add-PSSnapin “Microsoft.EnterpriseManagement.OperationsManager.Client”
Set-Location “OperationsManagerMonitoring::”
New-ManagementGroupConnection -ConnectionString:$RMS
Set-Location $RMS
$alerts = get-alert |where-object {$_.ResolutionState -eq 0}
foreach($alert in $alerts)
{
resolve-alert -comment “Resolving Alert” -Alert $alert
}
AD Password Expiration Report Script
Can someone make this PowerShell? :) It works great as it is but CDO is such a drag. Enjoy!
‘Script to list all password that will list
‘all accounts with passwords expiring within the next 30 days
On Error Resume Next
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
Const ONE_HUNDRED_NANOSECOND = .000000100
Const SECONDS_IN_DAY = 86400
DayCount = 30
OUtoSearch = “OU=NY”
Set OFSO = CreateObject(“Scripting.FileSystemObject”)
nof = “E:\logs\AcctsToExp.txt”
If OFSO.FileExists (nof) Then
OFSO.DeleteFile(“E:\logs\AcctsToExp.txt”)
End If
If not OFSO.FileExists (nof) Then
Set objFile = OFSO.CreateTextFile(nof)
End If
‘Const ForAppending = 8
‘Set objFile = OFSO.OpenTextFile (nof, ForAppending)
objFile.WriteBlankLines (1)
objFile.WriteLine “Passwords due to expire in the” & ” ” & OUtoSearch & ” OU” & ” during the next ” & DayCount & ” Days” & vbTab & vbTab & Now
objFile.WriteLine
Set objConnection = CreateObject(“ADODB.Connection”)
objConnection.Open “Provider=ADsDSOObject;”
Set objCommand = CreateObject(“ADODB.Command”)
objCommand.ActiveConnection = objConnection
objCommand.CommandText = “
“userAccountControl,distinguishedName,sAMAccountName,cn;subtree”
‘objCommand.CommandText = “
‘”userAccountControl,distinguishedName,sAMAccountName,cn;subtree”
‘-objCommand.CommandText = “
‘- “;userAccountControl,distinguishedName,sAMAccountName;subtree”
objCommand.Properties(“Page Size”) = 4000
objCommand.Properties(“Timeout”) = 90
objCommand.Properties(“Cache Results”) = True
Set objRecordSet = objCommand.Execute
intCounter = 0
‘wscript.echo objRecordset.RecordCount
If objRecordset.RecordCount > 0 then
objRecordset.MoveFirst
end if
Do Until objRecordset.EOF
Uname = objRecordset.Fields(“distinguishedName”)
ShName = objRecordset.Fields(“sAMAccountName”)
Namelenght = Len(ShName)
SpacesToAdd = 15 – NameLenght
DisplayName = ShName & Space(SpacesToAdd)
Set objUser = GetObject(“LDAP://” & Uname )
intUserAccountControl = objUser.Get(“userAccountControl”)
If intUserAccountControl And ADS_UF_DONT_EXPIRE_PASSWD Then
‘objFile.WriteLine DisplayName & vbTab & vbTab & “The password does not expire.”
Else
dtmValue = objUser.PasswordLastChanged
intTimeInterval = Int(Now – dtmValue)
Set objDomain = GetObject(“LDAP://DC=myco,DC=com”)
Set objMaxPwdAge = objDomain.Get(“maxPwdAge”)
If objMaxPwdAge.LowPart = 0 Then
objFile.WriteLine DisplayName & vbTab & vbTab & “The Maximum Password Age is set to 0, Password does not expire.”
Else
dblMaxPwdNano = Abs(objMaxPwdAge.HighPart * 2^32 + objMaxPwdAge.LowPart)
dblMaxPwdSecs = dblMaxPwdNano * ONE_HUNDRED_NANOSECOND
dblMaxPwdDays = Int(dblMaxPwdSecs / SECONDS_IN_DAY)
End If
If intTimeInterval >= dblMaxPwdDays Then
objFile.WriteLine DisplayName & vbTab & vbTab & “The password has expired.”
Else
If Int((dtmValue + dblMaxPwdDays) – Now) < DayCount Then
objFile.WriteLine DisplayName & vbTab & vbTab & "The password will expire on " & DateValue(dtmValue + dblMaxPwdDays) & " (" & Int((dtmValue + dblMaxPwdDays) - Now) & " days from today)."
End If
End If
End If
intCounter = intCounter + 1
objRecordset.MoveNext
Loop
objConnection.Close
objfile.close
OFSO.Close
'====================================================
'EMAIL Routine
'====================================================
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Password Expiration Report For New York Office"
objMessage.From = "PASSWORD-EXPIRATION@myco.com"
objMessage.To = "SupportSupervisors@myco.com"
objMessage.TextBody = "Password expiration for New York Attached"
objMessage.AddAttachment "e:\logs\acctstoexp.txt"
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.myco.com"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
SCOM RunAs Account Fixer PowerShell Script!
This is an awesome unpublished PowerShell script from Microsoft that will give you a menu to reset your RunAs accounts.
Other people have had this issue: http://social.technet.microsoft.com/Forums/en-US/operationsmanagerdeployment/thread/005e9f0d-476e-4212-b4fb-6e26d7dafdbb
Download PowerShell Script: Fix-Run-As-Accounts-SCOM-2013-SCOM-GOD
File Share Check and Email Script
I had to implement a script to check a file share for a client recently. This worked like a charm.
Option Explicit
‘Set Dimension
DIM fso
DIM objMessage
‘Set Object
Set fso = CreateObject(“Scripting.FileSystemObject”)
Function SendMail(strRecipient, strHeader)
Set objMessage = CreateObject(“CDO.Message”)
objMessage.Subject = strHeader
objMessage.From = “share-alert@myco.com”
objMessage.To = strRecipient
objMessage.TextBody = “Problem with file share!”
objMessage.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/sendusing“) = 2
objMessage.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserver“) = “SMTP.myco.com”
objMessage.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserverport“) = 25
objMessage.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout“) = 60
objMessage.Configuration.Fields.Update
objMessage.Send
Set objMessage = Nothing
End Function
‘Create Condition
If (fso.FileExists(“\\server\share\test.txt“)) Then
WScript.Quit()
Else
‘Alert User
Sendmail “alert@myco.com”,”ALERT: Share needs attention!”
End If
‘Exit Script
WScript.Quit()
Recent Comments