Posts Tagged ‘powershell’

I based this script off of one referenced here : http://blogs.msdn.com/b/emeamsgdev/archive/2012/10/29/outlook-code-importing-bank-holidays-from-an-outlook-hol-based-csv-file.aspx?CommentPosted=true#commentmessage

CSV Format

6011-image_thumb_6a014d4e1

However I modified Adding a Category to the item, as well as adding this to All Users of a AD Group recursively instead of a single user. This will add a list of Holidays to Users Calendars across an organisation. If run again it will not import duplicates and have fields there to delete the duplicate Calendar enteries if needed

The user running this will need the impersonation role setup see this :

New users can then have an email sent to them automatically ( http://blogs.technet.com/b/sukum/archive/2013/04/03/send-welcome-email-to-new-mailbox-users.aspx ) with a .HOL file to run ( P.S. The XML did not work in this , I have to add Lines 6-8 from this http://itnuts.wordpress.com/2013/09/03/exchange-2010-automatic-welcome-message-for-a-new-user/)


https://github.com/pariswells/pariswells.com/blob/master/saveappointmentintoalluserscalendar.ps1
GD Star Rating
loading...
GD Star Rating
loading...

I was trying to get a list of Active Computers on our Network. A DSQuery can give me a list of all computer , and I tried to get an inactive list for 4 weeks and subtract the value , however the Inactive List was not that acurate.

Instead I wanted to Query the PwdLastSet to

I found a few scripts online but they moved the computer accounts to OU’s , and I just needed this for auditing purposes. So I edited the tracked back script

Save the script as script.ps1 then run with .\script -OlderThan 30

param(
    [int] $OlderThan = 20
)
 
try {
    Import-Module ActiveDirectory -ErrorAction Stop -Verbose:$false
} catch {
    Write-Error "Active Directory module failed to Import. Terminating the script. More details : $_"
    exit(1)
}
 
try {
    #Get domain name
    $DomainDN = (Get-ADDomain -ErrorAction Stop).DistinguishedName
    #Get Computers in Domaing
    $Computers = Get-ADComputer -Filter * -Properties PasswordLastSet -SearchBase $DomainDN -ErrorAction Stop
} catch {
    Write-Error "Failed to query active Directory for computers. Exiting the script. More details : $_"
    exit(1)
}
$now = Get-Date
$agedate = (Get-Date).AddDays(-$OlderThan)
 
foreach($Computer in $Computers) {
$ComputerName = $computer.Name
$Computerpwdsetdate = $Computer.PasswordLastSet
 
    #$Computerpwdsetdate
    if($Computerpwdsetdate -lt $agedate) {
 
 
	#Write-Host "Expired $ComputerName"
 
	$computernumber = $computernumber + 1         
    }
 
 
}
 
Write-Host "Total = $computernumber"

 

GD Star Rating
loading...
GD Star Rating
loading...

Recently I rolled out an updated to Update the styles inside Word for Normal.dot. The update only updated the styles and did not change the autotext etc. After the update we wanted to check on a terminal server who had not been updated.

Open powershell and run the follinwg command

Get-ChildItem E:\RoamingProfilePath -Recurse | Where-Object {$_.LastWriteTime -lt “2012-06-23 00:00:00” -and $_.Name -eq “filename.dot“} | Export-Csc “C:\file.csv”

The excel sheet can be pruned for users via their profile path using the excel function

=SUBSTITUTE(SUBSTITUTE(B3,”E:\RoamingProfilePath“,””,1),”\AppData\Roaming\Microsoft\Templates”,””,1)

 

GD Star Rating
loading...
GD Star Rating
loading...

ADUsers&Comps**SolarWinds make a free tool GUI for this : http://downloads.solarwinds.com/solarwinds/Release/FreeTool/SolarWinds-Freetools-MS-Mini-Utilities.zip

*****More AD Cleaup Tools

http://www.adaxes.com/blog/cleanup-active-directory-with-powershell.html

You can run these commands in a command prompt on any DC or PC With Active Directory Tools installed

Time Perioud = Weeks so for example let’s work with 6

How to find the CN or OU Path

Open Active Directory Users and Compuer , Click on View and Advanced Features

Find the OU you need to reference and Click on Properties, Attribute Editor Tab and Copy the distinguishedName 

Inactive

Computer Accounts

Find Old Disabled or Enabled Computer accounts across the whole domain older than 6 weeks

dsquery computer -inactive 6 -limit 0

Powershell Find Only Enabled Computer inactive for 3 Months 

Search-ADAccount -ComputersOnly -AccountInactive -TimeSpan "90" | ?{$_.enabled -eq $True}

Find computer accounts old than 6 weeks and disable

dsquery computer -inactive 6 -limit 0 | dsmod computer -disabled yes

Find Old Computers in a Group CN e.g. if the Icon Looks like this : CN_Group

dsquery computer -inactive 6 -limit 0 CN=Computers,DC=domain,DC=local (Add to stop it going further then the current folder) -scope onelevel

Find Old Computers in a Operation Unit OU e.g. if the Icon Looks like this : OU

dsquery computer -inactive 6 -limit 0 OU=Clients,DC=domain,DC=local (Add to stop it going further then the current folder) -scope onelevel

Query THEN DELETE computer objects which have been inactive for 8 weeks in a specific OU and name starts with PCNAME

dsquery computer "OU=Computers,OU=OUNAME,DC=domain,DC=local" -inactive 8 -name PCNAME* | dsrm -noprompt

User Accounts

Find Old Disable or Enabled User accounts across the whole domain older than 6 weeks

dsquery user domainroot -name * -inactive 6

Powershell Find Only Enabled User inactive for 3 Months 

Search-ADAccount -UsersOnly -AccountInactive -TimeSpan "90" | ?{$_.enabled -eq $True}

Exchange Active User accounts

(Get-MailboxStatistics -Server <exchangeservername> | where {$_.LastLogonTime -gt ((get-date).AddDays(-60))}).count

Find Old User accounts across the whole domain older than 6 weeks and disable 

dsquery user domainroot -name * -inactive 6 | dsmod user -disabled yes

Active

Get-ADUser –filter * -Properties passwordLastSet,whencreated,lastlogondate,Enabled,PasswordNeverExpires | Where { ($_.passwordLastSet –eq $null –or $_.lastlogondate –gt (Get-Date).AddDays(-30)) -and ($_.Name -notlike “*svc*” -and $_.Name -notlike “*Admin*” -and $_.Name -notlike “*test*” -and $_.Name -notlike “*huonit*” -and $_.Name -notlike “*Room*” -notlike “*Mailbox*” -notlike “*Exchange*” -notlike “*Service*” -notlike “*Helpdesk*”) }| Select Name

 

GD Star Rating
loading...
GD Star Rating
loading...