Saturday, January 30, 2016

Server Core configuration from CMD

Network Configuration :

netsh
interface
ipv4
show interfaces



Select INx  (name - is selected index) for example 4

set address name=″4″ source=static address=192.168.0.50 mask=255.255.255.0 gateway=192.168.0.1


DNS Configuration:

If there is several dns servers set  index=1,2…

add dnsserver name=″4″  address=192.168.0.10 index=1

exit.

Set Hostname:

netdom renamecomputer WIN-FDP41E28535 /newname:SERVER1

Reboot Computer

shutdown -r -t 0


Join Computer to Domain

netdom join Server1 /domain:contoso.com /UserD:administrator@contoso.com /PasswordD:*


Create Firewall Rule:

netsh advfirewall firewall set rule group=″Remote administration″ new enable=yes

cscript C:\windows\system32\scregedit.wsf  /ar 0


OR Use SCONFIG 







Friday, January 29, 2016

Reset local admin password

Download Offline NT Password and Registry editor. -Soft is free!
Create bootable CD or USB.

Boot on Computer or Server.


Select Disk with installed WIndows



Select path ( windows\system32\config)











Chage efault


Configure NTP on Windows Server

Open Regedit as administrator

HKLM\System\CurrentControlSet\services\W32Time\TimeProviders\NtpServer

To enable NTP Server Change Enable , and set value 1




Restart Windows Time service :  

net stop w32time && net start w32time










Windows Server 2012 Install-Remove GUI


Install:

Install-WindowsFeature Server-Gui-Mgmt-Infra,Server-Gui-Shell –Restart

Remove:

Remove-WindowsFeature Server-GUI-Shell, server-gui-mgmt-infra -Restart

Find enabled Users not Member of Groups

Not member of group


(get-aduser -searchbase "OU=Test,DC=Test,DC=com" -Server test.com  -filter {(enabled -eq $true) -and ((memberof -ne "CN=Group1,OU=Groups,DC=test,DC=com") -and (memberof -ne "CN=Group2,OU=Groups,DC=test,DC=com"))}) |select UserPrincipalName |sort UserPrincipalName

Find AD users not loged on 90 days

Count:
Find AD enabled users form OU and Group:

$lastLogon = (get-date).adddays(-90).ToFileTime()

(get-aduser -searchbase "OU=Test,DC=test,DC=com" -Server test.com -filter {memberof -recursivematch "CN=Groupname,OU=Groups,DC=test,DC=com" -and (lastLogonTimestamp -lt $lastLogon) -and (enabled -eq $true)}).count

Export:

$lastLogon = (get-date).adddays(-90).ToFileTime()

(get-aduser -searchbase "OU=Test,DC=test,DC=com" -Server test.com -filter {memberof -recursivematch "CN=Groupname,OU=Groups,DC=test,DC=com" -and (lastLogonTimestamp -lt $lastLogon) -and (enabled -eq $true)}))}) -Properties lastlogondate | select Name, UserPrincipalName | sort name

PS Find Empty AD Groups

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

Exchange PowerShell: Find users hidden from the Global Address List

Get-Mailbox | Where {$_.HiddenFromAddressListsEnabled -eq $True} | Select Name, HiddenFromAddressListsEnabled | export-csv c:\hiddenfromGAL.csv

Source

Thursday, January 28, 2016

Low Disk Space Email Notification

# Set Global Parameters
$emailTO = "SomeOne@SomeDomain.com"
$emailFrom = "SomeOne@SomeDomain.com"
$smtpServer = "SMTPserverInfo"

$computers = ("server1","server2","server3","server4")
$i = 0

# Get Drive Data
$report = @(
foreach($computer in $computers)
{
$drives = Get-WmiObject -ComputerName $computer Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3}
     foreach($drive in $drives)
     {
          # Calculate Free Space
          $obj = new-object psobject -Property @{
               ComputerName = $computer
               Drive = $drive.DeviceID
               Size = $drive.size / 1GB
               Free = $drive.freespace / 1GB
               PercentFree = $drive.freespace / $drive.size * 100
               }
          # Monitor for 10% or less in free space and report accordingly
          if ($obj.PercentFree -lt 10) {
               $obj | Format-Table ComputerName,Drive,@{n='Size';e={'{0:N1}' -f $_.Size}},@{n='Free';e={'{0:N1}' -f $_.Free}},@{n='PercentFree';e={'{0:N1}' -f $_.PercentFree}} | Out-String
               $i++
               }
     }
   
}
)

# Send notification if script finds more than 0 drives with less than 10% free space
if ($i -gt 0)
   {
       foreach ($user in $emailTo)
                {
        echo "Sending Email Notification to $user"
        $smtp = New-Object Net.Mail.SmtpClient($smtpServer)
        $subject = "Server with Low Disk Space"
        foreach ($line in $report)
            {
                $body += "$line "
                }
        Send-MailMessage -to $user -From $emailFrom -SmtpServer $smtpServer -Subject $Subject -Body $body
                }
   }


Sorce

Saturday, January 23, 2016

Remove All Metro Apps via PowerShell in Windows 8

Remove all currently installed Metro Apps:

Get-AppxPackage -AllUsers | Remove-AppxPackage

If you wish to stop them from getting re-installed for the next new user:

Get-AppXProvisionedPackage -online | Remove-AppxProvisionedPackage –online

Friday, January 22, 2016

Disable Java Update

Run as administrator and disable updates :

C:\Program Files\Java\jre6\bin\javacpl.exe

or from Regedit for GPO:

[HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Update\Policy]
«EnableJavaUpdate»=dword:00000000
«EnableAutoUpdateCheck»=dword:00000000

Thursday, January 21, 2016

Windows Update in Audit mode on Windows 8.1

Download:

http://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc

After you have downloaded the module, do the following:
1.)  Copy the whole module folder (after unzipping) to %WINDIR%\System32\WindowsPowerShell\v1.0\Modules

2.) Start up PowerShell ISE as admin from admin tools

3.) Set-ExecutionPolicy RemoteSigned

4.) Import-Module PSWindowsUpdate

5.) Get-WUInstall

6.) The rest should be automated with some prompts

Restart Computer!

Shutdown or Reboot Computer CMD and PowerShell

CMD

Shutdown force :

shutdown -s -f -t 0

Restart Force:

shutdown -r -f -t 0


PowerShell :

Stop-Computer -Force

Restart-Computer -Force

Remote Computer :

 Stop-Computer -ComputerName computer  -Credential username -Force

Wednesday, January 13, 2016

Sharepoint Server Error in '/' Application.

Sharepoint Server Error in '/' Application, check on sql server service SQL Server (MSSQLSERVER). If  service is stopped start it or restart.


Sharepoint 2013 find SQL servers name

Open regedit :

\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\15.0\Secure\ConfigDb

Dsn key: Data Source= "server FQDN"

Find Users not signed Mail 30 days

get-mailbox  -resultsize unlimited | Get-MailboxStatistics |?{$_.LastLogonTime -lt (date)
.adddays(-30)} | ft DisplayName,ItemCount,LastLogonTimeLast,LogoffTime,LastLoggedOnUserAccount -auto

Windows Networking CMDs

1. To see your routing table, run either of these commands:
    
    route print

or

    netstat -r

2. To add an entry to your routing table that will be permanent, run the route add command with the –p option. Omitting that, the entry will be lost at next reboot:
    
route add 0.0.0.0 mask 0.0.0.0 172.16.250.5 –p


3. To see all open network connections

    netstat –an

How to find out all locked out accounts in AD using Powershell


Search-ADAccount -LockedOut
The output from this cmdlet will list all the locked out accounts.  

If you want to unlock all those accounts:
Search-ADAccount -LockedOut | Unlock-ADAccount

Temporary User Profile


   Log in with temp profile.
b)      Start registry editor by typing regedit in find box of Windows 7.
c)      Navigate the following location.
d)      You will see similar keys under profile list, but one with .bak, as shown below.

e)      The key with .bak is for the correct old profile. Currently your Windows 7 computer logged in with fresh (temporary) profile with same key. So, rename the new profile key ( which is not having.bak) and remove .bak from correct profile key. See below.

f)      That’s it. Log off and log in (or restart) with your user name and password. You must get your correct profile with icons and profile settings back in Windows 7, if you are lucky enough

Change default printer for all users on this computer

ntprint /setdefault name=<printer name> 

Add Static Route Windows

ROUTE ADD -P <target PC's IP> MASK <Subnet mask from ipconfig> <Default Gateway of the adapter in the domain> if <tried it with all possible interfaces>


route ADD -P 10.10.10.0 MASK 255.255.255.0 192.168.1.12

Nslookup

Find Kms Server:

nslookup -type=all _vlmcs._tcp


Check Lync DNS record:

NslookupSet type=srv_sip._tls.test.com (lync dns record )


MX

Nslookup
Set type=mx
Gmail.com

never Launch Startup Repair

bcdedit /set {default} bootstatuspolicy ignoreallfailures

install framework 3.5 on server 2012

dism /online /enable-feature /featurename:NetFX3 /all /Source:d:\sources\sxs /LimitAccess

Add Users to a Group

Import-module ActiveDirectory
$Group1='CN=testgroup,OU=Groups,DC=test,DC=com'

Add-ADGroupMember -Identity $Group1 -Member (Get-Content C:\tmp\import.txt)

Exchange 2010, 2013 PowerShell Maibox Import Commands

New-MailboxImportRequest  -Mailbox username  -FilePath \\server\pst\filename.pst
This command imports the PST file into the user’s mailbox. Large PST files can fail due to corrupt data on the mailbox.
New-MailboxImportRequest  -Mailbox username -FilePath \\server\pst\filename.pst -AcceptLargeDataLoss -BadItemLimit unlimited
This command imports the PST file into the user’s mailbox and bypasses any corrupt items in the mailbox.
Get-MailboxImportRequest | Get-MailboxImportRequestStatistics
This command allow you to view the status of your PST imports.

ADD A record to DNS Server


Import-Module DNSShell
$dns="dns server ip"
$zone="test.com
Import-Csv C:\tmp\import.csv
 | foreach {
    dnscmd $dns /recordadd $zone $($_.name) A $($_.ip)

}

CREATE USERS PS

$objOU=[ADSI]”LDAP://OU=Users,OU=Test,DC=test,DC=com”
$dataSource=import-csv -path "C:\tmp\users.csv"
foreach($dataRecord in $datasource) {
$cn=$dataRecord.FirstName + " " + $dataRecord.LastName
$sAMAccountName=$dataRecord.LoginAccount
$givenName=$dataRecord.FirstName
$sn=$dataRecord.LastName
$sAMAccountName=$sAMAccountName.ToLower()
$displayName=$givenName+ " " + $sn
$userPrincipalName=$sAMAccountName + "@test.com"

#place additional attributes here

$extensionAttribute="test"

#no additional attributes here

$objUser=$objOU.Create("user","CN="+$cn)
$objUser.Put("sAMAccountName",$sAMAccountName)
$objUser.Put("userPrincipalName",$userPrincipalName)
$objUser.Put("displayName",$displayName)
$objUser.Put("givenName",$givenName)
$objUser.Put("sn",$sn)

#here's where we will put the record using put() command
$objUser.Put("extensionAttribute1", $extensionAttribute)
#end of Put() command

$objUser.SetInfo()
$objUser.SetPassword("123-zxc")
$objUser.psbase.InvokeSet(“AccountDisabled”,$false)
$objUser.SetInfo()

}