PowerShell Culture and Help

https://powershell.org/forums/topic/invoke-command-remove-pscomputername/
https://powershellserveradmin.wordpress.com/2015/01/09/get-help-vs-help/
https://social.technet.microsoft.com/Forums/Lync/en-US/dea5d51d-0757-4916-86d8-c0b12ef55153/how-to-exclude-property-from-result-returned-by-powershell-command-?forum=sharepointadminprevious

Aliases
https://blogs.technet.microsoft.com/heyscriptingguy/2011/05/01/best-practice-for-using-aliases-in-powershell-scripts/

PowerShell session culture

https://p0w3rsh3ll.wordpress.com/2012/01/22/working-with-system-locale-and-user-locale/

## Test remote PS call from JACK on RHINO

$computerName = “lsc561.tw.ibm.com”
$remoteUser = “Administrator”
$remotePassword = “!Sp@-81#”
$credential = New-Object System.Management.Automation.PSCredential($remoteUser, (ConvertTo-SecureString $remotePassword -AsPlainText -Force))

invoke-command -ComputerName $computerName -Credential $credential `
-Authentication Credssp `
-scriptblock { `
function Set-Culture([System.Globalization.CultureInfo] $culture) { `
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture; `
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture; `
}; `
Set-Culture (Get-ItemProperty ‘HKCU:\Control Panel\International’).LocaleName; `
# Set-Culture $(Get-Culture).ToString(); `
# Set-Culture de-DE; `
[system.threading.thread]::currentthread.currentculture; `
$env:computername; `
help Add-DpSqlPolicy -Full; `
}

https://stackoverflow.com/questions/23909746/powershell-v4-not-importing-module-automatically
https://www.nigelboulton.co.uk/2011/05/problems-with-powershell-comment-based-help/

$cult = get-culture | select-object *
out-string -inputobject $cult -width 100

System.Text.Encoding utf_8 = System.Text.Encoding.UTF8;

// This is our Unicode string:
string s_unicode = “abcéabc”;

// Convert a string to utf-8 bytes.
byte[] utf8Bytes = System.Text.Encoding.UTF8.GetBytes(s_unicode);

// Convert utf-8 bytes to a string.
string s_unicode2 = System.Text.Encoding.UTF8.GetString(utf8Bytes);

MessageBox.Show(s_unicode2);

help Add-DpSqlPolicy -Full | select * -ExcludeProperty RunSpaceId | fl | out-string -Width 350
help Add-DpSqlPolicy -Full | select * -ExcludeProperty RunSpaceId | ft -autosize | out-string -Width 350

——————————————-

// Format from PowerShell Unicode to C# string
// Convert a string to Unicode bytes.
byte[] unicodeBytes = System.Text.Encoding.Unicode.GetBytes(text);
// Convert Unicode bytes to a string.
string text_string = System.Text.Encoding.Unicode.GetString(unicodeBytes);
Tm.TraceInformation(Tm.TraceFm, “text_string=” + text_string);
text = text_string;
Tm.TraceInformation(Tm.TraceFm, “text=” + text);

 

Advertisements
Posted in develop, windows | Tagged , , | Leave a comment

How to set the programming environment of Visual Studio

Q: I have set the programming environment of Visual Studio into C#. Now I want to change it to VC++.

A: To change the environment from C# to C++, please go to Tools menu >> Import and Export Settings >> Reset all settings.
Follow the instructions of the wizard and choose C++ as default development environment.

Posted in develop | Tagged , | Leave a comment

How to force restart the machine when you get A system shutdown is in progress.(1115)

shutdown /s /m \\hyper1vm6 /t 0
hyper1vm6: A system shutdown is in progress.(1115)

shutdown /a /m \\hyper1vm6
hyper1vm6: A system shutdown is in progress.(1115)

taskkill /s \\hyper1vm6 /U administrator /P password /im lsass.exe
>>> Causes a panic and the operating system HAS to restart

Posted in windows | Tagged , | Leave a comment

Legacy Restore INTO Behavior

It creates a new copy of the backup dbcomp. The new copy has the name specified in the INTO parameter.

For example,

tdpsqlc rest MARIADB Full /INTO=testmnt1

DPSQL trace shows the following T-SQL statement:

10/20/2017 10:09:54.096 [010124] [8996] : SqlApi.cpp (5525): Calling databaseH->ExecuteNonQuery()
wcslen(sqlWideCmdP): 265
sqlWideCmdSize : 4096
sqlWideCmdP : USE master RESTORE DATABASE [testmnt1] from VIRTUAL_DEVICE=N’TDPSQL-0000278C-0000′ WITH BLOCKSIZE=512, MAXTRANSFERSIZE=1048576, MOVE N’MARIADB’ TO N’C:\MARIADB_RESTORE_3\MARIADB.mdf’, MOVE N’MARIADB_log’ TO N’C:\MARIADB_RESTORE_3\MARIADB_log.ldf’, RECOVERY, REPLACE

Background

https://docs.microsoft.com/en-us/sql/t-sql/statements/restore-statements-transact-sql
E. Copying a database using BACKUP and RESTORE
The following example uses both the BACKUP and RESTORE statements to make a copy of the AdventureWorks2012 database. The MOVE statement causes the data and log file to be restored to the specified locations. The RESTORE FILELISTONLY statement is used to determine the number and names of the files in the database being restored. The new copy of the database is named TestDB. For more information, see RESTORE FILELISTONLY (Transact-SQL).
BACKUP DATABASE AdventureWorks2012
TO AdventureWorksBackups ;

RESTORE FILELISTONLY
FROM AdventureWorksBackups ;

RESTORE DATABASE TestDB
FROM AdventureWorksBackups
WITH MOVE ‘AdventureWorks2012_Data’ TO ‘C:\MySQLServer\testdb.mdf’,
MOVE ‘AdventureWorks2012_Log’ TO ‘C:\MySQLServer\testdb.ldf’;
GO

Posted in data protection | Tagged | Leave a comment

How to setup an Active Directory domain controller in VirtualBox

Verbatim copy from http://www.fixedbyvonnie.com/2015/04/how-to-setup-an-active-directory-domain-controller-in-virtualbox/#.WeXhhWf6Uxl

How to setup an Active Directory domain controller in VirtualBox
Posted on April 20, 2015 by vonnie — 4 Comments

Over the next three days I’m going to show you how to setup Active Directory and join a PC to your new domain but I want you to know this isn’t something you can learn by reading. You need to do it.

You need to sit in front of a real Windows Server 2012 machine. You need to join a real Windows workstation to the domain. You need to interact with the software.

But how can you realistically do this? Well there are two options; no wait – three options:

You could completely abase yourself by buying your boss’s children Christmas presents so he would be more amenable to letting you setup a lab in the office.
You could cough up a butt load of money to buy real equipment
You could setup a free virtual environment on your computer in a completely isolated network. Then you could install Windows 8.1 and Windows Server 2012 virtual machines and configure a virtual switch to connect both computers.

Are you with me on option 3? I hope so! Let me show you how simple it is to pull this off.

“Simple” and “quick” aren’t synonyms. So although it’s easy to get going it will take a few hours to download all the files and configure your virtual environment.

Let’s get started.

If our virtual Active Directory Domain controller were a big juicy burger we would need a few ingredients to make it:

VirtualBox
Windows 8.1 Pro
Windows Server 2012 R2
pFSense

Snag VirtualBox

First, download and install Virtualbox on your host machine. Keep all the defaults. The install should zip by in seconds. This is the bun for our proverbial burger.
Filch Windows 8.1 Pro

Next, we need to obtain a real Windows 8.1 Pro ISO image. You can download the Windows 8.1 Pro media directly from Microsoft. In fact, if you can actually legally download every version of Windows for free. Consider this the lettuce and tomatoes.
Grab Windows Server 2012 R2

You can get the Windows Server 2012 R2 iso directly from the Microsoft Evaluation Center. Just signup and download. This is the 1/4 pound of grass fed organic beef. Without this our Active Directory burger is nothing.
Pilfer pFSense

pFSense will be the virtual router that gives us the liberty to connect our internal VirtualBox guest machines to the internet. pFsense is our special sauce.

Completing the above four steps could take several hours because of the sheer size of the Windows ISO files. These files are gargantuan (4GBs per file) so make sure you have ample space on your hard drive before you start the download frenzy.

Once you have all the ISOs on your computer we can setup the virtual machines.
Configuring the Virtual Machines

Setting up Windows 8.1 Pro in VirtualBox is almost identical to setting up Windows 10 in VirtualBox. The only difference is that under the Network tab in your VirtualBox Settings, Adapter 1 must be set to Internal Network. The name should also match for all hosts participating in the same internal network. I recommend the default intnet.

The internal network adapter names must match on your VirtualBox hosts

To setup your virtual machines, click the prickly blueNew button in the Oracle VM VirtualBox Manager and pick your OS version and memory size. Leave the Hard drive defaults alone and click Create.

Windows Server 2012 Virtual Machine

Click Create again on the next screen to keep all the defaults for the file size and physical hard drive type.

VirtualBox setting defaults

After creating the image, select it and choose Settings from the Oracle VM Virtualbox Manager screen.

Pick the Storage tab, and under the Storage Tree you should see a CD icon. We need to browse to the ISO we downloaded earlier so that the Virtual Machine will boot to it just like a real machine would boot to a physical CD.

Adding the ISO to VirtualBox

Now you can go through the installation just like a normal install. Install Windows 8.1 Pro in the same fashion.

After you have both operating systems installed you’re ready to setup pFSense.
Making sense of pFSense in VirtualBox

Getting pfSense to work in VirtualBox is basically the same except for a few differences:

Under Settings > System > Motherboard the Base Memory should be set to 256 MB. As you can see pFsense doesn’t need a lot of memory: 256 MB is sufficient.

pFSense in VirtualBox

Next, under the Network tab under Adapter 1, make sure it’s enabled and attached to your Bridged Adapter. This will be come your WAN (internet facing) interface in pfSense.

Setting the network settings for pFsense in VirtualBox

Then boot up the virtual machine and press Enter on the boot screen

boot up pfSense

Quickly press “i” to dive into the Installer setup.

Enter the pFsense Installer

In the blue Configure Console screen, choose .

fixedbyvonnie-pfsense-setup

Go with the

Quick and easy pfSense

Go ahead and erase the Virtual Disk. There’s obviously nothing on it.

Erase the virtual disk

Choose the Standard Kernel

Use the Standard Kernel

Then once the installation finishes, eject the virtual CD and reboot.

Eject the pFsense ISO

Boot to the main screen and skip the question about setting up VLANs.

Right now, we need to assign our interfaces so press 1.

pFsense mainscreen

You’ll be asked to enter the WAN and LAN interface names. Use em0 and em1 respectively. em0 should correspond to your bridged virtualbox interface.

em0 and em1 for pfSense

Great, when this finishes press the number 2 to configure the IP subnet for the LAN.

I used 10.0.0.254 with mask 255.255.255.0 (24 bit mask).

Configuring the adapters in pFsense

There’s no need to enable DHCP or revert to HTTP so just press enter to skip passed those options.

pFsense Configured

We’re done with our pFSense setup! Leave it running and minimize the virtual machine window.
Setting IP addresses on the Windows guests

Now we’re ready to configure the static IP addresses on our Windows guest machines.

Open up the Network Connection settings in your Windows Server 2012 machine and configure the following settings for your Internet Protocol Version 4 (TCP/IPv4) item:

10.0.0.11
255.255.255.0
10.0.0.1

Windows Server 2012 settings for VirtualBox

The DNS should be 127.0.0.1 since we’re going to use the server itself as the DNS server.

On the Windows 8.1 Pro host, set the network settings as follows:

10.0.0.12
255.255.255.0
10.0.0.254

Windows 8.1 IP Settings

Also notice the DNS server is set to the IP of our Windows 2012 Server: 10.0.0.11.

Now as long as both machines have network adapters set to Internal Network with the same name, you’ll be able to communicate.

Let’s just kick off a ping to verify…

Pinging the domain controller

W00t!

Tomorrow starts your adventure setting up a Windows Server 2012 Active Directory environment.

You now have everything you need to follow along. You can do this. You will do this. I believe in you.

Posted in Uncategorized | Tagged , , | Leave a comment

Microsoft Update Catalog

You MUST ACCESS the Microsoft Update Catalog using Internet Explorer.
This is an example how to search the Monthly Quality Rollups for Windows 2012 R2.
http://www.catalog.update.microsoft.com/Search.aspx?q=2017%20Monthly%20Quality%20Rollup%20windows%202012%20r2

Posted in windows | Tagged , , | Leave a comment

Configure Windows Update

Run as Administrator

sc config wuauserv start=disabled
net stop wuauserv
Posted in tools, windows | Tagged | Leave a comment