Rob Simmers

Forum Replies Created

Viewing 15 posts - 1 through 15 (of 1,750 total)
  • Author
    Posts
  • in reply to: Help Formatting Output of a Script #257399
    Participant
    Topics: 13
    Replies: 1753
    Points: 3,136
    Helping Hand
    Rank: Community Hero

    Not really following what you are looking for. The data is by user, not by device. If you want to see how many devices instances there are, you could use grouping:

    in reply to: lcd error – ftp WinSCP powershell script #257252
    Participant
    Topics: 13
    Replies: 1753
    Points: 3,136
    Helping Hand
    Rank: Community Hero

    Use qoutes around the path:

    in reply to: Read computername from csv and list last logged on user in csv #257198
    Participant
    Topics: 13
    Replies: 1753
    Points: 3,136
    Helping Hand
    Rank: Community Hero

    There are a ton of resources that show you how to read from a CSV, even in this forum. Get-WMIObject is deprecated, use Get-CimInstance. The logic in the code could use some work.

    • Get all network profiles
    • Sort profiles on lastlogon descending
    • Select the first item with all properties
    • Where the lastlogon matches 14 char digit
    • Loop thru each objects
    • Create a new object with parsed date

    When I test, the date does not require parsing:

    Note that NULL lastlogon date are filtered out in the actual query, so no need for the Where or the for loop or creating another object:

    Participant
    Topics: 13
    Replies: 1753
    Points: 3,136
    Helping Hand
    Rank: Community Hero

    Display all properties so you can see what you specifically need:

    in reply to: Extracting data from excel and updating variables #257060
    Participant
    Topics: 13
    Replies: 1753
    Points: 3,136
    Helping Hand
    Rank: Community Hero

    Let’s start with something like this. Excel is the devil. It uses an old COM object and is painful. Take something like this:

    http://mekalikot.blogspot.com/2014/08/read-and-get-values-from-excel-file.html

    To extract information you have to emulate what you would do the in gui to select the cells and the loop through them to get data. Powershell uses PSObject, so you would have to loop through it to generate a PSObject to then export to a CSV to keep a copy for comparison. A bit ugly. Powershell can import a CSV directly into a PSObject and then you get all of the power of Powershell to do comparisons, filters, etc. on the content. If it were me, I would just try to grab the sheet I’m looking for and save it as a CSV like this:

    http://blog.powercram.com/2015/05/use-powershell-to-save-excel-worksheet.html

    This code create a CSV from the XLSX, if you have a previous csv to perform deltas then it will show you what changed. Otherwise, you and comparing nothing, but Compare-Object is used to output just for consistent output:

    The first run you have no previous data to perform deltas, so it would just be like this:

    When I ran this, it generated the previous file. The next time I ran it, I removed a row and added a new row to the XLSX:

    The side indicators show what in the previous (on the left) and the current file (on the right) based on ReferenceObject and DiffrenceObject respectively. If you run it again, then you would see that it’s all == because we overwrote the previous file. You could keep dated copies of the previous files for reference if you wanted to see changes. You could email the changes only to the subscriptions. Now that it’s a PSObject, you have the full flexibility of Powershell.

    Participant
    Topics: 13
    Replies: 1753
    Points: 3,136
    Helping Hand
    Rank: Community Hero

    Not aware of a method to not open a file into memory to modify it. Not sure how large the files are, but here are multiple methods to open and read the files:

    http://www.happysysadm.com/2014/10/reading-large-text-files-with-powershell.html

    The basic idea is still do load the file into memory, process it and either overwriting the file processed or generating a new file.

    in reply to: Convert string date format to DateTime object #257018
    Participant
    Topics: 13
    Replies: 1753
    Points: 3,136
    Helping Hand
    Rank: Community Hero

    Here is one method:

    Timezones can be enumerated like so:

    Output:

    in reply to: Get password expiration date from variable #256886
    Participant
    Topics: 13
    Replies: 1753
    Points: 3,136
    Helping Hand
    Rank: Community Hero

    Reference the samaccountname as the identity:

    in reply to: Extracting data from excel and updating variables #256865
    Participant
    Topics: 13
    Replies: 1753
    Points: 3,136
    Helping Hand
    Rank: Community Hero

    There is a module that may accelerate things:

    Anything you are doing in Excel is still using an old Excel COM object, Powershell is just executing the old COM code. For instance, if I wanted to get data from the last row in a certain column, I would run a macro and search for how to do that in vba:

    https://www.thespreadsheetguru.com/blog/2014/7/7/5-different-ways-to-find-the-last-row-or-last-column-using-vba

    Then you have to convert that VBA to Powershell, so I would search for something like ‘Powershell find xlCellTypeLastCell’

    • This reply was modified 5 days, 12 hours ago by grokkit. Reason: whitespace cleanup
    in reply to: Extracting data from excel and updating variables #256835
    Participant
    Topics: 13
    Replies: 1753
    Points: 3,136
    Helping Hand
    Rank: Community Hero

    The code you are referencing is not Powershell. It appears to be Excel expression language which is related to VBA. There is no Powershell posted that I can see thus far. Typically, to detect new lines you want have a date or a copy of the data from the last run to compare against the current data. Where is the data coming from originally? If Excel can be taken out of the equation, that would be a much better solution.

    in reply to: Help with exec() function #256763
    Participant
    Topics: 13
    Replies: 1753
    Points: 3,136
    Helping Hand
    Rank: Community Hero

    If you look at the Free Resources link on the left, there is a ebook on Error handling. You can try a standard try\catch:

    in reply to: Script for finding a list of distinguished AD names? #256748
    Participant
    Topics: 13
    Replies: 1753
    Points: 3,136
    Helping Hand
    Rank: Community Hero

    You cannot filter on DistinguishedName, it’s derived at runtime. If you just have the names, you would do something like this (not tested):

    • This reply was modified 5 days, 18 hours ago by Rob Simmers.
    Participant
    Topics: 13
    Replies: 1753
    Points: 3,136
    Helping Hand
    Rank: Community Hero

    Simply search for “Powershell GUI”. There are many options, however, you’re still going to have a Powershell script that has to be run to start a gui to then push a button. You could just download the file to the same location as the script and skip the gui part. Here is a link for one option:

    How to Build a PowerShell GUI for your Scripts

    in reply to: Contatenate 2 differents psobject #256589
    Participant
    Topics: 13
    Replies: 1753
    Points: 3,136
    Helping Hand
    Rank: Community Hero

    Typically, objects are not joined like this as there is key that is being joined on which is the links you mentioned above. Basically,, you can create another object and add the two objects, but you have to use the Select-Object with all of the properties or it will only show the properties of the first object added:

    in reply to: Question regarding input check in Powershell #256526
    Participant
    Topics: 13
    Replies: 1753
    Points: 3,136
    Helping Hand
    Rank: Community Hero

    There are a couple of ways to write the loop, but here is a basic example”

    The loop exits when all conditions are True.

    • This reply was modified 6 days, 15 hours ago by Rob Simmers.
Viewing 15 posts - 1 through 15 (of 1,750 total)