Thursday, October 17, 2013

Powershell: Restart a Remote Machine

Option 1: Prompt user for machine name to be restarted
CLS $cname = Read-Host "Enter Machine Name or IP Address" Restart-Computer -computerName $cname -Force

 Option 2: Enter the name directly in the code. cls Restart-Computer -computerName "EnterMachineNameHere" -Force

 Option 3: Reboot multiple Machines
cls $cname ="Server01, Server02, Server03" Restart-Computer -computer $cname -force

Joe Piggee





Powershell: List services on remote machine

# Use This to list\view services on remote server(s)
#Joe Piggee
---  Begin Code----
cls
gwmi win32_service -comp (gc c:\servers.txt) | select __server,name,startmode,state,status | Out-Gridview

--- End Code ---

Disable IPv6

 

By Joseph Piggee Sr.

http://support.microsoft.com/kb/929852

IPv6 can be disabled either through the DisabledComponents registry value or through the check box for the Internet Protocol Version 6 (TCP/IPv6) component in the list of items on the Networking tab for the properties of connections in the Network Connections folder. The following figure shows an example.

The DisabledComponents registry key affects all interfaces on the host. However, the check box on the Networking tab affects only the specific interface. The DisabledComponents registry value does not affect the state of the check box. Therefore, even if the DisabledComponents registry key is set to disable IPv6, the check box in the Networking tab for each interface can still be checked. This is expected behavior.

Note Unchecking the checkbox on a network adapter will not disable IPv6 on the host. It will unbind IPv6 from this adapter. To disable IPv6 on the host, follow the steps below.

To use the DisabledComponents registry value to check whether IPv6 was disabled, run the following command at a Windows command prompt: 
reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters /v DisabledComponents

You may receive the following error message: 
ERROR: The system was unable to find the specified registry key or value. 
If you receive this error message, the DisabledComponents registry value is not set. If the DisabledComponents value is set, it overrides the settings in the connection properties. 

To enable or to disable IPv6 or to selectively enable or disable components of IPv6 automatically, click the Fix this problem link. Then, click Runin the File Download dialog box, and follow the steps in this wizard.

Backup Active Directory

Joe Piggee

  1. Open NTBACKUP by either going to Run, then NTBACKUP and pressing Enter or by going to  Start / Accessories / System Tools. Or my personal method, Click Start/ Run/ Type NTBACKUP.
  2. If you are prompted by the Backup or Restore Wizard, I suggest you un-check the "Always Start in Wizard Mode" checkbox, and click on the Advanced Mode link.
  3. Inside NTBACKUP's main window, click on the Backup tab.
  4. Click to select the System State checkbox. Note you cannot manually select components of the System State backup. It's all or nothing.
  5. Enter a backup path for the BKF file. If you're using a tape device, make sure NTBACKUP is aware and properly configured to use it.
    Press Start Backup.
  6. The Backup Job Information pops out, allowing you to configure a scheduled backup job and other settings. For the System State backup, do not change any of the other settings except the schedule, if so desired. When done, press Start Backup. After a few moments of configuration tasks, NTBACKUP will begin the backup job.
  7. When the backup is complete, review the output and close NTBACKUP.

Windows Activation Error - 0x80072EE2 & 0x8007EFE

Joe Piggee

Error x80072EE2 & 0x8007EFE

This error normally indicates a connection issue. Very vague, but true. To fix this try the following:

Turn off the firewall, and retry activation
Check Date & time settings. If you needed to change anything on the date or time, restart the server before retrying the activation
Finally, make sure you aren't using a KMS key without a KMS server.
And verify the key code is correct.

To View or Change the Tombstone LifeTime

*To perform the following steps you'll need to be a member of the Enterprise Admins group.

By Joe Piggee Sr.
To view or change attribute values by using ADSIEdit:
  1. On the Start menu, point to Run and then type ADSIEdit.msc and press Enter.
  2. In the next window, click Action-> Connect to
  3. In the center, change the connection point to "Select a well known Naming Context"
  4. Click the drop down menu, and select Configuration, then click OK ADSIEDIT-1
  5. Navigate to Configuration->CN=Services->CN=Windows NT->CN=Directory Service, Right click, and select properties
  6. ADSIEDIT-2
  7. Scroll down to "tombstoneLifetime" and double click to edit. It will be displaying the current value, which will be in days.
  8. When done just click OK.
  9. Click OK and then close ADSIEdit.
* When you view properties on cn=Directory Service,cn=Windows NT, cn=Services,cn=Configuration,dc=, if no value is set it means that the default value is in effect. Any value that you type in the Edit Attribute box replaces the default value when you click Set .

Query Active Directory for a particular User

If you just want to know, for example, where a given user exists in your Active Directory, then searching for an account is a snap:
--- Begin code -----
cls
# sending LDAP query to Active Directory
#Change sAMAccountName for your query
$searcher = [ADSISearcher]'(&(objectClass=User)(objectCategory=person)(sAMAccountName=jpiggee*))'
# finding first match
$searcher.FindOne()
# finding ALL matches
$searcher.FindAll()
#This would find all user accounts with a SamAccountName that starts with "tobias". You can now use this approach to easily find out where an account is located:
# find account location
$searcher.FindAll() | Select-Object -ExpandProperty Path

---End Code ----

Joe Piggee

Get More Detailed Information Using GetDirectoryEntry()

To get more detailed information about an accounts using GetDirectoryEntry() to turn the search result into actual account objects:
# send LDAP query to Active Directory
$searcher = [ADSISearcher]'(&(objectClass=User)(objectCategory=person)(sAMAccountName=*))' 
# get 10 results max
$searcher.SizeLimit = 10 
# find account location
$searcher.FindAll() |
  # get account object
  ForEach-Object { $_.GetDirectoryEntry() } |
  # display all properties
  Select-Object -Property * |
  # display in a grid view window (ISE needs to be installed for this step)

  Out-GridView

# Joe Piggee

Wednesday, October 16, 2013

List machines with thier FQDN

Prerequisites: Create a file that has the list of machines netbios names, and create an empty systems.txt file on your root.
<#
Reference URL: http://blogs.technet.com/b/heyscriptingguy/archive/2010/03/11/hey-scripting-guy-march-11-2010.aspx
This file will read Machinelist from a file, try to get their DNS information,
and append that output to a txt file.
You can use the above mentioned URL for more information and exaples of the Try\Catch\Finally
#>
ForEach ($entry in (Get-Content c:\scripts\machinelist2.txt)) {
    Try {
        [net.dns]::GetHostEntry($entry).Hostname | Out-File -FilePath c:\systems.txt -Append
    } Catch {
        $entry | Out-File -FilePath c:\scripts\Machine_WithFQDN.txt -Append
    }
}
Joe P.