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

Wednesday, June 18, 2014

icacls - Manage file/folder permission to users via the command line

Manage in Command Prompt:
icacls C:\Users\Public\Desktop\Share /grant Everyone:(OI)(CI)F
Manage in PowerShell:
icacls C:\Users\Public\Desktop\Share /grant "Everyone:`(OI`)`(CI`)F"

WMIC - Uninstall application via the command Line

WMIC - Windows Management Instrumentation Command-line

Use Command Prompt and enter "WMIC" to bring up wmic mode
wmic:root\cli>

Generate a list of installed applications.
product get name

Uninstall a specific application (Ex: uninstall Java 7 Update 51)
product where name="Java 7 Update 51" call uninstall
Enter "Y" to continute the uninstallation process

Friday, March 14, 2014

Local Group Policy - Force Windows 7 to Work/Private Network

Open "gpedit.msc" -> Go to Computer Configration –> Windows Settings –> Security Settings –> Network list manager