Skip to main content

Posts

Showing posts from February, 2015

Word VBA get paper tray settings

VBA code below will get and set paper tray settings of a word document. Macro tested on Word 2010. Values 7 and 1 are the value output from the message box. I'm not sure whether values are dependent on printer driver. On my word 2010 those are the values that can be used to set paper tray settings. 7 - will set to "Automatically Select" 1 - will set to Tray1 If got documents received from other party that always retain the printer settings. A macro will be useful to change the settings or by doing it manually by going to Page Setup and change the paper tray settings. Sub getpapertray() Dim xtray1, xtray2 xtray1 = ActiveDocument.PageSetup.FirstPageTray xtray2 = ActiveDocument.PageSetup.OtherPagesTray MsgBox xtray1 MsgBox xtray2 'Set the tray to Automatically Select ActiveDocument.PageSetup.FirstPageTray = 7 'Set the tray to Tray 1 ActiveDocument.PageSetup.OtherPa...

Check Task Scheduler using command line

Using command line to check Task Scheduler could be daunting sometimes if you are a GUI junkie. But if you need to monitor remote system definitely command line would be the best choice. And using command line process can be automated without user intervention. Here are some examples on how to use command line to check Task Scheduler.   schtasks /query /fo LIST /v > sch_all_task.txt Command line above will query task scheduler and redirect the output to sch_all_task.txt Redirecting to a text file is useful. You will have a copy of the result in a text file for record purposes. If the output is not redirected to a text file some of the result cannot be seen on the command line window. The above command will list all the scheduled tasks results running on task scheduler. To check a single scheduled Task in command line use this command below: C:\>schtasks /query /v /fo list   /TN "Monitor Files" Sample Output: ...

Word VBA delete page selection

Sub Macro_VBA_Delete_Page() Selection.GoTo wdGoToPage, wdGoToAbsolute, 2 Selection.Bookmarks("\Page").Select Selection.Delete Unit:=wdCharacter, Count:=1 End Sub Selection.GoTo wdGoToPage, wdGoToAbsolute, 2 Line above will goto page number "2" Selection.Bookmarks("\Page").Select This will select the whole page. Selection.Delete Unit:=wdCharacter, Count:=1 As the keyword specified "Delete", it will delete the whole page   To delete 2 subsequent pages using VBA use code below: Sub Del_pages() Dim i  For i = 1 To 2 Selection.GoTo wdGoToPage, wdGoToAbsolute, 2 Selection.Bookmarks("\Page").Select   Selection.Delete Unit:=wdCharacter, Count:=1  Next End Sub Code above will delete page 2 and page 3 on the word document Selection.GoTo wdGoToPage, wdGoToAbsolute, 2 Code above will goto page 2 and once page 2 is deleted, page 3...

PowerShell Get AD user SID

Get user/s SID in Active Directory using SamAccountName. To check SID for a single user: (GET-ADUSER –Identity ) | select SID, UserPrincipalName (GET-ADUSER –Identity Pedro ) | select SID, UserPrincipalName Above example will get user Pedro SID and it's UPN. If need to get list of user's SID in Active Directory, it would be best to get the list on a text file and put users name on it. 1users.txt will have this list: UserA UserB FinanceA FinanceB Sales01 Sales02 Use the code below to read the text file and list user's SID and UPN. =============================== $pathToFile = "d:\1users.txt" $getTxtLines = Get-Content $pathToFile foreach ($LineUpdatex in $getTxtLines ) { #write-host $LineUpdatex `n #code below will display the output (GET-ADUSER –Identity $LineUpdatex ) | select SID, UserPrincipalName #use code below to export the output to CSV format #(GET...