Pages

Total Pageviews

Tuesday, January 15, 2013

Windows Administration

Get the list of Local Admin on Remote computers 

$Result = @()

foreach($server in (gc .\servers.txt)){


$computer = [ADSI]("WinNT://" + $server + ",computer")

$Group = $computer.psbase.children.find("Administrators")

function getAdmins

{$members = ($Group.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Adspath", ‘GetProperty’, $null, $_, $null)}) -replace ('WinNT://DOMAIN/' + $server + '/'), '' -replace ('WinNT://DOMAIN/', 'DOMAIN\') -replace ('WinNT://', '')
$members}

$Result += Write-Output "SERVER: $server"

$Result += Write-Output ' '
$Result += ( getAdmins )
$Result += Write-Output '____________________________'
$Result += Write-Output ' '
}
$Result > c:\results.txt

Invoke-Item c:\results.txt




Get the User and the export properties to CSV



Get-ADUser -Identity username -Properties * | Select-Object LastName, FirstName, SamAccountName, whenCreated, AccountIsDisabled, Account IsExpired, ParentContainer, @{n='memberOf';e={$_.MemberOf -join ';'}} | Sort-Object LastName | Export-Csv c:\temp\1.csv -NoTypeInformation -Force

 Enable disk cleanup in windows 2008 without restarting the server


Search cleanmgr.exe and cleanmgr.exe.mui Under windows\winsxs and copy the files in place in following folder

Cleanmgr.exe should go in %systemroot%\System32.

Cleanmgr.exe.mui should go in %systemroot%\System32\en-US.

You can now launch the Disk cleanup tool by running Cleanmgr.exe from the command prompt.

Logoff the disconneted dessions 

Following batch file can be used to logoff all the disconnected sessions in wink28


@echo off
:Top
for /f "tokens=1-7 delims=,: " %%a in ('query user ^| find /i "disc"') do if %%d GTR 32 (logoff %%b) else %%e GTR 32 (logoff %%b)
choice /T 120 /C 1 /D 1 /N
goto top




No comments:

Post a Comment