Sunday, July 30, 2017

Last System/Computer BootUpTime

Use below code to show up system/server LastBootUptime

Get-CimInstance -ClassName win32_operatingsystem -ComputerName Server01,Server02,Server03 | select csname, lastbootuptime | SORT CSNAME

OR

Get-CimInstance -ClassName win32_operatingsystem -ComputerName (Get-Content D:\serverS.TXT) | select csname, lastbootuptime | SORT CSNAME | ft -AutoSize

OR

gwmi win32_operatingsystem -comp Server01,Server02,Server03 | select PSComputerName, @{n='BootTime';e={$_.ConvertToDateTime($_.LastBootupTime)}}

Output:
 

Get Active Sync Mobile Device Statistics Report - O365

Here we are with PS code to list and report the Active Sync Mobile Device Statistics which help us to remove unused device for important user.

Sample Report:

===================Start of Script==================
#Connecting to O365 Powershell
#Use your own parameter here to connect O365.

$date = date

# Start of script code Get-MobileDeviceStatistics

Import-Csv "C:\test\MemberList.csv" | `
foreach { Get-MobileDeviceStatistics -Mailbox $_.Alias} | `
Select-Object -Property {$input},LastSyncAttemptTime,LastSuccessSync,DeviceType,DeviceID,DeviceModel,DeviceFriendlyName,DeviceOS,Status | `
Export-Csv "C:\test\ActiveSyncData.csv" -NoTypeInformation

#>
#End of script code Get-MobileDeviceStatistics

#Importing csv File (ActiveSyncData - MobileDeviceStats).
$csvfile = Import-Csv "C:\test\ActiveSyncData.csv" |`
 select @{l='DisplayName';e={$_.'$input'.split("=};")[1]}},LastSyncAttemptTime,@{l='LastSuccessSync';e={([datetime]$_.LastSuccessSync)}},DeviceType,DeviceID,DeviceModel,DeviceFriendlyName,DeviceOS,Status |`
 sort DisplayName

$Result = @()

foreach ($user in $csvfile)
{
$Temp = $user

$Result += [PSCustomObject] @{

User = "$($User.DisplayName)"
LastSyncAttemptTime = "$($USer.LastSyncAttemptTime)"
LastSuccessSync = "$($User.LastSuccessSync)"
DeviceType = "$($User.DeviceType)"

DeviceID = "$($User.DeviceID)"
DeviceModel = "$($User.DeviceModel)"
DeviceFriendlyName = "$($User.DeviceFriendlyName)"
DeviceOS = "$($User.DeviceOS)"
Status = "$($User.Status)"
                             }
$Outputreport = "<HTML><TITLE> ActiveSync Mobile Device Report</TITLE>
                     <BODY background-color:Cornsilk>
                     <font color =""#DC143C"" face=""Microsoft Tai le"">
                     <H2> ActiveSync Device Statistics as on $date </H2></font>
                     <font color =""#B8860B"" face=""Microsoft Tai le"">
                     <H2> ActiveSync/Mobile Device Statistics </H2></font>
                     <p font size=20><font face = 'calibri'> Note: Below statistics are to highlight all registered devices. <br>Detailed device statistics is attached as an .csv file.</br></font></p>
                     <p font size=20><font face = 'calibri'> Thresholds as below: <br><font face = 'calibri'><small><i> <font color = '#FF0000'>RED </font> = Not Synced since last <b>14 days</b> <br> <font color ='#008000'>GREEN </font>= Synced in last <b>14 days</b> </i></small></br></font></font></p>
                     <Table border=2 cellpadding=2 cellspacing=2>
                     <TR bgcolor=DarkGoldenRod align=center>
                     <TD><B><font face='calibri'>User</B></TD></font>
                     <TD><B><font face='calibri'>LastSyncAttemptTime</B></TD></font>
                     <TD><B><font face='calibri'>LastSuccessSync</B></TD></font>
                     <TD><B><font face='calibri'>DeviceType</B></TD></font>
                     <TD><B><font face='calibri'>DeviceID</B></TD></font>
                     <TD><B><font face='calibri'>DeviceModel</B></TD></font>
                     <TD><B><font face='calibri'>DeviceFriendlyName</B></TD></font>
                     <TD><B><font face='calibri'>DeviceOS</B></TD></font>
                     <TD><B><font face='calibri'>Status</B></TD></font>"
Foreach($Entry in $Result)
{
if([datetime]$Entry.LastSuccessSync -lt (Get-Date).AddDays(-14)) {$Cdrivecolor="OrangeRed"}`
else{$Cdrivecolor="Chartreuse"}
$Outputreport += "<TR bgcolor=BlanchedAlmond>"
$Outputreport += "<TD><font face='calibri'>$($Entry.User)</TD></font>
<TD align=center> <font face='calibri'>$($Entry.LastSyncAttemptTime)</TD></font>
<TD align=center bgcolor = $Cdrivecolor><font face='calibri'>$($Entry.LastSuccessSync)</TD></font>
<TD align=center><font face='calibri'>$($Entry.DeviceType)</TD></font>
<TD align=center><font face='calibri'>$($Entry.DeviceID)</TD></font>
<TD align=center><font face='calibri'>$($Entry.DeviceModel)</TD></font>
<TD align=center><font face='calibri'>$($Entry.DeviceFriendlyName)</TD></font>
<TD align=center><font face='calibri'>$($Entry.DeviceOS)</TD></font>
<TD align=center><font face='calibri'>$($Entry.Status)</TD></font>"
          }
          $Outputreport += "</Table></BODY></HTML>"
          }
$body =$outputreport

$Outputreport | out-file "C:\test\ActiveSyncMobDashboard.htm"

# Sending Email
$Recipient = "EmailAddress@domain.com"
$FromAddress = "EmailAddress@domain.com"
$SMTPAddress = 'domain.com'
Send-MailMessage -To $Recipient -From $FromAddress -Subject "Users ActiveSync Device status $date" -SmtpServer $SMTPAddress -body $body -BodyAsHtml `
-attachments "C:\test\ActiveSyncData.csv"
#>
===================END of a Script=======================

Saturday, July 4, 2015

Get-DistributionGroup - Restricted Groups - AcceptsMessagesOnlyFrom*

If there anything to explain as how one can get the restricted distribution groups with easily readable property containing a string of users, below would be the script for you. Try :)


Get-DistributionGroup -ResultSize Unlimited | where{$_.AcceptMessagesOnlyFromSendersOrMembers -ne $null} | select Name,@{Name="AcceptMessagesOnlyFromSendersOrMembers";Expression={[string]::join(";",($_.AcceptMessagesOnlyFromSendersOrMembers| foreach {$_.name }) )}},@{Name="AcceptMessagesOnlyFrom";Expression={[string]::join(";",($_.AcceptMessagesOnlyFrom| foreach {$_.name }) )}},@{Name="AcceptMessagesOnlyFromDLMembers";Expression={[string]::join(";",($_.AcceptMessagesOnlyFromDLMembers| foreach {$_.name }) )}},DisplayName,SamAccountName,PrimarySmtpAddress,OrganizationalUnit,@{n="EmailAddresses";e={$_.EmailAddresses}},@{Name="ManagedBy";Expression={[string]::join(";",($_.ManagedBy | foreach {$_.name }) )}},GroupType | Export-Csv C:\RestrictedDLsReport.csv -NoTypeInformation

:)

Monday, February 23, 2015

Add / Remove user in BookInPolicy / ResourceDelegate - Exchange 2013


Add / Remove user in BookInPolicy / ResourceDelegate - Exchange 2013 powershell

When we create a function of ResourceDelegate, below will be the effect:

#user gets added to calendar folder with access permissions as {Editor}
#user gets added to ResourceDelegates and not in BookInPolicy.

To add Calendar Resource Delegate we can use below function which creates a cmdlet ‘Add-CalendarResourceDelegate’ in powershell:

function Add-CalendarResourceDelegate {
Param(
$RoomName
, $newDelegate
)
$resourceDelegates = (Get-CalendarProcessing -Identity $RoomName).ResourceDelegates
$resourceDelegates += $newDelegate
Set-CalendarProcessing -Identity $RoomName -ResourceDelegates $resourceDelegates
}

CMD syntax:

Add-CalendarResourceDelegate -Identity $Roomname "MeetingRoom@Test.com" -newDelegate UserID9


To Remove All Users from ResourceDelegate:

Set-CalendarProcessing -Identity "MeetingRoom@Test.com" -ResourceDelegates $null

  
===========================================================

When we use function of Bookinpolicy below will be the effect:
#user gets added to bookinpolicy and current users will be retained.
#user gets added to calendar folder with access permissions as {LimitedDetails}

To add user in Calendar BookIn Policy we can use below function which creates a ‘Add-CalendarBookInPolicy cmdlet in powershell:

function Add-CalendarBookInPolicy {
Param(
$roomName
, $newUser
)
$bookInPolicy = (Get-CalendarProcessing -Identity $roomName).BookInPolicy
$bookInPolicy += $newUser
Set-CalendarProcessing -Identity $roomName -BookInPolicy $bookInPolicy
}


CMD syntax:
Add-CalendarBookInPolicy -Identity $Roomname "MeetingRoom@Test.com" -newUser UserID


To Remove All Users from BookinPolicy:
Set-CalendarProcessing -Identity "MeetingRoom@Test.com"  -BookInPolicy $Nul


To Remove Single User from ResourceDelegate:
function Remove-CalendarResourceDelegate {
Param(
$roomName
, $delegateToRemove
)
$resourceDelegates = (Get-CalendarProcessing -Identity $roomName).ResourceDelegates
$delegateToRemoveIdentity = (Get-Mailbox $delegateToRemove).Identity
$resourceDelegates.Remove($delegateToRemoveIdentity)
Set-CalendarProcessing -Identity $roomName -ResourceDelegates $resourceDelegates
}

#CMD syntax:
Remove-CalendarResourceDelegate -roomName “MeetingRooms@Test.com” -delegateToRemove User1

Note: Custom functions/cmdlet are only available until the current session is active. Next time when you start EMS, again we have to create function/cmdlet. To make it persistent need to write some other codes.

Wednesday, November 5, 2014

PING PONG :)


PING PONG :)
Below script will display the result on console.


 $PingMachines = Gc "C:\MachineList.txt"

ForEach($MachineName In $PingMachines)

{$PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$MachineName'" |

Select-Object StatusCode

If ($PingStatus.StatusCode -eq 0)

{Write-Host $MachineName -Fore "Green"}

Else

{Write-Host $MachineName -Fore "Red"}}

 

Note: copy and paste the above script into text file and save it as Pingclient.ps1

 
Below script will out the file in .csv format.

 

Get-Content "C:\ MachineList.txt" | ForEach-Object {

if(Test-Connection -ComputerName $_ -Quiet -Count 1) {

New-Object -TypeName PSCustomObject -Property @{

VMName = $_

'Ping Status' = 'Ok'

}

} else {

New-Object -TypeName PSCustomObject -Property @{

VMName = $_

'Ping Status' = 'Powered OFF'

}

}

} | Export-Csv -Path "C:\PingStatus.csv" –NoTypeInformation

 

Note: copy and paste the above script into text file and save it as Pingclients.ps1

Friday, October 24, 2014

Get Installed Patches – Automatic Services on remote servers

Get Installed Patches and All Services which are set Automatic on remote servers

If you ever want to know what patches have been installed on remote clients/servers you would require the below powershell script.

Local Commands:

Get-WmiObject Win32_QuickFixEngineering| Where-Object {$_.installedon -match "MM/DD/YYYY"} | Select-object CSName,Description,HotFixID,InstalledOn,InstalledBy,Caption | Export-Csv -Path Report.csv -NoTypeInformation


Remote Commands:

FullList:-
Get-WmiObject Win32_QuickFixEngineering -Computer (Get-Content –path Servers.txt)|Select-object CSName,Description,HotFixID,InstalledOn,InstalledBy,Caption | Export-Csv -Path C:\Report.csv –NoTypeInformation
InstalledOn Date Report:-
Get-WmiObject Win32_QuickFixEngineering -Computer (Get-Content –path C:\Servers.txt) | Where-Object {$_.installedon -match "MM/DD/YYYY"} | Select-object CSName,Description,HotFixID,InstalledOn,InstalledBy,Caption | Export-Csv -Path Report.csv -NoTypeInformation

GreaterThan-Date Report:-
Get-WmiObject Win32_QuickFixEngineering -Computer (Get-Content –path C:\ Servers.txt) | Where-Object {$_.installedon -GT "MM/DD/YYYY"} | Select-object CSName,Description,HotFixID,InstalledOn,InstalledBy,Caption | Export-Csv -Path Report.csv -NoTypeInformation

GT Sort by Date:
Get-WmiObject Win32_QuickFixEngineering -Computer (Get-Content –path C: \Servers.txt) | Where-Object {$_.installedon -GT "MM/DD/YYYY"} | Select-object CSName,Description,HotFixID,InstalledOn,InstalledBy,Caption | Sort-Object InstalledOn -Descending | Export-Csv -Path c:\Report.csv -NoTypeInformation

Check the Windows services are in “Running” states which are set to “Auto”.

Get-WmiObject Win32_Service -ComputerName (Get-content " Servers.txt") |where {($_.startmode -like "*auto*") -and ($_.state -notlike "*running*")}| select SystemName,DisplayName,Name,StartMode,State| Export-csv –path “C:\ Services_Report.csv” –NoTypeInformation

Tuesday, December 24, 2013

Disable Schema Master to replicate changes to other Domain Controllers while extending Schema

How to Disable Schema Master to avoid replicate changes to other Domain Controllers while extending Schema?

Time may come when you want to extend the Schema Master while you are Installing Exchange Server.
And don't want to Replicate until the Installation is successful. You may go for Isolating the Schema master by disabling its ability to replicate changes to other DC's in forest.

This can by done by executing the command :
repadmin /options +DISABLE_OUTBOUND_REPL

Once the outbound replication is halted you can proceed with extending schema and re-enable once the installation is successful. On other side, if Schema master fails you simply shut down the server, wipe it and seize the schema role on another DC.

Refer to the below Helpful commands as well:

  • To disable outbound replication on a domain controller, enter the following:
                c:\> repadmin /options +DISABLE_OUTBOUND_REPL

  • To re-enable outbound replication, enter the following:
                c:\> repadmin /options DISABLE_OUTBOUND_REPL

  • To disable inbound replication, enter the following:
                c:\> repadmin /options +DISABLE_INBOUND_REPL

  • To re-enable inbound replication, enter the following:
                c:\> repadmin /options DISABLE_INBOUND_REPL

------------------Happy Reading---------------