create csv with below format:
Expire.csv
User,Expiration_date
User1,12-15-2015
User2,12-01-2015
User3,3-30-2015
User4,1-3-2016
use below script:
I will try to help you complete your tough assessments and tricks to get data from system with help of scripts.
create csv with below format:
Expire.csv
User,Expiration_date
User1,12-15-2015
User2,12-01-2015
User3,3-30-2015
User4,1-3-2016
use below script:
Import-Csv 'expire.csv' | ForEach-Object { Set-ADUser -Identity $_.User -AccountExpirationDate $([datetime]$_.Expiration_date) }
$server = Get-Content C:\Users\SCCM_admin\Desktop\servers.txt
foreach ($ser in $server){
Write-Host "Getting info for server $ser" -ForegroundColor Green
Invoke-Command -ComputerName $ser -ScriptBlock {
$updateInfoMsg = "Windows Update Status: `n";
$UpdateSession = New-Object -ComObject Microsoft.Update.Session;
$UpdateSearcher = $UpdateSession.CreateupdateSearcher();
$Updates = @($UpdateSearcher.Search("IsAssigned=1 and IsHidden=0 and IsInstalled=0 and Type='Software'").Updates);
$Found = ($Updates | Select-Object -Expand Title);
$WindowsUpdateInfo = New-Object -ComObject Microsoft.Update.AutoUpdate;
$lastchecked = $WindowsUpdateInfo.Results;
#$WindowsUpdateInfo.Results
If ($Found -eq $Null) {
$updateInfoMsg += "Up to Date";
Write-host "Last checked:" ($WindowsUpdateInfo.Results).LastSearchSuccessDate -ForegroundColor Cyan
} Else {
Write-host "Last checked:" ($WindowsUpdateInfo.Results).LastSearchSuccessDate -ForegroundColor Cyan
$Found = ($Updates | Select-Object -Expand Title) -Join "`n";
$updateInfoMsg += "Updates available:`n";
$updateInfoMsg += $Found;
}
Return $updateInfoMsg, "`n";
Write-Host $updateInfoMsg
}
}
$TestCSVFile=”C:\Temp\DCPatchingStatus.CSV”
Remove-item $TestCSVFile -ErrorAction Ignore
$ThisStr=”Server,Connection,Command Status, Number of Updates Applied Since last 30 Days, Last Update Date,Final Status”
Add-Content “$TestCSVFile” $ThisStr
$GDCList = "C:\Patching\servers.txt"
$TotNo=0
$ItemCount=0
$TestText = “”
$TestStatus=””
$SumVal = “”
$AnyGap = “No”
$ErrorOrNot = “No”
$AnyOneOk = “No”
$TotDCsInError = 0
Foreach ($ItemName in Get-Content “$GDCList”)
{
$DCConError = “Ok”
$DCConStatus = “Ok”
$ProceedOrNot = “Yes”
$Error.Clear()
$AllServices = Get-WMIObject Win32_Service -computer $ItemName
IF ($Error.Count -ne 0)
{
$ProceedOrNot = “No”
$TotDCsInError++
$DCConError = $Error[0].Exception.Message
#$FinalStatusNow = “Not OK”
$FinalSTR = $ItemName+”,Error: $DCConError"
Add-Content “$TestCSVFile” $FinalSTR
}
IF ($ProceedOrNot -eq “Yes”)
{
$ComConError=”Ok”
$Error.Clear()
$TotHotFixes = Get-HotFix -ComputerName $ItemName | Where-Object {$_.Installedon -gt ((Get-Date).Adddays(-30))}
$AnyOneOk=”Yes”
$TotHF = $TotHotFixes.Count
$FinalStatusNow = “OK”
IF ($TotHF -eq 0)
{
$IsHFOk = “No”
$AnyGap = “Yes”
$FinalStatusNow = “WARNING: Not up to date”
}
$TotHotFixes = Get-HotFix -ComputerName $ItemName | ?{ $_.installedon } | sort @{e={[datetime]$_.InstalledOn}} | select -last 1
$LastNowAll = $TotHotFixes.InstalledOn.Date
IF ($AnyGap -eq “Yes”)
{
$TotNo++
}
$ThisSTr = $ItemName+”,”+$DCConError+”,”+$ComConError+”,”+$TotHF+”,”+$LastNowAll+”,”+$FinalStatusNow
Add-Content “$TestCSVFile” $ThisStr
}
else
{
$ComConError = $Error[0].Exception.Message
$FinalSTR = $ItemName+”,$DCConError #,”+$ComConError
#Add-Content “$TestCSVFile” $FinalSTR
}
}
$OthText = “”
IF ($TotDCsInError -ne 0)
{
$OthText = “Some server have not been checked due to connectivity or command issues.”
}
IF ($AnyGap -eq “Yes”)
{
$TestText = “Some servers have not been patched. $OthText”
$SumVal = $TotNo
$TestStatus=”High”
}
IF ($AnyGap -eq “No”)
{
$TestText = “All Servers have been patching since last 30 days. Please load and check result to ensure Last Pathing Date is current. $OthText”
$SumVal = “”
$TestStatus=”Passed”
IF ($AnyOneOk -eq “No”)
{
$TestText = “Error Executing Dynamic Pack.”
$SumVal = “”
$TestStatus=”Completed with Errors.”
}
}
$STR = $ADTestName +”,”+$TestStartTime+”,”+$TestStatus+”,”+$SumVal +”,”+$TestText
Extract Data From JustDial using Selenium Let us see how to extract data from Justdial using Selenium and Python. Justdial is a company th...