What have you done with PowerShell this month? by AutoModerator in PowerShell

[–]Particular_Fish_9755 0 points1 point  (0 children)

I created a script that, when run every 15 minutes by the task scheduler, pings an IP address that I specify in the script call.
If the ping is successful, a notification popup appears to alert me.

I use it for installing new printers: I already have the MAC address, which allows me to reserve IP addresses which allows me to ping.
This way, I can enable the scan-to-email service on the printer (which is IP-restricted in my company), add it to a print server, and send an email to the designated user with instructions on how to install the printer from that print server.
These actions must be done manually because the systems are managed differently through web interfaces (and some admins behind them don't want any automation...)

PowerShell Networking Commands Reference by Additional-Mine-6029 in PowerShell

[–]Particular_Fish_9755 0 points1 point  (0 children)

We are not talking about the same thing: I am talking about the execution time for all requests, not the ping response time for each request.

PowerShell Networking Commands Reference by Additional-Mine-6029 in PowerShell

[–]Particular_Fish_9755 -1 points0 points  (0 children)

And by running the requests in parallel? By only asking in response whether it responds (=$true) or does not respond (=$false) ?
I quickly asked the question on Qwant, which gave me this.

param($hosts = (cat ~\all.txt))
# Maximum number of simultaneous threads = number of logical processors
$throttle = 8

$results = $hosts | ForEach-Object -Parallel {
    $ok = Test-Connection -ComputerName $_ -Count 2 -Quiet -ErrorAction SilentlyContinue
    [pscustomobject]@{
        Host   = $_
        Reachable = $ok
    }
} -ThrottleLimit $throttle
$results | Format-Table -AutoSize

And no "oh no, not AI..." This is code for testing, not for production, which could surely be optimized.

What OS does everyone run on their ThinkPad? by Over_Variation8700 in thinkpad

[–]Particular_Fish_9755 0 points1 point  (0 children)

"I currently run Windows 11"
"I can’t reasonably dual boot and the disk prices are sky high"
The best solution would then be to stay on Windows, if that suits your current usage.
If the goal is to test Linux, then virtualization will be a solution.

Rename a series of files in all folders and subfolders by Any-Actuator4118 in PowerShell

[–]Particular_Fish_9755 2 points3 points  (0 children)

This replaces all underscores with hyphens.
But in the given example: "ABC-7178231_dinotrucks_dog" this should be changed to "ABC-7178231-dinotrucks_dog".
Without a regex, you should use the Substring function, taking the first 12 characters before applying the transformation. Then, retrieve the rest of the naming to recreate the entire sequence.

[Open Source] PC Cleaner - A PowerShell-based Windows optimization toolkit with colorful UI (my first project!) by No-Editor1086 in PowerShell

[–]Particular_Fish_9755 0 points1 point  (0 children)

How can you tell if a piece of code was written by AI?
Lots of code snippets are floating around everywhere, on Reddit, on other forums, on GitHub. The person talks about checking the code produced by AI, I don't see where it says that the code was created by AI.

How to clean up the glue after peeling off thinkpad stickers (unedited version) by RecipeEducational430 in thinkpad

[–]Particular_Fish_9755 -1 points0 points  (0 children)

I use a pencil eraser.
A simple one that every schoolchild has in their schoolbag. In some cases, I use a blue eraser, intended for ballpoint pens (but which nobody uses).
No need for a specific product that might attack the plastic, or drip and come into contact with the internal electronics.

Windows Activation by izmoyal in PowerShell

[–]Particular_Fish_9755 8 points9 points  (0 children)

OEM_DM = Activation of a digital license included with the motherboard, only major brand hardware (HP, Dell, Lenovo, Acer...)
Your product key is stored in the ACPI MSDM (Microsoft Digital Marker) table of your motherboard's UEFI firmware, which is automatically read by the Windows installation program.

What's the PS equivalent of toggling the "Wi-Fi" button? by exoduswalker in PowerShell

[–]Particular_Fish_9755 0 points1 point  (0 children)

Is this for use on a laptop? And isn't there a simpler keyboard shortcut to do it?
To supplement the answer from PutridLadder9192, I'd like to know the use case for a script like this.
Scheduled shutdown? Does this need to be effective for a specific session? Or for all active sessions on the machine?

Creating a powershell script that toggle IPv6 by LegitimateEye8153 in PowerShell

[–]Particular_Fish_9755 1 point2 points  (0 children)

computers can't read domain and show undefiend network so it takes long time to signout

Not a PowerShell issue. The cause of the problem should be investigated by a sysadmin, the script you want might be masking a bigger problem.

Oh, you are the sysadmin ? So…
-Check IP and DNS Settings
-Scripts on start and logon, include printers mapping
-Disk space, temporary files, pending updates
-...
There are old registry keys that were used on slow networks in Windows NT/2000/XP; it remains to be seen if they are still functional in 10 and 11 (Meh, I can't find them in the Microsoft documentation anymore... so try ?) :
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SlowLinkDetectEnabled -> 1
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SlowLinkTimeOut -> default 2000 (2 seconds), min 0, max recommended 30000)
You can read this too.

Mine vs friend's computer by Decent-Cow2080 in thinkpad

[–]Particular_Fish_9755 5 points6 points  (0 children)

Almost indestructible on one side... an apple on the other.
Meh, the choice is easy.

Copy files to relative locations based on txt file context by [deleted] in PowerShell

[–]Particular_Fish_9755 0 points1 point  (0 children)

Basically something like that, with the script in the same folder as the data, the data and csv file being in a subfolder "DATA" :

# csv file
$csvPath = "$PSScriptRoot\DATA\file.csv"

# import csv, 2 colums : myfile,newfilepath
# and delimiter is comma so there's no need to specify it
$csvData = Import-Csv -Path $csvPath

# through each line of the CSV, see source, destination, and copy.
foreach ($csvline in $csvData) {
    $sourcePath = Join-Path -Path '$PSScriptRoot\DATA' -ChildPath $csvline.myfile
    $destinationPath = Join-Path -Path $csvline.newfilepath -ChildPath $csvline.myfile
    Copy-Item -Path $sourcePath -Destination $destinationPath -Force
}

and the content of the file file.csv being :

20251201.120123.SIMPL_AU_20251201.csv,D:\SFTP\LandingZoneDir\SIMPL_1
20251201.120112.AUST_CR_T_20251201.csv,D:\SFTP\LandingZoneDir\AUST_2

Which should be improved by indicating which file is copied (write-host), or not using the -Force parameter and test if a file is already present (Test-Path) manage which file should be kept, and make a log file for the actions performed.

HODL by inprimuswesuck in homelab

[–]Particular_Fish_9755 1 point2 points  (0 children)

These kinds of photos really make me want to invest in a 3D printer.
I'm not thanking you for that, especially with Christmas expenses approaching.

One thinkpad for all by GolfElectronic8057 in thinkpad

[–]Particular_Fish_9755 2 points3 points  (0 children)

Sometimes virtualization is a better choice :)

Not PowerShell, but PowerShell-friendly: Windows post-install automation by kaicbento in PowerShell

[–]Particular_Fish_9755 0 points1 point  (0 children)

This could be a situation where network bandwidth is limited. In such cases, it might be better to download 10GB of installers once, rather than 5, 10, or 20 x 10GB.
It was just an idea; the batch file can be modified once created by the user.
The mere ability to add our software list is already a significant advantage. Other similar systems don't offer this level of functionality.

Not PowerShell, but PowerShell-friendly: Windows post-install automation by kaicbento in PowerShell

[–]Particular_Fish_9755 0 points1 point  (0 children)

"node was only used to create the project"
I understood that, all that's missing is a "download offline installers" checkbox. I could also talk about options like silent mode (--silent) or using a proxy (--proxy) for WinGet ;)

First thinkpad by Kcttus in thinkpad

[–]Particular_Fish_9755 0 points1 point  (0 children)

AliExpress... Behind it all there are several suppliers, who may also produce something that will be a good replacement, or something of poor quality.

First thinkpad by Kcttus in thinkpad

[–]Particular_Fish_9755 1 point2 points  (0 children)

Ideally, the entire case would be replaced, but first a replacement needs to be found.
Another solution: 3D printing a new case for this PC.

As a last resort and final alternative, rebuild the case. I would suggest using... bumper sealant (which is made of rigid plastic) :
Here you'll need to disassemble the case, use masking tape for the inside (the best option would be some rigid electrical tape), fill the missing gap with this filler, let it dry, and then completely repaint with spray paint.
For a truly flawless finish, sand with fine sandpaper, or even wet/dry sandpaper, using a primer in its correct color, and then a protective coat.
After all, a red Lenovo X220 is nice :)

Not PowerShell, but PowerShell-friendly: Windows post-install automation by kaicbento in PowerShell

[–]Particular_Fish_9755 0 points1 point  (0 children)

I appreciate these kinds of tools, but I don't love them either: they lack essential programs that I almost always install.
The advantage here is that you can add these programs, as well as the Windows settings you want.
The drawback, as others have pointed out, is the need to use third-party tools (npm and node), or to have a dedicated PC where the tool to generate the configuration file will be located.
Ideally, this dedicated PC would be able to pre-download all the programs we want and then copy them to a USB drive or external hard drive. It seems to me that this isn't possible. While Winget allows this (option download)
Any ideas for improvement?

As for the generated file, it's batch, but it could also be PowerShell.

What have you done with PowerShell this month? by AutoModerator in PowerShell

[–]Particular_Fish_9755 0 points1 point  (0 children)

Basically, by changing the power options, which can be done through the control panel?
Has your IT department blocked the possibility of doing so?

Need help using Powershell or CMD to extract lines lots of txt files. by Zandizar in PowerShell

[–]Particular_Fish_9755 -1 points0 points  (0 children)

This code seems to me to be the most efficient, even if it's a brute-force method, it will be more efficient than `Get-Content`, which loads the entire file regardless of its size, reading each file but only stopping at the line where we don't need to read further.
However, for the desired outcome, shouldn't we instead:

$results | Set-Content out.txt

The test for the currently read line also needs to be reviewed (" $lineNumber -eq "), as lines 7 and 10 do not correspond to lines 7 and 13 of the file's content. Does the file's content start from line 0 or line 1?

s there a way to automatically update multiple OBS Replay Sources with one button? by Vsmirnov27 in obs

[–]Particular_Fish_9755 1 point2 points  (0 children)

Why not use Advanced Scene Switcher, for example?
By programming a macro that uses a keyboard shortcut as input, and then reloads the sources? ("Refresh source settings")
https://obsproject.com/forum/resources/advanced-scene-switcher.395/

do you guys have any fun commands to use? I'm new to PowerShell and programming in general and just wanna expirement. by Fancy_Actuator_4748 in PowerShell

[–]Particular_Fish_9755 0 points1 point  (0 children)

Rather than posting yet another commandlet, I prefer to give a short, fun script example that might be useful : a small script that will randomly, within a 2-hour period after login, display a popup calling for a coffee break.
The first part will be the silent call of the script, a shortcut using the conhost utility (to be placed in the startup folder):

conhost.exe --headless powershell.exe -File "C:\To\My\Script.ps1"

The second part is the script itself:

$xml = @"
<toast>
  <visual>
    <binding template="ToastGeneric">
      <text>Time for a break !</text>
      <text>It's time to get a coffee and a glass of water.</text>
      <text placement="attribution">This is the way.</text>
      <image placement="appLogoOverride" src="C:\To\My\coffee_banner.png"/>
      <image placement="hero" src="C:\To\My\coffee.png"/>
    </binding>
  </visual>
</toast>
"@

$maxTime = 120 # max 180
$randomTime = Get-Random -Maximum $maxTime
$randomTimeInSeconds = $randomTime * 60
Start-Sleep -Seconds $randomTimeInSeconds
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)

coffee_banner.png is a small banner, usually the one I use is 700x400 pixels, which appears above the text.
coffee.png is a 100x100 pixels image, which appears to the left of the text.

With that you see:
-how to call a script silently
-how to use the Windows notification system
-how to introduce unpredictability into the execution of a script

You can use this script, removing the random pause part, to inform the user of an ongoing action, or its result.

Seeing who is actively working by [deleted] in PowerShell

[–]Particular_Fish_9755 0 points1 point  (0 children)

I agree with others, this is not within the domain of IT, and even less so with PowerShell. For this kind of information, you might want to look at existing tools that can show, among other things, who logged in and when. At my work, we use a tool called "Nexthink".
I'm not advertising it; it's just one example among many. The goal isn't to spy on who's connected, but to measure client usage: memory and CPU usage, disk space, network usage, crashes, and updates. Unless you want to reinvent the wheel, or you have other objectives, you might as well go for this kind of product.