I'm importing a CSV file and I need to return the most recent logged in date for a specific hostname. Any ideas? I've been trying to group objects and run a for-each on them but I can't manage to pull the latest. Here's an example of the data:
e.g. for mypc1 I want to return an object that includes the hostname, username and also the date of the latest login. In this case 2022-08-15 07:51:51.
Computer Name
Username
Date
mypc1
jcitizen
2022-07-06 18:00:20
mypc1
bmcgee
2022-08-15 07:51:51
mypc1
jmarsh
2021-05-25 12:49:14
mypc2
jmarsh
2022-08-12 07:45:55
mypc2
jsmith
2022-03-12 07:00:07
mypc3
osmith
2022-08-08 08:36:03
mypc3
moliver
2022-08-08 07:37:27
Related
So, I have the resource Group name and i want to programmatically (using powershell) set the subscription to the incoming resource group.
When i do a Get-AzResourceGroup I get the ResourceId which contains the the subscription id as part of a long string /subscriptions/<subscription id here>/resourceGroups/resourcegroupname. Is there a way to extract the subscription Id from that string?
You can get your subscription ID by triggering the below. You will also need to have azure cli installed.
az account list --refresh --query "[?contains(name, 'YOUR_SUBSCRIPTION')].id"
You can also split the output from powershell.
$myinput= "/subscriptions/xxxxxx-xxxxxx-xxxxxx-xxxxx-xxxxxx/resourceGroups/resourcegroupname".Split("/")
Write-Host $myinput[2]
I just want to assign the contacts to Application's field and another field with API Powershell but I don't know how to do it. could anyone help me?
According to their API documentation, there is no 'Application' resource type. Is it a custom resource, or a field on a different type of object? (what type?)
Try installing ITGlue's PowerShell wrapper module ITGlueAPI from the gallery (or github link):
Install-Module ITGlueAPI
Import-Module ITGlueAPI
# Check out all the available commands
Get-Command -Module ITGlueAPI
# initial setup:
Add-ITGlueBaseURI -base_uri 'http://myapi.gateway.example.com'
Add-ITGlueAPIKey -ApiKey 'your-key-here'
# Play around with these kinds of "Get-" commands which exist for each resource type:
# This is a good way to see how the data is formatted, and which fields exist per resource
Get-ITGlueFlexibleAssets
Get-ITGlueContacts -organization_id 1234 -filter_first_name 'Foo' -sort 'first_name'
# To make changes, run similar "Set-" or "New-" commands with the updates in hash table format:
Set-ITGlueContacts -id 1234 -data #{
location-id = 795
location-name = "San Francisco - HQ"
field-name = "Value"
}
I am using the PowerShell module BEMCLI and I want to create a report with these columns: list of servers, Jobs associated to the server with the last successful run.
I can get the list of servers with: Get-BEAgentServer
I can get also the list of jobs in success in a period with:
Get-BEJobHistory -JobStatus Succeeded -FromStartTime (Get-Date).AddHours(-24) | ft -auto
Is there an easy way to get what I want?
I run the command wevtutil qe Application /rd:false /f:text and I get an output as shown below. After sometime new event logs could have generated and I want to read only these new event logs i.e. Event[2], Event[3], Event[4] etc.
How can I use wevtutil tool to generate only these new event logs?
Event[0]:
Log Name: Application
Source: Microsoft-Windows-LoadPerf
Date: 2016-04-21T23:15:16.832
Event ID: 1000
Task: N/A
Level: Information
Opcode: Info
Keyword: N/A
User: S-1-5-18
User Name: NT AUTHORITY\SYSTEM
Computer: WIN-IONOGQTF9O5
Description:
Performance counters for the WmiApRpl (WmiApRpl) service were loaded successfully. The Record Data in the data section contains the new index values assigned to this service.
Event[1]:
Log Name: Application
Source: Microsoft-Windows-LoadPerf
Date: Date: 2016-04-21T23:15:13.097
Event ID: 3011
Task: N/A
Level: Information
Opcode: Info
Keyword: N/A
User: S-1-5-18
User Name: NT AUTHORITY\SYSTEM
Computer: WIN-IONOGQTF9O5
Description:
Unloading the performance counter strings for service WmiApRpl (WmiApRpl) failed. The first DWORD in the Data section contains the error code.
weventil is not PowerShell so I was mislead. However, you could just do this:
Get-EventLog -LogName Application -Newest -After ( Get-Date ).AddDays(-1)
/rd:false will read the oldest first so if your looking for newest it may not be the best query.
I'm not aware of a read/unread tag for eventlogs, you could create a custom object and add one but that may not be the best way to go around it.
You can also do the below
$lastRanDate = "2018-11-30T17:20:55" ##import from a txt file
$date = Get-date -UFormat %Y-%m-%dT%H:%M:%S
##Get's current date and formats as following example 2018-12-01T17:17:45
$difference = New-TimeSpan -Start $lastRanDate -End $date
##Calculate difference between start time and end time
$difference = $difference.TotalMilliseconds
wevtutil epl Application "C:\Users\Pipastrilo\Desktop\appTest.evtx" /q:"*[System[TimeCreated[timediff(#SystemTime) <= $difference]]]"
## exportLog logName Path query(TimeCreated between current and HowManayMillisecondsAgo
$lastRanDate = $date
##export $lastRunDate for future searches
I am trying to use get-azurermsubscription to get a list of available subscriptions in order to select one of five prior to running set-azurermcontext. I am getting the error:
Method not found: 'Microsoft.Azure.Subscriptions.Models.SubscriptionListResult'
get-azurermcontext displays a valid tenatant id and valid subscription id, but of course does not display all of the subscriptions.
I downloaded the March 2015 Powershell installer to make sure everything was up to date, but have the same issues.
Just upgraded to VisualStudio 2015 update 2 and powershell v5. Have another machine with a similar configuration that works fine.
What should I do to fix this issue?
I can't add a comment so doing it this way instead. On July 12 2016 AzureRM module received and update to version 1.6.0. I confirmed the cmd Get-AzureRMSubsctiption works from a Windows 10 machine.