Windows 10: PowerShell script

Discus and support PowerShell script in Windows 10 Support to solve the problem; The code below tests a series of IPs in a txt file.The result is as follows and is written in a txt file. 19.191.12.161 - online 19.191.12.162 -... Discussion in 'Windows 10 Support' started by kinderu81, Jul 20, 2021.

  1. kinderu81 Win User

    PowerShell script


    The code below tests a series of IPs in a txt file.The result is as follows and is written in a txt file. 19.191.12.161 - online 19.191.12.162 - offline 19.191.12.163 - offline 19.191.12.164 - offline 19.191.12.165 - offline also see the scrennshot Code: $Output= @()$GetIP = Get-Content "C:\Users\sdragu2\Desktop\GetIP.txt"foreach ($name in $GetIP){ if (Test-Connection -Delay 15 -ComputerName $name -Count 1 -ErrorAction SilentlyContinue) { #$Output+= "$name, online" $Output = $Output + "$name - online" Write-Host "$Name - online" -ForegroundColor Green } else { #$Output+= "$name, offline" $Output = $Output + "$name - offline" Write-Host "$Name - offline" -ForegroundColor Red }}Read-Host -Prompt "Press Enter to exit"$Output | Out-file "C:\Users\sdragu2\Desktop\Test-Connection.txt" Then I made the script in OOP, but another result is displayed. Code: class Connection{ [string] $Output = @() [string] $GetIP = @() [string] $Path Connection([string] $Path) { $this.GetIP = (Get-Content "$Path") } [void] PSPrint() { foreach ($name in $this.GetIP) { if (Test-Connection -Delay 15 -ComputerName $name -Count 1 -ErrorAction SilentlyContinue) { $this.Output+= "$name - online" Write-Host "$Name - online" -ForegroundColor Green } else { $this.Output+= "$name - offline" Write-Host "$Name - offline" -ForegroundColor Red } } } [void] ExitScript() { Read-Host -Prompt "Press Enter to exit" } [void] FilePrint() { $this.Output | Out-file "C:\Users\sdragu2\Desktop\Test-Connection.txt" }}$box = [Connection]::new("C:\Users\sdragu2\Desktop\GetIP.txt")$box.PSPrint()$box.ExitScript()$box.FilePrint() Do you have any idea why it is not displayed correctly in OOP?

    :)
     
    kinderu81, Jul 20, 2021
    #1

  2. PowerShell scripts not working with Call operator

    Hi,



    Thank you for writing to Microsoft Community Forums.



    I understand that you are facing issues while developing a PowerShell script using the Call operator. I would suggest you to refer the articles

    The Windows PowerShell ISE
    .



    However, as the issue is related to developing PowerShell scripts, I would suggest you to post your query on

    MSDN forums
    , where we have expertise and developers who are well equipped with the knowledge of developing PowerShell scripts in Windows.



    Regards,

    Prakhar Khare

    Microsoft Community – Moderator
     
    Prakhar_Khare, Jul 20, 2021
    #2
  3. Powershell script

    Hi Muhammed DanishM S,

    Thank you for posting your question in the Microsoft Community Forums.

    I would like to let you know that the Windows PowerShell command-line and scripting language can be used to automate many Group Policy tasks, including configuring registry-based policy settings and various Group Policy Management Console (GPMC) tasks.

    Refer to this article to know more.

    Group Policy Cmdlets in Windows PowerShell

    For more information, I would suggest you to post your query in
    MSDN Forums
    , where we have developers and support professionals who are well-equipped with the knowledge on PowerShell
    scripts to assist you with your query.

    Regards,

    Srimadhwa B

    Microsoft Community-Moderator
     
    Srimadhwa_B, Jul 20, 2021
    #3
  4. PowerShell script

    Powershell script

    How to write powershell script ( or command) to change the configuration in group policy administrative templates?
     
    Muhammed DanishM S, Jul 20, 2021
    #4
Thema:

PowerShell script

Loading...
  1. PowerShell script - Similar Threads - PowerShell script

  2. How to run PowerShell Scripts without Signing in Windows 10

    in Windows 10 News
    How to run PowerShell Scripts without Signing in Windows 10: [ATTACH]Windows PowerShell is a powerful terminal from Microsoft which allows you to automate and script tasks on Windows machines and interact with many of the applications available on them. It is a huge improvement over Command Prompt and is mostly aimed towards...
  3. Powershell Script - Reinstalling Application

    in Windows 10 Support
    Powershell Script - Reinstalling Application: Hoping someone can assist, I'm trying to create a powershell script that uninstalls and then reinstalls an application, the new installer is using an executable file (.exe). I've been able to get the commands to run when opening Powershell as Admin and copying the code in...
  4. Powershell Script to connect AD and check if the user is member of a group or not.

    in Windows 10 Customization
    Powershell Script to connect AD and check if the user is member of a group or not.: Can you help me to create a Powershell Script to connect AD and check if the user is member of a group or not from client machine and set a registery key based on the condition...
  5. How to convert PowerShell script (PS1) file to EXE with IExpress on Windows 10

    in Windows 10 News
    How to convert PowerShell script (PS1) file to EXE with IExpress on Windows 10: [ATTACH]You can wrap an executable file around a PowerShell script (PS1) so that you […] This article How to convert PowerShell script (PS1) file to EXE with IExpress on Windows 10 first appeared on TheWindowsClub.com. read more...
  6. Tweaking Performance Using PowerShell Scripts

    in Windows 10 Performance & Maintenance
    Tweaking Performance Using PowerShell Scripts: Hi, Regarding the many scripts that I saw online e.g. Sophia scripts...etc, does it remove the associated registry key files of the apps/services it uninstalls? 171269
  7. Pass an argument from a .bat file to PowerShell script

    in Windows 10 Support
    Pass an argument from a .bat file to PowerShell script: I have subscribed to a push notification service in order to be able to send push notifications to my phone. Here is the PowerShell script: Code: $uri = "https://api.pushover.net/1/messages.json" $parameters = @{ token = "token" user = "user" message = "Push Message" }...
  8. How to turn on or off Windows PowerShell script execution

    in Windows 10 News
    How to turn on or off Windows PowerShell script execution: [ATTACH]If you want to turn on or off Windows PowerShell script execution in Windows […] This article How to turn on or off Windows PowerShell script execution first appeared on TheWindowsClub.com. read more...
  9. Run Windows PowerShell scripts first at user logon, logoff, startup, and shutdown

    in Windows 10 News
    Run Windows PowerShell scripts first at user logon, logoff, startup, and shutdown: [ATTACH]If you want to run Windows PowerShell scripts first at user logon, logoff, startup, […] This article Run Windows PowerShell scripts first at user logon, logoff, startup, and shutdown first appeared on TheWindowsClub.com. read more...
  10. How to open a .html file in Edge in PowerShell script"

    in Windows 10 Network and Sharing
    How to open a .html file in Edge in PowerShell script": What do I have to do to open a local .html file in MS Edge? This works from command line: & "C:\Program Files x86\Microsoft\Edge\Application\msedge.exe" C:\Users\bernie\Desktop\combined_homework.html I've tried all of the methods below, and none work. I thought this...