Category: PowerShell

  • Make Link List with PowerShell

    A script to get a list of links off a given page. I found these two examples to start from: http://normansolutions.co.uk/post/using-powershell-to-check-all-pages-in-websitehttps://www.petri.com/testing-uris-urls-powershell.

    clear
    function get-URLlist($testPage, [int]$linkDepth){
        #set the counter
        [int]$i = 0     #loop thru the list of links, going to sub-pages until the counter equals the given link depth
        while($linkDepth -gt $i) {
            foreach($link in $testPage.Links) {
                #only look at links on the same site
                if($link.href.ToString() -notlike "http*") {
                    #if not already in the array, add it
                    if(!($sitemap.ContainsKey($link.innerText))){
                        $sitemap.add($link.innerText, $url + "/" + $link.href)
                        $testPage = Invoke-WebRequest "http://$url"
                        #check out the sub-pages one less level than the given link depth
                        $sitemap = get-URLlist -testPage $testPage -linkDepth $($linkDepth-1)
                }
            }
        }
        $i++
    }
    return $sitemap
    } try{
        #set your domain and the array to hold the links
        $url = "www.domain.com"
        $sitemap = @{}     #read the page
        $testPage = Invoke-WebRequest "http://$url"
        #get all the links into the array
        $sitemap = get-URLlist -testPage $testPage -linkDepth 5
        $sitemap
    }
    catch{
        "There was an error- `r`n$($_.Exception.Message)"
    }

    I wrote this with an understanding of what the links look like on this page, so the function formats them with the given URL.

  • Using Google domains with a dynamic IP

    This is a script to read the current public IP and update your Google domain with the new IP-

    #get the current IP
    $url = "https://ifconfig.co/json"
    $ip = Invoke-RestMethod $url
    #send the new IP to Google
    $updateCommand = "https://username:[email protected]/nic/update?hostname=dynamic.domain.com&myip=$($ip.ip)"
    Invoke-RestMethod $updateCommand

    Here is some documentation on Google on how to change your DNS via API- https://support.google.com/domains/answer/6147083. The short version is make a domain or subdomain dynamic. When you do this there will be a username and password generated for you, use this in the above script.

  • Setting time on Windows 2008

    I have my AD DC set the time for my network. Since it’s not really that good at keeping time I had to set the DC to pull the time from the govn’ment. I set all this via command line in Windows 2008. I would cite where I got this from but didn’t note it at the time, sorry!

    ### steps to set up NTP servers on DC ###
    0. make sure UDP port 123 is open bi-directionally
    1. stop time service (net stop w32time or in list of services)
    2. configure external sources-
    w32tm /config /manualpeerlist:"0.pool.ntp.org,1.pool.ntp.org,2.pool.ntp.org" /syncfromflags:manual 
    3. set DC as reliable-
    w32tm /config /reliable:yes
    4: start time service (same as above)
    5. check event viewer for errors

    So once the DC is ‘cool’ for time giving, how is far off is it?

    ### to check how off your time is ###
    w32tm /stripchart /computer:0.pool.ntp.org /dataonly

    Then set the DC to use the internet time.

    ### to set your time to internet time ###
    W32tm /resync /computer:time.windows.com /nowait

    Then on each client machine you use the following to set them to use the DC for time giving-

    ### set time from DC ### 
    net time \\home.server.com /set /y

    Good luck!

    UPDATE-

    This time I made note of where I got the instructions from- https://www.faqforge.com/windows-server-2016/configure-ntp-server-windows-server-2016/. The only addition this makes is to note the PowerShell command to update on the client side.