Found 975 Articles for Software & Coding

How to check if the computer is connected to a domain using PowerShell?

Chirag Nagrekar
Updated on 28-Dec-2020 07:03:41

16K+ Views

To check if a computer is connected to any domain we can use multiple methods. In this article, we can use two methods. One using the System Information of the computer and the second using the DirectoryServices .Net Class.First method using System Information and filter out a string called “Domain” which shows us if the computer is in the domain or the workgroup.systeminfo | findstr "Domain"OutputIf the computer is in the workgroup, It will show the workgroup name. For example, In the second method, we will use the directory service .Net class method name GetComputerDomain(). If the server is not connected to the ... Read More

How to Remove the computer from the AD domain using PowerShell?

Chirag Nagrekar
Updated on 28-Dec-2020 07:01:58

3K+ Views

To remove the computer from the domain we need to use the Remove-Computer command.Remove-Computer -ComputerName Test1-win2k16 `                 -UnjoinDomainCredential Labdomain\Administrator `                 -WorkgroupName WG -Restart -Force -PassThruIn the above example, the Computer name Test1-Win2k16 is going to remove from the domain with the domain credentials and it will be joined to WorkGroup named WG. If the system doesn’t restart due to any reason, you need to reboot the system manually.Here the computer name is the String[]. So you can provide multiple computers to remove from the domain. For example, Remove-Computer -ComputerName Test1-win2k16, ... Read More

How to Join Computer to the AD domain using PowerShell?

Chirag Nagrekar
Updated on 28-Dec-2020 07:00:56

2K+ Views

To join any workgroup computer in the domain using PowerShell, we can use the Add-Computer command but before that, there are a few Windows prerequisite that DNS must be configured properly and the domain controller should be reachable and others should suffice then only PowerShell can use the command to join computer into a domain.Add-Computer -ComputerName Test1-win2k16 `              -DomainCredential Labdomain\Administrator `              -DomainName Labdomain.local -Restart -Force -PassThruOnce you run the above command, it will ask you for the credential for the user you entered. In the above example, we are joining a ... Read More

How to create a Scheduled task with a task scheduler using PowerShell?

Chirag Nagrekar
Updated on 28-Dec-2020 06:59:47

751 Views

To create a task using GUI (As shown below image) we need a few settings like the Name of the task, trigger, and Action.Similarly, to create a new task in task scheduler using PowerShell comprises of several settings.Name of the taskThe time when the task to triggerAction − Do we need to schedule a program for execution or send an email on some event trigger.Description − This is optional. You can add a description of the task.Registering task − Final step is to register the created task.Above all actions use different cmdlets but they are part of a ScheduledTasks module. To ... Read More

How to start the specific task of the task scheduler using PowerShell?

Chirag Nagrekar
Updated on 28-Dec-2020 06:56:23

1K+ Views

To start the specific task of the task scheduler using PowerShell, we need to use the Start-ScheduledTask command.When we run the above command, we need to provide the task name.For example, Start-ScheduledTask -TaskName 'FirstTask'When you check the above task status, ExampleGet-ScheduledTask -TaskName 'FirstTask'Output:TaskPath TaskName  State -------- --------  ----- \        FirstTask RunningTo start the task on the remote computer, we first need to connect to the CIMSession of the remote computer and we can use the below command.$sess = New-CimSession -ComputerName Test1-Win2k12 Get-ScheduledTask -CimSession $sess -TaskName 'FirstTask' | Start-ScheduledTaskWe can also start the task directly with the command, Start-ScheduledTask using the CIMSession.Start-ScheduledTask -TaskName 'FirstTask' -CimSession $sessRead More

How to retrieve tasks in Task scheduler using PowerShell?

Chirag Nagrekar
Updated on 28-Dec-2020 06:55:09

17K+ Views

To retrieve the existing tasks in the task scheduler using PowerShell, we can use the PowerShell command Get-ScheduledTask. We can use the Task Scheduler GUI to retrieve the scheduled tasks. To retrieve using PowerShell, use the Get-ScheduledTask command.When we use the above command, it retrieves all the tasks from the different paths/folders as well including the root path. To retrieve tasks created at the root path we need to filter the task path, Get-ScheduledTask | where{$_.TaskPath -eq "\"}If we need to retrieve the specific task then we need to filter the task name, TaskPath TaskName                 ... Read More

How to install PowerShell Module?

Chirag Nagrekar
Updated on 18-Dec-2020 12:28:03

931 Views

There are two methods to install PowerShell modules. Online and Offline.Online MethodThis method is just like downloading the online package through Yum in the Unix system.We first need to search the package available on the internet using the Find-Module command. You can use the wildcard character if you don’t know the full module name. All the packages are downloaded from PowerShell Gallery (https://www.powershellgallery.com/).For example, if you want a Vmware PowerCLI module and you don’t know the full module name then just use the part of the name inside the Wildcard character(*).Find-Module *vmware* | Select Name, Version, RepositoryName       ... Read More

Explain JSON format in PowerShell.

Chirag Nagrekar
Updated on 18-Dec-2020 09:07:54

1K+ Views

Javascript Object Notation (JSON) is the light-weight structure which is easy to read by human and simple to parse and understand by machine. Although the name contains the Javascript, both Javascript and JSON are different and they have syntax and structure is different as well.You can get more information about JSONhttps://www.json.org/json-en.htmlIts basic structure is Key-Value pair but both are separated by a colon ‘:’. It has an almost similar structure as a hashtable, PSCustomObjecct. For example, {    "Name": "Albert Don" }If you have multiple Key-Value pairs, you can separate them with a comma. For example, {    "Name": "Albert ... Read More

How to write comment based Help in PowerShell?

Chirag Nagrekar
Updated on 18-Dec-2020 09:03:39

548 Views

In PowerShell when you create a complex script or function then it should be essential to create help for the end-users to easily understand your script functionality. Writing comment-based help or XML-based help, at the end is similar to Get-Help syntax for cmdlets or function which is the online version of help.For Example, Just open the PowerShell console and run the command below.Get-Help Get-WmiObjectAnd you can see the various help sections in the output like NAME, SYNOPSIS, SYNTAX, DESCRIPTION, PARAMETER, LINK. These are called Keywords. We can include all of them in the script of function manually to get the ... Read More

How to remove connected remote desktop user sessions using PowerShell?

Chirag Nagrekar
Updated on 15-Dec-2020 08:00:28

4K+ Views

We can remove connected RDP sessions using PowerShell and for that, we can use the cmd command “reset session” in PowerShell.  Let’s see the supported parameters for it.ExamplePS C:\> reset session /? Reset the session subsytem hardware and software to known initial values. RESET SESSION {sessionname | sessionid} [/SERVER:servername] [/V] sessionname         Identifies the session with name sessionname. sessionid           Identifies the session with ID sessionid. /SERVER:servername  The server containing the session (default is current). /V                  Display additional information.We can provide here session ... Read More

Advertisements