How to compile qt static source? - c++

I'm trying to follow the tutorial found here: https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW
I already have qt 6.3.1 installed, i download the PowerShell script and changed it to:
[CmdletBinding()]
param(
$QtSrcUrl = "https://download.qt.io/official_releases/qt/6.3/6.3.1/single/qt-everywhere-src-6.3.1.zip",
$QtStaticDir = "C:\Qt\Static", # NO TRAILING SLASH
$QtVersion = "6.3.1", #If you change this, you'll need to change the URL above to download as well...
$MingwDir = "",
[switch]$NoPause = $false
)
Im getting this error:
Out-File : Could not find a part of the path 'C:\Qt\Static\6.3.1\mkspecs\win32-g++\qmake.conf'.
At C:\Qt\qt-windows10-static-build.ps1:167 char:6
+ "# | Out-File -Append $File -Encoding Ascii
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Out-File], DirectoryNotFoundException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
The folder C:\Qt\Static\6.3.1 is empty, why does the ps script is searching for something inside of it?

Related

Parsing Rest query output

I am trying to parse the output of a rest api query of the form
$response = Invoke-RestMethod -Uri $uri -Headers $headers
$response.name | Select-String -Pattern ^role
returns an output similar to this below (elements separated by ::)
role::servicing2
role::collaboration::lei
role::commercial_lines::npds
role::nvp::windows::ucce_gold
role::oracle::linux::oracle_oid
role::splunk::splunk_enterprise::add_on
I need to read this output line by line and parse.
If there are just 2 elements eg. role::servicing2 ignore the line
If there are 3 elements, ignore the first element "role", prepend puppet_ to the second element and it becomes the project, the third element is the role (OS is unknown)
If there are 4 or more elements, ignore the first element "role", prepend puppet_ to the second element and it becomes the project, if the third element is "windows" or "linux" that is the OS, else OS is "unknown", and the last element \:\:'(\w+)'$ is the role.
Need an output in the form of an array or table or list in this format
(Don't necessarily need header)
Project OS Role
puppet_collaboration unknown lei
puppet_commercial_lines unknown npds
puppet_nvp windows ucce_gold
puppet_oracle linux oracle_oid
puppet_splunk unknown add_on
I have tried various regex expressions. Couldn't figure out the logic of walking this line by line and parsing appropriately into a list or array.
I think below code should do what you want:
$roles = #'
role::servicing2
role::collaboration::lei
role::commercial_lines::npds
role::nvp::windows::ucce_gold
role::oracle::linux::oracle_oid
role::splunk::splunk_enterprise::add_on
'# -split '\r?\n'
$result = $roles | ForEach-Object {
$parts = $_ -split '::'
switch ($parts.Count) {
2 { continue } # ignore this line
3 {
[PsCustomObject]#{
'Project' = 'puppet_{0}' -f $parts[1]
'OS' = 'unknown'
'Role' = $parts[2]
}
}
default {
[PsCustomObject]#{
'Project' = 'puppet_{0}' -f $parts[1]
'OS' = if ('windows', 'linux' -contains $parts[2]) {$parts[2]} else {'unknown'}
'Role' = $parts[-1]
}
}
}
}
# output on screen
$result
# output to CSV file
$result | Export-Csv -Path 'D:\roles.csv' -NoTypeInformation
For testing I have put the result of your $response.name | Select-String -Pattern ^role in a here-string.
Output:
Project OS Role
------- -- ----
puppet_collaboration unknown lei
puppet_commercial_lines unknown npds
puppet_nvp windows ucce_gold
puppet_oracle linux oracle_oid
puppet_splunk unknown add_on

Create multiple Folders on server then create network share for each as well

I am trying loop through a text file with a list of folder names I would like to create. Then also create a network share to the folder as well.
I am able to create the folder but I am getting stuck on creating the network share.
$folder ='\\networkserver\D$' #Root Directory to place the New folders in.
$routes = get-content 'C:\uncroutes.txt'
foreach ($routes in $routes) {
$newpath = Join-Path "$folder\" -ChildPath $routes
New-Item $newpath -type Directory
foreach ($newpath in $newpath) {
New-SmbShare -Name $newpath -Path $folder -FullAccess Administrator
}
}
This is the error message:
New-SmbShare -Name $newpath -Path $folder -FullAccess Adminis ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (MSFT_SMBShare:ROOT/Microsoft/Windows/SMB/MSFT_SMBShare) [New-SmbShare], CimException
+ FullyQualifiedErrorId : Windows System Error 5,New-SmbShare
Got it working with Help from #Adminofthings. Here is the working code.
$folder ='\\networkserver\D$' #Root Directory to place the New folders in.
$routes = get-content 'C:\uncroutes.txt' #list of folder Names
foreach ($route in $routes) {
$newpath = Join-Path "$folder\" -ChildPath $route
New-Item $newpath -type Directory
foreach ($ShareName in $ShareNames) {
$ShareName = ($route | sls -pattern "([0-9a-zA-Z-_ ]+)$").matches.value
$serverpath = "d:\$route"
New-SmbShare -Name $ShareName -Path $serverpath -FullAccess Administrator
}
}
If I assume correctly about uncroutes.txt and say that it contains a unc path on each line, then you can get the share name by using something like the code below:
$ShareName = ($route | sls -pattern "([0-9a-zA-Z-_ ]+)$").matches.value
Then pass $ShareName into your -name parameter.

Powershell script to open another script as admin

I have a script that I can double click and it'll open other scripts as admin. Works with some things but not everything. For one script, it opens the next window and then immediately closes it. For another, I get this error:
At MYPATH\InstallClient.ps1:33 char:78
+ ... tall_x64.msi" -force -recurse -ErrorAction Stop #Cleans out the file ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The string is missing the terminator: ".
At MYPATH\InstallClient.ps1:27 char:31
+ ForEach ($entry in $computers){ #start of foreach loop
+ ~
Missing closing '}' in statement block or type definition.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
Below is the script to open a script as an admin:
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "PS1 (*.ps1)| *.ps1"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
$inputfile = Get-FileName "MYPATH\Scripts"
powershell.exe -noprofile -command "&{start-process powershell -ArgumentList '-NoExit -noprofile -file $inputfile' -verb RunAs}"
This is the script that it gives the previous error for while trying to open:
Function Get-FileName($initialDirectory) #Function to choose a file
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "MSI (*.msi)| *.msi" #type of files that will be available for selection
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
$inputfile = Get-FileName "MyPath" #Directory that is going to open to select a file from
Function Get-FileName($initialDirectory) #Function to choose a file
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "CSV (*.csv)| *.csv" #type of files that will be available for selection
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
$inputfile1 = Get-FileName "MyPath\ServerLists"
$computers = import-csv $inputfile1
ForEach ($entry in $computers){ #start of foreach loop
$computername = $entry.computernames #this saves the single entry under computernames for each entry in csv file
Copy-item $inputfile -container -recurse \\$computername\C$\windows\temp #this copies the msi file that we selected to the computer entry called from the csv file's temp folder
Invoke-Command -Computername $computername –ScriptBlock {Start-process -Wait "C:\windows\temp\ShadowSuiteClientInstall_x64.msi"} | out-null #This starts the msi file that we just copied and waits for the installation to be completed before moving on
If($?){ #If the last command was successful
Echo "Installed ShadowSuiteClientInstall_x64 on $computername."
Remove-Item "\\$computername\C$\windows\temp\ShadowSuiteClientInstall_x64.msi" -force -recurse -ErrorAction Stop #Cleans out the file we copied into the temp folder
}
}
Does anyone have any ideas on why this will open some things fine but give this error for this script and immediately close other scripts without running them? Does anyone have a better way to navigate through scripts and select one to open as admin?
Ok I figured this out. I loaded the script into powershell ISE and I saw that it was compiling it incorrectly. It kept turning the -Scriptblock into an ae symbol instead of the - in front of scriptblock. Weird AF IMO but ok, I fixed it in ISE, which I recommend to anyone struggling with weird compiling errors like this.

Powershell v2.0 - find start path and instance and starting an application

I am trying to write a simple script that stops and then starts a process (Application).
I can stop it fine, but can't find a way to start it again.
The string to start the process should be: "c:\AppFolder\AppName.exe" instance1
my script is:
$appName = "AppName.exe"
$filter = "name like '%"+$appName+"%'"
$result = Get-WmiObject win32_process -Filter $filter
$processid = $result.ProcessId
$command = $result.CommandLine
stop-process $processid
start $command
If I run $result | select * I see that there is an item for CommandLine which is "C:\AppFolder\AppName.exe" instance1
But If I try and do:
$command = $result.CommandLine
stop-process $processid
start $command
I get start-process : This command cannot be executed due to the error: The system cannot find the file specified
But if I manually type into a powershell window start "c:\AppFolder\AppName.exe" instance1 the Application starts fine.
Am I missing something here?
(n.b. it was suggested to me in "powershell v2 - how to get process ID" that I could use
$processid = get-process appName | select -expand id to get the processid, but when I expanded this to get all the items (probably not the correct term?)
in the object I couldn't see an option for CommandLine or similar)
I found the following (but still doesn't work)
$command = Get-WmiObject win32_process -Filter $filter | select -expandproperty CommandLine
write-host $command
This writes "c:\AppFolder\AppName.exe" instance1
start-process $command
But this then results in the following error:
Start-Process : This command cannot be executed due to the error: The system cannot find the file specified
.
At line:11 char:14
+ start-process <<<< $command
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
However, running:
start-process "c:\AppFolder\AppName.exe" instance1
starts the application?
I think I've solved it!! (and it's quite simple really) After much googling. . .
Apparently the start-process cmdlet only accepts a file location.
In order to add an argument (in this case the instance name) I need to use the attribute -ArgumentList
So I need to get the CommandLine item, and split it up, then pass it back in two parts
e.g.
$result = Get-WmiObject win32_process -Filter $filter
$comLine = $result.CommandLine -split"( )"
$comm = $commLine[0]
$inst = $commLine[2]
start-process -FilePath $comm -ArgumentList $inst
And this works as I expected it to.

Using 'Pester' (PowerShell Unit-Testing framework) with properties

I am trying to wrap a text fixture around some PowerShell code that extends an object with a property. I get an error that appears to be caused by Pester. I have a contrived example below that displays what I am trying to do.
Has anyone succeeded in writing tests on functions that use properties with Pester?
The error I get:
Describing Get-PropertyOfItem
Select-Object : Property cannot be processed because property "should" already exists.
At C:\Repos\ClinicientOps\clinicientops\General\Functions\Get-PropertyOfItem.ps1:4 char:11
+ $files | Select-Object *, #{Name = "TestProperty"; Expression = { $dir.Length}} ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Windows:PSObject) [Select-Object], PSArgumentException
+ FullyQualifiedErrorId : AlreadyExistingUserSpecifiedPropertyNoExpand,Microsoft.PowerShell.Commands.SelectObjectCommand
My function:
function Get-PropertyOfItem {
$dir = "C:\"
$files = Get-ChildItem $dir
$files | Select-Object *, #{Name = "TestProperty"; Expression = { $dir.Length}} -Last 1
}
My test code:
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"
Describe "Get-PropertyOfItem" {
It "does something useful" {
$prop = Get-PropertyOfItem
$prop.TestProperty.should.be(3)
}
}
It appears to be a limitation they are investigating in version 2.
Pester version 2.0.1 has been silently released. You'll have to rewrite your expectation to be
$prop.TestProperty | Should Be 3
It also means that all your other tests will need to migrate to this pipeline form Expectation syntax.