Hi,
I need a power shell script to configure SNMP. I need to add an IP in Trap destination; it should then choose the option "Accept SNMP packets from any host and then should restart SNMP service.
Any help on above is highly appreciated! Ty
Hi,
I need a power shell script to configure SNMP. I need to add an IP in Trap destination; it should then choose the option "Accept SNMP packets from any host and then should restart SNMP service.
Any help on above is highly appreciated! Ty
Greetings,
I created a simple PowerShell script that has a file select dialog box to in turn, compress the file after it is selected. This works as expected, but when I try to run the command line ofpowershell -file test.ps1 it receives the following error code:
You cannot call a method on a null-valued expression.
At C:\test.ps1:13 char:4
+ if($OpenFileDialog.ShowDialog() -eq "OK")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Code below. Any ideas on how to fix this?:
Function Get-FileName($initialDirectory) { [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog $OpenFileDialog.initialDirectory = "C:\" $OpenFileDialog.filter = "All files (*.*)| *.*" $OpenFileDialog.ShowDialog() $OpenFileDialog.filename } if($OpenFileDialog.ShowDialog() -eq "OK") { # Get full path including file name $GetSourceFilePath = ($OpenFileDialog.filename) # Strip file extension from selected file so when file is compressed, it won't have the file extension as part of the compressed file $StripFileExtension = [System.IO.Path]::GetFileNameWithoutExtension($GetSourceFilePath) # Get file path without file name $GetFilePath = Get-ChildItem "$GetSourceFilePath" $DirectoryOnly = $GetFilePath.DirectoryName # Compress specified file and overwrite existing file if same name via the -Force option Compress-Archive -LiteralPath $GetSourceFilePath -CompressionLevel Optimal -DestinationPath $DirectoryOnly\$StripFileExtension".zip" -Force } else { Write-Host "Operation cancelled" -ForegroundColor Red }
Trying to insert formula into Excel using Powershell.
Tried the following
$worksheet.Cells.Item($row,2).Formula = '=' + $worksheet1 + "!" + 'E5'
$worksheet.Cells.Item($row,2).Formula = '=' + $worksheet1 + '!' + 'E5'
$worksheet.Cells.Item($row,2).Formula = '=' + $worksheet1 + "`!" + 'E5'
These fail and opens a dialog box to select a file.
$worksheet.Cells.Item($row,2).Formula = '="' + $worksheet1 + '"!E5'
Exception from HRESULT: 0x800A03EC
At C:\excelInsert.ps1:229 char:17
+ ... $worksheet.Cells.Item($row,2).Formula = '="' + $trimedTes ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
$worksheet.Cells.Item($row,2).Formula = '=' + $worksheet1 + '`!' + 'E5'
Exception from HRESULT: 0x800A03EC
At C:\excelInsert.ps1:229 char:17
+ ... $worksheet.Cells.Item($row,2).Formula = '=' + $worksheet1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
If I remove the ! I can get it to work. Anyone know how to insert !
Hello Everyone,
I am new to PowerShell so I was hoping for someone to point me in the right direction and not necessarily give me an answer.
I have a text file (list of names) I would like to export to CSV.
get-content file =$names
In column A I would like the string format to read "\\$fileshare\users\$name" with the script asking for a user input for the fileshare location. Each cell in column A would have the format "\\$fileshare\users\$name".
Then I would like to skip over to column D and have the string "https://nycourts-my.sharepoint.com/personal/'$name'_nycourts_gov"
Column E would need to be autofilled with the string "Documents"
If anyone can help point me in the right direction to get started that would be great.
Much appreciated!
Hello
I've worked hard at creating my first powershell GUI (form).
It seems at the moment the only way I can run the form is to open the ISE and run it. It then displays the form and all is good.
What is the best way to create this to run as you would run a regular app? Ex: double click the file and have it open the form etc.
Thank You
Terry
Hi
I am trying to establish the failover relation ship between two windows servers (w1 and w2 which are 2012 version) with power shell commands like
Add-DhcpServerv4Failover -ComputerName "dhcpserver.contoso.com" -Name "SFO-SIN-Failover" -PartnerServer 10.0.0.99 -ScopeId 10.10.10.0,10.20.20.0 -LoadBalancePercent 70 -MaxClientLeadTime 2:00:00 -AutoStateTransition $True -StateSwitchInterval
2:00:00
but this command will be executed on one of windows server from an external linux machine(external remote), where winrm being the interface between the linux and windows. This winrm will carry the command from linux and gets executed on w1 at that time it is trying to communicate to another windows server w2 to cross check failover already exists or not but it is unable to communicate w2 stack trace gives me permission denied
<S S="Error">Add-DhcpServerv4Failover : Failed to verify if a failover relationship by the_x000D__x000A_</S>It says permission denied can i know what are the permissions for the user to establish the failover relation ship, the issue is it is unable to communicate the peer server to cross check when i sent request from linux server (linux-->server1-->server2) how to add permission to user to perform communication.
Reference: Posted same issue in the below link
https://social.technet.microsoft.com/Forums/en-US/c3f0dfc3-7875-4993-889d-be91868b939b/unable-to-add-dhcp-failover-peer-relation-from-remote-server?forum=winserveripamdhcpdns
Thanks TejaShetty
Hello ,
someone can please guide me how to add - and -notcontains to this?
Get-DistributionGroup -ResultSize Unlimited -erroraction 'silentlycontinue' | where { (Get-DistributionGroupMember $_.Name -erroraction 'silentlycontinue'| foreach {$_.PrimarySmtpAddress}) -contains "$Gmember" -and -notcontains "$GmemberNot"
}
basically i want to find DL's with a group member and without specific group member
thank you
Hi
I am trying to establish the failover relation ship between two windows servers (w1 and w2 which are 2012 version) with power shell commands like
Add-DhcpServerv4Failover -ComputerName "dhcpserver.contoso.com" -Name "SFO-SIN-Failover" -PartnerServer 10.0.0.99 -ScopeId 10.10.10.0,10.20.20.0 -LoadBalancePercent 70 -MaxClientLeadTime 2:00:00 -AutoStateTransition $True -StateSwitchInterval
2:00:00
but this command will be executed on one of windows server from an external linux machine(external remote), where winrm being the interface between the linux and windows. This winrm will carry the command from linux and gets executed on w1 at that time it is trying to communicate to another windows server w2 to cross check failover already exists or not but it is unable to communicate w2 stack trace gives me permission denied
<S S="Error">Add-DhcpServerv4Failover : Failed to verify if a failover relationship by the_x000D__x000A_</S>It says permission denied can i know what are the permissions for the user to establish the failover relation ship, the issue is it is unable to communicate the peer server to cross check when i sent request from linux server (linux-->server1-->server2) how to add permission to user to perform communication.
Reference: Posted same issue in the below link
https://social.technet.microsoft.com/Forums/en-US/c3f0dfc3-7875-4993-889d-be91868b939b/unable-to-add-dhcp-failover-peer-relation-from-remote-server?forum=winserveripamdhcpdns
Thanks TejaShetty
Get-LocalGroupMember administrators | Where-Object {$_.PrincipalSource -eq 'MicrosoftAccount'} | Get-LocalUser
This code fails because I don't know how to trim the computer name from the local user account name. Can someone show me?
It's trying to send "computername\username".....Get-LocalUser wants the username.
adam
We use Crowdstrike for malware protection and one function we use at times is Containment which quarantines a machine from network resources. I have the following working for me to get the two event IDs related to Containment but what I would like
to do is get the status of the machine by knowing which of the two IDs was the last entry. Contained = 5, Online = 6. Based on the ouput below the machine is Online. Ideally what I would want is something like "if last entry = 6 then machine is
online" or "if last entry = 5 then machine is offline". Any ideas on how to accomplish this?
$CSCstatus = Get-WinEvent -LogName 'CrowdStrike-Falcon Sensor-CSFalconService/Operational' | Where-Object {$_.Id -like "5" -or $_.Id -like "6"} $CSCstatus
ProviderName: CrowdStrike-Falcon Sensor-CSFalconService TimeCreated Id LevelDisplayName Message ----------- -- ---------------- ------- 2/6/2019 9:52:23 AM 6 Information Your computer is back online. 2/5/2019 10:44:05 PM 5 Warning Your computer is offline to keep it safe. Please contact IT for more information. 2/5/2019 4:29:19 PM 6 Information Your computer is back online. 2/5/2019 4:24:09 PM 5 Warning Your computer is offline to keep it safe. Please contact IT for more information.
Need a powershell script that will pull users from text and pull the users samaccountname and homedirectory
what i have keeps erroring -
users = ForEach ($user in $(Get-Content C:\utilities\users.txt)) {
Get-AdUser $user -Filter * -SearchBase "OU=dudes,OU=alpha,DC=domain,MI=OK,DC=local" -Properties sAMAccountName,HomeDirectory
}
$users |
Select-Object SamAccountName,Department,Mail |
Export-CSV -Path C:\utilities\output55.csv -NoTypeInformation
thanks
Is there a way to setup powershell script that gets executed whenever cpu or memory utilization exceeds certain percentage?
I want to capture certain counters when an event occurs (when cpu or memory utilization exceeds certain percentage).
I do not want to run it at reguar intervals as a scheduled task.
Any pointers would be helpful.
Hi folks.
I'm trying to make a script for query all the users from specific OU in my domain and get the Username
, First and Last name, and last login date in an Excel format from each user , and export the result to a csv file .
Could anyone help?
Thanks in Advance,
Kousic
Hi there,
I#m currently building a powershell transfer script that uses the WinSCP .NET assembly in order to upload files. I have defined a class in which I'm initializing things like the WinSCP.SessionOptions etc. These types are defined in the WinSCPnet.dll. At the beginning of my script I'm importing the assembly with
Add-Type -Path <Path-to-assembly.dll>
Later in my class definition I have a variable like this that is not yet initialized
[WinSCP.SessionOptions]$Script:SessionOption
When I try to run the script I always get "Type not found" error referencing to the line where I'm declaring the uninitialized variable. Thiis problem is not limited to the WinSCP assemblies. I'm also getting it when I call a static method no matter if it's a system or a custom assembly. It's also not possible to debug the problem because no breakpoint is reached.
What can I do to solve that?
Thanks in advance
Update-Trobleshoooter
Hello Everyone,
i'm exporting a CSV file from a an SQL view i have that looks like that :
emp_bin,emp_mail,DIRECT_MANAGER_GIN,emp_mobile,emp_phone
B10035000,jim.Danijela@test.com,,,
B0170051,,,+33 (0) 1 7 712 12 12,
B0179113,,,+33 (0) 1 11111111,
B0030096,john.smith@test.com,,+33 (0) 1 12121212,
as you can see some fields are empty,
and when i run my script:
$CSVData = Import-Csv -Path C:\Scripts\file_export_from_db.csv $Users = Get-ADUser -Filter * -Properties SamAccountName -SearchBase "OU=Users,OU=Office,OU=test,DC=test,DC=COM" Foreach ($Line in $CSVData) { $emp_gin = $Line.emp_gin $Username = ($Users | Where {$_.SamAccountName -eq $emp_gin}).SamAccountName $Params = @{ Identity = $Username EmailAddress = $Line.emp_mail mobile = $Line.emp_mobile OfficePhone = $Line.emp_phone } If ($Username) {Set-ADUser @Params; Write-Host "Set new attributes info for $Username"} }
i getting the errors below
Set-ADUser : replace
At line:16 char:31
+ If ($Username) {Set-ADUser <<<< @Params; Write-Host "Set new attributes info for $Username"}
+ CategoryInfo : InvalidOperation: (t0097986:ADUser) [Set-ADUser], ADInvalidOperationException
+ FullyQualifiedErrorId : replace,Microsoft.ActiveDirectory.Management.Commands.SetADUser
can anyone help me understand how to fix this ?
Thanks
Hitch Bardawil
Hey Everyone,
i'm trying to set a constant Value for a contact when an equivalent user is found in AD
i have this code :
$users = Get-ADObject -filter 'objectClass -eq "User"' -Properties samAccountName -SearchBase "OU=Users,OU=Office,OU=test,DC=test,DC=COM"| select samAccountName $contacts = Get-ADObject -filter 'objectClass -eq "Contact"' -Properties SamAccountName,mailNickname,extensionAttribute10 -SearchBase "OU=Contacts,OU=Office,OU=test,DC=test,DC=COM" Foreach ($Line in $users) { $samAccountName = $Line.samAccountName $Username = ($contacts | Where {$_.mailNickname-eq $SamAccountName}).mailNickname $Params = @{ extensionAttribute10 = "DIS" } If ($Username) {Set-ADObject $Username -add Set-ADUser @Params;} }
for some reason i am not able to set a value for a contact, i was able to do it for users but cannot seem to find any info the web about setting it for a contact.
it's telling me that i cannot find it as i am trying to identify the contact by its mailnickname since it does not have a samaccount name
any ideas on how to proceed ?
Cheers
Hitch Bardawil
PowerShell 5.1.17763.134
Windows 10 Professional, 10.0.17763.0
I am running into an odd issue with one of my machines since updating windows recently. Hard tabs appear to use the window width rather than the familiar 8 spaces. This is the only machine that exhibits this behavior out of the three machines I use PowerShell. All three machines share the same PowerShell profile. All three machines are using the default console settings. Running with a profile does not affect observed behavior.
Running PowerShell within command prompt: <tt>cmd /c powershell -NoProfile</tt>
|PS C:\> "aaa`tbbb`tccc" | |aaa bbb ccc | | | |PS C:\> cat tab.txt | |aaa bbb ccc | | | |PS C:\> |
Running PowerShell directly from a shortcut, pinned taskbar shortcut, or from the executable directly, e.g.: <tt>powershell -NoProfile</tt>:
|PS C:\> "aaa`tbbb`tccc" | |aaa b| |bb c| |cc | | | |PS C:\> cat tab.txt | |aaa b| |bb c| |cc |
Resizing the window affects indentation, such that a hard tab will always clear the entire window width.
...
Perhaps there is a console or registry setting that I am missing? Here are the default terminal settings that all terminals should be using:
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Console] "CtrlKeyShortcutsDisabled"=dword:00000000"CurrentPage"=dword:00000000"CursorColor"=dword:ffffffff"CursorSize"=dword:00000019"EnableColorSelection"=dword:00000000"ExtendedEditKey"=dword:00000001"ExtendedEditKeyCustom"=dword:00000000"FilterOnPaste"=dword:00000000"ForceV2"=dword:00000001"FullScreen"=dword:00000000"HistoryBufferSize"=dword:00000064"HistoryNoDup"=dword:00000001"InsertMode"=dword:00000001"LineSelection"=dword:00000001"LineWrap"=dword:00000001"LoadConIme"=dword:00000001"NumberOfHistoryBuffers"=dword:00000008"PopupColors"=dword:000000f5"QuickEdit"=dword:00000000"ScreenBufferSize"=dword:0bb80078"ScreenColors"=dword:00000007"ScrollScale"=dword:00000001"TrimLeadingZeros"=dword:00000000"VirtualTerminalLevel"=dword:00000001"WindowAlpha"=dword:000000ff"WindowSize"=dword:00280078"WordDelimiters"=dword:00000000
Hello,
i am trying to build script that read the data from CSV file, the only data exist on this file is the EmployeeID.
so i need to read the EmployeeID and for each employeeID exist in this sheet in need to disable that user and change the Description to "Disabled based on the HR Request"
below script is not working for me any help plz
$path = "D:\Private\sample-data.csv" $LIST=IMPORT-CSV $path $UseremployeeID = $USER.employeeID FOREACH ($Person in $LIST) { $UserID = Get-ADUser -Filter {employeeID -eq ($LIST.Row[1])} foreach ($USER in $UserID){ Set-ADUser -Identity $User -Description "Disabled based on the HR Request" -Enabled $false } }