Powershell getting values via regex - regex

Normally , I can catch values beginning with Windows Server like below script. But I want to get version number for operating systems as well.
Windows Embedded
Windows XP
Windows 7
Windows 10
Windows Server® 2008 Standard
Windows Server® 2008 Enterprise
So , it will be only 7 ,XP , 10 , Embedded , 2008 inside version variable.
Script :
$server = Get-ADComputer -Filter "Name -eq '$computer'" -Properties OperatingSystem -ErrorAction SilentlyContinue
$version = ([regex]'Windows Server (\d+)').Match($server.OperatingSystem).Groups[1].Value

This match every line and capture exactly what you want :
Windows(?: Server)?[^\w\r\n]+(\w+).*

Related

Why won't my Unreal 5 project build, even though visual studios does not detect any issues?

I'm brand spanking new to the Unreal engine, and only know a little c++, but I've been following this tutorial to the exact detail (asides from naming variables slightly different things, but I'm consistent so it doesn't matter):
https://www.youtube.com/watch?v=KQgOqyYoHAs
Visual studios says there's "No issues found", but when I try to build (at 34:10 in the video, after following all of the right instructions) it fails and I get this message:
2>UnrealBuildTool : error : Unhandled exception: Dependency file "C:\Users\Administrator\Documents\Unreal Projects\MyProject7\Intermediate\Build\Win64\UnrealEditor\Development\MyProject7\MyProject7.init.gen.cpp.json" version ("1.2") is not supported version
all I understand is that something I have isn't the right version but what is that thing? Thank you
$search = '^\s*"Version":\s"1\.2",$'
$replace = ' "Version": "1.0",'
$folder = '.\Intermediate'
Get-ChildItem -Path $folder -Filter *.json -Recurse -File -Name| ForEach-Object {
$file = Join-Path $folder $_
(Get-Content $file) -replace $search, $replace | Set-Content $file
}
kinda jank powershell script i have been using to fix this. needs to be done any time you modify a source file. wish i had a better fix.
NVM I solved it by changing line of code near the top in that "MyProject7.init.gen.cppjson" from "1.2" to "1.0", and tried rebuilding it. I kept getting errors that mentioned other files that still had that 1.2 number, so I just kept changing them until the errors stopped showing up.
I have resolved "json 1.2" issue after updating to Visual Studio 2022 17.2.2 (tool chain 14.32.31329) and Unreal Engine to 5.0.2.
Possibly updating the tool chain is enough, but I did not check it.
With this update I am also able to build under VS with Unreal Engine Editor opened in the background.
Enjoy!

How can I extract the Short Operating System name using regex in Groovy?

I am trying to obtain the output "Windows Server 2008" from the following input string:"The operating system in the remote workstation is Microsoft Windows Server 2008 R2 Enterprise"
But I only get: "Windows Server" not the "2008"
I tried in www.regex101.com and I believe I have the right regex
def sentence = "The operating system in the remote workstation is Microsoft Windows Server 2008 R2 Enterprise"
def regexWinWorkstation = "Microsoft (Windows [a-zA-Z0-9]+)"
def regexWinServer = "Microsoft (Windows Server [a-zA-Z0-9]+)"
def result = sentence.find(regexWinWorkstation) {
println it[1]
}
if (!result) {
result = sentence.find(regexWinServer){
println it[1]}
}
Expected output: "Windows Server 2008"
Actual output:"Windows Server"
def sentences = [
"The operating system in the remote workstation is Microsoft Windows Server 2008 R2 Enterprise",
"The operating system is Microsoft Windows 10 Professional",
"The operating system is Windows XP"
]
def regexWinOptionalServer = /(?<=Microsoft )?Windows (Server )?[a-zA-Z0-9]+/
sentences.each{
println it.find(regexWinOptionalServer)
}
prints
Windows Server 2008
Windows 10
Windows XP

ODBC export to Excel fails under Windows 7, Windows 8.x and Windows 10

I just created some code (at the bottom) from scratch that shows a simple Excel export. The code fails with an exception when database.OpenEx is called.
The exception shown is:
Reservierter Fehler (-5016); es gibt keine Meldung für diesen Fehler.
Ungültiges Attribut für die Verbindungszeichenfolge. CREATE_DB
Ungültiges Attribut für die Verbindungszeichenfolge. CREATE_DB
Ungültiges Attribut für die Verbindungszeichenfolge. CREATE_DB
Ungültiges Attribut für die Verbindungszeichenfolge. CREATE_DB
Allgemeine Warnung Registrierungsschlüssel 'Temporary (volatile) Jet DSN for process 0x844 Thread 0x1850 DBC 0xab824c Excel' kann nicht geöffnet werden.
Ungültiges Attribut für die Verbindu
The english translation would be something like "Reserved Error" and "Invalid connection string attribut"!
We can repro this on Windows 7, Windows 8.1 and Windows 10. We suggest that there is a problem with a Windows security update, but we are not sure. Similar code worked for years.
Can anybody see failures in the connection string?
Can anybody repro this problem?
EDIT: Windows 7 seams to be affected too.
The following security patches causes this problems:
Windows 7 KB4041681
Windows 8.1 KB40416393
Windows 10 KB4040724
KB4041676
Here the code (the code is just a fast copy from Codeproject). My only change was to make it unicode compatible.
CDatabase database;
CString sDriver = _T("MICROSOFT EXCEL DRIVER (*.XLS)"); // exactly the same name as in the ODBC-Manager
CString sExcelFile = _T("demo.xls"); // Filename and path for the file to be created
CString sSql;
TRY
{
// Build the creation string for access without DSN
sSql.Format(_T("DRIVER={%s};DSN='';READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s"),
sDriver.GetString(), sExcelFile.GetString(), sExcelFile.GetString());
// Create the database (i.e. Excel sheet)
if (database.OpenEx(sSql,CDatabase::noOdbcDialog))
{
// Create table structure
sSql = _T("CREATE TABLE demo (Name TEXT,Age NUMBER)");
database.ExecuteSQL(sSql);
// Insert data
sSql = _T("INSERT INTO demo (Name,Age) VALUES ('Bruno Brutalinsky',45)");
database.ExecuteSQL(sSql);
sSql = _T("INSERT INTO demo (Name,Age) VALUES ('Fritz Pappenheimer',30)");
database.ExecuteSQL(sSql);
sSql = _T("INSERT INTO demo (Name,Age) VALUES ('Hella Wahnsinn',28)");
database.ExecuteSQL(sSql);
}
// Close database
database.Close();
}
CATCH_ALL(e)
{
e->ReportError();
e->Delete();
}
END_CATCH_ALL;
The problem arises in fact due to a bug in the security updates. Currently I see no other solution than to uninstall, the security patch or using another export format.
Affected patches are:
Windows 7 SP1 and Windows Server 2008 R2 SP
KB4041681 -- 2017-10 Security Monthly Quality Rollup for Windows 7 for x86-based Systems
KB4041678 -- 2017-10 Security Only Quality Update for Windows Embedded Standard 7 for x64-based Systems
Windows 8.1 and Windows Server 2012 R2
KB4041693 -- 2017-10 Security Monthly Quality Rollup for Windows 8.1 for x86-based Systems
KB4041687 -- 2017-10 Security Only Quality Update for Windows 8.1 for x86-based Systems
Windows 10 and Windows Server 2016 (version 1607)
KB4041691 -- 2017-10 Cumulative Update for Windows 10 Version 1607 and Windows Server 2016
Windows 10 and Windows Server 2016 (version 1703)
KB4041676 -- 2017-10 Cumulative Update for Windows 10 Version 1703
There are multiple threads in other communities (Tectnet, Answers, Social MSDN) discussing the same problem without any workaround except uninstalling the patch.
Edit (2017-11-21): For Windows 10 the bug is fixed with KB4048955!
I got exactly the same problem since the Windows update from 12/10/2017
Information below solve the problem on Win7 but problem is not solved on Win10.
on Win10, it is ::SQLConfigDataSource(hwndParent, fRequest, sDriver, sAttributes) which generate "Unhandled exception"
SOLUTION for Win7:
I have additional parameters: FIL=Excel 2000,DriverID=790 DRIVER={Microsoft Excel Driver (*.xls)}
It seems to be solved using: FIL=Excel 12.0,DriverID=1046 DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}
This will work if you have a version of Excel compatible with these parameters. You can try versions between Excel 2000 and Excel 12.0, too.
For PC with only Excel 2000 so new parameters do not work at first : To solve the problem I install AccessDatabaseEngine_X64.exe from Microsoft Download; this enabled the use of the Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)
Example of parameters:
m_sDsn ="DRIVER={Microsoft Excel Driver (*.xls)};DSN='ODBC_NameXls';FIRSTROWHASNAMES=1;READONLY=TRUE;CREATE_DB="Excelfilename.xls";DBQ=Excelfilename.xls;FIL=Excel 2000;DriverID=790";
m_sDsn ="DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DSN='ODBC_NameXls';FIRSTROWHASNAMES=1;READONLY=TRUE;CREATE_DB="Excelfilename.xls";DBQ=Excelfilename.xls;FIL=Excel 12.0,DriverID=1046";
m_Database->OpenEx(m_sDsn, CDatabase::openReadOnly | CDatabase::noOdbcDialog);

Replacing a string in all config files across machines with a script

I have the below task and I am wondering what would be the best and quick way to do this. I am thinking scripting rather than a C# app but struggling with scripting in DOS. I wanted to use powershell but not sure if all the machines have powershell installed :
I have around 15 windows machines and in each machine, I want to find all *.config files (in say C:\ and D:) and replace a specific word (db name).
I can execute this locally or execute this remotely, since I have login access to the machines. But the tough part is the script.
Any pointers would be great to start.
Thanks.
Wikipedia has some info on what versions of Windows have PowerShell.
PowerShell version 1.0 was released in 2006 for Windows XP SP2/SP3, Windows Server 2003, and Windows Vista....Version 2.0 is integrated with Windows 7 and Windows Server 2008 R2 and is released for Windows XP with Service Pack 3, Windows Server 2003 with Service Pack 2, and Windows Vista with Service Pack 1. Version 3.0 is integrated with Windows 8 and with Windows Server 2012. Microsoft has also made PowerShell 3 available for Windows 7 with Service Pack 1, for Windows Server 2008 with Service Pack 1, and for Windows Server 2008 R2 with Service Pack 1.
To install version 3 on Win 7 you need the WMF 3.0 package
This is untested and destructive so test it first.- it is designed to search C: and D: drives and all subdirectories and modifies all *.config files.
It is set to look in c:\abc and d:\abc trees atm so put some files and folders in there and test it.
#echo off
for /f "delims=" %%a in ('dir c:\abc\*.config d:\abc\*.config /b /s /a-d') do (
call :sar "%%a" "%%a.tmp" "db_name" "new_db_name"
move /y "%%a.tmp" "%%a" >nul
)
goto :EOF
:sar
:: inputfile outputfile regexp_search replacement
if "%~5"=="" (set global=true) else (set global=false)
set s=regex.replace(wscript.stdin.readall,"%~4")
>_.vbs echo set regex=new regexp
>>_.vbs echo regex.global=%global%
>>_.vbs echo regEx.IgnoreCase=True
>>_.vbs echo regex.pattern="%~3"
>>_.vbs echo wscript.stdOut.write %s%
cscript /nologo _.vbs <"%~1" >"%~2"
del _.vbs
goto :EOF

_getch() doesn't work on windows server 2012

I need a DLL for users can type password and not echo on the screen.
So I use _getch() for getting chars with no echo like this,
//get character with no echo
ch = _getch();
and compile the code use microsoft vs2005.
It works on windows server 2003/2008, but on the new windows server 2012, it echos the characters to the screen.
My problem is why _getch() echo characters only on windows server 2012? and how to fix it?
Use cin.get() in place of getch() .