none
Parsing date from PS Object comparing date and actioning if older than 60 days RRS feed

  • General discussion

  • Hi, 

    Hi,

    We have a number of Azure NSG entries in a NSG which are dynamically added by another process which are named in the format of "1653993491-2018-10-19"

    What we would like to do is have a powershell script that, pulls all inbound rules on the NSG, parses out the date out of the name and checks once a day if the entries are older than X days(60) from current date and removes the respective rule. 

    Anyone have any suggestion this? Not sure how to go about making a loop to pull it for all lines and check. The parsing aspect I feel should not be too complicated.  Anyone has any tips suggestions for the loop would be appreciated as a starting point. 

    Rules can be pulled with

    https://docs.microsoft.com/en-us/powershell/module/azurerm.network/get-azurermnetworksecurityruleconfig?view=azurermps-5.1.1

    Thanks in advance!



    • Edited by PStudios Friday, January 19, 2018 7:46 PM
    • Changed type Bill_Stewart Monday, March 12, 2018 8:21 PM
    • Moved by Bill_Stewart Monday, March 12, 2018 8:22 PM This is not "scripts on demand"
    Friday, January 19, 2018 7:41 PM

All replies

  • Example extracting using regular expression:


    "1653993491-2018-10-19" | Select-String "\d+-(.+)" | ForEach-Object { [DateTime] $_.Matches[0].Groups[1].Value }



    -- Bill Stewart [Bill_Stewart]

    Friday, January 19, 2018 7:49 PM