AI – PowerShell – Toying With Removing Hyperlinks

email me
clear-host

$string1 = '<a href="https://eddiejackson.net/this_is_a_test.jpg" rel="lightbox noopener" target="_blank"><img class="TEST" src="https://eddiejackson.net/this_is_a_test.jpg" width="264" height="198"></a>'
$string2 = '<a href="https://eddiejackson.net/this_is_a_test.jpg" rel="lightbox noopener" target="_blank"><strong></strong></a>

<a href="https://eddiejackson.net/this_is_a_test.jpg" rel="lightbox noopener" target="_blank">This is a test

</a><a href="https://eddiejackson.net/this_is_a_test.jpg" rel="lightbox noopener" target="_blank"><strong></strong></a>'
$string3 = '<a href="https://eddiejackson.net/this_is_a_test.jpg" rel="lightbox noopener" target="_blank"><img class="TEST" src="https://eddiejackson.net/this_is_a_test.jpg" width="264" height="198"></a>'
$string4 = '<a href="https://eddiejackson.net/this_is_a_test.jpg" rel="lightbox noopener" target="_blank"><strong></strong></a>

<a href="https://eddiejackson.net/this_is_a_test.jpg" rel="lightbox noopener" target="_blank">This is a test

</a><a href="https://eddiejackson.net/this_is_a_test.jpg" rel="lightbox noopener" target="_blank"><strong></strong></a>'

write-host "{{{ REMOVE HYPERLINKS FROM STRING }}}"
write-host ""
write-host ""

# NOT A BEST USE OF REGEX

write-host "INPUT1"
$string1
$a = $string1 -replace "<([^>]*)(?:a href|:\w+)=(?:'[^']*'|""[^""]*""|[^\s>]+)([^>]*)>","`$1`$2"
# using the -replace - not optimal
$b = $a -replace "",""
$c = $b -replace 'rel="lightbox"',""
$d = $c -replace 'rel="noopener noreferrer"',""
$e = $d -replace 'target="_blank"',""
$f = $e -replace 'target="_parent"',""
$g = $f -replace 'target="_top"',""
$h = $g -replace 'target="_new"',""
$i = $h -replace 'rel="noopener noreferrer"',""
write-host ""
Write-host "OUTPUT1: RETURNS JUST IMG SRC"
$i
write-host "`n`n"

# GETTING WARMER WITH THESE

Write-host "INPUT2"
$string2
write-host ""
Write-host "OUTPUT2: RETURNS EVERYTHING BUT URL"
$x = $string2 -replace "<([^>]*)(?:a href|:\w+)=(?:'[^']*'|""[^""]*""|[^\s>]+)([^>]*)>",""
$y = $x -replace "",''
$y

write-host "`n`n"

Write-host "INPUT3"
$string3
write-host ""
Write-host "OUTPUT3: RETURNS EVERYTHING BUT URL"
$x = $string4 -replace ("<([^>]*)(?:a href|:\w+)=(?:'[^']*'|""[^""]*""|[^\s>]+)([^>]*)>",""); $y = $x -replace "",""
$y

write-host "`n`n"

# THIS IS THE BEST USAGE OF REGEX

Write-host "INPUT4"
$string4
write-host ""
Write-host "OUTPUT4: RETURNS EVERYTHING BUT URL"
$x = $string4 -replace "<([^>]*)(?:a href|:\w+)=(?:'[^']*'|""[^""]*""|[^\s>]+)([^>]*)>|(",""
$x
write-host "`n`n"

Screenshot

PowerShell – Check Password Complexity

email me

clear-host

$Password = Read-Host "{{ PASSWORD COMPLEXITY VERIFICATION }}`n`nPassword must meet these requirements:
`n`nAt least one upper case letter [A-Z]`nAt least one lower case letter [a-z]`nAt least one number [0-9]`nAt least one special character (!,@,%,^,&amp;,$,_)`nPassword length must be 7 to 25 characters.`n`n`nEnter Password"

if(($Password -cmatch '[a-z]') -and ($Password -cmatch '[A-Z]') -and ($Password -match '\d') -and ($Password.length -match '^([7-9]|[1][0-9]|[2][0-5])$') -and ($Password -match '!|@|#|%|^|&amp;|$|_'))
{
Write-Host "`nPassword is valid!`n"
}
else
{
Write-Host "`nPassword is invalid!`n"
}

 

Notes

clear-host

$RegEx = @”
^((?=.*[a-z])(?=.*[A-Z])(?=.*\d)|(?=.*[a-z])(?=.*[A-Z])(?=.*[^A-Za-z0-9])|(?=.*[a-z])(?=.*\d)(?=.*[^A-Za-z0-9])|(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]))([A-Za-z\d@#$%^&amp;amp;£*\-_+=[\]{}|\\:’,?/`~”();!]|\.(?!@)){8,16}$
“@

"Wo0@12345678" -cmatch $RegExp

Java – Fibonacci Sequence in Array

email me

Compiled and tested here: http://www.browxy.com/

With Initialized Array

import java.util.Scanner;

public class FibSeries {

public static void main (String [] args){

// fib sequence
int [] x = {0,1,1,2,3,5,6,13,21,34,55};

int i;

for (i=0; i<x.length; i++){

// output
System.out.print(x[i] + " ");

}
}
}

// screen output
// 0 1 1 2 3 5 8 13 21 34 55

With For Loop

import java.util.Scanner;

public class FibSeries {

public static int fibonacci(int n) {
int x = 0;
int y = 1;

// compute fib sequence
for (int i = 0; i < n; i++) {
int z = x;
x = y;
y = z + y;
}
return x;
}

public static void main(String[] args) {

for (int i = 0; i < 11; i++) {
// output
System.out.print(fibonacci(i) + " ");
}
}
}

// screen output
// 0 1 1 2 3 5 8 13 21 34 55

Windows – Add Runonce Key

email me

Manually in HKEY_CURRENT_USER

REG ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v RunScript /t REG_SZ /d “C:\setup\script.cmd” /f

 

Manually in HKEY_USERS

REG ADD HKU\S-1-5-21-3492930481-2827506072-2794401122-1001\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v RunScript /t REG_SZ /d “C:\setup\script.cmd” /f

 

HKEY_CURRENT_USER via Script (or…SCCM)

REG LOAD HKU\TEMP “C:\Users\Default\ntuser.dat”
REG ADD HKU\TEMP\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v RunScript /t REG_SZ /d “C:\setup\script.cmd” /f
REG UNLOAD HKU\TEMP

 

All Profiles via Load and Unload via Script

FOR /D %%D IN (“C:\Users\*”) DO IF EXIST “%%D\NTUSER.DAT” REG LOAD HKU\TEMP “%%D\NTUSER.DAT” && (REG ADD HKU\TEMP\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v Reg_Value /t REG_SZ /d Reg_Data /f & REG UNLOAD HKU\TEMP)

 

Using PowerShell

$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce"
$regKey = "RunScript"
$regValue = "c:\setup\script.cmd"

IF(!(Test-Path $regPath))

{

New-Item -Path $regPath -Force | Out-Null

New-ItemProperty -Path $regPath -Name $regKey -Value $regValue -PropertyType STRING -Force | Out-Null}

ELSE {

New-ItemProperty -Path $regPath -Name $regKey -Value $regValue -PropertyType STRING -Force | Out-Null}

 

Using PowerShell App Deployment Toolkit

[scriptblock]$HKCURegistrySettings = {
Set-RegistryKey -Key 'HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce' -Name 'RunScript' -Value '"c:\setup\script.cmd"'-Type String -ContinueOnError:$True
}
Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings

 

Using C# in Visual Studio


using Microsoft.Win32; //used by Registry

namespace PlayingAround
{
class WriteReg
{
public static void Main(string[] args)
{
// define variables
const string userRoot = "HKEY_CURRENT_USER";
const string subkey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce";
const string keyName = userRoot + "\\" + subkey;

// set registry key
Registry.SetValue(keyName, "RunScript", "C:\\setup\\script.cmd", RegistryValueKind.String);

}
}
}

 

Using AutoIt in SciTE-Lite

WriteReg()

Func WriteReg()
  ; Write key
  RegWrite("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce", "RunScript", "REG_SZ", "C:\setup\script.cmd")
EndFunc ;==>WriteReg

C++ Return Addition with Integers

email me
#include "stdafx.h"
#include<iostream>
#include<string>

using namespace std;

int main()
{
	unsigned int userInput;
	unsigned long long addition = 0;
	string sum = "0";

	cout << "Enter an integer: ";
	cin >> userInput;

	for (int i = 1; i <= userInput; ++i)
	{
		addition += i;
		std::string intCast = std::to_string(i);
		sum = sum + "+" + intCast;
	}

	sum.replace(0, 2, "");//if you don't want to see 0+

	cout << "\nSum of " << sum << "=" << addition;
	cin.get();

	cin.get();

	return 0;
}

C++ Return Factorial with Integers

email me
#include "stdafx.h"
#include<iostream>
#include<string>

using namespace std;

int main()
{
	unsigned int userInput;
	unsigned long long factorial = 1;
	string sum = "0";

	cout << "Enter an integer: ";
	cin >> userInput;

	for (int i = 1; i <= userInput; ++i)
	{
		factorial *= i;
		std::string intCast = std::to_string(i);
		sum = sum + "*" + intCast;
	}

	sum.replace(0, 2, "");//if you don't want to see 0+

	cout << "\nFactorial of " << sum << "=" << factorial;
	cin.get();

	cin.get();

	return 0;
}

C++ Return Factorial

email me
#include "stdafx.h"
#include<iostream>

using namespace std;

int main()
{
	unsigned int userInput;
	unsigned long long factorial = 1;

	cout << "Enter an integer: ";
	cin >> userInput;	

	for (int i = 1; i <= userInput; ++i)
	{
		factorial *= i;
	}

	cout << "Factorial of " << userInput << " = " << factorial;
	cin.get();

	cin.get();

	return 0;
}

SCCM – IP Addresses

email me

A dirty little secret of Microsoft, and why you don’t see IP address columns in the SCCM console, is that MS stores all the IP addresses of a machine into a single row, into an array. So, when viewed, you’ll see 1-6 (or more) IP addresses all crammed together. Not great.

 

Here are some common methods for dealing with IP addresses. I normally just run the queries directly on the SQL DB, but you can also use SCCM Reporting and SCCM Queries under Monitoring.

 

SCCM REPORT TO LIST IP ADDRESSES – LITE VERSION

select distinct
A.Name0,c.IPAddress0,
D.IP_Subnets0
from v_R_System A
inner join v_FullCollectionMembership B on A.ResourceID=B.ResourceID
Inner join v_GS_NETWORK_ADAPTER_CONFIGUR C ON A.ResourceID=C.ResourceID
Inner Join v_RA_System_IPSubnets D ON A.ResourceID=D.ResourceID
where CollectionID=@COLLID and C.IPEnabled0='1'
group by A.Name0,c.IPAddress0 ,D.IP_Subnets0
order by A.Name0,c.IPAddress0 ,D.IP_Subnets0

 

SCCM REPORT TO LIST IP ADDRESSES – FULL VERSION

SELECT distinct
CS.name0 as 'Server Name',
OS.Caption0 as 'OS',
CU.Manufacturer0 as 'Manufacturer',
CU.Model0 as 'Model',
RAM.TotalPhysicalMemory0/1024 as [RAM (MB)],
processor.Name0 as 'Processor',
BIOS.ReleaseDate0 as 'BIOS Manufacture Date',
OS.InstallDate0 as 'OS Install Date',
IP.IP_Addresses0 AS 'IP Address'

from
v_R_System CS
FULL join v_GS_PC_BIOS BIOS on BIOS.ResourceID = CS.ResourceID
FULL join v_GS_OPERATING_SYSTEM OS on OS.ResourceID = CS.ResourceID
FULL join V_GS_X86_PC_MEMORY RAM on RAM.ResourceID = CS.ResourceID
FULL JOIN v_GS_PROCESSOR Processor on Processor.ResourceID=CS.ResourceID
FULL join v_GS_SYSTEM_ENCLOSURE SE on SE.ResourceID = CS.ResourceID
FULL join v_GS_COMPUTER_SYSTEM CU on CU.ResourceID = CS.ResourceID
join v_RA_System_IPAddresses IP on IP.ResourceID = CS.ResourceID

WHERE CS.Operating_System_Name_and0 LIKE '%nt%server%'
AND IP.IP_Addresses0 NOT LIKE '192.168%'
AND IP.IP_Addresses0 NOT LIKE '172.10%'
AND IP.IP_Addresses0 NOT LIKE '%:%'
AND IP.dhcpenabled0 = 0

group by
CS.Name0,
OS.Caption0,
CU.Manufacturer0,
CU.Model0,
RAM.TotalPhysicalMemory0,
BIOS.ReleaseDate0,
OS.InstallDate0,
Processor.Name0,
BIOS.ReleaseDate0,
IP.IP_Addresses0
Order by CS.Name0

 

IP ADDRESSES SINGLE COLUMN

Select Distinct

SD.Name0,

IP.IpAddress0

From v_Gs_System SD

Join v_Gs_Network_Adapter_Configur IP

On SD.ResourceId = IP.ResourceId

Where IP.DefaultIPGateway0 Is Not NULL

And IP.IPAddress0 Is Not NULL

And IP.IPAddress0 <> '0.0.0.0'

Order By SD.Name0

 

DISTINCT ADDRESSES, multiple rows

SELECT v_RA_System_ResourceNames.Resource_Names0 AS [Resource name],
v_RA_System_IPAddresses.IP_Addresses0 AS [IP Address]
FROM v_RA_System_MACAddresses INNER JOIN
v_RA_System_ResourceNames ON v_RA_System_MACAddresses.ResourceID = v_RA_System_ResourceNames.ResourceID INNER JOIN
v_RA_System_IPAddresses ON v_RA_System_MACAddresses.ResourceID = v_RA_System_IPAddresses.ResourceID

SINGLE IP ADDRESS
SELECT DNSHostName0 AS [NetBIOS Name],
CASE WHEN IPAddress0 like '%,%' THEN left(IPAddress0,CHARINDEX(',',IPAddress0)-1)
ELSE IPAddress0 END AS [IP Address]
FROM v_GS_NETWORK_ADAPTER_CONFIGUR
WHERE ([dbo].[v_GS_NETWORK_ADAPTER_CONFIGUR].IPAddress0 not like 'fe%')
and ([dbo].[v_GS_NETWORK_ADAPTER_CONFIGUR].IPAddress0 IS NOT NULL)
and ([dbo].[v_GS_NETWORK_ADAPTER_CONFIGUR].IPAddress0 not like '169.254.%')
and ([dbo].[v_GS_NETWORK_ADAPTER_CONFIGUR].DefaultIPGateway0 IS NOT NULL)
and ([dbo].[v_GS_NETWORK_ADAPTER_CONFIGUR].IPEnabled0 = '1')

 

SCCM QUERY RETURN IPs TO ONE COLUMN

select Name, IPAddresses,
LastLogonUserDomain,
LastLogonUserName,
ResourceType,
NetbiosName,
ClientType
from sms_r_system
where Client = 1 and SMS_R_System.Name = SMS_R_System.Name

C++ Input and Output

email me

Compiled in Visual Studio 2017.

#include "stdafx.h"
#include<stdio.h>
#include<cstdio>
#include<iostream>

#define size 50

using namespace std;

class card {

    char title[size];
    char author[size];
    int num_book;

public:
    void store();
    void show();
};

void card::store()
{
    cout << "Enter Title: "; std::cin.getline(title,size); //cin >> title;

    cout << "Enter Author: "; std::cin.getline(author,size); //cin >> author;

    cout << "Enter number of copies: "; cin >> num_book;
	getchar();
	// if char std::cin.getline(num_book, 3);

}

void card::show()
{

	std::cout << "\nTitle: " << title << "  \nAuthor: " << author << "\nCopies: " << num_book;

}

// ENTRY POINT - GOVERNOR
int main()
{
    int choice;

    card b1, b2;

    cout << "{{{ Library Management System }}}\n\n";

// INPUT
    cout << "\nStore book-1 information\n";
    b1.store();

    cout << "\nStore book-2 information\n";
    b2.store();

// OUTPUT
    cout << "\n\nInformation of book-1";
    b1.show(); 

    cout << "\n\nInformation of book-2";
    b2.show();
    cin.get();

}

Screenshot

Java – Prime Numbers with User Input

email me

Compiled and tested here: http://www.browxy.com/

import java.util.Scanner;

class Main {
public static void main(String[] args) {

Scanner reader = new Scanner(System.in);
System.out.println("Enter a number: ");
int N = reader.nextInt(); // user input.

// Array
// 0 - prime, 1 - composite
int[] arr = new int[N + 1];
arr[0] = arr[1] = 1;

// loop from 2 to square root of N
for (int i = 2; i <= Math.sqrt(N); i++) {

// check if prime
if (arr[i] == 0) {

// add all factors of i to composite numbers to N
for (int j = i * i; j <= N; j += i) {
arr[j] = 1;
}
}
}

// Print all positions for which fields are not reset
for (int i = 0; i < arr.length; i++) {
if (arr[i] == 0) {
System.out.print(i + ", ");
}
}
}
}

C++ Basic Math

email me

Compiled in Visual Studio 2017.

#include "stdafx.h"
#include<iostream>
#include<string>

using namespace std;

// METHOD 1
void messages (void)
{
	// initialize strings
	string xString1;

	// output message
	xString1 = "Doing basic math. \n\nLet's try some math in the console.\n";
	cout << xString1 << endl;

}

// METHOD 2
void addition (void)
{

	// initialize variables
	int xInt1, xInt2, xResult;

	xInt1 = 9;
	xInt2 = 4;

	// do some addition
	xResult = xInt1 + xInt2;		

	// do some casting
	std::string castInt1 = std::to_string(xInt1);
	std::string castInt2 = std::to_string(xInt2);

	std::string output = "\nAddition: ";
	output += castInt1 + " + " + castInt2 + " = " + std::to_string(xResult);

	cout << output << endl;

}

// METHOD 3
void subtraction(void)
{

	// initialize variables
	int xInt1, xInt2, xResult;

	xInt1 = 9;
	xInt2 = 4;

	// do some subtraction
	xResult = xInt1 - xInt2;

	// do some casting
	std::string castInt1 = std::to_string(xInt1);
	std::string castInt2 = std::to_string(xInt2);

	std::string output = "\nSubtraction: ";
	output += castInt1 + " - " + castInt2 + " = " + std::to_string(xResult);

	cout << output << endl;

}

// METHOD 4
void multiplication(void)
{

	// initialize variables
	int xInt1, xInt2, xResult;

	xInt1 = 9;
	xInt2 = 4;

	// do some multiplication
	xResult = xInt1 * xInt2;

	// do some casting
	std::string castInt1 = std::to_string(xInt1);
	std::string castInt2 = std::to_string(xInt2);

	std::string output = "\nMultiplication: ";
	output += castInt1 + " x " + castInt2 + " = " + std::to_string(xResult);

	cout << output << endl;

}

// METHOD 5
void wait(void)
{
	string xString2;

	// wait for keypress
	xString2 = "\n\nPress any key to continue...";
	cout << xString2 << endl;
	cin.get();

}

// ENTRY POINT - PROGRAM GOVERNOR
int main()

{
	// call messages
	messages();

	// call addition
	addition();

	// call subtraction
	subtraction();

	// call multiplication
	multiplication();

	// call wait
	wait();

}

Notes

std::to_string

string to_string (int val);
string to_string (long val);
string to_string (long long val);
string to_string (unsigned val);
string to_string (unsigned long val);
string to_string (unsigned long long val);
string to_string (float val);
string to_string (double val);
string to_string (long double val);
Convert numerical value to string

Returns a string with the representation of val.

The format used is the same that printf would print for the corresponding type:

type of valprintf
equivalent
description
int"%d"Decimal-base representation of val.
The representations of negative values are preceded with a minus sign (-).
long"%ld
long long"%lld
unsigned"%u"Decimal-base representation of val.
unsigned long"%lu
unsigned long long"%llu
float"%f"As many digits are written as needed to represent the integral part, followed by the decimal-point character and six decimal digits.
inf (or infinity) is used to represent infinity.
nan (followed by an optional sequence of characters) to represent NaNs (Not-a-Number).
The representations of negative values are preceded with a minus sign (-).
double"%f
long double