Read local group policy using powershell commands - powershell

Iam unable to get Gpresult of local group policy using powershell. I need help on this to get the local gpo's on windows Server 2022

not much you want to share with us about what you have tried. you could do:
#Export gpresult into xml
gpresult /x C:\Users\Administrator\Documents\gpo.xml
#Load xml
$xml = New-Object xml
$xml.Load("C:\Users\Administrator\Documents\gpo.xml")
$xml contains the information.

Related

SSAS Deployment Via Powershell Corrupting Format String

I am having a problem when deploying cubes via PowerShell that I don’t know how to fix. In my solution I have some measures with FormatString: \£ #,##0;-\£ #,##0. If I deploy them normally via Visual Studio, the XMLA I pull from the SSAS server after deployment will have <FormatString>\£ #,##0;-\£ #,##0</FormatString> which is all good and expected. However, if I deploy via PowerShell, the resulting XMLA from the server is <FormatString>\£ #,##0;-\£ #,##0</FormatString>.
I realise the issue is with £ being parsed, but I am not sure how to resolve it.
The bit of background here is that I am using Octopus Deploy, and I've extracted the PowerShell below where the issue occurs:
$modelpath = "C:\...\Project_Name.xmla"
$Path_To_Microsoft_AnalysisServices_Deployment = "C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Microsoft.AnalysisServices.Deployment.exe"
$SSAS_Project_Name = "Project_Name"
$Path_To_SSAS_Bin_Folder = "F:\Octopus Deploy\CustomInstallation\Project_Name\Content"
$FilePath_asdatabase = "$Path_To_SSAS_Bin_Folder\$SSAS_Project_Name.asdatabase"
$FilePath_deploymenttargets = "$Path_To_SSAS_Bin_Folder\$SSAS_Project_Name.deploymenttargets"
$FilePath_configsettings = "$Path_To_SSAS_Bin_Folder\$SSAS_Project_Name.configsettings"
$FilePath_deploymentoptions = "$Path_To_SSAS_Bin_Folder\$SSAS_Project_Name.deploymentoptions"
Start-Process -FilePath $Path_To_Microsoft_AnalysisServices_Deployment -ArgumentList "`"$FilePath_asdatabase`"","/s:`"$FilePath_DeploymentLog`"","/o:`"$SSAS_Project_Name.xmla`"","/d" -Wait -NoNewWindow
# Load the Adomd Client
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.AnalysisServices.AdomdClient”) | Out-Null;
# Connect to the server
Write-Host "Executing Deployment Script"
$serverName = “Data Source=.”
$conn = New-Object Microsoft.AnalysisServices.AdomdClient.AdomdConnection $serverName
$conn.Open()
# Read XMLA
$xmla = Get-Content $modelpath
# Execute XMLA
$cmd = New-Object Microsoft.AnalysisServices.AdomdClient.AdomdCommand $xmla, $conn
return $cmd.ExecuteNonQuery();
I have done some investigation and I’ve found the following:
The xmla file produced by PowerShell (not in the snippet) has the correct Format String \£ #,##0;-\£ #,##0
The .asdatabase file also has the correct format string
I suspect that something is happening either at:
Start-Process -FilePath $Path_To_Microsoft_AnalysisServices_Deployment -ArgumentList “`”$FilePath_asdatabase`””,”/s:`”$FilePath_DeploymentLog`””,”/o:`”$SSAS_Project_Name.xmla`””,”/d” -Wait -NoNewWindow
or further down at:
# Execute XMLA
$cmd = New-Object Microsoft.AnalysisServices.AdomdClient.AdomdCommand $xmla, $conn
return $cmd.ExecuteNonQuery();
Any help would be appreciated.
PS: I’ve tried playing with the Format String when setting it in the solution but haven’t been able to find a solution. Note that I can’t simple use “Currency” b/c the server is set to English (US).
The answer to this is to specify the encoding. From Jeroen in the comment in response to my question:
It looks like PowerShell is auto-detecting the encoding of the XMLA incorrectly as Windows-1252, when it's actually UTF-8 (without a BOM). Try $xmla = Get-Content $modelpath -Encoding UTF8. It may also be the case that the XMLA itself is actually incorrect -- make sure to inspect it in an editor capable of reporting the encoding, like Notepad++, not just have it echo back by PowerShell itself. – Jeroen Mostert 15 mins ago

IE save as pop up automation using powershell

Automating a process where i download a report from a link and save it in a particular folder. I can use sendkeys to automate this but under headless condition it fails. Is there any way in powershell to automate this.
So you need to download a file via Powershell. You'll need to know a direct link to it, then you can automate it via this script:
$url = "http://your-site/report.xlsx"
$output = "$PSScriptRoot\report.xlsx"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $output)
There are other options how to download the file via Powershell, but this is the best tradeoff for you.

Is there anyway to connect to SSAS using Service account while using powerpivot to get the data from cube?

We are using Excel 2010 into our office to produce some reports. We are using powerpivot plug in to connect to SSAS cube. The only problem is when, it is using windows authentication and I want to use SQL Server Service Account instead of windows account. I went to advance connection and tried to type my user id and password but it is greyed out?
Any help would be really appreciated.
I am using this powershell script which opens the Excel file and refresh it.
``1. Dir "C:\Users\New folder" -Recurse | % {
$ExcelObject = New-Object -ComObject Excel.Application
$ExcelObject.Visible = $false
$ExcelObject.DisplayAlerts = $false
$WorkBook = $ExcelObject.Workbooks.OpenXML($_.FullName)
$WorkBook.RefreshAll()
$WorkBook.Save()
$WorkBook.Close()
$ExcelObject.Quit()
}
SSAS only accepts Windows auth. But you can close all Excel windows then start Excel from a command line like this:
runas /netonly /user:REALDOMAIN\YOURDOMAINUSERNAME "c:\path\to\excel.exe"
Then when it connects to Windows auth resources remotely it will connect as the user you mention in the runas command.

Decode powershell command to code

It is possible decode (or show what to do) command Powershell?
I try use command connect-msolservice, but i get exceptions:
.
So maybe if I get content command, i can configure system to this connection.
Yes, you can use ILSpy to decode powershell dll. Download ILSpy.
For find path .dll with your cmdlets, use powershell command:
Get-Command connect-msolservice | fl DLL,ImplementingType
Or you can use a native solution to view the Metadata of the builtin (or any other cmdlets)
$Metadata = New-Object System.Management.Automation.CommandMetaData (Get-Command Connect-MSOLService)
$Contents = [System.Management.Automation.ProxyCommand]::Create($Metadata)
credit to http://windowsitpro.com/blog/powershell-proxy-functions

PowerShell Script To Automatically Print SSRS 2008R2 Report

Can I use a Powershell to generate and print an SSRS report (with parameters) to a network printer.
I will use a SQL Agent job poll a table for new order entries. When an order comes in I want to generate an SSRS report and print it to one of many remote printers (printer will be one of the input parameters) on our network, e.g., print a pick ticket in the appropriate warehouse when an order is placed.
We currently use batch files to print to local printers, but the program hangs often and does not scale well.
In this case:
Report Name: Ticket System
Parameters are: Date and Department
Report Format:PDF
#Place adobe in your path
$env:Path = $env:Path + ";C:\Program Files (x86)\Adobe\Reader 11.0\Reader"
#Specify variables and pass parameters and specify format of report PDF (to keep things simple)
$url = "http://$serverName/ReportServer?/$reportFolder/Ticket+System&Date=3-31-2014&Department=Finance&rs:Format=PDF"
#Use alternative credentials as needed to access report server
$webclient = New-Object System.Net.WebClient
$webclient.UseDefaultCredentials = $TRUE
$file = "C:\temp\report.pdf"
$webclient.DownloadFile($url,$file)
#Specify printer \\server\name
$printer = "\\NorthSide\SharpPrinter"
#The /s /o switch may not be necessary. You can test it out.
AcroRd32.exe /s /o /t $file $printer
Get-Process AcroRd32.exe | kill
References:
This link will indicate how to pass parameters to a report via url
http://msdn.microsoft.com/en-us/library/ms155391.aspx
This link will indicate how to access a report in a printable format via url
http://msdn.microsoft.com/en-us/library/ms154040.aspx
This link will show you how to use powershell to write this file to the filesystem via url.
http://teusje.wordpress.com/2011/02/19/download-file-with-powershell/
This link will show you how to push the job to the spooler. Using Powershell version 4.0
http://technet.microsoft.com/en-us/library/hh849886.aspx
If you are having trouble using powershell in a sql agent job, I alternatively would do the polling with a Task Scheduler job and query your database using the SQLPS module.
Hope that helps.