Good day,
PowerShell rookie here…
If I output to the screen like this:
foreach($databasePermission in $database.EnumDatabasePermissions($user.Name))
{
Write-Host $databasePermission.PermissionState $databasePermission.PermissionType "TO" $databasePermission.Grantee
}
I get this, which is what I want:
Grant CONNECT TO dbo
However, if I try to output to a text file like this:
foreach($databasePermission in $database.EnumDatabasePermissions($user.Name))
{
"$databasePermission.PermissionState $databasePermission.PermissionType TO $databasePermission.Grantee" | Out-File $filename
}
My results repeat like this:
[dbname] Database: cust_serv, Grant, CONNECT.PermissionState [dbname] Database: cust_serv, Grant, CONNECT.PermissionType TO [dbname] Database: cust_serv, Grant, CONNECT.Grantee
Thanks!
If you access properties of an object in a string, you have to enclose it in
$(...):Look at the difference between
and