ping with timestamp in powershell


ping -t 8.8.8.8 | Foreach{“{0} – {1}” -f (Get-Date),$_} > c:\ping_log.txt

Advertisements

Cluster WMI query Test


Set-ExecutionPolicy unrestricted

cls

If(import-module failoverclusters)
{

Write-Host “Imported Cluster module”

}

Write-Host “Getting the cluster nodes…” -NoNewline
$nodes = Get-ClusterNode
Write-host “Found the below nodes ”
Write-host ” ”
$nodes
Write-host “”
Write-host “Running the WMI query….”
Write-host ” ”
ForEach ($Node in $nodes)
{
Write-Host -NoNewline $node

if($Node.State -eq “Down”)
{

Write-Host -ForegroundColor White ” : Node down skipping”
}

else
{

Try
{
#success

$result = (get-wmiobject -class “MSCluster_CLUSTER” -namespace “root\MSCluster” -authentication PacketPrivacy -computername $Node -erroraction stop).__SERVER
Write-host -ForegroundColor Green ” : WMI query succeeded ”
}
Catch
{

#Failure

Write-host -ForegroundColor Red -NoNewline ” : WMI Query failed ”
Write-host “//”$_.Exception.Message
}
}

}

# save as .ps1

user login time track


echo %username%,%date:~7,2%-%date:~4,2%-%date:~10,4%,%time:~0,5% >> \\10.10.1.42\Daily_Attendance\Check1.csv

Note : save as filename.bat and store in netlogon folder

Logon script

Posted in Script. 1 Comment »

Unlock Active-Directory Users Account via PowerShell


Import Module Active-Directory

Run command Search-ADAccount – LockedOut

Search-ADAccount -LockedOut

Search and unlock all account in domain

Search-ADAccount -LockedOut | Unlock-ADAccount
Limit the search to a specific OU,

Search-ADAccount -SearchBase “OU=Users,OU=Skepper,DC=MyDomain,DC=net” -LockedOut | Unlock-ADAccount
Limit search to Users Only

Search-ADAccount -UsersOnly -LockedOut | Unlock-ADAccount

Active directory country code and country update


Import-Csv E:\users.csv | foreach {set-aduser -Identity $_.samaccountname -Replace @{c=”AU”;co=”Australia”;countrycode=36}}

Note: users.csv excel sheet users samaccount details.

How to Get an Active Directory OU Permissions Report

How to Find Account Lockout Source


Import-Module ActiveDirectory
$UserName = Read-Host “Please enter username”
#Get main DC
$PDC = (Get-ADDomainController -Filter * | Where-Object {$_.OperationMasterRoles -contains “PDCEmulator”})
#Get user info
$UserInfo = Get-ADUser -Identity $UserName
#Search PDC for lockout events with ID 4740
$LockedOutEvents = Get-WinEvent -ComputerName $PDCEmulator.HostName -FilterHashtable @{LogName=’Security’;Id=4740} -ErrorAction Stop | Sort-Object -Property TimeCreated -Descending
#Parse and filter out lockout events
Foreach($Event in $LockedOutEvents)
{
If($Event | Where {$_.Properties[2].value -match $UserInfo.SID.Value})
{

$Event | Select-Object -Property @(
@{Label = ‘User’; Expression = {$_.Properties[0].Value}}
@{Label = ‘DomainController’; Expression = {$_.MachineName}}
@{Label = ‘EventId’; Expression = {$_.Id}}
@{Label = ‘LockoutTimeStamp’; Expression = {$_.TimeCreated}}
@{Label = ‘Message’; Expression = {$_.Message -split “`r” | Select -First 1}}
@{Label = ‘LockoutSource’; Expression = {$_.Properties[1].Value}}
)

}}

# Refer :https://www.netwrix.com/how_to_find_account_lockout_source.html

%d bloggers like this: