We help IT Professionals succeed at work.

Powershell

20K

Solutions

8K

Contributors

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

Looking for help in getting input from a .csv file for copying group members from one group to another.  Both are Unified groups.

This code works for a single group to group copy:
$List = Get-UnifiedGroupLinks -Identity "Group1" -LinkType Members | Select-Object -expandproperty name
Add-UnifiedGroupLinks -Identity "Group2" -LinkType Members -Links $List

Open in new window


This is what I setup in for foreach:

$Groups = Import-Csv -Path .\GroupInput.csv
foreach ($Group in $Groups) {
    $List = Get-UnifiedGroupLinks -Identity $_.SourceGroup -LinkType Members | Select-Object -expandproperty name
    Add-UnifiedGroupLinks -Identity $_.TargetGroup -LinkType Members -Links $List
}

Open in new window


Error I'm getting is:
Cannot bind argument to parameter 'Identity' because it is null.
    + CategoryInfo          : InvalidData: (:) [Get-UnifiedGroupLinks], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Get-UnifiedGroupLinks
    + PSComputerName        : outlook.office365.com

GroupInput.csv:
SourceGroup,TargetGroup
Group1,Group2
0
I have mailbox servers ( exchange 2016) in DAG , there are 2 scripts i need to run:

location of 1st one is under C drive - temp- start-xxx1.ps1 script

the 2nd script is under: E-program files-microsoft-exchangeserver-v15-scripts- xxx2.ps1 script

when i open exchange server, need to open Exchange management shell or powershell script?

can you let me know how to run: once i upon either of these, should i point the prompt to current directory?
0
Hello,

I have the following powershell script that can disable users by employeeID

Import-Module ActiveDirectory
Import-Csv "C:\Users.csv" | ForEach-Object {
$employeeID = $_."EmployeeID"
Get-ADUser -LDAPFilter "(employeeID=$employeeID)"  | Disable-ADAccount
Write-Host "User $employeeID disabled"
}

Open in new window


but I'm looking to have this script output the into .csv or .txt that the employeeID was disabled or the employeeID wasn't found

Thank you,
0
Powershell- Add AD Group to AD User by Distinguished Name

I have a list of 30+ AD Groups that i want add back to an AD User Object. Whats the best powershell script that will allow me to add these groups back to the user if i have a CSV file that has a list of all the AD Groups ind CN format with no header? I can add a header if need be.
1CN-names-for-AD-groups.png
0
I am trying to add to my existing offboarding script the ability to set a mailbox to shared upon offboarding a user.

I tried using:

Set-Mailbox -EmailAddress Iperez@contoso.com -Type Shared

Open in new window


But it keeps giving me this error.

Cannot display the prompt for "Identity" because type "Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter" cannot be
loaded.

I have already connected to Exchange Online and can run the Set-Mailbox command. Am i missing some module? Or do you know what i am doing wrong?
0
Powershell Experts, question. I run this script to remove all AD Groups from users that are being off-boarded. Works great, the only  thing is that when it loops through, it asks me after each one it loops though. Even when i click yes to all it still goes on to the next group and asks permission again to remove. Am i missing a parameter or what am i doing wrong? I want it to loop through, remove all AD groups for the AD user object and not ask me if its OK to remove.


Get-ADUser $disableduser -Properties MemberOf | Select -Expand MemberOf | %{Remove-ADGroupMember $_ -member $disableduser}

Open in new window


Remove-All-AD-Memberships-yes-to-all.png
0
Can someone help me modify this script so the output is for each group in its own CSV as the group name and date ?



code]Import-Module -Name Activedirectory
[array]$Members=$null
Get-Content C:\Temp\groups.txt | % {
$Group = Get-ADGroup $_  -ErrorAction SilentlyContinue
If ($Group){
$members += Get-ADGroup $Group.Name -Properties Members |
            Select-Object -ExpandProperty Members |
            Get-ADObject -properties Samaccountname |
            ?{$_.ObjectClass -eq "user"}  | Get-aduser -Properties Samaccountname,name|
      Select-Object -Property @{L='GroupName'
e={$Group.Name}},Samaccountname,name
 }
}
$Members | Select-Object -Property * |Export-Csv -Path "C:\Temp\GroupName_$((Get-Date -Format MM-dd-yyyy-hh-mm)).csv" -NoTypeInformation[/code]
0
Hello,

Please, I need a script for found some photos ".JPG" from  naming list file ( NamePhoto.txt or NamePhoto.csv)  in a folder and some sub Folders and after copy it in another folder.

In Fact ,

 NamePhoto.txt File  contain :

Photo1.JPG
Photo2.JPG
.
Photo6.JPG
PhotoKK.JPG

Best regards,
0
Hi,


How to check in Windows IIS website which certificate it uses?
0
Hi,


Is there a PowerShell or tool that can list all certificates used in Windows web site?

I want to see who will expire.
0
I ran this script. It contacts AD but does not respond with results. It just waits for another entry.

C:\Save> Get-ADUser -Filter {mail -like 'emailaddress'} -Properties * | fl workid
C:\Save> _

It looks like above
0
Hello,

I search to format result on the below command :

$NetIPAddresses = (Get-NetIPAddress | where {$_.InterfaceAlias -match "10" -and $_.AddressFamily -eq "IPv4"}
) |  format-table IPAddress, InterfaceAlias -auto

echo $NetIPAddresses

IPAddress     InterfaceAlias
---------     --------------
112.164.60.9  HT-10
10.111.22.59  DT-10
10.111.22.58  DT-10
10.111.22.56  DT-10
10.111.160.90 AD-10

I want to group the result in three columns :

DT-10                                                            HT-10                           AD-10
10.111.22.59;10.111.22.58;10.111.22.56      112.164.60.9          10.111.160.90

Thank you

Regards
0
Would it be possible to have a powershell Script to  restart Mulitple Vm's from jump host  and get their uptime after reboot.

Thanks in advance!
1
Would it be possible to  have a script to restart   a service from jump host to multiple servers and place it automatic.

Service name would be besclient.

Thanks in advance!
0
1) we have DAG 1 AND DAG 2 in different datacenter A ( DAG1) and datacenter B( DAG2)


there are 2 mailbox servers in each DAG

MX01 MBX02 IN DAG 01  AND MBX3 AND MBX4 IN DAG02, There are other 50 mailbox databses  but all are having same copies like one mentioned.

so just giving an example of DB01,

DB01 which is on MBX01 having AP 1 AND DB01 having AP 2 on MBX02
DB01 which is also on MBX03  having AP 3
DB01 having active preference of 4  on MBX 04( lagged copy)

I wanted to know how reseeding will take place automatically

if something happens to DB01 on mbx1 , will db01 on mbx02 take over on its own provided it is in healthy state?

Also in what situation DB01 with AP 3 and AP 4 come into picture


wont we use powershell like movedatabase command? in what situation we will use the command and when seeding auto will take place?

bit confused
0
Hi,


Is it possible to export all Teams users from O365?

I think we need to do it by PowerShell right?
0
Dear all,

I wrote that code to get from a list a list of computer in a OU their vendor name, model name and serial value.

When running the code $vendor, $name and $$identifyingNumber values are null and I am getting this message "Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)"

The computer is not offline
If I run tthe script like this $vendor = (Get-WMIObject  -ComputerName MAD001 Win32_ComputerSystemProduct).name  it works

Could you help?

Thks

$computers = Get-ADComputer -Filter * -SearchBase "OU=Madrid,OU=Spain,OU=Europe,OU=Root,DC=contoso,DC=com" -Properties * | Select-Object DNSHostName  
foreach ($computer in $computers) {
    $vendor = (Get-WMIObject Win32_ComputerSystemProduct -ComputerName $computer).Vendor
    $name = (Get-WMIObject Win32_ComputerSystemProduct -ComputerName $computer ).Name
    $identifyingNumber = (Get-WMIObject Win32_ComputerSystemProduct -ComputerName $computer ).IdentifyingNumber
}

Open in new window

1
I have following JSON file and i need update the displayName to contain either QA or Production :

{
    "analytics": [
      {
        "kind": "Scheduled",
        "displayName": "RO-0024-DEV GPO Scheduled Task",
        "description": "test",
        "severity": "Low",
        "enabled": true,
        "query":"SecurityEvent | where EventID == \"5145\"  | where AccountType == \"User\"",
        "queryFrequency": "5H",
        "queryPeriod": "6H",
        "triggerOperator": "GreaterThan",
        "triggerThreshold": 5,
        "suppressionDuration": "6H",
        "suppressionEnabled": false,
        "tactics": [
          "Persistence",
          "LateralMovement",
          "Collection"
        ],
        "PlayBookName": "Test447"

      }
    ]  
}

Open in new window


i am running a powershell script via Azure Devops build agent and depending on the Tennant, i want to change the DisplayName that contains Dev to QA or Prod.

i have tried the following for testing however it fails:

$rules = Get-Content -Raw -Path .\TestJson.json | ConvertFrom-Json
$rules.analytics.displayname = "test"

Open in new window


i get the following error:

The property 'displayname' cannot be found on this object. Verify that the property exists and can be set.
At line:1 char:1
+ $rules.analytics.displayname = "test"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

Open in new window


Thank you in advance.

Regards,
Kelly
0
Sam Jabobs just helped me with this the other day ..

Anyone know how I could add a link to file within each group ? so the idea is I want to point to a file where the group owner can click on and get
a CSV of all the group members.


Import-Module UniversalDashboard

$Dashboard = New-UDDashboard -Title "Title" -Content {
    New-UDLayout -Columns 3 -Content {
        New-UDCard -Title "AD Group1" -Text "$((get-adgroupmember ‘AD Group1’).Count) members"
        New-UDCard -Title "AD Group2" -Text "$((get-adgroupmember ‘AD Group2’).Count) members"
        New-UDCard -Title "AD Group3" -Text "$((get-adgroupmember ‘AD Group3’).Count) members"
        New-UDCard -Title "AD Group4" -Text "$((get-adgroupmember ‘AD Group4’).Count) members"
        New-UDCard -Title "AD Group5" -Text "$((get-adgroupmember ‘AD Group5’).Count) members"
        New-UDCard -Title "AD Group6" -Text "$((get-adgroupmember ‘AD Group6’).Count) members"
        New-UDCard -Title "AD Group7" -Text "$((get-adgroupmember ‘AD Group7’).Count) members"
    }
}

Start-UDDashboard -Dashboard $Dashboard -Port 10005

Open in new window

0
We have a terminal server that has been accessed by a few users. I would like to know which user's process takes more CPU.  Sysadmin out there must be using a simple PS script to gather the top 10 CPU process consumed by end-users, I will appreciate if you could share with me.  I use below command at present, but can not e-mail to group of users.
Get-Process -IncludeUserName | Sort-Object CPU -desc | Select -first 5| Select ProcessName,ID,CPU,UserName,Description | Format-Table -AutoSize
0
I need a powershell script to export the serial numbers of all the machines from AD
0
Hi EE ...anyone know how to use Universal Dashboard ?

I want to create a simple dash that will show the AD group name and total members.
Would the option below the best way or other options you suggest ?

Also , how do I enter the Poweshell string ? (get-adgroupmember ‘GroupName’).count


Import-Module UniversalDashboard

$Dashboard = New-UDDashboard -Title "Title" -Content {
    New-UDLayout -Columns 3 -Content {
        New-UDCard -Title "AD Group1"
        New-UDCard -Title "AD Group2"
        New-UDCard -Title "AD Group3"
        New-UDCard -Title "AD Group4"
        New-UDCard -Title "AD Group5"
        New-UDCard -Title "AD Group6"
        New-UDCard -Title "AD Group7"
    }
}

Start-UDDashboard -Dashboard $Dashboard -Port 10005

Open in new window

0
How do I add a conditional for the ipAddress.

if IpAddress -eq "-" do not count it or do not add it into the csv. See attachment

Get-WinEvent -FilterHashTable @{LogName='Security'; ProviderName='Microsoft-Windows-Security-Auditing';id=4624; StartTime="3/28/20"; EndTime="3/30/20"} | ForEach-Object {
	$xml = [xml]$_.ToXml().Replace('xmlns', 'dummy')
	$_ | Select-Object -Property TimeCreated, MachineName,`
	 @{n='TargetUserName';	e={"$($xml.SelectSingleNode("Event/EventData/Data[@Name='TargetDomainName']").InnerText)\$($xml.SelectSingleNode("Event/EventData/Data[@Name='TargetUserName']").InnerText)"}},
	 @{n='LogonType'; e={$xml.SelectSingleNode("Event/EventData/Data[@Name='LogonType']").InnerText}},
	 @{n='WorkstationName'; e={$xml.SelectSingleNode("Event/EventData/Data[@Name='WorkstationName']").InnerText}},
	 @{n='IpAddress'; e={$xml.SelectSingleNode("Event/EventData/Data[@Name='IpAddress']").InnerText}},
	 @{n='IpPort'; e={$xml.SelectSingleNode("Event/EventData/Data[@Name='IpPort']").InnerText}}
	} | Export-Csv D:\ger\SCRIPTS\EventID_4624.csv -nti

Open in new window

EventID_4624---Copy.csv
0
I am looking to develop a powershell script that can process off-boarding for my team. We have a Hybrid On-Prem/Office 365 Environment.  I would like it to do the following:

For the On-Prem side:
  • Disable the AD Object
  • Put Date and Time Object was disabled in the Description Field in the AD Object
  • Remove all AD Memberships (Except Domain User) ***If possible create a log of that users memberships somewhere so we can revert back if need be.
  • Move Object to the _Disabled OU

For the Office 365 side:
  1. Block Sign-in
  2. Force out any logged in Session (optional)
  3. Remove All O365 Licenses
  4. Convert Mailbox to Shared Mailbox

Thank you very much on your assistance with this. We need this urgently as we have massive layoffs in our company. Thank you and Stay Safe.

Also please provide the Powershell Modules needed to complete these commands. Or do i need to run them from a domain controller or the exchange server. Thanks.
0
Hello I have enable audit policies in our domain and would like to read the Message content of the security log and grab the New Logon and Network Information fields

I am executing the following script

Get-WinEvent -Computername DomainController01 -FilterHastTable @{logname='security';ProviderName='Microsoft-Windows-Security-Auditing';id=4624;StartTime="3/27/20";EndTime=3/28/20"}

or by using Get-EventLog

Open in new window


See screenshot, how do i grab the individual properties or some properties from the Message section ?

Thanks for your help,
Screen-Shot-2020-03-27-at-5.54.44-PM.png
0

Powershell

20K

Solutions

8K

Contributors

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.