Get-User -RecipientTypeDetails UserMailbox | where {$_.UseraccountControl -notlike “*accountdisabled*”} | Select Name,WindowsEmailAddress,SAMAccountName,FirstName,LastName | Export-Csv c:\1\contacts.txt -Encoding unicode
Import-Csv "C:\1\contacts.txt" | ForEach-object { New-MailContact -Name $_.Name -externalEmailAddress $_.WindowsEmailAddress -Alias $_.SAMAccountName -FirstName $_.FirstName -LastName $_.LastName -OrganizationalUnit "Contacts" }
$scriptBlock={
$wmi = Get-WmiObject -Class Win32_OperatingSystem
($wmi.ConvertToDateTime($wmi.LocalDateTime) – $wmi.ConvertToDateTime($wmi.LastBootUpTime)).TotalHours
}
$UpTime = @()
Import-Module ActiveDirectory
Get-ADComputer -Filter 'ObjectClass -eq "Computer"' -SearchBase "OU=someOu,DC=someDomain,DC=someTld" -SearchScope Subtree `
| % { $Uptime += `
(New-Object psobject -Property @{
"ComputerName" = $_.DNSHostName
"UpTimeHours" = (Invoke-Command -ComputerName $_.DNSHostName -ScriptBlock $scriptBlock)
}
)
}
$UpTime | Where-Object {$_.UpTimeHours -ne ""} | sort-object -property @{Expression="UpTimeHours";Descending=$false} | `
Select-Object -Property ComputerName,@{Name="UpTimeHours"; Expression = {$_.UpTimeHours.ToString("#.##")}} | `
Format-Table -AutoSize