First Post and new to scripting/powershell so apologies for any formatting or if I leave something out. Currently trying to use a script to restart a list of IP's from a text file.
When I run the script and run a constant ping on my test device, nothing happens. When I run psexec \insert IP shutdown /r /t 0 within powershell it works. Wondering why I can't get ISE to run my psexec command for me?
$user = $env:USERNAME
if(!(Test-Path -Path c:\temp\Scripts\$user))
{
mkdir c:\temp\Scripts\$user -Force
}
if(!(Test-Path -Path C:\temp\Scripts\$user\DeviceIps.txt))
{
New-Item -Path C:\temp\Scripts\$user\DeviceIps.txt
}
Else
{
#If the file exists, it clears your previous query
Clear-Content -Path C:\temp\Scripts\$user\DeviceIps.txt
}
#Invokes file to enter multiple searches/filters
Invoke-Item -Path C:\temp\Scripts\$user\DeviceIps.txt
Pause
$ip = Get-Content -Path C:\Temp\Scripts\$user\DeviceIps.txt
foreach($ip in $DeviceIps){
& psexec.exe \\$ip shutdown /r /t 0
}