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. Can't install updates with Powershell Windows update script after kb5040442

    in Windows 10 Gaming
    Can't install updates with Powershell Windows update script after kb5040442: I am using the following script to update Windows images during Hashicorp Packer builds: https://www.powershellgallery.com/packages/AppVeyorBYOC/1.0.82/Content/hyper-v%5CWindows%5Cscripts%5Cwin-updates.ps1The script stops working on Windows 11 22h2 and 23h2 OS versions after...
  3. Can't install updates with Powershell Windows update script after kb5040442

    in Windows 10 Software and Apps
    Can't install updates with Powershell Windows update script after kb5040442: I am using the following script to update Windows images during Hashicorp Packer builds: https://www.powershellgallery.com/packages/AppVeyorBYOC/1.0.82/Content/hyper-v%5CWindows%5Cscripts%5Cwin-updates.ps1The script stops working on Windows 11 22h2 and 23h2 OS versions after...
  4. Powershell script, custom module call crashing session

    in Windows 10 Gaming
    Powershell script, custom module call crashing session: Hey,Currently running into an issue with a custom PowerShell script that I own.The script has been in production almost daily for the past 4-5 years but the past couple weeks it's been erroring out on me for reasons I don't understand. The script in question is an AD mgmt...
  5. Powershell script, custom module call crashing session

    in Windows 10 Software and Apps
    Powershell script, custom module call crashing session: Hey,Currently running into an issue with a custom PowerShell script that I own.The script has been in production almost daily for the past 4-5 years but the past couple weeks it's been erroring out on me for reasons I don't understand. The script in question is an AD mgmt...
  6. help with powershell 5.1 script for copying and moving folders and all their contents

    in Windows 10 Gaming
    help with powershell 5.1 script for copying and moving folders and all their contents: This is the script I wrote:$sources = Read-Host "Enter source folder paths comma-separated" $sourceList = $sources -split ',' $destinations = @"E:\DestinationFolder1", "F:\DestinationFolder2", "W:\DestinationFolder3", "\\ServerName\SharedFolderDestination" foreach $source in...
  7. help with powershell 5.1 script for copying and moving folders and all their contents

    in Windows 10 Software and Apps
    help with powershell 5.1 script for copying and moving folders and all their contents: This is the script I wrote:$sources = Read-Host "Enter source folder paths comma-separated" $sourceList = $sources -split ',' $destinations = @"E:\DestinationFolder1", "F:\DestinationFolder2", "W:\DestinationFolder3", "\\ServerName\SharedFolderDestination" foreach $source in...
  8. Old PowerShell 5.1 scripts won't run on new laptop

    in Windows 10 Gaming
    Old PowerShell 5.1 scripts won't run on new laptop: When I got a new laptop all my settings, programs, and files were transferred over to it from and old Windows 10 desktop pc.When I try and run scripts that I have written previously they won't run and I get an error:PS C:\WINDOWS\system32> bb : The term 'b' is not recognized...
  9. Old PowerShell 5.1 scripts won't run on new laptop

    in Windows 10 Software and Apps
    Old PowerShell 5.1 scripts won't run on new laptop: When I got a new laptop all my settings, programs, and files were transferred over to it from and old Windows 10 desktop pc.When I try and run scripts that I have written previously they won't run and I get an error:PS C:\WINDOWS\system32> bb : The term 'b' is not recognized...
  10. Preview Voice for Microsoft Helena not working after installing via PowerShell Script

    in Windows 10 Software and Apps
    Preview Voice for Microsoft Helena not working after installing via PowerShell Script: Hi,I am working with a machine that has Windows 10 Enterprise 2016 LTSB with OS Version 1607. I had to install the Spanish Language Pack and the Microsoft Helena Text to Speech voice via offline Meaning that I had no access to internet. I was able to install the Spanish...