Skip to main content

Posts

Showing posts with the label Powershell

AD-Powershell for Active Directory Administrators

http://social.technet.microsoft.com/wiki/contents/articles/5819.ad-powershell-for-active-directory-administrators.aspx Computer object commands List all computer accounts in a domain Get-ADComputer –Filter {Name –Like "*"} View all computers that are logged in for 90 days to the Active Directory Search-ADaccount -AccountInactive -Timespan 90 -ComputersOnly OR $lastLogon = (get-date).adddays(-90).ToFileTime() Get-ADComputer -filter {lastLogonTimestamp -gt $lastLogon}  Find and delete all disabled Computer accounts in Active Directory Search-ADAccount -AccountDisabled -ComputersOnly | Sort-Object | Remove-ADComputer Find and delete disabled computer accounts from a specific OU Search-ADAccount -AccountDisabled -Searchbase "OU=IT,DC=Contoso,DC=Com" -ComputersOnly | Sort-Object | Remove-ADComputer Find and delete all computer accounts that no longer have signed up since 11/20/2011 to the Active Directory Search-ADAccount -AccountInactive -DateTime "20.11.2011...

Unable to find a default server with Active Directory Web Services running

Install  .Net Framework 3.5 Sp1 Need to install hotfix:   http://support.microsoft.com/kb/969429 http://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=20556 Install Active directory management gateway service (Windows6.0-KB968934) from  http://www.microsoft.com/en-us/download/details.aspx?id=2852  

Create a list of local administrators with PowerShell

1.        Create folder :    C:\Temp 2.        Save a text file with the name servers.txt and add server names 3.        Create a .PS1 file with the name “ Get-LocalGroupMembers . ps1 ”with below PowerShell code: **********************************************************     [ CmdletBinding () ] Param (     [ Parameter (    ValueFromPipeline = $true ,                 ValueFromPipelineByPropertyName = $true                 ) ]     [ string []]     $ComputerName = $env:ComputerName ,     [ Parameter () ]     [ string ]     $LocalGroupName = "Administrators" ,   ...

Powershell script to remote reboot servers

$RebootList = Get-Content RebootServers.txt foreach( $Rsrv in $RebootList ) { Write-host “Issuing remote reboot command to $Rsrv” # Command to force reboot the remote server (gwmi Win32_OperatingSystem -ComputerName $Rsrv).Win32Shutdown (6) } That’s all. You can replace the  (6)  with any of the following: 0 = Log off 1 = Shutdown 2 = Reboot 8 = Power off 4 = Forced log off 5 = Forced shutdown 6 = Forced reboot 12 = Forced power off *******************************************   Note: 1. Create a text file – in this case RebootServers.txt 2. Populate RebootServers.txt with the names of the servers you want to reboot. One server name per line. Make sure there are no blank lines after the last server name. 3. Save the RebootServers.txt file in the same directory as the PS1 script (like the one you created – RemoteShutDown.ps1) 4. Run the script to reboot servers.