Powershell: Difference between revisions

From Piszczynski
piszczynski>Aleks
piszczynski>Aleks
Line 39: Line 39:
<pre>
<pre>
add-mppreference -exclusionpath "<full filepath - eg C:\users\downloads>"
add-mppreference -exclusionpath "<full filepath - eg C:\users\downloads>"
</pre>
Get members of ad group:
<pre>
get-adgroupmember -identity "<name of adgroup>" | select-object name
</pre>
</pre>

Revision as of 13:53, 27 November 2019

Handy Powershell

Restart computer remotely

restart-computer -Computername [hostname] -Credential [domain\username] -force

Connect to remote powershell session:

$cred=Get-Credential
$sess = New-PSSession -Credential $cred -ComputerName <remotemachinename>
Enter-PSSession $sess
<Run commands in remote session>
Exit-PSSession
Remove-PSSession $sess


Output Command History to text file:

Get-History | ForEach-Object { $_.CommandLine } > $env.USERPROFILE\testoutput.txt


Export details of users in a specific OU:

$OUpath = '<place OU path here distinguished name of ou in attribute editor>'
$ExportPath = '<place where to put output>'
Get-ADUser -Filter * -SearchBase $OUpath | Select-object DistinguishedName,Name,UserPrincipalName,sAMAccountName | Export-Csv -NoType $ExportPath

Script to ping IP address and log time and status of ping:

https://github.com/AleksPish/NetworkPingTest/blob/master/NetworkDownTest.ps1


Add Exclusions to security check from downloaded programs:

add-mppreference -exclusionpath "<full filepath - eg C:\users\downloads>"

Get members of ad group:

get-adgroupmember -identity "<name of adgroup>" | select-object name