Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

{

*nix

Grep

grep '^a.*e$' file

This means: look for those lines starting (^) with a, then 0 or more characters and finally and e at the end of the line ($).

grep -riL done *

Search for all of the file names that do not contain the text "done" (recursive, case insensitive)

grep -ri "p 2425" * 

Useful for searching Radmind command files for transcripts (p) from a specific year (2425) (recursive, case insensitive)

vi

https://www.cs.colostate.edu/helpdocs/vi.html

Macintosh

Killing Things

...

osascript -e ‘tell application “safari” to quit’

Starting A Shell Script

#!/bin/bash

Split a Text File into pieces based on text

...

split -p '^1 row.*' Software\ on\ Refreshing\ Windows\ Computers.txt 

Macintosh

Killing Things

Quit an App

osascript -e ‘tell application “safari” to quit’

Starting A Shell Script

#!/bin/bash

Ditto

Creating a zip file

sudo -s

...

copy 1st GUID

diskutil cs delete GUID

 

"Change Image Host Name"

after deploying image but NOT restarting, open a terminal window from the utilities menu

defaults read /Volumes/Macintosh\ HD/var/kace/ds/imageinfo.plist

defaults write /Volumes/Macintosh\ HD/var/kace/ds/imageinfo.plist ImageHostname XXXX###-##XX

Remove Quarantine Flag from an app

remove a from a .dmg or .zip before unpacking

from a terminal window

xattr -c nameofthe.dmg

Finding a developer's code sign number

codesign -dv /path/to/kext

Windows

Using Environment Variables

Sooooo.  I forgot to talk to you about something, Sam.  I'm going to paste it here so we can chat asynchronously before I go on vacation.With the Windows K1000 packages that need updating, we're going to rewrite the install.bat files (and any other related files) to use environment variables instead of c:\This needs to happen in the body of the files and the command at the top that gets you to the native command prompt.  I've updated the wiki page of code snippits:https://wiki.carleton.edu/display/itskb/Reb%27s+Handy+Bits+of+Code#Reb'sHandyBitsofCode-GettingtotheNativecmdpromptAnd here is one of the office install.bat files as an example:

No Format
========================================================
@echo off
if not exist "%windir%\sysnative\cmd.exe" goto :gonenative
echo Relaunching with x64 cmd.exe...
"%windir%\sysnative\cmd.exe" /C "%~dpnx0"
goto :EOF

:gonenative
REM ---paste the rest of your batch code below this line---

========================================================
If exist "%ProgramFiles%\KACE\ds\office rd /s /q "%ProgramFiles%\KACE\ds\office\" 
echo Copying Office Repo
xcopy office\Office-2023.05.11\office "%ProgramFiles%\KACE\ds\office" /e /c /h /i /r /y /z
echo Installing Office
"%ProgramFiles%\KACE\ds\office\setup.exe" /configure "%ProgramFiles%\KACE\ds\office\2021uon-2022.05.11.xml"
cscript.exe "%ProgramFiles%\Microsoft Office\Office16\ospp.vbs" /sethst:kms3.ads.carleton.edu
cscript.exe "%ProgramFiles%\Microsoft Office\Office16\ospp.vbs" /act
reg delete HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run /v TeamsMachineInstaller /f

You can see the Windows environment variables by typing SET in the command prompt.Some of them resolve to the same place, so for c:\ProgramData, let's use %ProgramData%, not %ALLUSERSPROFILE%. For c:\Program Files, let's use %ProgramFiles% and not %ProgramW6432%. Let's use %SystemDrive% and not %HOMEDRIVE% and %windir% not %Systemroot%. It's probably most important that we do this for commonly used applications.

Imaging

Change Image Host Name

After imaging (and NOT auto rebooting), return to main menu. Go into Recovery and open Command Prompt. 

i:\imaging\bin\changeimagehostname.cmd

then press enter and input the new host name as prompted

Batch File Reference

http://steve-jansen.github.io/guides/windows-batch-scripting/index.html

...

No Format
If Exist C:\Windows\SysWOW64 (
 GOTO x64
 ) ELSE (
GOTO x86
 )
 
:x64
do some stuff
GOTO END
 
:x86
do some stuff
GOTO END
 
:END
 
 

 


Converting to gpt

 


CMD:

Diskpart

select disk 0 

...

Initialize-Disk -Number 0 -PartitionStyle GPT

 

Getting System Info

Detecting Windows Version

CMD:

 ver | find "6.3" >nul && goto WIN8

...

Get-WindowsEdition -Verbose -Online

Detecting Hardware Model

  if /i "%WMICModel:~0,7%"=="20074DU" set TP=y

...

Using 7-Zip to Unzip to a directory

...


"%~dp07za.exe" x -y -o"C:\Program Files (x86)\NotePadPlusPlus" "%~dp0npp.6.6.6.bin.7z"

...

No Format
If Exist C:\Windows\SysWOW64 (
 do some stuff for 64-bit Windows
 ) ELSE (
do some other stuff for 32-bit Windows
 )
Powershell:

...


No Format
$x = Get-WmiObject win32_operatingsystem
if( $x.OSArchitecture -eq "64-bit") { 
       do stuff in 64-bit Windows
       } else {
       do some stuff in 32-bit Windows
       }

 

...



Getting to the Native cmd prompt
No Format
======================================================== 
@echo off
if not exist c:\windows"%windir%\sysnative\cmd.exe" goto :gonenative
echo Relaunching with x64 cmd.exe...
c:\windows"%windir%\sysnative\cmd.exe" /C "%~dpnx0"
goto :EOF

:gonenative
REM ---paste the rest of your batch code below this line---
  ========================================================

...

	netsh advfirewall firewall add rule name="Google Earth" dir=in action=allow program="C:\Program Files (x86)\Google\Google Earth\client\googleearth.exe"

...


Registry Stuff

Importing into the 64bit Registry

...


reg delete HKLM\Software\Inkscape /f

K1000

/wiki/spaces/itskb/pages/26116466

Google

Remove Duplicates

https://developers.google.com/apps-script/articles/removing_duplicates

Script Text

No Format
function removeDuplicates() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var data = sheet.getDataRange().getValues();
  var newData = new Array();
  for(i in data){
    var row = data[i];
    var duplicate = false;
    for(j in newData){
      if(row.join() == newData[j].join()){
        duplicate = true;
      }
    }
    if(!duplicate){
      newData.push(row);
    }
  }
  sheet.clearContents();
  sheet.getRange(1, 1, newData.length, newData[0].length)
      .setValues(newData);
}


Get Usernames from K1000 Inventory Dump (User Logged)


No Format
=IF(LEFT(O2,4)="ADS\", RIGHT(O2,LEN(O2)-4), O2)

Append to username


No Format
=B2&"@carleton.edu"

Conditional Format if Data in H1 is listed in Column K of PilotUsers Sheet


No Format
=match(H1,indirect("PilotUsers!K:K"),0)

Return data in Column 1 that is NOT in Column 2

No Format
=ArrayFormula(FILTER('2018.11.09 All'!A:A,ISERROR(match('2018.11.09 All'!A:A,'2018.10.09 All'!A:A,0))))

Return value from column D, where column A matches the specified data)

No Format
=VLOOKUP(A3, '2018.11.09 All'!A:D, 4, FALSE)