'How can I get the Log directory?
I have recently installed SSAS on my servers and instead of going through 24 of them, I am writing a script to get back the logDir of the servers.
I am trying to do something like this:
Import-Module SqlServer
$Analysis_Server = New-Object Microsoft.AnalysisServices.Server
$Analysis_Server.connect("$server")
$Analysis_Server.ServerProperties.LogDir
I am trying to find the logDir property from here to no avail.
If I use ServerProperties
, I get a list of all properties available like this:
Name : LogDir
Type :
Value : S:....
DefaultValue : \data
PendingValue : S:...
RequiresRestart : True
IsReadOnly : False
DisplayFlag : True
Category : Basic
Units : Folder
PropertyName : LogDir
FolderName
But if I do: $Analysis_Server.ServerProperties.LogDir.value
or $Analysis_Server.ServerProperties.LogDir
, it returns nothing.
Update
This is how I plan to run through multiple servers:
$h = @{}
Import-Csv '$csvFile' | ForEach-Object {
$h += @{$($_.Server -split '\s*,\s*') }
}
Import-Module SqlServer
foreach($server in $h.Keys){
$result = "$server"
Write-Host $result
$Analysis_Server = New-Object Microsoft.AnalysisServices.Server
$Analysis_Server.connect("$server")
$Analysis_Server.ServerProperties['LogDir'].value
}
This is my CSV file (I plan to use this for multiple purposes, so I only want to get the servers not databases for this case):
I got back this error:
Missing '=' operator after key in hash literal.
Solution 1:[1]
This might get you part of they way there. I don't have an analysis server at my disposal you may have to change this up a bit till you get it right.
$servers=get-content c:\temp\servers.txt
$hash=new-object hashtable
$Analysis_Server = New-Object Microsoft.AnalysisServices.Server
foreach($s in $servers)
{
$Analysis_Server.connect("$s")
$hash.add($s, $"$($Analysis_Server.ServerProperties['LogDir'])")
}
To see more great content on hashtables checkout this link: https://kevinmarquette.github.io/2016-11-06-powershell-hashtable-everything-you-wanted-to-know-about/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | thom schumacher |