MoonPoint Support Logo

 

Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
November
Sun Mon Tue Wed Thu Fri Sat
         
22 23
24 25 26 27 28 29 30
2024
Months
NovDec


Sun, Jun 30, 2024 9:12 pm

Determining the version of a PDF document

If you have a Portable Document Format (PDF) file and wish to determine the version of the PDF standard used for the document, that information is stored in the first line of the file. You can open the file with a text editor, such as the Windows Notepad application on a Microsoft Windows system and view the first line to determine the PDF version used for the file. You will see %PDF-x.y where x.y is the version of the PDF standard used in the creation of the file, e.g., %PDF-1.7 for version 1.7.

On a Microsoft Windows system, you could also open a PowerShell window (you can type PowerShell in the Windows Search field and click on the application when you see it returned in the list of results) and use the Get-Content cmdlet and the -First parameter followed by the number one. E.g.:

PS C:\> Get-Content "July 2024 Newsletter.pdf" -First 1
%PDF-1.7
PS C:\>

Related:

  1. PowerShell Get-Content equivalents to Linux head and tail commands
    Date: March 22, 2024

[/os/windows/PowerShell] permanent link

Mon, Apr 15, 2024 9:01 pm

Calculating a hash value for a file with Get-FileHash

The PowerShell cmdlet Get-FileHash provides a cryptographic hash function that will allow you to determine a hash value of a file on a Microsoft Windows system. By default, the cmdlet uses the SHA-256 hash function, but you can specify other functions, such as MD5, using the -Algorithm parameter. You can change the output to a list format by piping the output of the cmdlet to Format-List.

PS C:\users\public\downloads> Get-FileHash ".\rel_x64_Xming-7-7-1-1-setup.exe"

Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
SHA256          B7B4C0A191E315686A2481DCC8BBB27D6D7A156FBF689768E48CF08207B86560       C:\users\public\downloads\rel...


PS C:\users\public\downloads> Get-FileHash ".\rel_x64_Xming-7-7-1-1-setup.exe" | Format-List


Algorithm : SHA256
Hash      : B7B4C0A191E315686A2481DCC8BBB27D6D7A156FBF689768E48CF08207B86560
Path      : C:\users\public\downloads\rel_x64_Xming-7-7-1-1-setup.exe



PS C:\users\public\downloads> Get-FileHash -Algorithm MD5 ".\rel_x64_Xming-7-7-1-1-setup.exe"

Algorithm       Hash                                                                   Path
---------       ----                                                                   ----
MD5             BA200636A596A84E0877901CE89D1C2E                                       C:\users\public\downloads\rel...


PS C:\users\public\downloads>

[ More Info ]

[/os/windows/PowerShell] permanent link

Fri, Mar 22, 2024 9:44 pm

PowerShell Get-Content equivalents to Linux head and tail commands

The Windows PowerShell Get-Content cmdlet can provide the equivalent to the Unix/Linux head and tail commands. E.g., suppose a file named somefile.txt contains the following ten lines:
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10

The following Get-Content commands could be used to obtain the first 5 and the last 5 lines in the file.

PS C:\Users\Arnold\Documents> Get-Content somefile.txt -Head 5
line 1
line 2
line 3
line 4
line 5
PS C:\Users\Arnold\Documents> Get-Content somefile.txt -Tail 5
line 6
line 7
line 8
line 9
line 10
PS C:\Users\Arnold\Documents> Get-Content somefile.txt -TotalCount 5
line 1
line 2
line 3
line 4
line 5
C:\Users\Arnold\Documents>

The TotalCount parameter can function like the Head parameter and will return the first x number of lines specified with x being 5 in the example above. You can also use it to obtain a specific line, though. E.g., if you wished to see the 7th line in the file, you could use the command below.

PS C:\Users\Arnold\Documents> (Get-Content Somefile.txt -TotalCount 7)[-1]
line 7
PS C:\Users\Arnold\Documents>

By default the delimiter for lines is the newline, aka end-of-line character, \n, but you can change that with the -Delimiter parameter.

References:

  1. Get-Content
    Microsoft Learn

[/os/windows/PowerShell] permanent link

Fri, Sep 15, 2023 5:14 pm

Determining the Serial Number of a Disk Drive with PowerShell

If you need to determine the serial number of a hard disk drive (HDD) attached to a Microsoft Windows system, you can do so from a PowerShell window using the cmdlet Get-Disk (you can open a PowerShell window by typing PowerShell in the Windows "Type here to search field on a Windows 10 system and then selecting the app when it is returned in the list of search results). If you just want a list of drives attached to the system by a USB connection, you can pipe the output of the cmdlet to the Where-Object cmdlet where you can filter on just drives that have a USB connection as shown below.

PS C:\> Get-Disk | Where-Object -FilterScript {$_.Bustype -Eq "USB"}
Number Friendly Name Serial Number                    HealthStatus         OperationalStatus      Total Size Partition
                                                                                                             Style
------ ------------- -------------                    ------------         -----------------      ---------- ----------
1      SanDisk Cr... 03025228050421082418             Healthy              No Media                      0 B RAW
2      USB2.0 Car... 606569746800                     Healthy              No Media                      0 B RAW
4      USB2.0 Car... 606569746802                     Healthy              No Media                      0 B RAW
5      USB2.0 Car... 606569746803                     Healthy              No Media                      0 B RAW
3      USB2.0 Car... 606569746801                     Healthy              No Media                      0 B RAW
6      WD My Pass... WXM1A375CKEZ                     Healthy              Online                  931.48 GB GPT


PS C:\>

[ More Info ]

[/os/windows/PowerShell] permanent link

Wed, Sep 13, 2023 10:22 pm

Filtering Windows Updates by a Specific Date

When I logged into a user's Microsoft Windows 10 system to check on a problem, I found the system had rebooted late the night before, September 12, 2003, at a time much later than I would expect the user to be working, so I didn't think she had rebooted it. I didn't know if the reboot might be related to the problem she reported to me or could possibly just be Microsoft Windows rebooting because of an automatically installed update. From a command prompt window, you can obtain the last time the system was rebooted using the systeminfo command. To see just the last reboot time and not all of the other output it provides, you can filter the output with the find command by piping the output of the systeminfo command to the find command. You can check on updates that have been installed using the Windows Management Instrumentation Command-line (WMIC) command wmic qfe list ("qfe" stands for "Quick Fix Engineering"). Since that command can also generate a lot of output for updates on dates you may not be interested in, you can also filter that output with the find command.

[ More Info ]

[/os/windows/PowerShell] permanent link

Fri, Mar 05, 2021 1:38 pm

Obtain Monitor Manufacturer Information Using PowerShell

I wanted to be able to obtain information on a monitor attached to a Windows 10 desktop system, including the manufacturer, model number, serial number, and date of manufacture, from a command-line interface (CLI). One way to do that is by using PowerShell, which Microsoft provides as part of its Windows operating system. You can open a PowerShell window on a Microsoft Windows 10 system by typing PowerShell in the "Type here to search" field at the bottom of the Windows display. You should see the Windows PowerShell app listed as an option you can click on to open a PowerShell window. If you type gwmi WmiMonitorID -Namespace root\wmi at the prompt and hit enter, you will see information similar to the following output displayed.

PS C:\> gwmi WmiMonitorID -Namespace root\wmi


__GENUS                : 2
__CLASS                : WmiMonitorID
__SUPERCLASS           : MSMonitorClass
__DYNASTY              : MSMonitorClass
__RELPATH              : WmiMonitorID.InstanceName="DISPLAY\\HPN360C\\5&2c03a83e&0&UID262_0"
__PROPERTY_COUNT       : 9
__DERIVATION           : {MSMonitorClass}
__SERVER               : YTTERBIUM
__NAMESPACE            : root\wmi
__PATH                 : \\YTTERBIUM\root\wmi:WmiMonitorID.InstanceName="DISPLAY\\HPN360C\\5&2c03a83e&0&UID262_0"
Active                 : True
InstanceName           : DISPLAY\HPN360C\5&2c03a83e&0&UID262_0
ManufacturerName       : {72, 80, 78, 0...}
ProductCodeID          : {51, 54, 48, 67...}
SerialNumberID         : {67, 78, 75, 48...}
UserFriendlyName       : {72, 80, 32, 51...}
UserFriendlyNameLength : 13
WeekOfManufacture      : 12
YearOfManufacture      : 2020
PSComputerName         : YTTERBIUM



PS C:\>

[More Info ]

[/os/windows/PowerShell] permanent link

Sat, Oct 21, 2017 10:13 pm

Using PowerShell to determine the installed version of Windows

You can determine the version of Microsoft Windows installed on a system from a PowerShell prompt using [System.Environment]::OSVersion.Version or (Get-WmiObject -class Win32_OperatingSystem).Caption.

PS C:\Users\Public> [System.Environment]::OSVersion.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      15063  0


PS C:\Users\Public> (Get-WmiObject -class Win32_OperatingSystem).Caption
Microsoft Windows 10 Pro
PS C:\Users\Public> (Get-WmiObject -class Win32_OperatingSystem)


SystemDirectory : C:\WINDOWS\system32
Organization    : Microsoft
BuildNumber     : 15063
RegisteredUser  : Jeanne
SerialNumber    : 00330-80000-00000-AA775
Version         : 10.0.15063



PS C:\Users\Public>

[ More Info ]

[/os/windows/PowerShell] permanent link

Fri, Oct 20, 2017 10:57 pm

Querying disks with the PowerShell Get-Disk cmdlet

You can use the PowerShell Get-Disk cmdlet to query disk drives within or attached to a PC running the Microsoft Windows operating system. E.g.:

PS C:\Users\Public> Get-Disk

Number Friendly Name Serial Number                    HealthStatus         OperationalStatus      Total Size Partition
                                                                                                             Style
------ ------------- -------------                    ------------         -----------------      ---------- ----------
0      ST3320418AS               9VMNNJDN             Healthy              Online                  298.09 GB MBR
4      Generic- C... 058F63626421                     Healthy              No Media                      0 B RAW
6      Generic- M... 058F63626423                     Healthy              No Media                      0 B RAW
3      Generic- S... 058F63626420                     Healthy              No Media                      0 B RAW
5      Generic- S... 058F63626422                     Healthy              No Media                      0 B RAW
1      Lexar USB ... AA58ZF9FJCCALAOA                 Healthy              Online                   14.92 GB MBR
2      WD My Pass... WXP1A27034VH                     Healthy              Online                  931.48 GB GPT


PS C:\Users\Public>

[ More Info ]

[/os/windows/PowerShell] permanent link

Fri, Oct 13, 2017 10:59 pm

Checking the uptime for a Windows system using PowerShell

If you want to determine how long a Microsoft system has been running since it was last rebooted from a command-line interface (CLI), you can do so using PowerShell. You can do so by subtracting the last boot time from the current date and time. The Get-Date cmdlet shows the current date and time and (Get-CimInstance Win32_OperatingSystem).LastBootUpTime shows the last time the system was booted.

PS C:\Users\public\documents> (Get-CimInstance Win32_OperatingSystem).LastBootUpTime

Tuesday, October 10, 2017 9:12:14 PM


PS C:\Users\public\documents> (Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime


Days              : 3
Hours             : 1
Minutes           : 29
Seconds           : 26
Milliseconds      : 717
Ticks             : 2645667172021
TotalDays         : 3.06211478243171
TotalHours        : 73.4907547783611
TotalMinutes      : 4409.44528670167
TotalSeconds      : 264566.7172021
TotalMilliseconds : 264566717.2021



PS C:\Users\public\documents>

You can use the alias GCIM for Get-CimInstance to save some typing, if you wish.

PS C:\Users\public\documents> (GCIM Win32_OperatingSystem).LastBootUpTime

Tuesday, October 10, 2017 9:12:14 PM


PS C:\Users\public\documents>

[/os/windows/PowerShell] permanent link

Tue, Oct 10, 2017 11:31 pm

Wget and curl functionality via PowerShell on a Windows system

If you are accustomed to using the wget or cURL utilities on Linux or Mac OS X to download webpages from a command-line interface (CLI), there is a Gnu utility, Wget for Windows , that you can download and use on systems running Microsoft Windows. Alternatively, you can use the Invoke-WebRequest cmdlet from a PowerShell prompt, if you have version 3.0 or greater of PowerShell on the system. You can determine the version of PowerShell on a system by opening a PowerShell window and typing $psversiontable. E.g., in the example below from a Windows 10 system, the version of PowerShell is 5.1.15063.674.

PS C:\Users\public\documents> $psversiontable

Name                           Value
----                           -----
PSVersion                      5.1.15063.674
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.15063.674
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS C:\Users\public\documents>

If you have version 3.0 or later, you can use wget or curl as an alias for the Invoke-WebRequest cmdlet, at least up through version 5.x. E.g., if I want to download the home page for the website example.com to a file named index.html, I could use the command wget -OutFile index.html http://example.com at a PowerShell prompt. Or I could use either of the following commands, instead:

curl -OutFile index.html http://example.com
Invoke-WebRequest -OutFile index.html http://example.com

[ More Info ]

[/os/windows/PowerShell] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo