WWN’s on Windows Server 2012 R2 using PowerShell.


Get-InitiatorPort | Select-Object -Property PortAddress | Format-Table -AutoSize
Advertisements

Export AD user attributes


csvde -d “dc=dxc,dc=local” -f dxc.csv -s dxc.local -t 389 -r “(&(objectClass=person)(!objectclass=computer))” -l “DN, cn, co, company, department, description, displayName, facsimileTelephoneNumber, givenName, homePhone, l, mail, mobile, objectClass, pager, physicalDeliveryOfficeName, sAMAccountName, sn, streetAddress, title, userAccountControl, userPrincipalName, manager, extensionAttribute1, extensionAttribute2, extensionAttribute3, extensionAttribute8, extensionAttribute12, info, target Address, lastLogonTimestamp, employeeType, accountExpires, Manager”

 

CPU,Memory usage


GC C:\server.txt | % {
$Comp = $_
If (Test-Connection $Comp -Quiet){
$Mem = GWMI -Class win32_operatingsystem -computername $COMP
New-Object PSObject -Property @{
Server = $Comp
“CPU usage” = “$((GWMI -ComputerName $COMP win32_processor | Measure-Object -property LoadPercentage -Average).Average) %”
“Memory usage” = “$(“{0:N2}” -f ((($Mem.TotalVisibleMemorySize – $Mem.FreePhysicalMemory)*100)/ $Mem.TotalVisibleMemorySize)) %”
“Total FreeSpace” = “$(“{0:N2}” -f ((Get-WmiObject -Class win32_Volume -ComputerName $COMP -Filter “DriveType = ‘3’” | Measure-Object -property FreeSpace -Sum).Sum /1GB)) GB”
}
}
Else{
“” | Select @{N=”Server”;E={$Comp}},”CPU usage”,”Memory usage”,”Total FreeSpace”
}
}| Select Server,”CPU usage”,”Memory usage”,”Total FreeSpace” |
Export-Csv C:\report.csv -nti

DHCP backup


$hostname = $(Get-WmiObject Win32_Computersystem).name

$date = get-date -f ‘dd-MM-yyyy’

#Deletes backup folder items older than 7 days.

$TargetUNC2 = “\\172.16.196.26\c$\DHCP_Backup\Backup”

Get-ChildItem $TargetUNC2 | where {$_.Lastwritetime -lt (date).adddays(-7)} | Remove-Item remove-item -ErrorAction SilentlyContinue -Confirm:$false

netsh dhcp server backup “C:\DHCP_Backup\Backup\$hostname-$date”

Compuer lastlogontimestamp


Get-ADcomputer -SearchBase “OU=Laptops,OU=Computers,OU=Rishra,OU=India,DC=dxc,DC=local” -Properties * -Filter * | select name, operatingSystem, @{Name=”Stamp”; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}} | Export-Csv “C:\Desktop\321.csv”

AD replication report


repadmin /showrepl * /csv >D:\ADReplication.txt

FInd IE Version on Remote Computers using PowerShell


Function IEVersion {
$Prop = [ordered]@{}
$ComputerName = Cat C:\computers.txt
$ErrorActionPreference = “Stop”
foreach ($computer in $ComputerName)
{

Try {
$Syntax = GWMI win32_operatingsystem -cn $computer
$Prop.Computername = $Syntax.CSName
$Prop.OperatingSystem = $Syntax.Caption
$Prop.ServicePack = $Syntax.CSDVersion
$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(‘LocalMachine’, $computer)
$RegKey= $Reg.OpenSubKey(“SOFTWARE\\Microsoft\\Internet Explorer”)
$Prop.IEVersion = $Regkey.GetValue(“svcVersion”)

New-Object PSObject -property $Prop
}

Catch
{

Add-Content “$computer is not reachable” -path $env:USERPROFILE\Desktop\UnreachableHosts.txt
}
}
}
#HTML Color Code
#http://technet.microsoft.com/en-us/librProp/ff730936.aspx
$a = “<!–mce:0–>”
IEVersion | ConvertTo-HTML -head $a -body ”

IE Version

” |
Out-File $env:USERPROFILE\Desktop\DomainController.htm #HTML Output
Invoke-Item $env:USERPROFILE\Desktop\DomainController.htm

%d bloggers like this: