{
*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
Split a Text File into pieces based on text
(The text in this case is "1 row"
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
ditto -ck foldername foldername.zip
DiskUtil
Converting from core storage
diskutil cs list
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
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:
======================================================== @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
If Statement Examples:
IF, no ELSE
if exist %SystemRoot%\system32\Macromed\Flash\flash.ocx %SystemRoot%\system32\Macromed\Flash\UninstFl.exe -q -u %SystemRoot%\system32\Macromed\Flash\flash.ocx if exist %SystemRoot%\system32\Macromed\Flash\flash6.ocx %SystemRoot%\system32\Macromed\Flash\UninstFl.exe -q -u %SystemRoot%\system32\Macromed\Flash\flash6.ocx
IF, ELSE
If Exist C:\Windows\SysWOW64 ( do some stuff for 64-bit Windows do maybe another line of stuff ) ELSE ( do some other stuff for 32-bit Windows and maybe another line of stuff )
IF, ELSE, GOTO
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
clean
convert gpt
Powershell:
Clear-Disk -Number 0
Initialize-Disk -Number 0 -PartitionStyle GPT
Getting System Info
Detecting Windows Version
CMD:
ver | find "6.3" >nul && goto WIN8
This will detect Windows 8 and goto a section in a batch file for Win8
Powershell:
$Bitness = Get-WMIObject win32_operatingsystem
$Bitness.OSarchitecture
or
(Get-WMIObject win32_operatingsystem).OSarchitecture
Get-WindowsEdition -Verbose -Online
Detecting Hardware Model
if /i "%WMICModel:~0,7%"=="20074DU" set TP=y
Detects Model = 20074DU and sets a variable
Killing Things
Kill a task
CMD:
taskkill /F /IM iTunesHelper.exe
PowerShell:
Stop-Process -Force -Name iTunesHelper
Stop a Service
CMD:
net stop "Apple Mobile Device"
net stop "Intel(R) Management and Security Application Local Management Service"
Powershell:
Stop-Service -Force -DisplayName "Apple Mobile Device"
Stop-Service -Force -DisplayName "Intel(R) Management and Security Application Local Management Service"
Introducing wait time
PING -n 30 127.0.0.1>NUL
Installing Things
Install an MSI based Program
msiexec.exe /i ENX7Inst.msi USERCANAPPLYUPDATES=F /qb
Apply an MSI patch
msiexec.exe /update ENX7Update.msp /qb
Using 7-Zip to Unzip to a directory
"%~dp07za.exe" x -y -o"C:\Program Files (x86)\NotePadPlusPlus" "%~dp0npp.6.6.6.bin.7z"
Testing for 64bit Windows
CMD:
If Exist C:\Windows\SysWOW64 ( do some stuff for 64-bit Windows ) ELSE ( do some other stuff for 32-bit Windows )
Powershell:
$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
======================================================== @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--- ========================================================
xcopy flags
/e /c /i /h /r /y /z
Dealing with UnTrusted Drivers
The solution is quite simple. Using a VM or a system for testing, install the software and check off "Always Trust software from [Publisher]". What this does is place a certificate in the local computers certificate store that will rid future installs from Novell of this dialogue. What we do then, is export the certificate and put it into your install script. Follow the below to conquer this problem:
- In your test environment, install the program fully and be sure to click 'Always trust software from [Publisher]
- Run certmgr.msc and navigate to Trusted Publishers then Certificates
- The certificate from the publisher will show up there. Right click and click All Tasks -> Export. Save the file.
You now have the certificate from the test environment. You need to import this to the computers being deployed to prior to the install. Simply run the following command in your install script before the program install:
certutil -addstore "TrustedPublisher" MyCertificate.cer
Uninstalling Things
Uninstall an MSI based Program
echo Attempting to uninstall Endnote X6
MsiExec.exe /x{86B3F2D6-AC2B-0016-8AE1-F2F77F781B0C} /qn
You can find this code in HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall
Running an Uninstall.exe from an Unknown folder
FOR /D %%G in ("c:\Program Files\R\*") Do "%%G\unins000.exe" /SILENT
FOR /D %%G in ("c:\Program Files (X86)\R\*") Do "%%G\unins000.exe" /SILENT
Deleting a folder with a wildcard
for /D %%f in ("c:\Program Files\Inkscape"*) do rd "%%f" /s /q
Cleanup
Delete Desktop Shortcuts
FOR /D %%G in ("c:\Users\*") Do del "%%G\Desktop\EditPad Lite 7.lnk"
If you know the location of the shortcut, you can do the following:
del /F /Q "yourpathhere"
i.e. del /F /Q "c:\Users\Public\Desktop\Evernote.lnk"
Copying Start Menu Shortcuts
mkdir "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\NotepadPlusPlus"
xcopy "startmenu\notepad++.lnk" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\NotepadPlusPlus" /e /c /i /h /r /y /z
Adding Firewall Exceptions
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.exe import registryfile.reg /reg:64
Verifying stuff in the 64bit Registry in a KBOX Script
Verify that
HKLM64\Software\path to your stuff
Deleting Registry Keys
reg delete HKLM\Software\wOW6432Node\Inkscape /f
reg delete HKLM\Software\Inkscape /f
K1000
/wiki/spaces/itskb/pages/26116466
Remove Duplicates
https://developers.google.com/apps-script/articles/removing_duplicates
Script Text
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)
=IF(LEFT(O2,4)="ADS\", RIGHT(O2,LEN(O2)-4), O2)
Append to username
=B2&"@carleton.edu"
Conditional Format if Data in H1 is listed in Column K of PilotUsers Sheet
=match(H1,indirect("PilotUsers!K:K"),0)
Return data in Column 1 that is NOT in Column 2
=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)
=VLOOKUP(A3, '2018.11.09 All'!A:D, 4, FALSE)