How to get a list of versions between the latest version and some previous version for a specific object - powershell

I'm currently trying to use AWS Tools for PowerShell (https://docs.aws.amazon.com/powershell/latest/reference/index.html) to pull down files from S3.
My question is about how I can get a list of all versions between the latest version and some older version (further on, I will then pull down specific versions of an object to do things with it).
Figuring out the latest version is easy:
(Get-S3ObjectMetadata -BucketName $S3Bucket -Key $file_to_import).VersionId
Also getting a list of all available versions for an object is easy:
(Get-S3Version -BucketName $S3Bucket -Prefix $file_to_import).Versions
This gives me something like this:
BucketName Key IsLatest VersionId
---------- --- -------- ---------
fake_bucket_name test.file True JNvMus2dzvwbHTALXOiROE6eYK2CbQkN
fake_bucket_name test.file False .pLXJQtvTDLn2kGVyzxXLwHo06DM.eOK
fake_bucket_name test.file False E_Pldt5QUK69Bkqi4Vzea5YElVITu5vW
fake_bucket_name test.file False qfHFNcyUPwgQX4Vj.YRUyvKR4iC1LHDN
fake_bucket_name test.file False .Oq9yR3tmY4xeA2sKcbhO5fhbNgTHN_5
fake_bucket_name test.file False IqkH06Z17rJy9b43WKwbdlQmYTIKnQCi
fake_bucket_name test.file False zpd4vZJaP9d8sU2MgOBliDZg5g7dpQI3
fake_bucket_name test.file False aUkj3nf_LHzvF6iJFi6MDP8yN5yZx4s4
fake_bucket_name test.file False voXfE2Yucyfk3lYQxuEHoF531i27rqiw
fake_bucket_name test.file False vpHy533Js8gTBwmVF5Gwfx8gzRHJmuGO
fake_bucket_name test.file False rCLVePiKJ_kG4m99YK6T58OOWPgXYqc6
fake_bucket_name test.file False PQ5pPgMep3qmAhXnApl792OTzOgtEBJp
fake_bucket_name test.file False 8x84RYnc7S5Do0DOZqSC2L42q06yYoSl
fake_bucket_name test.file False LbyQxsfN..p6VmJARs3GZ7aF.Mzh_Q9C
fake_bucket_name test.file False LALPxyI5myYQbnWXv5XSPdnqpDMZp5E8
Where I'm stuck right now is how I can get a list only between the latest version and a specific previous version.
Say, I know I need everything that is newer then VersionId qfHFNcyUPwgQX4Vj.YRUyvKR4iC1LHDN.
So, I would need a list like this:
BucketName Key IsLatest VersionId
---------- --- -------- ---------
fake_bucket_name test.file True JNvMus2dzvwbHTALXOiROE6eYK2CbQkN
fake_bucket_name test.file False .pLXJQtvTDLn2kGVyzxXLwHo06DM.eOK
fake_bucket_name test.file False E_Pldt5QUK69Bkqi4Vzea5YElVITu5vW
I tried using the Get-S3Version command again, making use of the KeyMarker and the VersionIdMarker:
(Get-S3Version -BucketName $S3Bucket -KeyMarker $file_to_import -VersionIdMarker $last_processed_version -Prefix $file_to_import).Versions
But this only gives me all versions BEFORE instead of AFTER the VersionId I used as VersionIdMarker.
The result looks more like this and is the exact opposite of what is needed:
BucketName Key IsLatest VersionId
---------- --- -------- ---------
fake_bucket_name test.file False .Oq9yR3tmY4xeA2sKcbhO5fhbNgTHN_5
fake_bucket_name test.file False IqkH06Z17rJy9b43WKwbdlQmYTIKnQCi
fake_bucket_name test.file False zpd4vZJaP9d8sU2MgOBliDZg5g7dpQI3
fake_bucket_name test.file False aUkj3nf_LHzvF6iJFi6MDP8yN5yZx4s4
fake_bucket_name test.file False voXfE2Yucyfk3lYQxuEHoF531i27rqiw
fake_bucket_name test.file False vpHy533Js8gTBwmVF5Gwfx8gzRHJmuGO
fake_bucket_name test.file False rCLVePiKJ_kG4m99YK6T58OOWPgXYqc6
fake_bucket_name test.file False PQ5pPgMep3qmAhXnApl792OTzOgtEBJp
fake_bucket_name test.file False 8x84RYnc7S5Do0DOZqSC2L42q06yYoSl
fake_bucket_name test.file False LbyQxsfN..p6VmJARs3GZ7aF.Mzh_Q9C
fake_bucket_name test.file False LALPxyI5myYQbnWXv5XSPdnqpDMZp5E8
What is a proper way of getting a list of more recent VersionIds starting with some past VersionId?
Am I just missing something basic?

I don't know if it's too late but I ended up using this:
Get-S3Object -BucketName "my-bucket" -Region my-region | ForEach-Object {
$key = $_.Key
(Get-S3Version -BucketName "my-bucket" -Region my-region).Versions | Where-Object {$_.Key -eq $key} | Sort-Object LastModified
}
This will sort each object by version from latest to oldest. You can increase performance by using -Key "s3-path-to-object" at Get-S3Object

Related

cloud-init - Hostname strange behavior

I am using the cloud-Assembly to create a VM with following settings:
hostname:redhat-kouvas-1500-localtest
domain: test.local
Cloud Assembly code below:
cloudConfig: |
#cloud-config
preserve_hostname: false
prefer_fqdn_over_hostname: false
hostname: '${input.hostname}'
fqdn: '${input.hostname}.${input.domain}'
What I am getting is the following:
redhat-kouvas-1500-localtest log]# hostname
redhat-kouvas-1500-localtest.test.local
cat /var/lib/cloud/data/set-hostname
{
"fqdn": "redhat-kouvas-1500-localtest.test.local",
"hostname": "redhat-kouvas-1500-localtest"
}
cat /var/lib/cloud/data/previous-hostname
redhat-kouvas-1500-localtest.test.local[root#redhat-kouvas-1500-localtest log]#
Do you know why the cloud-init has this strange behavior??
================================================================================
Copied the following from cloud-init documentation
cloud-init-documentation link
Internal name: cc_set_hostname
Module frequency: once-per-instance
Supported distros: all
Config schema:
preserve_hostname: (boolean) If true, the hostname will not be changed. Default: false.
hostname: (string) The hostname to set.
fqdn: (string) The fully qualified domain name to set.
prefer_fqdn_over_hostname: (boolean) If true, the fqdn will be used if it is set. If false, the hostname will be used. If unset, the result is distro-dependent.
Examples:
preserve_hostname: true
# --- Example2 ---
hostname: myhost
fqdn: myhost.example.com
prefer_fqdn_over_hostname: true
Issue resolved by changing the preserve_hostname: True

Adding owner to Pester test results

Is there a way to add an owner per test to the NUnit results exported by Pester?
What I’m hoping to do is notify the owner via teams or email through an Azure devops pipeline (I don’t have this fully sorted yet). As a start I think I’ll need the option to add an owner per test.
There's no functionality explicitly in Pester for identifying a test owner. You can add Tags to tests, but it doesn't look like Tags are exported anywhere in the NUnit results. I think the only option for now would be to add an owner into the title of the test, and then parse that out from the NUnit results:
Describe 'My Tests' {
It 'Should be true [owner: Mark Wragg]' {
$true | Should -Be $true
}
It 'Should be false [owner: Mark Wragg]' {
$true | Should -Be $true
}
It 'Should be true [owner: Bob Bobson]' {
$false | Should -Be $true
}
}
Output in NUnit file:
<results>
<test-case description="Should be true [owner: Mark Wragg]" name="My Tests.Should be true [owner: Mark Wragg]" time="0.0134" asserts="0" success="True" result="Success" executed="True" />
<test-case description="Should be false [owner: Mark Wragg]" name="My Tests.Should be false [owner: Mark Wragg]" time="0.0133" asserts="0" success="True" result="Success" executed="True" />
<test-case description="Should be true [owner: Bob Bobson]" name="My Tests.Should be true [owner: Bob Bobson]" time="0.1436" asserts="0" success="False" result="Failure" executed="True">

400 Bad Request with MS Graph when adding list items

For the life of me I can't successfully add SharePoint list items. I have in the past, now I'm stumped, using either Invoke-WebRequest or Invoke-RestMethod. I am able to update (PATCH) without issue, and can do all sorts of GET operations against the same sites, lists, items, etc.
Here's a fiddler capture of my actual HTTP POST request (Guid's fudged):
POST https://graph.microsoft.com/v1.0/sites/2df3a5af-979d-46d6-b24d-14e4e4b58aa9/lists/2252b849-53f9-4816-bc0b-d9183357c702/items HTTP/1.1
Content-Type: application/json
Authorization: Bearer eyJ0f...
User-Agent: MSGraphPSEssentials/0.4.0
Host: graph.microsoft.com
Content-Length: 537
{
"Fields": {
"AccountStatus": "Enabled",
"DisplayName": "Fictional User 1",
"UserId": "67853e89-65a9-431d-a3b1-1d60ab74dc1f",
"ADObjectGuid": "56752e89-65a9-431d-a3b1-1d61ab78dc1f",
"AccountCreated": "2019-03-12",
"AADObjectId": "8df5db8d-1d7a-4b35-b498-138eef2946fa",
"AccountType": "AD-Synced",
"ADLastLogonDate": "2020-08-25"
}
}
For each of the fields/columns shown, the content type on the SPO list is either "single line of text" or "date and time", and in either case, no data is required. There are no other columns on the list that are required (purposely while I troubleshoot this).
Can anyone spot anything obvious that would cause me to receive 400 Bad Request and the only additional info provided is "Invalid Request"
Here's a fiddler capture of an example response:
HTTP/1.1 400 Bad Request
Date: Thu, 29 Apr 2021 14:26:08 GMT
Content-Type: application/json
Cache-Control: no-cache
Transfer-Encoding: chunked
Strict-Transport-Security: max-age=31536000
request-id: 87190763-4bfe-4a88-a69e-154fd60aad81
client-request-id: 87190763-4bfe-4a88-a69e-154fd60aad81
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"East US","Slice":"E","Ring":"5","ScaleUnit":"004","RoleInstance":"BL02EPF000035AB"}}
da
{"error":{"code":"invalidRequest","message":"Invalid request","innerError":{"date":"2021-04-29T14:26:08","request-id":"87190763-4bfe-4a88-a69e-154fd60aad81","client-request-id":"87190763-4bfe-4a88-a69e-154fd60aad81"}}}
0
Finally, here are the columns as returned by successful MS Graph request to /sites/<ID>/lists/<ID>?Expand=Columns:
>$columns.columns |select Name, DisplayName, ReadOnly, Required
name displayName readOnly required
---- ----------- -------- --------
ManagerDisplayName ManagerDisplayName False False
ManagerEmail ManagerEmail False False
Ignore Ignore False False
UserId UserId False False
Title Title False False
ComplianceAssetId Compliance Asset Id True False
IgnoreReason IgnoreReason False False
ADObjectGuid ADObjectGuid False False
AADObjectId AADObjectId False False
ADLastLogonDate ADLastLogonDate False False
AADLastSignIn AADLastSignIn False False
DisabledDate DisabledDate False False
ReEnabledDate ReEnabledDate False False
JobTitle JobTitle False False
Status Status False False
ResolvedReason ResolvedReason False False
NewAADLastSignIn NewAADLastSignIn False False
AssignedLicenses AssignedLicenses False False
AADCreationType AADCreationType False False
AccountCreated AccountCreated False False
DisplayName DisplayName False False
Email Email False False
AccountType AccountType False False
NewADLastLogonDate NewADLastLogonDate False False
ID ID True False
ContentType Content Type False False
Modified Modified True False
Created Created True False
Author Created By True False
Editor Modified By True False
_UIVersionString Version True False
Attachments Attachments False False
Edit Edit True False
LinkTitleNoMenu Title True False
LinkTitle Title True False
DocIcon Type True False
ItemChildCount Item Child Count True False
FolderChildCount Folder Child Count True False
_ComplianceFlags Label setting True False
_ComplianceTag Retention label True False
_ComplianceTagWrittenTime Retention label Applied True False
_ComplianceTagUserId Label applied by True False
_IsRecord Item is a Record True False
AppAuthor App Created By True False
AppEditor App Modified By True False
My problem is 100% only with adding new items. I wish there was more helpful info in the returned error response. Note, I'm getting the same behavior if I try to do this through the $batch endpoint. Here's the error info available that way:
>$test.responses.body.Error
code message innerError
---- ------- ----------
invalidRequest Invalid request #{date=2021-04-29T14:41:34; request-id=cdf96c25-41e1-437b-9698-64389a2dc36b; client-request-id=cdf96c25-41e1-437b-9698-64389a2dc36b}
...again just 'Invalid Request' :(.
Shamefully this problem was simply the capital "F" in "Fields" in my body. It is case sensitive (evidently). "fields" solved it. I was going to delete the question, but in case it might help someone I'll leave it.

Updating JObject (Newtonsoft.Json.Linq.JContainer) in PowerShell

I am trying to update a JObject in PowerShell but running into some issues.
Currently I have:
PS> $jObject.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False JObject Newtonsoft.Json.Linq.JContainer
PS> $jObject
Type : Object
HasValues : True
First : {}
Last : {}
Count : 3
Parent : {"pollingIntervalInS": "3600" "observedCertificates": [
"<CertUri1>",
"<CertUri2>",
"<CertUri3>"
] "requireInitialSync": true}
Root : {secretsManagementSettings}
Next :
Previous :
Path : secretsManagementSettings
LineNumber : 0
LinePosition : 0
IsReadOnly : False
AllowNew : True
AllowEdit : True
AllowRemove : True
SupportsChangeNotification : True
SupportsSearching : False
SupportsSorting : False
IsSorted : False
SortProperty :
SortDirection : Ascending
IsFixedSize : False
SyncRoot : System.Object
IsSynchronized : False
Keys : {pollingIntervalInS, observedCertificates, requireInitialSync}
I am trying to updated the "observedCertificates" list with another entry. have tried converting to json, and also tried to work with the newtonsoft assembly to modify but without any results.
Any tips on how to proceed would be appreciated.

android appium optionalIntentArguments multiple boolean extra params

Appium for android has optionalIntentArguments capability. The question is I would like to pass in multiple Boolean extra parameter (--ez). Anyone know how to do that ? Thank you
I have tried
--ez IN_APP_USAGE_ENABLED true --ez WEB_DASHBOARD_IS_SHOW true
--ez IN_APP_USAGE_ENABLED true, --ez WEB_DASHBOARD_IS_SHOW true
--ez IN_APP_USAGE_ENABLED true, WEB_DASHBOARD_IS_SHOW true
--ez IN_APP_USAGE_ENABLED true WEB_DASHBOARD_IS_SHOW true
--ez [IN_APP_USAGE_ENABLED true, WEB_DASHBOARD_IS_SHOW true]
they always return with error in appium
You can try below method to use :
capabilities.setCapability("optionalIntentArguments","--ez IN_APP_USAGE_ENABLED true --ez WEB_DASHBOARD_IS_SHOW true");