Quantcast
Channel: PowerShell
Viewing all 15370 articles
Browse latest View live

Help with a script that pulls list of AD users and returns manager info

$
0
0

Hi All,

I am struggling with building a script to pull a list of AD users from a .csv and exports a list with their username, name, and managers email. I can pull this information using the below line but I can't seem to get it to pull from users listed in my .csv. Any help would be great! Thank you!

Get-ADUser -filter * -properties * | select Displayname, EmailAddress, @{Name="ManagerEmail";Expression={(get-aduser -property emailaddress $_.manager).emailaddress}}


O365 license by attribute name

$
0
0

I need to export O365 license based on a specific attribute value, like extensionAttribute1 value=AAA in AD. Can this be done. 

here is part of the script, how would I remove the " Name -eq '$Site'" and add  extensionAttribute1 value=AAA ?
$Base = Get-ADOrganizationalUnit -Filter "Name -eq '$Site'" -server $Server | select DistinguishedName
$Searchbase = $Base.distinguishedname

    if ($Searchbase){
        $Users += Get-ADUser -Filter * -Properties userprincipalname -searchbase $Searchbase -server $Server | select userprincipalname
    }

}

need script to Update the Users info from CSV

$
0
0

Hello All,

I have the CSV file mixed enable and disable users with their information together, it is attached here and the command that I want to share it with you below.
I need to update the user's information just to enable users (NOT for disabled users) and the thing is, I need to use Manager (FirstName LastName) to update their managers(NOT USERNAME). is there command -searchbase to search the Firstname and Lastname of managers and then get the username of them to update the user's manager???
This Command is not working and I just wrote for myself as I am new with Powershell.Manager bolded in below and needs search on AD and get the username from manager attributes.
#############CSV##############
UserName,GivenName,SN,DisplayName,PhoneNumber,Email,Description,City,Country,Office,Title,Company,Department,Manager,employeeID,Mobile,Fax
...

error using Install-WindowsFeature

$
0
0

Hi all,

need help with the following error and to be honest it is making me feel stupid as i cant find an answer and it shouldn't be this difficult.

Scenario : Win 2016 server - IIS, .Net 4.6 and many other roles and features enabled and .xml exported during the install of the roles and features. now i need to import the roles and features to another Win 2016 server using the Install-WindowsFeature in PowerShell but it gives me the following error when trying to import the .xml on another server:

----- I am running PS as Admin with Admin rights to the server, there is no other features.xml or any other .xml at the filepath

------PS command and error below-----

PS C:\Windows\system32 Install-WindowsFeature -ConfigurationFilePath "E:\features.xml"

Install-WindowsFeature : An unsupported number of files was provided. There should be only...

Restart hanging PowerShell script

$
0
0

I've written a program that has to run quite a few PowerShell scripts. The problem is that these scripts occasionally just hang and do nothing. This causes several issues, firstly it means the program just sits in limbo waiting forever but the main issue is that I have data from different sources that links to these scripts.

For instance lets say I have a contact within my database that also has a contact within office 365. The script to delete the database contact will run fine but very occasionally the powershell script will not. Meaning the contact is no longer listed in the system but is in fact still there within office 365.
Is there a way to detect whether a script is hanging and if so, restart that script?
Here's an example PS script that I'm using:
Powershell
import-module.\VIS-AD-Functions.ps1$Data=Get-Content-Raw".\...

need help with bulk folder creation, hidden shares, add security groups , ntfs

$
0
0

i got a text file with a list of 600 Hidden shares that needs to be created on a local windows 2019 servers connected to a domain the shares needs to be created under this location d:\shares each share folder mostly two Global security groups in AD, saysuppose the share name is RD-BOM-Confidential, the security groups are RD-BOM-Confidential-Modify( Modify access) and RD-BOM-Confidential-ReadOnly (read only access) while AC-NYK-Sales has only one security groups AC-NYK-Sales-Modify( Modify access) the security groups are already created in FIM

what i need is a script to create the following

1) created all the 600 folders under shares 2) share the folders hidden ( a must) 3) share level should have local administratars group full access, backup full access, *-modify change access -Readonly only read access 4) security Tab, local...

I want to get the Windows Version from computers in an OU using PowerShell.

$
0
0

I don't want the build number.  The code below will only show OS build number, but I would like to have it be just the version along with the computer name next to it (ex. Computer1 - 1709,Computer2 - 1803.)

Will be using this for building a report for Windows Updates and which machines to target.

Text
[System.Environment]::OSVersion.Version

find out which server is running iis

$
0
0

righty ho people... apologies for the question but being on coffee detox (dont ask - just know needs to be no more coffee for 2 weeks) - brain is not functioning right now...

Got a old client who now needs to have a certificate added for their main website. turns out someone switched off the main server running iis and decommissioned it. thing is, no one has any idea from their third party it support which server is running or is meant to be running iis for the cert to be added. 

question...is there a way to scan all the servers for which one is running iis so i know which server to add the cert too? or shall i say replace the old cert.

i am in two minds to just add it to a random server and see what happens haha


Import-CSV With Line Breaks

$
0
0

Hi All,

I'm trying to import a CSV and get the last column name however there is an issue where the export (from SQL) Contains line breaks.

Export from SQL:

Powershell
Invoke-SQLcmd-ServerInstance$dataSource-query$SQLQuery-U$user-P$pwd-Database$database|export-csv-path$DailySummaryCSV-notypeinformation

Output:

Text
"Depot","Member","13/11/2019 Wed","14/11/2019 Thu","15/11/2019 Fri","16/11/2019 Sat","17/11/2019 Sun","18/11/2019 Mon","19/11/2019 Tue","20/11/2019 Wed","21/11/2019 Thu","22/11/2019 Fri","23/11/2019 Sat","24/11/2019 Sun","25/11/2019 Mon","26/11/2019 Tue","27/11/2019 Wed" "1","Member1 ","10","16","2","0","0","3","59","0","0","1","0","0","0","0","0" "2","Member2 ","4702","4650","4419","1528","150","5553","4962","4618","4641","4069","1467","127","5095","4803","4212" "4","Member3...

Can not convert System.String error powershell.

$
0
0

It works with one printer but it does not work with multiple printers. I am getting System.String error:

Powershell
$OldServerName="oldservername"$NewServerName="newservername"#Get existing network printers$CurrentPrinters=Get-WmiObjectWin32_Printer|Where-Object{($_.Network-eq"true")-and($_.SystemName-eq"\\"+$OldServerName)}#Map the printers from a new server.if($CurrentPrinters|Select-Object-ExpandPropertyName|ForEach-Object{$newprintername=$CurrentPrinters.Name-Replace($OldServerName,$NewServerName)Add-Printer-ConnectionName$newprintername}){#Remove existing network printers$CurrentPrinter|ForEach-Object{$_.delete()}}

Command substitution question.

$
0
0

Can anyone provide an explanation for this, please?

Text
PS C:\Users\user\empty Compare-Object ( write-output "hello" ) ( Get-FileHash .\2\test02 ) InputObject SideIndicator ----------- ------------- @{Algorithm=SHA256; Hash=4E388AB32B10DC8DBC7E28144F552830ADC74787C1E2C0824032078A79F227FB; Path=C:\Users\user\empty\2\test02} = hello <= PS C:\Users\user\empty> Compare-Object ( Get-FileHash .\1\test01 ) ( Write-Output "hello" ) InputObject SideIndicator ----------- ------------- hello = @{Algorithm=SHA256; Hash=09AABCD859E4A72F92230E07E6FA14A1848AF2F98D4D0E85F18EA4A697115621; Path=C:\Users\user\empty\1\test01} <= PS C:\Users\user\empty> Compare-Object ( Get-FileHash .\1\test01 ) ( Get-FileHash .\2\test02 ) PS C:\Users\user\empty 

Powershell - Import-CSV concatenated columns, where-object

$
0
0

I concatenated 3 columns of CSV file, and need to filter based on those 3 values.

I managed to concatenate these 3 columns but no idea how to filter results based on it, below returns nothing:

Import-Csv "C:\1.csv" | Select-Object @{n=’ResourceName’;e={$_.FIRST_NAME + "," + $_.LAST_NAME + "," + $_.ADDRESS} `
| Where-Object {$_.FIRST_NAME -like "Petar" -and $_.LAST_NAME -like "Petrovic" -and $_.ADDRESS -like "Prvomajska 1"}

Powershell
Import-Csv"C:\1.csv"|Select-Object@{n=ResourceName;e={$_.FIRST_NAME+","+$_.LAST_NAME+","+$_.ADDRESS}`|Where-Object{$_.FIRST_NAME-like"Petar"-and$_.LAST_NAME-like"Petrovic"-and$_.ADDRESS-like"Prvomajska 1"}

Experimental Featrures in PowerShell 7

$
0
0

As many of you may know, I'm excited about PowerShell 7 and the wealth of IT Pro goodness it brings. For many, it's a wonderful gift at this time of year! Inside PowerShell 7's Preview releases is a number of new, experimental, features, which you can turn on, or not. I just LOVE these!.

I've created a How-To article showing how to view, enable, and disable these features : https://community.spiceworks.com/how_to/166656-how-to-use-experimental-features-with-powershell-7

Please take a look!

Powershell Profile not loading PowerCLI

$
0
0

A few years ago I created a PS profile to load PowerCLI modules and all was peachy. Recently upgraded my laptop to Win10 and the modules no longer load. I am assuming this is due to the version of Powershell. I believe it was also loading snap-ins.

Modules were loading from a network location within my user profile and worked across any PC, laptop I logged into.

I would like to start fresh, clean out all extraneous versions and get this working again. I cannot recall the guide I used to initially set this up, but I am sure it no longer applies to the current PS versions. Currently running ESXi free 5.5 and will be upgrading the lag to the latest version

Creating Adv Auditing GP with Powershell

$
0
0

I'm trying to create a script to create a couple of GPOs with Powershell. I cannot easily add a reg key to set adv audit policies but I found where this information is stored in a policy. I am able to create the policy and then add a file with the necessary setting settings in it. When I run the script, I see my new policies but when I go to review the settings, it does not initially display the adv audit policy settings. When I edit one of the policies and navigate to the settings, I can see my settings in there. If I go in and alter any setting in there and then hit apply, then I am able to see all of the settings I have set. This may be hard to visualize so I did a small screen recording of it and converted it to a gif.


Here is a sample of the code I'm using. I've condensed by removing some of the adv audit settings and only putting...


Experimental Features in PowerShell 7

$
0
0

As many of you may know, I'm excited about PowerShell 7 and the wealth of IT Pro goodness it brings. For many, it's a wonderful gift at this time of year! Inside PowerShell 7's Preview releases is a number of new, experimental, features, which you can turn on, or not. I just LOVE these!.

I've created a How-To article showing how to view, enable, and disable these features : https://community.spiceworks.com/how_to/166656-how-to-use-experimental-features-with-powershell-7

Please take a look!

Quote Of The Day, My Way

$
0
0

I know this isn't significant or all that useful to most, but I'm trying to share what I can.

Remember the old Unix "QOTD"? My best-remembered favorite is "LOOK OUT, BEHIND YOU!"... :^)

I miss that. PowerShell gave it back, in the $Profile. I just posted a Script, essentially my $Profile with my specific needs culled to show just this, at this link:

https://community.spiceworks.com/scripts/show/4731-ps-profile-gets-quotes

I'm happy to receive comments, feedback, suggestions for improvement, whatever. If you like it, just pass it on.

Thanks,

Powershell command - ADUser not in group

$
0
0

I need a command in powershell to tell me what users I have within the "security" OU that are not in the ADGroup "Management Staff"

Please can anyone help?

Thanks

Retrieve Specific Computer Information from AD

$
0
0

I am trying to pull specific computer information for system accountability. The problem im having is that I am pulling too much information that I don't want currently, and at the same time not all the information I need.

The items I need are:

Hostname, IP address, Last Logon, Operating System and Version, MAC, Serial Number, Make and Model

Right now the extra information im pulling is the SID, SAMAccount and a few others. I'm pretty sure I could set the Hostname after its pulled from AD and add it as another column in the .csv, but alas my knowledge has not grown to that point yet.

Powershell Script - Copy content from a file begin with a keyword

$
0
0

Hi Guys,

I have a requirement of copying content from a text file and print the output where the copy should begin with matching keyword in a file. Attached here is the sample file.

I need a script in such a way that it should copy all the contents beginning after "Group: primary Servers:" and print only the ip address as output..

Following are my script, but it displays content from beginning. Please note: my input file will vary each time. its actually an output on sho dns command on proxy. I need only the primary and alternate dns servers print as otput.

Text
$ips3 = 'C:\Users\Nishad.Ummar\Documents\test2.txt' $ips33 ='C:\Users\Nishad.Ummar\Documents\test3.txt' Get-Content $ips3 | Select-String -Pattern "primary" -Context 17 | Set-Content $ips33 $IPRegex = "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" $ipadd2 = Get-Content $ips33 |...
Viewing all 15370 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>