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

Installing software by choco using script

$
0
0

Hi i am installing software using choco package manager using these commands 
1- choco install visualstudio2019community and
2- choco install adobereader

i need to add scipt that waits while 1 task complete successfully, than run another task 
how can i manage   


Delete Outlook meeting room calendar subject for everyone except administrators

$
0
0

I am currently using the following command to hide calendar item subject for all meetings in MeetingRoom1. However, I would like to set this to false for 2 administrators so they can still see meeting title.  Could you help me complete this and add exceptions to set false for 2 admins?

Powershell
Set-CalendarProcessing-IdentityMeetingRoom1-DeleteSubject$true

Powershell - Fill variables with a previous command

$
0
0

Hi!

Having an bit of an issue with my Powershell script. I'm currently running this below -

Get-ADComputer -Filter * -Properties * | FT Name,OperatingSystem, LastLogonDate -AutoSize

Which lists Computers and operating systems in my Active Directory.

I want to fill this variable $Computers with the Computer names discovered in my command above.

Anyone got any idea how I do this ?

Thanks!!!

Uninstall from startup script

$
0
0

The below script works without any issue, but when I run it from my startup script it didn't work.

What's wrong?

Powershell
#Check if the server is in the List to uninstall the local Java application.if((Get-content\\NAS\Servers\java\QA_serverlist.txt)-match$env:computername){$App="Java 8"$javaVer=Get-ChildItem-PathHKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall,HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall|Get-ItemProperty|Where-Object{$_.DisplayName-match$App}|Select-Object-PropertyDisplayName,UninstallStringForEach($verin$javaver){If($ver.UninstallString){$uninst=$ver.UninstallStringStart-Processcmd-ArgumentList"/c $uninst /quiet /norestart"-NoNewWindowWrite-Output$([string](get-date)+"`t $ver.DisplayName Removed from $env:computername ")|out-file...

Combining multiple sets into one file

$
0
0

Hey all,

I have a somewhat complicated, at least to me, requirement. A vendor wants me to extract some data from SQL Server into a delimited file. This was wold normally not be an issue, however this is complicated by the fact that they want me to extract two different data sets in a parent child relationship, with the parent records having one number of columns and the child having a different.

Again this would not be too big of an issue however the vendor insisted that each parent record has exactly the defined number of columns and child records have its own set of defined number of columns.

The only tools that are available to me to accomplish this is SSIS, Integration Builder and Power Shell, though my knowledge of Integration Builder is very very low.

From what i know this is not really possible in SSIS, with the exception of putting...

PowerShell - Mapped Drive is created & accessible but not displayed

$
0
0

I've been working on a script to create new users in Active Directory and I've got everything working except this last piece...mapping a Home Folder to a drive to a network drive. I've attached just the piece of the script that creates this.

I've got the piece to create the folder and set the FullControl and Ownership permissions and to set the appropriate drive letter and path in the User Account. This all works correctly.
The issue is that the actual mapping of the drive when the user logs in is missing. They can manually go to the folder via FQDN, but the mapped drive doesn't show in "My Computer" with the rest as it should, nor can I use U:\ in File Explorer to get to the folder. (see image uploaded)
If I go to the User account in ADUC and change the drive letter off of U and then back again, ADUC will prompt if I want to grant Full...

Key not valid for use in specified state error

$
0
0

HI,

I have created a text file and saved my plain string there, then run below command to encrypt it:

'passkey' | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Set-Content -Path C:\PreShareKeyEncypted.txt

-

Next steps, I ran below commands to read from the encrypted text file and passed it to the next line:

$PreSharedKeyEncrypted = Get-Content -Path c:\system\PreShareKeyEnc.txt | ConvertTo-SecureString

Add-VpnConnection -Name "VPN" -ServerAddress "vpn.xxxx.com" -TunnelType "L2TP" -L2tpPsk "$PreSharedKeyEncrypted" -EncryptionLevel "Required" -AuthenticationMethod MSChapv2 -UseWinlogonCredential -SplitTunneling -RememberCredential -Force

When I run this script on my system it works as expected, however when I run it on another machine, it errors our with these errors:

1- "key not valid for use in specified state", and...

Why is my powershell code only detecting 1 selected item in multi select list

$
0
0

Hi All,

I have a list box with approximately 10 items of choice in a multi-select list box.

What I want to do is have a user select lets say 4 choices. With those 4 choices (any out of the 10) I want to then perform certain tasks

- Add this variable to another

- Add second variable to another

the code i have is below

Powershell
$AppsLstBox=New-Objectsystem.Windows.Forms.ListBox$AppsLstBox.text="listBox"$AppsLstBox.width=155$AppsLstBox.height=289$AppsLstBox.location=New-ObjectSystem.Drawing.Point(14,174)$AppsLstBox.SelectionMode='MultiExtended'[void]$AppsLstBox.Items.Add('A')[void]$AppsLstBox.Items.Add('B')[void]$AppsLstBox.Items.Add('C')[void]if($AppsLstBox.selecteditem-eq"A"){$Securitygroups+="$Variable1`n"}if($AppsLstBox.selecteditem-eq"B"){$Securitygroups+="$Variable2"}

but it will only look at...


Edit sharepoint online ps to display individual users in sharepoint group

$
0
0

How do i edit sharepoint online powershell script to display individual users in sharepoint group. Or if possible add a delimited filter so that i can sort in excel.

Currently the usernames are lump in one box and i have a hard time sorting out the users 1 by 1.

Below is the script i am using:

Get-SPOSiteGroup-Sitehttps://abc.sharepoint.com/sites|selectTitle, @{Name='Users';Expression={foreach ($userin$_.Users) {[string]::join(";",(Get-SPOUser-Site https://abc.sharepoint.com/sites/-LoginName$user).DisplayName -join ";")}}} |export-csvC:\temp\users.csv-NoTypeInformation


.exe file installation for remote machines through powershell

$
0
0

Hi Everyone,

Can anyone, please guide me to install .exe file installation for remote machines through powershell.

Query User Remote Desktop Server - Send email to all users

$
0
0

I'm trying to create a script that will send an email all logged on users to a specific Remote Desktop server.

I've discovered this topic that discusses a script to list all logged on users. However.. it is designed to detected just the 1 logged on user. https://community.spiceworks.com/topic/1889622-query-user-to-csv

Powershell
functionGet-users{$s=QueryUser/SERVER:COMPUTERNAME$numberofusers=$s.Length-1$ht=@()For($i=2;$i-le$numberofusers;$i++){$str=$s[$i]$S=@{UserName=$str.split(' ')[0].substring(1)logontime=$str.split(' ')[-1]logondate=$str.split(' ')[-2]}$ht+=$s}Return$ht}Get-Users

How do I modify the script above, to list multiple logged on users without generating the error...

Text
Exception calling "Substring" with "1" argument(s): "startIndex cannot be larger than length of...

List of urls in notepad to be open and save the content using powershell

$
0
0

Folks,

I am doing a health check script in proxy device, things are working perfect in CLI and at the end of the script have requirement of loading multiple proxy urls which are saved in notepad, script need to do : open all the URLs in IE multiple tabs and when it prompt, pick the credentials automatically (use the same credentials which supplied as read-host for cli login , example : $User = username and $pass = password already supplied) and save the entire content from the web page to another text file.
I have attempted to write a small portion of the script as below,
Text
 $urls = Get-Content "C:\url.txt" foreach($url in $urls){ Start-Process $url } } 

which just open up urls in default browser (my case browser is edge), Need you guys help on 1) open the URLs in IE 2) save the file 3)supply credential , all would happen using...

Create a PowerShell script that would get the last 30 days history logon of Dom

$
0
0

Dear All,

I would like to write a Power Shell script that would do the following:
- If the user is member of (Domain admins) get me the last 30 days history logon of this user in any Domain joined computer.

I created something now but it still lacks a lot as it reads the security events on the Domain controller and brings the users,time and matches them with the Domain admin group as in the attached screenshot

I would appreciate if someone can help me evolve this script into something useful

Powershell
$Rusers=Get-WinEvent-Computerdc02-FilterHashtable@{Logname='Security';ID=4672}-MaxEvents50|`select@{N='User';E={$_.Properties[1].Value}},TimeCreated$DAUsers=Get-ADGroupMember-Identity"Domain Admins"Foreach($DAUserin$DAUsers){$DomainUser=$DAUser.SamAccountNameforeach($Ruserin$Rusers){$RAUser=$Ruser.UserIf(...

PowerShell for each Loop problem

$
0
0

Hi all, I have a PowerShell script I've cobbled together for removing Adobe products and installing Adobe DC from a network share.

I'm trying to adjust it such that I can run it against multiple pc's simultaneously. Here's what I have so far.

Powershell
#Suggest running script from ISE in rdweb.Set-ExecutionPolicyUnrestricted-Force## Remove Adobe if present## $appToMatch = '*app name*' replace with desired namesGet-Process*outlook*,*AcroRd*,*Excel*,*Winword*|kill-Force-easilentlycontinue$appToMatch='*Adobe*'$e=$MyInvocation.InvocationName$pshome$log=$env:temp+'\PSuninstall.log'functionGet-InstalledApps{Log-write$log'Start Get-InstalledApps'if([IntPtr]::Size-eq4){$regpath='HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'Log-write$log'Found x86'}else{$regpath=@('HKLM:\Software\Microsoft...

powershell to send alert

$
0
0

Hello all,

I have 2 csv files, lets say X and Y

first csv file(X) with product name, second csv file(Y) with header product name, site, process state.

second csv(Y) is being created by a script, i want to add more to the script. after the script created the CSV file(Y) I want script to compare both csv files(X and Y) and if any product from first csv(X) is present in second csv(Y) and process state is failed send email alert.

Is that possible?


Connecting to office exchange through PowerShell on Mac

$
0
0

Hello. I've been trying to connect to exchange through PowerShell that i've installed on my mac. I've followed the instructions from many github forums and haven't had any luck.

Here's what I do.

Text
$UserCredential = Get-Credential$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid -Credential $UserCredential -Authentication Basic -AllowRedirection; 

Here's the error:

Text
New-PSSession : This parameter set requires WSMan, and no supported WSMan client library was found. WSMan is either not installed or unavailable for this system. At line:1 char:1 + New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri ht ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo     : ResourceUnavailable: (:) [New-PSSession],...

Powershell Automation (On-Boarding)

$
0
0

I have finally finished my employee turn over script and decided to keep on with the fun and start an on-boarding script. I have come to a block in trying to figure out how to go about this I will post below the two version i have of the script. What i want to achieve is creating a user, assigning them a license, adding the to certain distribution list. Where i'm stuck at is trying to figure out how to create a user and assign a license. Where i'm getting lost at is trying to figure out how i can both create a entire user with one variable and how to reference it later in the script by just the user name

Powershell
$NewUser=Import-ModuleActiveDirectoryconnect-msolserviceNew-msoluser-LicenseAssignmentCincinnatiSymphony:STANDARDWOFFPACK-UsageLocationUS-Displayname-Firstname-Lastname-userPrincipalNameImport-Module...

Disabling null / empty entry in Input Box

$
0
0

Hey All,

I'm trying to build a simple script that removes entries from a DB for decommissioned asset. While the script itself works OK, I need to stop user from being able to pass 'empty' or 'null' parameter in the pop up box (effectively hitting OK without typing anything at all). Here is what I have so far:

Powershell
Add-Type-AssemblyNameMicrosoft.VisualBasic$computers=[Microsoft.VisualBasic.Interaction]::InputBox('Enter asset name','Asset Name')$SQLServer="SQLSERVERNAME"$SQLDBName="DBNAME"$SqlQuery="SELECT * FROM hosts WHERE UPPER(HOSTNAME) LIKE UPPER ('$computers%');"$SqlConnection=New-ObjectSystem.Data.SqlClient.SqlConnection$SqlConnection.ConnectionString="Server = $SQLServer; Database = $SQLDBName;Integrated Security = True;"$SqlCmd=New-ObjectSystem.Data.SqlClient.SqlCommand$SqlCmd.CommandText=...

PowerShell ignore Arguments list for kasperky Un-installation

$
0
0

Hello !

i'm trying to do Kasperky Endpoint 10 uninstallation in silent mode with Powershel, but powershel is dont taking in account argument list.

#### Uninstallation of Kaspersky Sliently 

Start-Process -FilePath "KES\setup.exe" -Verb runas -ArgumentList '/pKLPASSWD=mypassword','/S','/X','/v"/qn"'

Start-sleep -s 15

Some one can tell me please what is the good syntax.

Thanks you,

Log off certain disconnected sessions - only certain users

$
0
0

I'm trying to make a script where i can log off disconnected sessions, but exclude certain users.

I'm having trouble figuring it out, it keeps disconnecting all users. Can anyone take a look at it ?

Powershell
functionGet-Sessions{$queryResults=querysession$starters=New-Objectpsobject-Property@{"SessionName"=0;"UserName"=0;"ID"=0;"State"=0;"Type"=0;"Device"=0;}$UsersToExclude=@("test1', 'test2')  foreach ($result in $queryResults) { If ($starters.username -NotIn $UsersToExclude') { try { if($result.trim().substring(0, $result.trim().indexof("")) -eq "SESSIONNAME") { $starters.UserName = $result.indexof("USERNAME"); $starters.ID = $result.indexof("ID"); $starters.State = $result.indexof("STATE"); $starters.Type = $result.indexof("TYPE"); $starters.Device = $result.indexof("DEVICE"); continue;...
Viewing all 15370 articles
Browse latest View live


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