Monday, October 27, 2014

Fix "Windows update cannot currently check for updates because the service is not running"

Go to "Control Panel" -> "System and Security" -> "Administrative Tools" -> "Services"
(or use Command Prompt and run "services.msc" to bring up Services control panel)

1: Stop Windows Update Service.

2: Rename/Delete "SoftwareDistribution" folder.
    (Full path: C:\Windows\SoftwareDistribution\)

3: Start Windows Update Service.



Wednesday, September 10, 2014

PowerShell - Change / Mute Audio Volume

Volume Mute Button
$obj = new-object -com wscript.shell
$obj.SendKeys([char]173)

Volume Down Button
$obj = new-object -com wscript.shell
$obj.SendKeys([char]174)

Volume Up Button
$obj = new-object -com wscript.shell
$obj.SendKeys([char]175)

** Each volume counter = 2%
Ex: Set Volume to 50%
Function Set-Speaker($Volume){ $ws = new-object -com wscript.shell;1..50 | % { $ws.SendKeys([char]174)};1..$Volume | % { $ws.SendKeys([char]175) } }
Set-Speaker(25)

PowerShell - Remote Add/Join Computers to domain

$domainAdminCred = Credential
$localAdminCred = Credential

$ScriptBlock = {
  param($domainAdminCred, $computer)
  $domain = "Domain"
  Write-Host "[processing '$computer' ...]"
  Add-Computer -DomainName $domain -Credential $domainAdminCred -OUPath "OU=group1,DC=testing,DC=com" -Restart -Force
}

$IP = "192.168.1.101"
$computer = "PC-01"
Invoke-Command $IP -ScriptBlock $ScriptBlock -ArgumentList $domainAdminCred, $computer -Credential $localAdminCred
$IP = "192.168.1.102"
$computer = "PC-02"
Invoke-Command $IP -ScriptBlock $ScriptBlock -ArgumentList $domainAdminCred, $computer -Credential $localAdminCred

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