I am having a CSV file that has full name of users (First Name + last name), i want to extract only the first name using Powershell, is there any way how can i do it?
How Can I get First Name from Full Name in CSV file
Dynamic Parameter Doesn't Show After Using Validated Set Parameter
Hi all,
I've been playing about with my new New-CompanyADUser cmdlet in our Company-AD module, and I'm experiencing a weird problem with my dynamic parameter: it won't appear at all after I've chosen an option within a validated set parameter that has more than one word.
For example, if I write:
New-CompanyUser-UKUser-FirstNameTest-LastNameUser-Title"Office Admin"-ManagerSpiceWorks-FloorAnnex
I can then continue using the 'Groups' parameter, which automatically pulls the information from AD, like:
New-CompanyUser-UKUser-FirstNameTest-LastNameUser-Title"Office Admin"-ManagerSpiceWorks-FloorAnnex-GroupsAccounts,'Office Admins','26B Street Name'
But if I select another option for 'Floor' that has more than one word, I can't call it, like:
New-CompanyUser-UKUser-FirstNameTest...
Powershell syntax for -Filter
So I want $userDLs to contain all the distribution groups that the $userDN belongs to. If i run:
$userDLs=Get-DistributionGroup-Filter{members-eq"CN=My Distinguished,OU=Object,DC=Name,DC=com"}
Then $UserDLs contains exactly what I want it to. But if I run:
$userDN=get-user$User.SrcName|select-ExpandPropertyDistinguishedName$userDLs=Get-DistributionGroup-Filter{members-eq$userDN}
then $userDN is a system.string that contains
CN=MyDistinguished,OU=Object,DC=Name,DC=com
But $UserDLs contains a list of groups from, I don't know where, as if it had somehow matched part of the string or something - i don't know. But it's not the groups I'm expecting.
I also tried putting inverted commas around the variable ie
$userDN=get-user$User.SrcName|select-ExpandProperty...
powershell script to install java
Hello all,
I am deploying java with sccm and i have powershell script to do some extra work. when I deploy the application with powershell script it does all the things except install. it launches the java file but exits with out doing anything.
Start-Process -Wait "jre-8u45.exe" -ArgumentList '/s WEB_Java=0 AUTO_UPDATE=0 WEB_JAVA_SECURITY_LEVEL=H /L c:\temp\jre-8u45-windows-x64.log' -PassThru
Any ideas?
regards
ps script for get Full/send as access/Send on behalf
looking for a script to get Full, Send As and Send on behalf access of the users who has access to a shared mailbox
$emailaddress="XXX@xxx.com","xxx@xxx.com"$MailboxPermissions=@()foreach($emailin$emailaddress){$mailbox=get-mailbox-identity$email$FullAccess=$mailbox|Get-MailboxPermission|where{($_.AccessRights-eq"FullAccess")-and-not($_.User-like"NT AUTHORITY\SELF")}$SendAs=$mailbox|Get-ADPermission|?{($_.ExtendedRights-like"*send*")-or($_.ExtendedRights-like"*full*")-and-not($_.User-like"*\self*")}$MailboxInfo=New-ObjectSystem.Object$MailboxInfo|Add-Member-typeNoteProperty-nameDisplayName-value$mailbox.displayname$MailboxInfo|Add-Member-typeNoteProperty-nameFullAccess-value$FullAccess.User$MailboxInfo|Add-Member-typeNoteProperty-name...
Rename files if already exist while downloading using IWR to single folder
Hi All,
Quick background,
i have a script that i have pieced together that downloads all files and folders and structure that meet the filtering criteria (in this case all files who have column data that contains the "Colour" "Red") within a SharePoint site collection to a local drive. This works fine now. I have created it to log any files and their URL's that can't be downloaded which are over length.
My next task is to redownload these files from the logging list to a Top Level folder. The simplest method i feel is to use Invoke-WebRequest with default creds. I can almost get this to work how i would like, except that as i am downloading to a single folder, there maybe files in the various URL's that have the same name, so currently it is just overwriting any existing files.
I have tried to rename them but this did not work, so instead...
Replacing Reserved Characters in Text Strings
I am working on Adding and replacing text inside of some xml files and am getting hung up on the "<" character (the less than character).
I am just using a simple replace. My line of code is as follows:
(Get-Content $directoryPath) | Select-String -Pattern "" -AllMatches | Replace "", "" | Replace "" "", ""
When I test the script I am seeing the following error: The '<' operator is reserved for future use.
Any suggestions on how to deal with these reserved characters?
Export data from Active Directory by a specific OU and group using PowerShell
Hi all,
I would like to export specific information from AD using PowerShell that is from a specific OU and group that contains only certain information for export such as, Name, Description, whether or not the "user cannot change password" setting is checked, whether or not it's set to NeverExpires, date created and last logon information. I'm not sure quite how to construct the script since I'm fairly new to PS, so any suggestions on how to do this would be appreciated.
I've tried something like Get-ADUser -filter * -SearchBase "OU=xxx,OU=xxx,DC=xxx,DC=xxx" | select -exp GivenName,SN,Description,CannotChangePassword,PasswordNeverExpires,accountExpires,lastLogon
It doesn't really do anything
thank you!
Resolving a LOT of DNS
I have almost 16000 URL entries on a blacklist in my firewall (half dozen analysts with varying degrees of experience). I want to turn them into IP address so I can filter out the country codes I already block, of which I have a splunk setup for already. I'm trying to use Resolve-DNS to accomplish this. but the output I want is two columns (Name, IPAddress) and no line breaks in between, if something fails to resolve, forget it and move on: this is what I have, I know I'm missing something stupid:
$dnslist=Import-CSVC:\users\me\naughtylist.txtforeach($villainin$dnslist){Resolve-DNS-typeA-Name$villain.url-ErrorActionSilentlyContinue|SelectName,IPAddress|Format-list|Out-Filec:\users\me\BlockIP.csv-Append}
Neally, what am I doing wrong, sensei?
RPC server unavailable when using quering using wmi
I have a server that all of a sudden will not accept a wmi query for diskspace. This server has been in production for years. Nothing has changed on it. Everything was working fine until yesterday when all of sudden wmi queries stopped working. The server is online and reachable by all clients.
Attempting to Automate Remote Desktop Services Activation - Svr 2016
Hi People,
I have been looking through the net for days and I'm totally stuck. I roll out servers with the same config often for different clients and I am attempting to automate as much as I can as it is all currently done manually.
I am trying to get a powershell script that will go into Remote Desktop services manager and activate the server with an automatic connection with the following details:
First name - John
Lastname - Doe
Company - powershell pty ltd
Country - Australia
E-mail - a@B.com
Licence program - Select licence
Agreement Number - 0000000
Svr Type/License Type - RDS per user cal
Number of Licenses - 5
After which I need to edit the GPO under Computer Policy Computer Configuration Administration Templates Windows Components Remote Desktop Services Remote Session Host Licensing
Use the specified Remote Desktop License Servers...
Get folder and all file size
Hi all,
I saw this post and got almost all i wanted.
https://community.spiceworks.com/topic/1971559-getting-folder-subfolder-file-list-and-sizes
it was Gungir(Script below from him), so i tried but it does not list the filename and file size in the main folder. Example : C:\Folder , inside this folder has abc.xls and aaa.doc
So the result does not publish to me but all subfolder's content is published. So can anyone tell me how to edit to get main folder(C:\Folder) files to be shown?
$RootFolder='C:\Folder'functionGet-FormattedSize{param([parameter(Mandatory=$true)][int64]$Size)switch($Size){{$Size-gt1GB}{'{0:N2} GB'-f($Size/1GB);break}{$Size-gt1MB}{'{0:N2} MB'-f($Size/1MB);break}{$Size-gt1KB}{'{0:N2} KB'-f($Size/1KB);break}default{"$Size B";break}}}$Results=...
How to copy a powershell locally and then run it upon login
I've recently a powershell script that creates an email signature and sets it as the default, which works perfect. We'd like to implement it company-wide by storing it in our sysvol folder which everyone can access and having group policy take that file, copy it to a users local machine and then run it upon login everytime. We have some users who work off-site on laptops and don't always connect to the VPN so i'd like that file to still be saved locally from the last time they logged in on-site and still be able to use it without having to connect to the VPN.
Would the simplest way to achieve this be to have two Group Policies, one that overwrites that file locally upon login everytime and a second that runs that file upon login? I created the Powershell but do not have much experience in Group Policy.
Thanks
filter multiple properties ?
Gents
I like to filter an application to query its uninstall string using Powershell
Get-ItemProperty HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select DisplayName,UninstallString
I get the whole list but like to filter it to ONE particular app "PrintForm 2018 CS".
How can I filter the property DisplayName without loosing the property UninstallString ?
I came only so far that I can filter the DisplayName:
((Get-ItemProperty HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*).DisplayName -eq 'PrintForm 2018 CS')
Powershell run: "WMIC product where name="appname" call uninstall"
Is there a way I can achive with POWERSHELL what I do with the command batch? Obviously I can only uninstall the product using this command (but I use a powershell script to query other things before)
WMIC product where name="PrintForm 2018 CS" call uninstall
Add-VPNConnection PowerShell Script - register IP in DNS
I have created an Add-VPNConnection script that creates an SSTP VPN connection phonebook entry for All Users. I have a way to push it out to the computers in my organization, and all is almost perfect. I have one final detail that I cannot seem to resolve through scripting. I want to set this connection to automatically register in DNS.
This is equivalent to editing the advanced TCP/IP settings in the GUI and checking the box on the DNS tab to "Register this connection's addresses in DNS."
I can't believe that MS omitted this important option from Add-VPNConnection or Set-VPNConnection, and I haven't come across another way to set this.
Any suggestions?
Dataset not returning any rows from Sql Query - Powershell
Hi,
I am trying to connect to SQL server via Power shell which I have successfully but when i am trying to return a count of the number of rows in the data-set it returns as 0. Why has the Data-set not populated?
$SQLServer = "kisp-sql-dw" #use Server\Instance for named SQL instances! $SQLDBName = "kings_datawarehouse" $SqlQuery = "SELECT TOP (1000) [CallNumber],[CallActionNumber] FROM [Kings_DataWarehouse].[dbo].[CurrentCallActions]" $SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True" $SqlCmd = New-Object System.Data.SqlClient.SqlCommand $SqlCmd.CommandText = $SqlQuery $SqlCmd.Connection = $SqlConnection $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $SqlAdapter.SelectCommand = $SqlCmd $DataSet =...
Pull All Users in AD Groups Who Have been Inactive for 30 Days
I am trying to pull some information about those who have been inactive for the last 30 days in AD Groups. Here is what I have so far:
$Groups="Group1"$DaysInactive=30$time=(Get-Date).AddDays(-($DaysInactive))Get-ADGroupMember-Identity"$Groups"-Recursive|Whereobjectclass-eq'user'|Get-ADUser-Filter{LastLogonTimeStamp-lt$time-andenabled-eq$true}-PropertiesDisplayname,Enabled|SelectDistinguishedName,samAccountName,Name,Displayname,Enabled|Export-CsvC:\Group1.csv
I get an error saying that the Get-ADUser : The input object cannot be bound to any parameters for the command either because the command does not take pipeline unput or the input and its properties do not match any of the parameters that take pipline input.
I am not sure what I am doing wrong. I get a list of some users in the CSV...
Using powershell to create an outlook signature, write it to a file
So i just created a powershell script that creates a signature based on AD information and writes it to a word doc then runs it and sets the signature as the default. Now i am trying to create another script that does the same thing but instead of running it and setting the default signature it saves the signature it created to a file. I then want to use group policy to run that file on login (for laptop users who are off site and not connected to VPN)
Currently when you login onsite the script is saved from our FS server to your local machine via GPO, then the script is ran locally (via GPO)
For laptop users this wont work because the script cant get the AD info which is why i want a separate GPO for them that calls for that created file.
How do i make this write to a signature file instead of a html file / word doc? Ive attached the...
Build ACL Array then step through and change
I'm trying to scan through a directory and change folder acls. The idea is to get acls from each folder via an imported CSV file, and then change anything other than a specified ACL to Read only. I'm having trouble finishing up with this as I'm still a powershell newb. I'm stuck at line $acl.SetAccessRule($permissionRule) which gives the error "Exception calling "SetAccessRule" with "1" argument(s): "Some or all identity references could not be translated."
The get line is commented out on purpose for testing.