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