Hi,
Im trying to get ftp authorisation rules and export them to json to compare with settings in a json to verify.
This is a part of my json:
"Add": [
{
"users": "",
"roles": "Ftp",
"permissions": "Read, Write"
},
{
"users": "",
"roles": "FtpBackupUser",
"permissions": "Read"
},
{
"users": "FtpRolUser",
"roles": "",
"permissions": "Read"
},
{
"users": "FtpMeetingMobileUser",
"roles": "",
"permissions": "Read"
},
{
"users": "FtpDocBeheerUser",
"roles": "",
"permissions": "Read"
},
{
...
$AuthorisationRuleOnDir =
@(
Get-WebConfiguration -filter /system.ftpserver/security/authorization -Location "Ftp Site" -PSPath 'MACHINE/WEBROOT/APPHOST' |
Foreach {
$_.GetCollection() |
Foreach { $_.Attributes |
Format-Table name, value -HideTableHeaders }
}
)
This is the result:
PS C:\WINDOWS\system32> $AuthorisationRuleOnDir
accessType 0
users
roles Ftp
permissions 3
accessType 0
users
roles FtpBackupUser
permissions 1
accessType 0
users FtpRolUser
roles
permissions 1
accessType 0
users FtpMeetingMobileUser
roles
permissions 1
If I want to convert it it creates this a lot of them:
PS C:\WINDOWS\system32> $AuthorisationRuleOnDir | ConvertTo-Json
[
{
"pageHeaderEntry": null,
"pageFooterEntry": null,
"autosizeInfo": null,
"shapeInfo": {
"hideHeader": true,
"repeatHeader": false,
"tableColumnInfoList": "Microsoft.PowerShell.Commands.Internal.Format.TableColumnInfo Microsoft.PowerShell.Commands.Internal.Format.TableColumnInfo",
"ClassId2e4f51ef21dd47e99d3c952918aff9cd": "e3b7a39c089845d388b2e84c5d38f5dd"
},
"groupingEntry": null,
"ClassId2e4f51ef21dd47e99d3c952918aff9cd": "033ecb2bc07a4d43b5ef94ed5a35d280"
},
{
"shapeInfo": null,
"groupingEntry": null,
"ClassId2e4f51ef21dd47e99d3c952918aff9cd": "9e210fe47d09416682b841769c78b8a3"
},
{
"formatEntryInfo": {
"formatPropertyFieldList": "Microsoft.PowerShell.Commands.Internal.Format.FormatPropertyField Microsoft.PowerShell.Commands.Internal.Format.FormatPropertyField",
"multiLine": false,
"ClassId2e4f51ef21dd47e99d3c952918aff9cd": "0e59526e2dd441aa91e7fc952caf4a36"
},
"outOfBand": false,
"writeStream": 0,
"ClassId2e4f51ef21dd47e99d3c952918aff9cd": "27c87ef9bbda4f709f6b4002fa4af63c"
},
{
...
I tried different approaches but never get the correct layout for a descent json:
$AuthorisationRuleOnDir = (
Get-WebConfiguration -filter /system.ftpserver/security/authorization -Location "Ftp Site" -PSPath 'MACHINE/WEBROOT/APPHOST' |
Foreach { $_.GetCollection() }
)
PS C:\WINDOWS\system32> $AuthorisationRuleOnDir
Attributes : {accessType, users, roles, permissions}
ChildElements : {}
ElementTagName : add
Methods :
Schema : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema
Attributes : {accessType, users, roles, permissions}
ChildElements : {}
ElementTagName : add
Methods :
Schema : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema
Attributes : {accessType, users, roles, permissions}
ChildElements : {}
ElementTagName : add
Methods :
Schema : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema
Attributes : {accessType, users, roles, permissions}
ChildElements : {}
ElementTagName : add
Methods :
Schema : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema
....
$AuthorisationRuleOnDirJSON = (
$AuthorisationRuleOnDir |
ForEach-Object {
(Foreach { $_.Attributes | Foreach { $_.name + """: """ + $_.value } } | ConvertTo-Json).Replace('\', '')
}
)
PS C:\WINDOWS\system32> $AuthorisationRuleOnDirJSON
[
"accessType": "0",
"users": "",
"roles": "Ftp",
"permissions": "3"
]
[
"accessType": "0",
"users": "",
"roles": "FtpBackupUser",
"permissions": "1"
]
[
"accessType": "0",
"users": "FtpRolUser",
"roles": "",
"permissions": "1"
]
[
"accessType": "0",
"users": "FtpMeetingMobileUser",
"roles": "",
"permissions": "1"
]
[
...
So how can I export it to json like the example