Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Powershell Script. Where am I going wrong?

$
0
0

Hi folks,

I am working on my first powershell script.  The goal of it is to parse a URI, pick-out all valid IP addresses, and write a UTF8 w/o BOM encoded file containing just the IP addresses to a directory.  The script actually works well when executed from powershell.  However, when I attempt to execute it using Windows Task Scheduler, the file is not written.  Interestingly, Windows Task Scheduler seems to think the script is running correctly.  When I run the script via task scheduler, I do so on demand, as "Administrator".  The program is "powershell", and then I paste in the script text into the arguments.  It's taken me two days to get to this point, and it's dismaying seeing that I can't get it to auto-execute in Task Scheduler.  Is anyone able to get it going?  If so, please share details / screenshots.

Thanks so much folks!  I think this might be the first of many PS scripts I write.  Please excuse the sloppiness!

 

$list_uri = "https://isc.sans.edu/ipsascii.html?limit=500"; $output_file_and_directory="c:\blacklists\sans.list"; $dynamic_list = Invoke-WebRequest -usebasicparsing $list_uri;[REGEX]::Matches($dynamic_list.Content,'\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b').Value > c:\blacklists\dynamic.temp; $dynamiccontent = get-content c:\blacklists\dynamic.temp; [System.IO.File]::WriteAllLines("$output_file_and_directory", $dynamiccontent) ; remove-item c:\blacklists\dynamic.temp


Viewing all articles
Browse latest Browse all 8583

Trending Articles