Skip to main content

Posts

Showing posts with the label Elevated CMD

PowerShell restart remote server with confirmation

Restart a remote PC or server and ask user to confirm reboot before proceeding.

Here’s the code:
$server_q="D-Box-007"
$response_confirmation=[Microsoft.VisualBasic.Interaction]::MsgBox("Restart this server: "+$server_q,'YesNo',"Confirm to reboot?")

switch ( $response_confirmation )
{
Yes{ Restart-Computer-ComputerName$server_q} No{ Write-Host"Restart Cancelled"} }
Code above will prompt the user with “Yes” or “No”, yes will send the restart or reboot command to the remote server or computer, and no will cancel or exit the execution.

PowerShell code above also demonstrate how to use a switch case statement and use the response to perform an action, in regar

PowerShell check access or folder permissions

In an Active Directory domain, one of the common issues is folder permissions. Of course, permission must be restricted as much as possible. In order, confidential data or things that only a group of people will know, is not made available to everyone.

Employee salaries on a network share made available to everyone, will cause some employees to be disheartened. Such data, the access or folder permission should be checked properly.
One way to check a folder permission is to assume or login as a certain user that is not supposed to have access to such data and checked whether the data can be viewed or not.
Aside from restricting permissions for confidential data; data supposed to be accessed by everyone but some user’s complaint that they are unable to access then this will also cause some problem and may end up not being productive for the users.
One way to check is to go to the user’s workstation and verify whether the user is unable to access. This kind of issue is not hard to solve…

List lnk or shortcut files in Windows with PowerShell

Link files or files with .lnk extension is also called shortcut files in Windows and is quite handy when accessing files, documents, or application programs when it is placed on a location where you needed it most. So you don’t have to browse all the way to the location of the file, instead just click the shortcut and the file or program will be opened.
As time goes by, shortcut files or .lnk files can easily be forgotten or sometimes it will just clutter on the desktop or in any sub folders in the computer.
How to list or get all shortcut files in Windows? Or aka how to get all .lnk files on the system?
PowerShell can easily list all the lnk or shortcut files, and determine when was the last time the shortcut link was used or modified.
Here’s the code using PowerShell on how to check all the ‘.lnk’ files on the system, Windows shortcuts has an extension of “.lnk” and its actual properties points to the location or path of the file.
PowerShell one-liner code to get all lnk files.
Get-CimIns…

Get PowerShell version on remote computers

PowerShell version on remote computers must be installed with the latest version if possible. It would make life easier.
New version comes with of course, new features and more fun. And if all servers or PCs has the same PowerShell version, then you need to create one version of PowerShell that works for all computers or servers.
But how to get PS version on remote computers?
To get the version locally, it’s quite straight forward:
Method 1: ($Psversiontable).PSVersion
Method 2:
(get-host).Version
To get version on remote computers, just add a few lines from the command above.

#--------- save as Get_PS_Version.ps1 or any file name $xversion= (get-host).Version $xversion_output="PowerShell Version: "+$xversion
$pc_name=$env:computername $pc_output="Computer Name: "+$pc_name

$xversion_output+"`n">>c:\scripts\output\$pc_name.txt $pc_output>>c:\scripts\output\$pc_name

WMIC command get CPU Load Percentage

Getting CPU load percentage is quite helpful in determining whether the server or computer is on a heavy performance, this would also indicate whether there is a need to increase the memory or add another CPU to the machine.

Of course, when the CPU has a lot of load, performance will be impacted directly. Which basically means that the machine will not be working perfectly.
Checking the CPU load will also help to troubleshoot, if the services on the machine or server is experiencing slow performance.
Here’s the wmic command line which check the CPU Load Percentage.
wmic cpu list status

Sample output: AvailabilityCpuStatusCurrentVoltageDeviceIDErrorCleared 319CPU0
ErrorDescriptionLastErrorCodeLoadPercentageStatusStatusInfo 15OK3

The command can be used to monitor remote servers or computers to check the load percentage and just save the output to a text file for review or monitoring purposes.

Cheers..Till next time. Hope it helps. 😊

================================ Free Android Apps:
Clic…

Backup SystemState Windows Server to a network share

Backup SystemState of a server to a network share is preferable rather than backing up to another partition within the local server.
Backing up to a network share is quite a good practice, so just in case anything goes wrong to the local server the system state is still safe since the backup is on a network share.
So, it’s like the old adage. Don’t put eggs in one basket. If all eggs are in one basket and if the basket is broken then everything is gone. Same logic goes to a server backup, protecting a server with a backup but then putting the backup to a local partition does not really protect the server from hard disk failure.
How to backup system state using wbadmin to a network share?
It’s quite straight forward but command prompt must be run at an elevated mode, and a network share that is accessible by the server and has enough space to hold the backup.
Command below will work with Windows 2008 and Windows 2012; newer version of Windows may still work but not tested.
wbadmin star…

Copy or migrate shared folders to another server

Migrating or copying files to another server and retaining the permissions is a common task when migrating a file server.
If all permissions are successfully retained it will make the migration seamless and nobody will ever notice that a migration has taken place.
If there are shared folders and with different permissions, re-sharing the folder by scratch is just time consuming and giving access denied to users will be inevitable.
But how to copy files and folders, like it was exactly done on the old server?
In Windows environment, just 3 steps are needed. 3 steps sound easy and quick.
Steps below will work for NTFS permissions and folder access rights solely depends on it.
a.Copy the files to the new server and retaining its permissions while files and folders are being copied b.Export the shares registry (old server) c.Import the shares registry (new server)
The link below from Microsoft website shows how xcopy can copy folder and retain the permissions.
https://support.microsoft.com/…