When to choose development of a PowerShell Module over PowerShell Script

To understand what modules can do for you, read this: https://learn.microsoft.com/en-us/powershell/scripting/developer/module/writing-a-windows-powershell-module?view=powershell-7.1 In a nutshell, Windows PowerShell modules allow you to partition, organize, and abstract your Windows PowerShell code into self-contained, reusable units. With these reusable units, administrators, script developers, and cmdlet developers can easily share their modules directly with others. Script developers can also repackage … Read more

How can I verify that a string is a valid IPv4 or IPv6 address in batch?

Check for valid IPv4: @if (@X)==(@Y) @end /* JScript comment @echo off cscript //E:JScript //nologo “%~f0” %* exit /b %errorlevel% @if (@X)==(@Y) @end JScript comment */ WScript.Quit(ValidateIPaddress(WScript.Arguments.Item(0))); function ValidateIPaddress(ipaddress) { return !(/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress)) } For valid IPv6 address: @if (@X)==(@Y) @end /* JScript comment @echo off cscript //E:JScript //nologo “%~f0” %* exit /b %errorlevel% @if (@X)==(@Y) … Read more

How to capture the Return Value of a ScriptBlock invoked with Powershell’s Invoke-Command

$remotesession = new-pssession -computername localhost invoke-command -ScriptBlock { cmd /c exit 2} -Session $remotesession $remotelastexitcode = invoke-command -ScriptBlock { $lastexitcode} -Session $remotesession $remotelastexitcode # will return 2 in this example Create a new session using new-pssession Invoke your scripblock in this session Fetch the lastexitcode from this session

PSEXEC, access denied errors

Hi i am placing here a summary from many sources online for various solutions to “access is denied” : most information can be found here (including requirements needed) – sysinternal help as someone mentioned add this reg key, and then restart the computer : reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f Read … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)