Thursday, August 21, 2014

DHCP Testing Command

Bring up Command Prompt and run:
netsh dhcp show server

Will receive the following result:
-----------------------------------------------------------------------------------------------
1 Servers were found in the directory service:

        Server [pdcsc.server.com] Address [192.168.100.1] Ds location: cn=pdcs
.server.com

Command completed successfully.
-----------------------------------------------------------------------------------------------

Wednesday, August 20, 2014

Windows 8.1 Set Network to be Private / Public

1. Use Command Prompt and run "secpol.msc"
2. Click on "Network List Manager Policies"
3. Double-click on your network
4. Click on "Tab Network Location"
5. Set "Location Type" to "Private" (or "Public")

Thursday, August 7, 2014

PowerShell - Remote Configure Static/DHCP IP Address

For Static IP:
$sc = {
param($IP)
$wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled ='true'";
$wmi.EnableStatic($IP, "255.255.255.0");
$wmi.SetGateways("192.168.1.1", 1);
$wmi.SetDNSServerSearchOrder(@("192.168.1.1","8.8.8.8"))
}

$IP = "192.168.1.101"
$job = Invoke-Command 192.168.1.121 -ScriptBlock $sc -ArgumentList $IP -AsJob -Credential $cred
Wait-Job $job -Timeout 20
$IP = "192.168.1.102"
$job = Invoke-Command 192.168.1.122 -ScriptBlock $sc -ArgumentList $IP -AsJob -Credential $cred
Wait-Job $job -Timeout 20



For DHCP IP:
$sc = {
$wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled ='true'";
$wmi.EnableDHCP();
$wmi.SetDNSServerSearchOrder();
}

$job = Invoke-Command 192.168.1.101 -ScriptBlock $sc -AsJob -Credential $cred
Wait-Job $job -Timeout 20
$job = Invoke-Command 192.168.1.102 -ScriptBlock $sc -AsJob -Credential $cred
Wait-Job $job -Timeout 20


Wednesday, July 9, 2014

PowerShell - Uninstall Application for Lab Computers Simultaneously

# Loop through the server list
Get-Content -Path "C:\Scripts\Computers.txt" | %{

  # Define what each job does
  $ScriptBlock = {
    param($server)
    Write-Host "[processing '$server' inside the job]"
    $app = Get-WmiObject -Class Win32_Product -computer $server -Filter "Name = 'Java 7 Update 60'"
    $app.Uninstall()
    Start-Sleep 60
  }

  Write-Host "processing $_..."

  # Execute the jobs in parallel
  Start-Job $ScriptBlock -ArgumentList $_
}

Get-Job

While (Get-Job -State "Running")
{
  Start-Sleep 10
}

Get-Job | Receive-Job

Monday, June 30, 2014

PowerShell - Add/Join Computer to domain

$pc = "PC-01"
$domain = "Domain"
$user = "Administrator"
$pass = cat C:\securestring.txt | convertto-securestring
$username = "$domain\$user"
$computer = "NewPCName"
$credential = New-Object System.Management.Automation.PSCredential($username,$pass)
Add-Computer -ComputerName $pc -DomainName $domain -newname $computer -OUPath "OU=group1,DC=testing,DC=com" -Restart -Force -Credential $credential
EXIT

PowerShell - Remove/Unjoin Computer from domain

$pc = "PCName"
$user = "Administrator"
$pass = cat C:\securestring.txt | convertto-securestring
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "$pc\$user",$pass
$domain = "Domain"
$user2 = "Administrator"
$pass2 = cat C:\securestring2.txt | convertto-securestring
$domcred = new-object -typename System.Management.Automation.PSCredential -argumentlist "$domain\$user2",$pass2
Remove-Computer -Computer $pc -UnjoinDomainCredential $domcred -LocalCredential $cred -Workgroup workgroup -PassThru -Force -restart

PowerShell - Write Credentials to File


$FilePath = "C:"
Write-Host "Enter login as domain\id:"
Read-Host | Out-File $FilePath\id.txt

Write-Host "Enter user password:"
Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File $FilePath\securestring.txt