Sunday, December 10, 2017

How to copy from All members in a ADGroup to Another

How to copy from All members in a  ADGroup  to Another


Get-ADGroupMember -Identity 'Old Group' | ForEach-Object {Add-ADGroupMember -Identity 'New Group' -Members $_.distinguishedName}

Regards
Bijesh

Sunday, November 12, 2017

How to get list of empty groups in active directory

     When we do cleanup activity in Ad,we might wanted to check if any empty groups exist's.How to get the list of empty groups in Ad ?

We can get the list easily with help of Active  directory power shell .Below is the one-liner command to pull the information

Get-ADGroup -Filter * -Properties Members | where {-not $_.members} | select Name | Export-Csv C:\ADemptygroupLIST.csv –NoTypeInformation

Regards
Bijesh
Blog4IT

Wednesday, November 8, 2017

Command To Get the list of Active directory users with account expire date

DSQUERY Command To Get the list of  Active directory users with account expire date

dsquery user -name * -limit 0 | dsget user -samid -acctexpires


Regards
Bijesh

Command to add DNS record

Simple Command to Add add DNS record

Dnscmd  ServerName /recordadd  <DomainName> HostEntry A <x.x.x.x>

Regards
Bijesh

Veeam Powershell command to get the list of job completed with status Success

Veeam Powershell command to get the list of job completed with status Success

Get-VBRJob | Where-Object {$_.GetLastResult() -ne "Failed" -and $_.GetLastResult() -ne "None" -and $_.findlastsession().progress.stoptime -ge (Get-Date).addhours(-24)} |Select-object  @{Name="Job";Expression={$_.Name}}, @{Name="Status";Expression={$_.GetLastResult()}}, @{Name="ID";Expression={$_.id}}, @{Name="Job Msg";Expression={$_.FindLastSession().info.description}}, @{Name="Session";Expression={$_.FindLastSession()}} | Select-Object "Job","Status","ID"

Regards
Bijesh

Veeam Powershell command to get the list of job completed with status Failed/Warning

Veeam Powershell command to get the list of job completed with status Failed/Warning

 Get-VBRJob | Where-Object {$_.GetLastResult() -ne "Success" -and $_.GetLastResult() -ne "None" -and $_.findlastsession().progress.stoptime -ge (Get-Date).addhours(-24)} |Select-object  @{Name="Job";Expression={$_.Name}}, @{Name="Status";Expression={$_.GetLastResult()}}, @{Name="ID";Expression={$_.id}}, @{Name="Job Msg";Expression={$_.FindLastSession().info.description}}, @{Name="Session";Expression={$_.FindLastSession()}} | Select-Object  "Job","Status","ID"


Regards
Bijesh

Tuesday, November 7, 2017

Power shell command to get last windows update install date

Powershell command to get last windows update install date


Get-hotfix -ComputerName <Servername> | select-Object Source,installedon -first 1


Regards
Bijesh

Horizon View Powercli command to Get number of unassigned VM’s Count in pool

Horizon View  Powercli command to Get number of unassigned VM’s Count in a pool


Get-Pool | Select Pool_id, @{Name="Unassigned VMs";Expression={($_ | Get-DesktopVM | ? {$_.user_displayname -eq "$null"}).Count}}

Regards
Bijesh

Power shell Command to export mailbox to PST

Power Shell command –To export mailbox to PST


  New-MailboxExportRequest –Mailbox  <Username>  –FilePath \\<servername>\Sharename\user.pst


    PS:          -FilePath parameter only accepts a UNC path (\\servername\share).

Regards
Bijesh

Monday, November 6, 2017

Powershell Command to Access New-PSSession for remote exchange server


Access New-PSSession for remote exchange server



$exg = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<server fqdn>/PowerShell/ -Authentication Kerberos

Import-PSSession $exg


Regards
Bijesh

Command to get Power shell session History

Simple command to get PS Session History



How to save power shell session input and output to a file


Sometime while working on powershell we may want to save the ran command and output to a file .How do we save the session input and output to a file ?



To Start saving the transcript,

    start-transcript -Path <FileName>

To Stop saving the transcript

    stop-transcript




Regards
Bijesh

Tuesday, October 31, 2017

Powershell Script to get Clustername from Ad Computer Object


We can get Adcomputerobjects from Ad..But how to filter or list out  the Cluster name from Ad.

Below is a simple Powershell Script to get Cluster name(Alias) from Ad Computer Object


Get-ADComputer -Filter 'servicePrincipalName -Like "*MSClusterVirtualServer*"' -Properties Name, LastLogonTimestamp, pwdLastSet, servicePrincipalName| Select Name, @{n='LastLogonTimestamp';e={[DateTime]::FromFileTime($_.LastLogonTimestamp)}}, @{n='pwdLastSet';e={[DateTime]::FromFileTime($_.pwdLastSet)}}, DistinguishedName 



Regards
Bijesh

PowerShell command to get Print queue from print server



Get-WMIObject Win32_printer -Computername <servername> |Format-Table -AutoSize

Monday, October 30, 2017

Powershell script to reboot multiple servers







$Servers=Get-Content c:\users\Bijesh\ServerRebootlist.txt

$cred = Get-Credential "localHost\administrator"

ForEach ($Server in $servers)
{
write-Host $Server

 #Restart-Computer -ComputerName $Server -Force -ThrottleLimit 10 -Credential $cred

}


Regards
Bijesh

Sunday, October 29, 2017

How to Combine two HTML File to single

How to Combine two HTML File to single

          There are some scenarios  where we need to combine multiple html out put single ,How do we do that ...Powers shell have simple command to get this done,lets see who to achieve that



Html File one -> C:\Users\Bijesh\Desktop\HTML-Report1.html

Html Fine Two ->C:\Users\Bijesh\Desktop\HTML-Report.html


Here is the One line Powershell command to combine two Html files ...


(Get-Content "C:\Users\Bijesh\Desktop\HTML-Report1.html") + (Get-Content "C:\Users\Bijesh\Desktop\HTML-Report.html") | Set-Content "C:\Users\Bijesh\Desktop\Combined.html"

Regards
Bijesh

Batch Script to Restart service on multiple servers

Batch Script to Restart service on multiple servers


The Following example is to Restart the service "wuauserv"  on list of servers

Save the below Line to a batch file (.CMD  or .Bat) and execute to restart the service


@echo off
for /f %%i in (C:\Users\Bijesh\Desktop\Server.txt) do sc \\%%i start "wuauserv"


Regards
Bijesh