Tuesday, May 17, 2016

Mac OS X - Active Directory Mobile Account

Use Command prompt and execute the following command:

/System/Library/CoreServices/ManagedClient.app/Contents/Resources/createmobileaccount

usage: createmobileaccount -n username [-h homepath] [-P | [-p password]] [-e] [-q] [[-x] | [-X]] [[-s] | [-S]] [-u syncURL] [-t urlPath] [-d] [-v]
-n username : user record name.
-h homepath : user home path; Default is "/Users/<username>".
-p password : user password.
-P : prompt for user password. A user password is required to create a FileVault home.
-e encrypt : encrypt new home with FileVault.
-q quota : max size in bytes of FileVault home.
-x : create as external account on non-boot volumes. Default.
-X : create as mobile account account non-boot volumes.
-d : disable external account creation.
-s : set home sync on if home created.
-S : set home sync off if home created. Default.
-u syncURL : server target of home synchronization.
-t urlPath : additional path after syncURL.
-v : verbose output.
Examples:
createmobileaccount -n jsmith
createmobileaccount -v -P -n jsmith
createmobileaccount -vsxn jsmith -h /Volumes/HD3/jhome
createmobileaccount -vsxn jsmith -h /Volumes/HD3/jhome -u nfs:/server.apple.com/bigs/homes -t myusers/macos/jhome
Notes:
- createmobileaccount must run as root.
- If you do not specify a password, the account's cached password will be created during the account's first log in.

createmobileaccount -vsxn COYOTEID -h /Users/COYOTEID


The OpenDirectory cached the users password locally. To delete cached information that is no longer valid other than to delete the information, we had to delete the user while keeping the users homedirectory.

sudo dscl . -remove /Users/[username]
This will remove the user [username] from the userlist but keeps the homedirectory as it is.

Note: You should only do so with a cached mobile user!!!! To find out about your cached users run this snippet:


dscl . -list /Users AuthenticationAuthority | grep LocalCachedUser | awk '{print $1}'

Friday, March 25, 2016

PowerShell - Rename Computer in Active Directory

Execute the command below and restart the computer.

Rename-Computer -ComputerName "OLD_COMPUTER_NAME" -NewName "NEW_COMPUTER_NAME" -DomainCredential $cred

Wednesday, September 9, 2015

PowerShell - Uninstall Sophos Antivirus Programs

1. Stop the Sophos AutoUpdate Service to prevent a potential update during the removal process.
2. Gather information for all Sophos applications.
3. Uninstall the applicaions

Enter-PSSession IP_ADDRESS -Credential $cred
net stop "Sophos AutoUpdate Service"
Get-WmiObject -Class win32_product -Filter "Name like '%sophos%'"
$obj = Get-WmiObject -Class win32_product -Filter "Name like '%sophos%'"
$obj.Uninstall()

Monday, May 18, 2015

PowerShell - Detect/Change/Activate Power Plans

Detect Computer power plans
gwmi -NS root\cimv2\power -Class win32_PowerPlan | select ElementName, IsActive | ft -a

Change/Activate power plan
 - Method 1: Using the CIM cmdlets
$powerplan = Get-CimInstance -Name root\cimv2\power -Class win32_PowerPlan -Filter "ElementName = 'High Performance'"
Invoke-CimMethod -InputObject $powerplan -MethodName Activate
$powerplan = Get-CimInstance -Name root\cimv2\power -Class win32_PowerPlan -Filter "ElementName = 'Power Saver'"
Invoke-CimMethod -InputObject $powerplan -MethodName Activate
 - Method 2: Using Get-WmiObject
$powerplan = gwmi -NS root\cimv2\power -Class win32_PowerPlan -Filter "ElementName ='High Performance'"
$powerplan.Activate()
$powerplan = gwmi -NS root\cimv2\power -Class win32_PowerPlan -Filter "ElementName ='Power Saver'"
$powerplan.Activate()

Turn Off Hard Drive Sleep
powercfg -CHANGE -disk-timeout-ac 0

Tuesday, April 7, 2015

PowerShell - Check Hard Drive Size

 Get C: Drive size
$disk = ([wmi]"\root\cimv2:Win32_logicalDisk.DeviceID='C:'")
"C: has {0:#.0} GB free of {1:#.0} GB Total" -f ($disk.FreeSpace/1GB),($disk.Size/1GB) | write-output

Monday, March 9, 2015

PowerShell - Print Queue

List Printers
Get-WMIObject -Class Win32_Printer | Select Name,DriverName,PortName,Shared,ShareName | ft -auto

Show Print Queue Status
Get-WMIObject Win32_PerfFormattedData_Spooler_PrintQueue | Select Name, @{Expression={$_.jobs};Label="CurrentJobs"}, TotalJobsPrinted, JobErrors

Delete a print queue (Ex: hp deskjet 960c series)
$p = Get-WmiObject -Class Win32_printer -filter "name='hp deskjet 960c series'"
$p.delete()

Wednesday, February 25, 2015

Mac OS X - Change ComputerName/HostName/LocalHostName via the command line

ComputerName - Used for Computer Name, File Sharing, and AppleTalk.
scutil --set ComputerName "YourComputerName"

HostName - Displayed in the default terminal command prompt.(user@hostname).
scutil --set HostName "YourHostName"

LocalHostName - Used for Bonjour-aware services on the local network.
scutil --set LocalHostName "YourLocalHostName"